[Xfce4-commits] <xfce4-appfinder:master> Fix launching in collapsed mode.

Nick Schermer noreply at xfce.org
Thu Sep 22 18:24:01 CEST 2011


Updating branch refs/heads/master
         to 13a440371c6d3037fecabae89152b47c3094c97b (commit)
       from 089c512a02ecc85ba6be9a3583c70b768148504c (commit)

commit 13a440371c6d3037fecabae89152b47c3094c97b
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Sep 22 18:23:11 2011 +0200

    Fix launching in collapsed mode.

 src/appfinder-actions.c |   63 +++++++++++++++++-----------------------------
 src/appfinder-actions.h |   11 +-------
 src/appfinder-window.c  |   34 +++++++++++++++++++++---
 3 files changed, 53 insertions(+), 55 deletions(-)

diff --git a/src/appfinder-actions.c b/src/appfinder-actions.c
index 3d57f4b..c2d4620 100644
--- a/src/appfinder-actions.c
+++ b/src/appfinder-actions.c
@@ -518,28 +518,23 @@ xfce_appfinder_actions_get_unique_id (XfceAppfinderActions *actions)
 
 
 
-XfceAppfinderActionsResult
+gchar *
 xfce_appfinder_actions_execute (XfceAppfinderActions  *actions,
                                 const gchar           *text,
-                                GdkScreen             *screen,
                                 GError               **error)
 {
-  GSList                     *li;
-  XfceAppfinderAction        *action;
-  XfceAppfinderActionsResult  result = XFCE_APPFINDER_ACTIONS_NOTHING_FOUND;
-  GError                     *err = NULL;
-  gchar                      *cmd = NULL;
-  GMatchInfo                 *match_info = NULL;
-  gchar                      *expanded;
-
-  appfinder_return_val_if_fail (error != NULL && *error == NULL, XFCE_APPFINDER_ACTIONS_NOTHING_FOUND);
-  appfinder_return_val_if_fail (GDK_IS_SCREEN (screen), XFCE_APPFINDER_ACTIONS_NOTHING_FOUND);
-  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_ACTIONS (actions), XFCE_APPFINDER_ACTIONS_NOTHING_FOUND);
-  appfinder_return_val_if_fail (text != NULL, XFCE_APPFINDER_ACTIONS_NOTHING_FOUND);
-
-  for (li = actions->actions;
-       result == XFCE_APPFINDER_ACTIONS_NOTHING_FOUND && li != NULL;
-       li = li->next)
+  GSList              *li;
+  XfceAppfinderAction *action;
+  GError              *err = NULL;
+  gchar               *cmd = NULL;
+  GMatchInfo          *match_info = NULL;
+  gboolean             found = FALSE;
+
+  appfinder_return_val_if_fail (error != NULL && *error == NULL, NULL);
+  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)
     {
       action = li->data;
 
@@ -554,13 +549,14 @@ xfce_appfinder_actions_execute (XfceAppfinderActions  *actions,
           if (g_str_has_prefix (text, action->pattern))
             {
               cmd = xfce_appfinder_actions_expand_command (action, text);
-              result = XFCE_APPFINDER_ACTIONS_SUCCEED;
+              found = TRUE;
             }
           break;
 
         case XFCE_APPFINDER_ACTION_TYPE_REGEX:
           if (action->regex == NULL)
             {
+              /* allocate the regex */
               action->regex = g_regex_new (action->pattern, 0, 0, &err);
               if (action->regex == NULL)
                 {
@@ -576,9 +572,13 @@ xfce_appfinder_actions_execute (XfceAppfinderActions  *actions,
             {
               /* expand the command string */
               cmd = g_match_info_expand_references (match_info, action->command, &err);
-
               if (G_UNLIKELY (err != NULL))
-                *error = err;
+                {
+                  *error = err;
+                  cmd = NULL;
+                }
+
+              found = TRUE;
             }
 
           if (match_info != NULL)
@@ -588,24 +588,7 @@ xfce_appfinder_actions_execute (XfceAppfinderActions  *actions,
         }
     }
 
-  if (result == XFCE_APPFINDER_ACTIONS_SUCCEED
-      && cmd != NULL
-      && *error == NULL)
-    {
-      /* also expand variables... */
-      expanded = xfce_expand_variables (cmd, NULL);
-      g_free (cmd);
-      cmd = expanded;
-
-      APPFINDER_DEBUG ("spawn command \"%s\"", cmd);
-
-      if (xfce_spawn_command_line_on_screen (screen, cmd, FALSE, FALSE, error))
-        result = XFCE_APPFINDER_ACTIONS_SUCCEED;
-      else
-        result = XFCE_APPFINDER_ACTIONS_ERROR;
-    }
-
-  g_free (cmd);
+  appfinder_assert ((cmd != NULL) == found);
 
-  return result;
+  return cmd;
 }
diff --git a/src/appfinder-actions.h b/src/appfinder-actions.h
index 8f62003..c27ec8e 100644
--- a/src/appfinder-actions.h
+++ b/src/appfinder-actions.h
@@ -35,23 +35,14 @@ typedef struct _XfceAppfinderAction       XfceAppfinderAction;
 #define XFCE_IS_APPFINDER_ACTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_APPFINDER_ACTIONS))
 #define XFCE_APPFINDER_ACTIONS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_APPFINDER_ACTIONS, XfceAppfinderActionsClass))
 
-typedef enum
-{
-  XFCE_APPFINDER_ACTIONS_SUCCEED, /* launched an action */
-  XFCE_APPFINDER_ACTIONS_NOTHING_FOUND, /* no suitable action found */
-  XFCE_APPFINDER_ACTIONS_ERROR /* action found, but spawn error */
-}
-XfceAppfinderActionsResult;
-
 GType                       xfce_appfinder_actions_get_type      (void) G_GNUC_CONST;
 
 XfceAppfinderActions       *xfce_appfinder_actions_get           (void) G_GNUC_MALLOC;
 
 gint                        xfce_appfinder_actions_get_unique_id (XfceAppfinderActions  *actions);
 
-XfceAppfinderActionsResult  xfce_appfinder_actions_execute       (XfceAppfinderActions  *actions,
+gchar                      *xfce_appfinder_actions_execute       (XfceAppfinderActions  *actions,
                                                                   const gchar           *text,
-                                                                  GdkScreen             *screen,
                                                                   GError               **error);
 
 G_END_DECLS
diff --git a/src/appfinder-window.c b/src/appfinder-window.c
index da0b6bf..91bc2e8 100644
--- a/src/appfinder-window.c
+++ b/src/appfinder-window.c
@@ -800,19 +800,43 @@ xfce_appfinder_window_icon_theme_changed (XfceAppfinderWindow *window)
 
 
 static gboolean
-xfce_appfinder_window_execute_command (const gchar          *cmd,
+xfce_appfinder_window_execute_command (const gchar          *text,
                                        GdkScreen            *screen,
                                        XfceAppfinderWindow  *window,
                                        GError              **error)
 {
-  gboolean succeed = FALSE;
+  gboolean  succeed = FALSE;
+  gchar    *action_cmd = NULL;
+  gchar    *expanded;
+
+  appfinder_return_val_if_fail (error != NULL && *error == NULL, FALSE);
+  appfinder_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
+
+  if (!IS_STRING (text))
+    return TRUE;
 
   if (window->actions == NULL)
     window->actions = xfce_appfinder_actions_get ();
 
-  if (xfce_appfinder_actions_execute (window->actions, cmd, screen, error)
-        == XFCE_APPFINDER_ACTIONS_SUCCEED)
-    succeed = TRUE;
+  /* try to match a custom action */
+  action_cmd = xfce_appfinder_actions_execute (window->actions, text, error);
+  if (*error != NULL)
+    return FALSE;
+  else if (action_cmd != NULL)
+    text = action_cmd;
+
+  if (IS_STRING (text))
+    {
+      /* expand variables */
+      expanded = xfce_expand_variables (text, NULL);
+
+      /* spawn the command */
+      APPFINDER_DEBUG ("spawn \"%s\"", expanded);
+      succeed = xfce_spawn_command_line_on_screen (screen, expanded, FALSE, FALSE, error);
+      g_free (expanded);
+    }
+
+  g_free (action_cmd);
 
   return succeed;
 }


More information about the Xfce4-commits mailing list