[Xfce4-commits] <xfce4-appfinder:master> Add option to save custom command matches.

Nick Schermer noreply at xfce.org
Sat Oct 29 21:38:01 CEST 2011


Updating branch refs/heads/master
         to 5c43bc62f81c7fadd1d1066739eda0c9d985fefd (commit)
       from 89aeebb161060366c35eb2e62a43d51156d1e136 (commit)

commit 5c43bc62f81c7fadd1d1066739eda0c9d985fefd
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Oct 29 18:31:31 2011 +0200

    Add option to save custom command matches.
    
    If you use the matches to quickly execute something
    special, you probably don't want to save this in the
    command history, so make this an option.

 src/appfinder-actions.c         |   29 ++++++++++++++++++++++++++++-
 src/appfinder-actions.h         |    1 +
 src/appfinder-preferences.c     |   15 ++++++++-------
 src/appfinder-preferences.glade |   26 +++++++++++++++++++++++---
 src/appfinder-window.c          |   17 +++++++++++++----
 5 files changed, 73 insertions(+), 15 deletions(-)

diff --git a/src/appfinder-actions.c b/src/appfinder-actions.c
index 39e2a8b..d5351b5 100644
--- a/src/appfinder-actions.c
+++ b/src/appfinder-actions.c
@@ -77,6 +77,7 @@ struct _XfceAppfinderAction
   gint                 unique_id;
   gchar               *pattern;
   gchar               *command;
+  guint                save : 1;
 
   GRegex              *regex;
 };
@@ -155,18 +156,22 @@ xfce_appfinder_actions_load_defaults (XfceAppfinderActions *actions)
     { XFCE_APPFINDER_ACTION_TYPE_REGEX, 0,
       "^(file|http|https):\\/\\/(.*)$",
       "exo-open \\0",
+      FALSE,
       NULL },
     { XFCE_APPFINDER_ACTION_TYPE_PREFIX, 0,
       "!",
       "exo-open --launch TerminalEmulator %s",
+      FALSE,
       NULL },
     { XFCE_APPFINDER_ACTION_TYPE_PREFIX, 0,
       "!w",
       "exo-open --launch WebBrowser http://en.wikipedia.org/wiki/%s",
+      FALSE,
       NULL },
     { XFCE_APPFINDER_ACTION_TYPE_PREFIX, 0,
       "#",
       "exo-open --launch TerminalEmulator man %s",
+      FALSE,
       NULL }
   };
 
@@ -179,6 +184,7 @@ xfce_appfinder_actions_load_defaults (XfceAppfinderActions *actions)
       action->unique_id = i + 1;
       action->pattern = g_strdup (defaults[i].pattern);
       action->command = g_strdup (defaults[i].command);
+      action->save = defaults[i].save;
 
       actions->actions = g_slist_prepend (actions->actions, action);
     }
@@ -210,6 +216,7 @@ xfce_appfinder_actions_load (XfceAppfinderActions *actions,
   gchar                prop[32];
   gint                 type;
   gchar               *pattern, *command;
+  gboolean             save;
   const GValue        *value;
   guint                i;
   gint                 unique_id;
@@ -266,11 +273,15 @@ xfce_appfinder_actions_load (XfceAppfinderActions *actions,
               g_snprintf (prop, sizeof (prop), "/actions/action-%d/command", unique_id);
               command = xfconf_channel_get_string (actions->channel, prop, NULL);
 
+              g_snprintf (prop, sizeof (prop), "/actions/action-%d/save", unique_id);
+              save = xfconf_channel_get_bool (actions->channel, prop, FALSE);
+
               action = g_slice_new0 (XfceAppfinderAction);
               action->type = type;
               action->unique_id = unique_id;
               action->pattern = pattern;
               action->command = command;
+              action->save = save;
 
               actions->actions = g_slist_prepend (actions->actions, action);
             }
@@ -348,6 +359,9 @@ xfce_appfinder_actions_save (XfceAppfinderActions *actions,
 
           g_snprintf (prop, sizeof (prop), "/actions/action-%d/command", action->unique_id);
           xfconf_channel_set_string (actions->channel, prop, action->command);
+
+          g_snprintf (prop, sizeof (prop), "/actions/action-%d/save", action->unique_id);
+          xfconf_channel_set_bool (actions->channel, prop, action->save);
         }
     }
 
@@ -417,6 +431,11 @@ xfce_appfinder_actions_changed (XfconfChannel        *channel,
                   g_free (action->command);
                   action->command = g_value_dup_string (value);
                 }
+              else if (strcmp (field, "save") == 0
+                       && G_VALUE_HOLDS_BOOLEAN (value))
+                {
+                  action->save = g_value_get_boolean (value);
+                }
 
               break;
             }
