[Xfce4-commits] <design:master> Spawn in terminal if entry starts with $.

Nick Schermer noreply at xfce.org
Thu Jun 2 21:04:02 CEST 2011


Updating branch refs/heads/master
         to 04f4ac252a4049090c808407752dadcd03f57499 (commit)
       from a549829178bc323c0ec1032eb203442e47a5d5ea (commit)

commit 04f4ac252a4049090c808407752dadcd03f57499
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Jun 2 21:01:26 2011 +0200

    Spawn in terminal if entry starts with $.
    
    Like for # to open manual pages, use $ to start the command
    in a terminal. This breaks launching variables, but who uses
    that? This will also be a way to "store" the run_in_terminal
    in the history log.

 .../demo-code/c/appfinder-window.c                 |   41 ++++++++++++--------
 1 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c
index a35f105..12aef60 100644
--- a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c
+++ b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c
@@ -69,6 +69,8 @@ struct _XfceAppfinderWindow
   GtkWidget *button_launch;
   GtkWidget *bin_collapsed;
   GtkWidget *bin_expanded;
+
+  gint       last_window_height;
 };
 
 static const GtkTargetEntry target_list[] =
@@ -118,6 +120,8 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
   GtkWidget          *button;
   GtkTreePath        *path;
 
+  window->last_window_height = 400;
+
   window->model = xfce_appfinder_model_new ();
   window->category_model = xfce_appfinder_category_model_new ();
   g_signal_connect_swapped (G_OBJECT (window->model), "categories-changed",
@@ -521,9 +525,8 @@ xfce_appfinder_window_execute (XfceAppfinderWindow *window)
   gboolean          result = FALSE;
   GdkScreen        *screen;
   const gchar      *text;
-  GdkModifierType   state;
-  gboolean          in_terminal = FALSE;
-  gchar            *cmdline, *tmp;
+  gboolean          in_terminal;
+  gchar            *cmdline, *exo_open;
   const gchar      *exo_open_prefix[] = { "file://", "http://", "https://" };
   guint             i;
 
@@ -542,21 +545,24 @@ xfce_appfinder_window_execute (XfceAppfinderWindow *window)
     }
   else
     {
-      if (gtk_get_current_event_state (&state)
-          && (state & GDK_CONTROL_MASK) != 0)
-        in_terminal = TRUE;
-
       text = gtk_entry_get_text (GTK_ENTRY (window->entry));
-      cmdline = xfce_expand_variables (text, NULL);
-
       if (g_str_has_prefix (text, "#"))
         {
           /* open manual page in the terminal */
-          tmp = g_strconcat ("man ", cmdline + 1, NULL);
-          g_free (cmdline);
-          cmdline = tmp;
+          cmdline = g_strconcat ("man ", text + 1, NULL);
           in_terminal = TRUE;
         }
+      else if (g_str_has_prefix (text, "$"))
+        {
+          /* open in the terminal */
+          cmdline = xfce_expand_variables (text + 1, NULL);
+          in_terminal = TRUE;
+        }
+      else
+        {
+          cmdline = xfce_expand_variables (text, NULL);
+          in_terminal = FALSE;
+        }
 
       result = xfce_spawn_command_line_on_screen (screen, cmdline, in_terminal, FALSE, &error);
       if (!result)
@@ -570,9 +576,9 @@ xfce_appfinder_window_execute (XfceAppfinderWindow *window)
           if (result)
             {
               /* try to spawn again */
-              tmp = g_strconcat ("exo-open ", cmdline, NULL);
-              result = xfce_spawn_command_line_on_screen (screen, tmp, FALSE, FALSE, &error);
-              g_free (tmp);
+              exo_open = g_strconcat ("exo-open ", cmdline, NULL);
+              result = xfce_spawn_command_line_on_screen (screen, exo_open, FALSE, FALSE, &error);
+              g_free (exo_open);
             }
         }
 
@@ -616,10 +622,13 @@ xfce_appfinder_window_set_expanded (XfceAppfinderWindow *window,
     {
       gtk_window_set_geometry_hints (GTK_WINDOW (window), NULL, NULL, 0);
       gtk_window_get_size (GTK_WINDOW (window), &width, NULL);
-      gtk_window_resize (GTK_WINDOW (window), width, 400);
+      gtk_window_resize (GTK_WINDOW (window), width, window->last_window_height);
     }
   else
     {
+      if (gtk_widget_get_visible (GTK_WIDGET (window)))
+        gtk_window_get_size (GTK_WINDOW (window), NULL, &window->last_window_height);
+
       hints.max_height = -1;
       hints.max_width = G_MAXINT;
       gtk_window_set_geometry_hints (GTK_WINDOW (window), NULL, &hints, GDK_HINT_MAX_SIZE);



More information about the Xfce4-commits mailing list