[gnome-commander] GnomeCmdFileList: simplify code for select() and unselect() using patterns



commit 687fe85a05822c133bde5cd13c7cb2521c8b4a7b
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Sat May 7 09:40:07 2011 +0200

    GnomeCmdFileList: simplify code for select() and unselect() using patterns

 src/gnome-cmd-file-list.cc         |   37 +++++++++--------------------------
 src/gnome-cmd-file-list.h          |   14 +++++++-----
 src/gnome-cmd-patternsel-dialog.cc |    6 +++-
 3 files changed, 22 insertions(+), 35 deletions(-)
---
diff --git a/src/gnome-cmd-file-list.cc b/src/gnome-cmd-file-list.cc
index ae5003f..74383fd 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -582,24 +582,19 @@ static void toggle_files_with_same_extension (GnomeCmdFileList *fl, gboolean sel
 }
 
 
-inline void toggle_with_pattern (GnomeCmdFileList *fl, const gchar *pattern, gboolean case_sens, gboolean mode)
+void GnomeCmdFileList::toggle_with_pattern(Filter &pattern, gboolean mode)
 {
-    g_return_if_fail (GNOME_CMD_IS_FILE_LIST (fl));
-
-    Filter filter(pattern, case_sens, gnome_cmd_data.filter_type);
-
-    for (GList *tmp=fl->get_visible_files(); tmp; tmp=tmp->next)
+    for (GList *i=get_visible_files(); i; i=i->next)
     {
-        GnomeCmdFile *f = (GnomeCmdFile *) tmp->data;
+        GnomeCmdFile *f = (GnomeCmdFile *) i->data;
 
-        if (f && f->info)
-            if (filter.match(f->info->name))
-            {
-                if (mode)
-                    fl->select_file(f);
-                else
-                    fl->unselect_file(f);
-            }
+        if (f && f->info && pattern.match(f->info->name))
+        {
+            if (mode)
+                select_file(f);
+            else
+                unselect_file(f);
+        }
     }
 }
 
@@ -1977,18 +1972,6 @@ void GnomeCmdFileList::select_row(gint row)
 }
 
 
-void GnomeCmdFileList::select_pattern(const gchar *pattern, gboolean case_sens)
-{
-    toggle_with_pattern (this, pattern, case_sens, TRUE);
-}
-
-
-void GnomeCmdFileList::unselect_pattern(const gchar *pattern, gboolean case_sens)
-{
-    toggle_with_pattern (this, pattern, case_sens, FALSE);
-}
-
-
 void GnomeCmdFileList::invert_selection()
 {
     GnomeCmd::Collection<GnomeCmdFile *> sel = priv->selected_files;
diff --git a/src/gnome-cmd-file-list.h b/src/gnome-cmd-file-list.h
index 3d08533..ca79a84 100644
--- a/src/gnome-cmd-file-list.h
+++ b/src/gnome-cmd-file-list.h
@@ -26,6 +26,7 @@
 #include "gnome-cmd-clist.h"
 #include "gnome-cmd-collection.h"
 #include "gnome-cmd-xml-config.h"
+#include "filter.h"
 
 #define GNOME_CMD_TYPE_FILE_LIST              (gnome_cmd_file_list_get_type ())
 #define GNOME_CMD_FILE_LIST(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), GNOME_CMD_TYPE_FILE_LIST, GnomeCmdFileList))
@@ -127,8 +128,13 @@ struct GnomeCmdFileList
     void select_all();
     void unselect_all();
 
-    void select_pattern(const gchar *pattern, gboolean case_sens);
-    void unselect_pattern(const gchar *pattern, gboolean case_sens);
+    void toggle_file(GnomeCmdFile *f);
+    void toggle();
+    void toggle_and_step();
+    void toggle_with_pattern (Filter &pattern, gboolean mode);
+
+    void select(Filter &pattern)                       {  toggle_with_pattern(pattern, TRUE);                           }
+    void unselect(Filter &pattern)                     {  toggle_with_pattern(pattern, FALSE);                          }
     void select_all_with_same_extension();
     void unselect_all_with_same_extension();
     void invert_selection();
@@ -139,10 +145,6 @@ struct GnomeCmdFileList
     gint get_row_from_file(GnomeCmdFile *f)            {  return gtk_clist_find_row_from_data (*this, f);               }
     void focus_file(const gchar *focus_file, gboolean scroll_to_file=TRUE);
 
-    void toggle_file(GnomeCmdFile *f);
-    void toggle();
-    void toggle_and_step();
-
     void sort();
     GList *sort_selection(GList *list);
 
diff --git a/src/gnome-cmd-patternsel-dialog.cc b/src/gnome-cmd-patternsel-dialog.cc
index 1da8528..b166646 100644
--- a/src/gnome-cmd-patternsel-dialog.cc
+++ b/src/gnome-cmd-patternsel-dialog.cc
@@ -53,10 +53,12 @@ static void on_ok (GtkButton *button, GnomeCmdPatternselDialog *dialog)
 
     const gchar *s = gtk_entry_get_text (GTK_ENTRY (dialog->priv->pattern_entry));
 
+    Filter pattern(s, case_sens, gnome_cmd_data.filter_type);
+    
     if (dialog->priv->mode)
-        dialog->priv->fl->select_pattern(s, case_sens);
+        dialog->priv->fl->select(pattern);
     else
-        dialog->priv->fl->unselect_pattern(s, case_sens);
+        dialog->priv->fl->unselect(pattern);
 
     gnome_cmd_data.search_defaults.name_patterns.add(s);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]