@@ -523,6 +542,7 @@ xfce_appfinder_actions_get_unique_id (XfceAppfinderActions *actions)
 gchar *
 xfce_appfinder_actions_execute (XfceAppfinderActions  *actions,
                                 const gchar           *text,
+                                gboolean              *save_cmd,
                                 GError               **error)
 {
   GSList              *li;
@@ -536,7 +556,7 @@ xfce_appfinder_actions_execute (XfceAppfinderActions  *actions,
   appfinder_return_val_if_fail (XFCE_IS_APPFINDER_ACTIONS (actions), NULL);
   appfinder_return_val_if_fail (text != NULL, NULL);
 
-  for (li = actions->actions; !found && li != NULL; li = li->next)
+  for (li = actions->actions; li != NULL; li = li->next)
     {
       action = li->data;
 
@@ -588,6 +608,13 @@ xfce_appfinder_actions_execute (XfceAppfinderActions  *actions,
 
           break;
         }
+
+      if (found)
+        {
+          if (save_cmd != NULL)
+            *save_cmd = action->save;
+          break;
+        }
     }
 
   appfinder_assert ((cmd != NULL) == found);
diff --git a/src/appfinder-actions.h b/src/appfinder-actions.h
index c27ec8e..b227bcd 100644
--- a/src/appfinder-actions.h
+++ b/src/appfinder-actions.h
@@ -43,6 +43,7 @@ gint                        xfce_appfinder_actions_get_unique_id (XfceAppfinderA
 
 gchar                      *xfce_appfinder_actions_execute       (XfceAppfinderActions  *actions,
                                                                   const gchar           *text,
+                                                                  gboolean              *save_cmd,
                                                                   GError               **error);
 
 G_END_DECLS
diff --git a/src/appfinder-preferences.c b/src/appfinder-preferences.c
index 37a4c6b..4bd69ec 100644
--- a/src/appfinder-preferences.c
+++ b/src/appfinder-preferences.c
@@ -68,7 +68,7 @@ struct _XfceAppfinderPreferences
 
   GtkTreeSelection *selection;
 
-  gulong            bindings[3];
+  gulong            bindings[4];
   gulong            property_watch_id;
 };
 
@@ -376,7 +376,7 @@ xfce_appfinder_preferences_action_populate (XfceAppfinderPreferences *preference
   const GValue *value;
   gint          unique_id;
   gchar         prop[32];
-  gchar        *pattern, *command;
+  gchar        *pattern;
   guint         i;
   gint          restore_id = -1;
   GtkTreeIter   iter;
@@ -400,9 +400,6 @@ xfce_appfinder_preferences_action_populate (XfceAppfinderPreferences *preference
         g_snprintf (prop, sizeof (prop), "/actions/action-%d/pattern", unique_id);
         pattern = xfconf_channel_get_string (preferences->channel, prop, NULL);
 
-        g_snprintf (prop, sizeof (prop), "/actions/action-%d/command", unique_id);
-        command = xfconf_channel_get_string (preferences->channel, prop, NULL);
-
         gtk_list_store_insert_with_values (GTK_LIST_STORE (store), &iter, i,
                                            COLUMN_UNIQUE_ID, unique_id,
                                            COLUMN_PATTERN, pattern,
@@ -412,7 +409,6 @@ xfce_appfinder_preferences_action_populate (XfceAppfinderPreferences *preference
           gtk_tree_selection_select_iter (preferences->selection, &iter);
 
         g_free (pattern);
-        g_free (command);
       }
 
       xfconf_array_free (array);
@@ -445,7 +441,8 @@ xfce_appfinder_preferences_selection_changed (GtkTreeSelection         *selectio
   {
      { "type", "active", G_TYPE_INT },
      { "pattern", "text", G_TYPE_STRING },
-     { "command", "text", G_TYPE_STRING }
+     { "command", "text", G_TYPE_STRING },
+     { "save", "active", G_TYPE_BOOLEAN }
   };
 
   appfinder_return_if_fail (GTK_IS_TREE_SELECTION (selection));
@@ -478,6 +475,10 @@ xfce_appfinder_preferences_selection_changed (GtkTreeSelection         *selectio
         gtk_entry_set_text (GTK_ENTRY (object), "");
       else if (GTK_IS_COMBO_BOX (object))
         gtk_combo_box_set_active (GTK_COMBO_BOX (object), 0);
+      else if (GTK_IS_TOGGLE_BUTTON (object))
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (object), FALSE);
+      else
+        appfinder_assert_not_reached ();
 
       if (unique_id > -1)
         {
diff --git a/src/appfinder-preferences.glade b/src/appfinder-preferences.glade
index 3ae52e3..f9a5b7a 100644
--- a/src/appfinder-preferences.glade
+++ b/src/appfinder-preferences.glade
@@ -229,9 +229,9 @@
                             <property name="can_focus">True</property>
                             <property name="model">actions-store</property>
                             <property name="headers_clickable">False</property>
+                            <property name="rules_hint">True</property>
                             <property name="enable_search">False</property>
                             <property name="search_column">0</property>
-                            <property name="rules_hint">True</property>
                             <child>
                               <object class="GtkTreeViewColumn" id="treeviewcolumn1">
                                 <property name="title" translatable="yes">Pattern</property>
@@ -326,7 +326,7 @@
                   <object class="GtkTable" id="table1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="n_rows">3</property>
+                    <property name="n_rows">4</property>
                     <property name="n_columns">2</property>
                     <property name="column_spacing">12</property>
                     <property name="row_spacing">6</property>
@@ -334,11 +334,11 @@
                       <object class="GtkEntry" id="command">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
+                        <property name="tooltip_text" translatable="yes">If the type is set to prefix, %s will be replaced with the string after the pattern, %S with the complete entry text. For regular expressions you can use \0 and \<num>.</property>
                         <property name="invisible_char">•</property>
                         <property name="invisible_char_set">True</property>
                         <property name="primary_icon_activatable">False</property>
                         <property name="secondary_icon_activatable">False</property>
-                        <property name="tooltip_text" translatable="yes">If the type is set to prefix, %s will be replaced with the string after the pattern, %S with the complete entry text. For regular expressions you can use \0 and \<num>.</property>
                         <property name="primary_icon_sensitive">True</property>
                         <property name="secondary_icon_sensitive">True</property>
                       </object>
@@ -435,6 +435,26 @@
                         <property name="right_attach">2</property>
                       </packing>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <object class="GtkCheckButton" id="save">
+                        <property name="label" translatable="yes">_Save match in command history</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
diff --git a/src/appfinder-window.c b/src/appfinder-window.c
index c34d4eb..83a9a96 100644
--- a/src/appfinder-window.c
+++ b/src/appfinder-window.c
@@ -803,6 +803,7 @@ static gboolean
 xfce_appfinder_window_execute_command (const gchar          *text,
                                        GdkScreen            *screen,
                                        XfceAppfinderWindow  *window,
+                                       gboolean             *save_cmd,
                                        GError              **error)
 {
   gboolean  succeed = FALSE;
@@ -819,7 +820,7 @@ xfce_appfinder_window_execute_command (const gchar          *text,
     window->actions = xfce_appfinder_actions_get ();
 
   /* try to match a custom action */
-  action_cmd = xfce_appfinder_actions_execute (window->actions, text, error);
+  action_cmd = xfce_appfinder_actions_execute (window->actions, text, save_cmd, error);
   if (*error != NULL)
     return FALSE;
   else if (action_cmd != NULL)
@@ -855,6 +856,7 @@ xfce_appfinder_window_execute (XfceAppfinderWindow *window)
   const gchar      *text;
   gchar            *cmd = NULL;
   gboolean          regular_command = FALSE;
+  gboolean          save_cmd;
 
   if (!gtk_widget_get_sensitive (window->button_launch))
     return;
@@ -871,7 +873,7 @@ xfce_appfinder_window_execute (XfceAppfinderWindow *window)
           if (!result && regular_command)
             {
               gtk_tree_model_get (model, &iter, XFCE_APPFINDER_MODEL_COLUMN_COMMAND, &cmd, -1);
-              result = xfce_appfinder_window_execute_command (cmd, screen, window, &error);
+              result = xfce_appfinder_window_execute_command (cmd, screen, window, NULL, &error);
               g_free (cmd);
             }
         }
@@ -879,8 +881,15 @@ xfce_appfinder_window_execute (XfceAppfinderWindow *window)
   else
     {
       text = gtk_entry_get_text (GTK_ENTRY (window->entry));
-      if (xfce_appfinder_window_execute_command (text, screen, window, &error))
-        result = xfce_appfinder_model_save_command (window->model, text, &error);
+      save_cmd = TRUE;
+
+      if (xfce_appfinder_window_execute_command (text, screen, window, &save_cmd, &error))
+        {
+          if (save_cmd)
+            result = xfce_appfinder_model_save_command (window->model, text, &error);
+          else
+            result = TRUE;
+        }
     }
 
   gtk_entry_set_icon_from_stock (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_PRIMARY,


More information about the Xfce4-commits mailing list