Re: PATCH: panel run dialog redux



> I got the new patch almost ready ... but I want to implement the
> auto-opening of a document or directory (if the user doesn't enter an
> executable). No time to finish that tonight, so I will send an updated
> patch tomorrow.

I didn't get that implemented. Now sure how to do it. If somebody else
wants to try it ... go nuts. ;)

The hopefully final patch is attached. The disclosure widget still
doesn't have a mnemonic cause I don't know how to add one. Somebody else
will have to do that.

Some updated screenshots: http://members.shaw.ca/fworsley/screenshots

- Frank
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/ChangeLog,v
retrieving revision 1.1730
diff -u -r1.1730 ChangeLog
--- ChangeLog	2002/05/01 21:34:03	1.1730
+++ ChangeLog	2002/05/07 20:21:14
@@ -1,3 +1,9 @@
+2002-05-02  Frank Worsley  <fworsley shaw ca>
+
+	* gnome-run.c: revamp the run dialog. Show 'Advanced' entry field
+	by default and rename advanced button to 'Known Applications' to
+	display list of known applications when clicked. Plus other fixes.
+	
 2002-05-01  Glynn Foster  <glynn foster sun com>
 
 	* foobar-widget.c: (append_actions_menu): Re-order Actions menu
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/Makefile.am,v
retrieving revision 1.278
diff -u -r1.278 Makefile.am
--- Makefile.am	2002/04/29 20:30:09	1.278
+++ Makefile.am	2002/05/07 20:21:14
@@ -87,6 +87,7 @@
 	drawer-widget.c		\
 	sliding-widget.c	\
 	floating-widget.c	\
+	disclosure-widget.c	\
 	rgb-stuff.c		\
 	panel.c			\
 	applet.c		\
@@ -128,6 +129,7 @@
 	drawer-widget.h		\
 	sliding-widget.h	\
 	floating-widget.h	\
+	disclosure-widget.h	\
 	rgb-stuff.h		\
 	panel.h         	\
 	applet.h         	\
Index: gnome-run.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/gnome-run.c,v
retrieving revision 1.95
diff -u -r1.95 gnome-run.c
--- gnome-run.c	2002/04/15 17:11:07	1.95
+++ gnome-run.c	2002/05/07 20:21:14
@@ -42,6 +42,7 @@
 #include "applet.h"
 #include "button-widget.h"
 #include "foobar-widget.h"
+#include "disclosure-widget.h"
 #include "menu-fentry.h"
 #include "menu.h"
 #include "multiscreen-stuff.h"
@@ -72,14 +73,17 @@
 static GSList *add_icon_iters = NULL;
 static guint add_icon_idle_id = 0;
 static guint add_items_idle_id = 0;
+static guint find_icon_timeout_id = 0;
 
 static GList *executables = NULL;
 static GCompletion *exe_completion = NULL;
 
-static GtkWidget* create_advanced_contents (void);
 static void       update_contents          (GtkWidget *dialog);
 static void       unset_selected           (GtkWidget *dialog);
+static void	  unset_pixmap		   (GtkWidget *gpixmap);
+static gboolean	  find_icon_timeout	   (gpointer   data);
 
+
 static void
 fill_executables_from (const char *dirname)
 {
@@ -221,7 +225,7 @@
 
 	if (!ditem) {
 		panel_error_dialog ("failed_to_load_desktop",
-				    _("Failed to load this program!\n%s"),
+				    _("Failed to run this program: '%s'"),
 				    error->message);
 		g_clear_error (&error);
 		return;
@@ -237,7 +241,7 @@
 
 	if (!gnome_desktop_item_launch (ditem, NULL, 0, &error)) {
 		panel_error_dialog ("failed_to_load_desktop",
-				    _("Failed to load this program!\n%s"),
+				    _("Failed to run this program: '%s'"),
 				    error->message);
 		g_clear_error (&error);
 		return;
@@ -249,21 +253,15 @@
 static void 
 run_dialog_response (GtkWidget *w, int response, gpointer data)
 {
-	GtkEntry *entry;
+	GtkWidget *entry;
         GtkWidget *list;
 	char **argv = NULL;
 	char **temp_argv = NULL;
 	int argc, temp_argc;
-	const char *s;
+	char *s = NULL;
+	char *escaped = NULL;
 	char **envv = NULL;
 	int envc;
-        gboolean use_advanced;
-        
-	use_advanced = gconf_client_get_bool (
-				panel_gconf_get_client (),
-				panel_gconf_general_key (
-					panel_gconf_get_profile (), "advanced_run_dialog"),
-				NULL);
 
 	if (response == GTK_RESPONSE_HELP) {
 		panel_show_help ("specialobjects", "RUNBUTTON");
@@ -273,13 +271,12 @@
 		goto return_and_close;
 	}
         
-        list = g_object_get_data (G_OBJECT (run_dialog), "dentry_list");
-        
         if (g_object_get_data (G_OBJECT (run_dialog), "use_list")) {
 		GtkTreeSelection *selection;
 		GtkTreeModel *model;
 		GtkTreeIter iter;
 
+	        list = g_object_get_data (G_OBJECT (run_dialog), "program_list");
 		selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
 
 		/* just return if nothing selected */
@@ -291,9 +288,10 @@
         } else {
 		GtkToggleButton *terminal;
 
-                entry = GTK_ENTRY (g_object_get_data (G_OBJECT (w), "entry"));
+                entry = g_object_get_data (G_OBJECT (w), "entry");
 
-                s = gtk_entry_get_text(entry);
+                s = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
+		escaped = g_markup_escape_text (s, -1);
 
                 if (string_empty (s))
                         goto return_and_close;
@@ -330,8 +328,10 @@
                 }
 
                 if ( ! g_shell_parse_argv (s, &temp_argc, &temp_argv, NULL)) {
-                        panel_error_dialog (_("Failed to execute command:\n"
-                                              "%s"), s);
+                        panel_error_dialog ("run_error",
+					    _("Failed to execute command: '%s'"),
+					    escaped);
+					    
                         goto return_and_close;
                 }
 
@@ -387,10 +387,9 @@
                 if (gnome_execute_async_with_env (g_get_home_dir (),
                                                   argc, argv,
                                                   envc, envv) < 0) {
-                        panel_error_dialog(_("Failed to execute command:\n"
-                                             "%s\n"
-                                             "%s"),
-                                           s, g_strerror (errno));
+                        panel_error_dialog("run_error",
+					   _("Failed to execute command: '%s'\n\nDetails: %s"),
+                                           escaped, g_strerror (errno));
                 }
         }
         
@@ -398,6 +397,8 @@
 	g_strfreev (argv);
 	g_strfreev (temp_argv);
 	g_strfreev (envv);
+	g_free (s);
+	g_free (escaped);
 	gtk_widget_destroy (w);
 }
 
@@ -405,6 +406,7 @@
 browse_ok (GtkWidget *widget, GtkFileSelection *fsel)
 {
 	const char *fname;
+	char *text, *new;
 	GtkWidget *entry;
 
 	g_return_if_fail (GTK_IS_FILE_SELECTION (fsel));
@@ -413,15 +415,13 @@
 
 	fname = gtk_file_selection_get_filename (fsel);
 	if (fname != NULL) {
-		const char *s = gtk_entry_get_text (GTK_ENTRY (entry));
-		if (string_empty (s)) {
-			gtk_entry_set_text (GTK_ENTRY (entry), fname);
-		} else {
-			char *str = g_strconcat (s, " ", fname, NULL);
-			gtk_entry_set_text (GTK_ENTRY (entry), str);
-			g_free (str);
-		}
+		text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
+		new = g_strconcat (text, " ", fname, NULL);
+		gtk_entry_set_text (GTK_ENTRY (entry), new);
+		g_free (text);
+		g_free (new);
 	}
+	
 	gtk_widget_destroy (GTK_WIDGET (fsel));
 }
 
@@ -430,7 +430,7 @@
 {
 	GtkFileSelection *fsel;
 
-	fsel = GTK_FILE_SELECTION(gtk_file_selection_new(_("Choose a program to run")));
+	fsel = GTK_FILE_SELECTION (gtk_file_selection_new (_("Choose a file")));
 	gtk_window_set_transient_for (GTK_WINDOW (fsel),
 				      GTK_WINDOW (run_dialog));
 	g_object_set_data (G_OBJECT (fsel), "entry", entry);
@@ -494,19 +494,39 @@
 static void
 sync_entry_to_list (GtkWidget *dialog)
 {
-        GtkWidget *clist;
-        GtkWidget *entry;
         gboolean blocked;
+	gboolean enable_program_list;
+	GtkWidget *entry;
 
         blocked = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog),
 						      "sync_entry_to_list_blocked"));
         if (blocked)
                 return;
         
-        clist = g_object_get_data (G_OBJECT (dialog), "dentry_list");
-        entry = g_object_get_data (G_OBJECT (dialog), "entry");
+	enable_program_list = gconf_client_get_bool (
+		  	      panel_gconf_get_client (),
+			      panel_gconf_general_key (
+				   panel_gconf_get_profile (), "enable_program_list"),
+			      NULL);
+	
+	if (enable_program_list) {
+	        unset_selected (dialog);
 
-        unset_selected (dialog);
+		entry = g_object_get_data (G_OBJECT (dialog), "entry");
+	
+		if (find_icon_timeout_id != 0) {
+			/* already a timeout registered so delay it for another half-second. */
+			g_source_remove (find_icon_timeout_id);
+			find_icon_timeout_id =
+				g_timeout_add_full (G_PRIORITY_LOW, 250, find_icon_timeout,
+				 		    entry, NULL);		
+		} else {
+			/* no timeout registered so start a new one. */
+			find_icon_timeout_id =
+				g_timeout_add_full (G_PRIORITY_LOW, 250, find_icon_timeout,
+			 			    entry, NULL);	
+		}
+	}
 }
 
 static void
@@ -524,7 +544,7 @@
 			   "sync_entry_to_list_blocked",
 			   GINT_TO_POINTER (TRUE));
         
-        list = g_object_get_data (G_OBJECT (dialog), "dentry_list");
+        list = g_object_get_data (G_OBJECT (dialog), "program_list");
         entry = g_object_get_data (G_OBJECT (dialog), "entry");
         terminal_toggle = g_object_get_data (G_OBJECT (dialog), "terminal");
 
@@ -580,65 +600,74 @@
 }
 
 static void
-toggle_contents (GtkWidget *button,
+toggle_contents (GtkWidget *disclosure,
                  GtkWidget *dialog)
 {
-        gboolean use_advanced;
+        gboolean show_program_list;
         
-	use_advanced = gconf_client_get_bool (
+	show_program_list = gconf_client_get_bool (
 				panel_gconf_get_client (),
 				panel_gconf_general_key (
-					panel_gconf_get_profile (), "advanced_run_dialog"),
+					panel_gconf_get_profile (), "show_program_list"),
 				NULL);
 
 	gconf_client_set_bool (
 		panel_gconf_get_client (),
 		panel_gconf_general_key (
-			panel_gconf_get_profile (), "advanced_run_dialog"),
-		!use_advanced,
+			panel_gconf_get_profile (), "show_program_list"),
+		!show_program_list,
 		NULL);
 
         update_contents (dialog);
 }
 
 static GtkWidget*
-create_toggle_advanced_button (const char *label)
+create_disclosure_widget ()
 {
-        GtkWidget *align;
-        GtkWidget *button;
-
-        align = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
+        GtkWidget *disclosure;
+        gboolean show_program_list;
 
-        button = gtk_button_new_with_label (label);
+        disclosure = cddb_disclosure_new (_("Known Applications"),
+					  _("Known Applications"));
 
-        gtk_container_add (GTK_CONTAINER (align), button);
+	show_program_list = gconf_client_get_bool (
+				panel_gconf_get_client (),
+				panel_gconf_general_key (
+					panel_gconf_get_profile (), "show_program_list"),
+				NULL);
 
-        g_signal_connect (G_OBJECT (button), "clicked",
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (disclosure), show_program_list);
+		
+	g_object_set_data (G_OBJECT (run_dialog), "disclosure", disclosure);
+	  
+        g_signal_connect (G_OBJECT (disclosure), "clicked",
                             G_CALLBACK (toggle_contents),
                             run_dialog);
 
-        g_object_set_data (G_OBJECT (run_dialog),
-			   "advanced_toggle_label",
-			   GTK_BIN (button)->child);
-        
-        return align;
+        return disclosure;
 }
 
 static void
 entry_changed (GtkWidget *entry,
                gpointer   data)
 {
+	GtkWidget *button;
+	char *text;
+	
+	/* desensitize run button if no text entered */
+	text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
+	button = g_object_get_data (G_OBJECT (run_dialog), "run_button");
+	if (strlen (text) == 0) {
+		gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
+	} else {
+		gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
+	}
+	g_free (text);
+
 	if (run_dialog != NULL)
 		sync_entry_to_list (run_dialog);
 }
 
-/* Called when advanced contents are switched to or first shown */
-static void
-advanced_contents_shown (GtkWidget *vbox, gpointer data)
-{
-        /* does nothing at the moment */
-}
-
 static void
 activate_run (GtkWidget *entry, gpointer data)
 {
@@ -648,26 +677,48 @@
 }
 
 static GtkWidget*
-create_advanced_contents (void)
+create_simple_contents (void)
 {
         GtkWidget *vbox;
         GtkWidget *entry;
         GtkWidget *gentry;
+	GtkWidget *pixmap;
         GtkWidget *hbox;
+	GtkWidget *vbox2;
+	GtkWidget *hbox2;
         GtkWidget *w;
+	gboolean enable_program_list;
         
         vbox = gtk_vbox_new (FALSE, 0);
-
-        hbox = gtk_hbox_new(0, FALSE);
+	
+        hbox = gtk_hbox_new (FALSE, 0);
+        gtk_box_pack_start (GTK_BOX (vbox), hbox,
+                            TRUE, TRUE, GNOME_PAD_SMALL);
+			    
+        w = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
+        pixmap = gtk_image_new ();
+	g_object_set_data (G_OBJECT (run_dialog), "pixmap", pixmap);
+	gtk_container_add (GTK_CONTAINER (w), pixmap);
+        gtk_box_pack_start (GTK_BOX (hbox), w,
+			    FALSE, FALSE, 10);
+        unset_pixmap (pixmap);
+	
+	vbox2 = gtk_vbox_new (FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (hbox), vbox2,
+			    TRUE, TRUE, GNOME_PAD_SMALL);
 	
         gentry = gnome_entry_new ("gnome-run");
-        gtk_box_pack_start (GTK_BOX (hbox), gentry, TRUE, TRUE, 0);
+        gtk_box_pack_start (GTK_BOX (vbox2), gentry,
+			    TRUE, TRUE, GNOME_PAD_SMALL);
+
         /* 1/4 the width of the first screen should be a good value */
-	g_object_set (G_OBJECT (gentry),
-		      "width_request", (int)(multiscreen_width (0) / 4),
-		      NULL);
+	g_object_set (G_OBJECT (gentry),"width_request",
+		      (int)(multiscreen_width (0) / 4), NULL);
 
         entry = gnome_entry_gtk_entry (GNOME_ENTRY (gentry));
+	gtk_tooltips_set_tip (panel_tooltips, entry, _("Command to run"), NULL);
+        gtk_combo_set_use_arrows_always (GTK_COMBO (gentry), TRUE);
+        g_object_set_data (G_OBJECT (run_dialog), "entry", entry);
 
         g_signal_connect (G_OBJECT (entry), "event",
 			  G_CALLBACK (entry_event),
@@ -676,48 +727,48 @@
 			  G_CALLBACK (kill_completion),
 			  NULL);
 
-	gtk_tooltips_set_tip (panel_tooltips, entry, _("Executable name for selected application"), NULL);
- 
-        gtk_combo_set_use_arrows_always (GTK_COMBO (gentry), TRUE);
-        g_object_set_data (G_OBJECT (run_dialog), "entry", entry);
-
 	g_signal_connect (G_OBJECT (entry), "activate",
 			  G_CALLBACK (activate_run),
 			  NULL);
-        g_signal_connect (G_OBJECT (entry),
-			  "changed",
+			  
+        g_signal_connect (G_OBJECT (entry), "changed",
 			  G_CALLBACK (entry_changed),
 			  NULL);
-        
-        w = gtk_button_new_with_mnemonic (_("_Browse..."));
-        g_signal_connect(G_OBJECT(w), "clicked",
-                           G_CALLBACK (browse), entry);
-        gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE,
-                            GNOME_PAD_SMALL);
 
-        gtk_box_pack_start (GTK_BOX (vbox), hbox,
-                            FALSE, FALSE, GNOME_PAD_SMALL);
+	hbox2 = gtk_hbox_new (FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox2), hbox2,
+			    TRUE, TRUE, GNOME_PAD_SMALL);
 
         w = gtk_check_button_new_with_mnemonic(_("Run in _terminal"));
-        g_object_set_data (G_OBJECT (run_dialog), "terminal", w);
-        gtk_box_pack_start (GTK_BOX (vbox), w,
-                            FALSE, FALSE, GNOME_PAD_SMALL);
-        
-        g_object_set_data_full (G_OBJECT (run_dialog),
-				"advanced",
-				g_object_ref (vbox),
-				(GDestroyNotify) g_object_unref);
+	g_object_set_data (G_OBJECT (run_dialog), "terminal", w);
+        gtk_box_pack_start (GTK_BOX (hbox2), w,
+                            TRUE, TRUE, 0);
 
-        g_object_set_data_full (G_OBJECT (run_dialog),
-				"advanced-entry",
-				g_object_ref (entry),
-				(GDestroyNotify) g_object_unref);
-        
-        g_signal_connect (G_OBJECT (vbox),
-			  "show",
-			  G_CALLBACK (advanced_contents_shown),
-			  NULL);
+        w = gtk_button_new_with_mnemonic (_("Append File..."));
+        g_signal_connect(G_OBJECT(w), "clicked",
+                         G_CALLBACK (browse), entry);
+	gtk_box_pack_start (GTK_BOX (hbox2), w,
+			    FALSE, FALSE, 0);
+
+	enable_program_list = gconf_client_get_bool (
+		  	      panel_gconf_get_client (),
+			      panel_gconf_general_key (
+				   panel_gconf_get_profile (), "enable_program_list"),
+			      NULL);
+	
+	/* only create disclosure widget if really needed */
+	if (enable_program_list) {
+	        w = create_disclosure_widget ();
+		gtk_box_pack_start (GTK_BOX (vbox), w,
+				    FALSE, FALSE, GNOME_PAD_SMALL);
+	}
 
+        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (run_dialog)->vbox),
+                            vbox,
+                            FALSE, FALSE, 0);
+
+	gtk_widget_show_all (vbox);
+        
         return vbox;
 }
 
@@ -744,7 +795,112 @@
 	gtk_tree_view_append_column (treeview, column);
 }
 
+static GdkPixbuf*
+get_icon_for_command (char *text, char *ditem)
+{
+	QuickDesktopItem *qitem;
+	GdkPixbuf *pixbuf = NULL;
+
+	if (text == NULL || text[0] == '\0' || ditem == NULL) {
+		return NULL;
+	}
+
+	qitem = quick_desktop_item_load_uri (ditem /*file */,
+					     "Application" /* expected type */,
+					     TRUE /* run tryexec */);
+
+	if (qitem != NULL && qitem->exec != NULL) {
+		char **tokens;
+		char *exec;
+		char *command;
+		char *icon;
+		
+		/* find basename of exec from desktop item.
+		   strip of all arguments after the initial command */
+		tokens = g_strsplit (qitem->exec, " ", -1);
+		exec = g_path_get_basename (tokens[0]);
+		g_strfreev (tokens);
+		
+		/* same for the user command */
+		tokens = g_strsplit (text, " ", -1);
+		command = g_path_get_basename (tokens[0]);
+		g_strfreev (tokens);
+					
+		if (exec != NULL && command != NULL && strcmp (exec, command) == 0) {
+			icon = gnome_desktop_item_find_icon (qitem->icon,
+							     48 /* desired size */,
+							     0 /* flags */);
+			if (icon != NULL) {
+				pixbuf = gdk_pixbuf_new_from_file (icon, NULL);
+				g_free (icon);
+			}
+		}
+
+		g_free (exec);
+		g_free (command);			
+		quick_desktop_item_destroy (qitem);
+	}
+
+	return pixbuf;
+}
+
 static gboolean
+find_icon_timeout (gpointer data)
+{
+	GtkListStore *list;
+	GtkTreeIter *iter;
+	GtkTreeModel *model;
+	GtkTreePath *path;
+	GtkWidget *pixmap;
+	GValue *value = NULL;
+	char *name;
+
+	pixmap = g_object_get_data (G_OBJECT (run_dialog), "pixmap");
+	list = g_object_get_data (G_OBJECT (run_dialog), "program_list");
+	model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
+	path = gtk_tree_path_new_root ();
+	iter = g_new0 (GtkTreeIter, 1);
+	value = g_new0 (GValue, 1);
+	
+	gtk_tree_model_get_iter (model, iter, path);
+
+	do {
+		gtk_tree_model_get_value (model, iter,
+					  COLUMN_NAME,
+					  value);
+				  
+		name = g_strdup (g_value_get_string (value));
+		g_value_unset (value);
+
+        	if (name != NULL) {
+			GdkPixbuf *pixbuf;
+			char *text;
+			
+			text = gtk_editable_get_chars (GTK_EDITABLE (data), 0, -1);
+			pixbuf = get_icon_for_command (text, name);
+		
+			if (pixbuf != NULL) {
+				gtk_image_set_from_pixbuf (GTK_IMAGE (pixmap), pixbuf);
+				find_icon_timeout_id = 0;
+				return FALSE;
+			}
+			
+			g_free (text);
+			g_free (name);
+		}
+	
+        } while (gtk_tree_model_iter_next (model, iter));
+
+	gtk_tree_path_free (path);
+	gtk_tree_iter_free (iter);
+
+	unset_pixmap (pixmap);
+	
+	find_icon_timeout_id = 0;
+	return FALSE;
+}
+
+static gboolean
 add_icon_idle (GtkListStore *list)
 {
 	GtkTreeIter *iter;
@@ -902,18 +1058,16 @@
 static void
 unset_selected (GtkWidget *dialog)
 {
-        GtkWidget *label;
         GtkWidget *gpixmap;
         GtkWidget *desc_label;
         GtkWidget *entry;
         GtkWidget *list;
         char *text;
         
-        label = g_object_get_data (G_OBJECT (dialog), "label");
         gpixmap = g_object_get_data (G_OBJECT (dialog), "pixmap");
         desc_label = g_object_get_data (G_OBJECT (dialog), "desc_label");
         entry = g_object_get_data (G_OBJECT (dialog), "entry");
-        list = g_object_get_data (G_OBJECT (dialog), "dentry_list");
+        list = g_object_get_data (G_OBJECT (dialog), "program_list");
         
 	if (entry != NULL) {
 		text = gtk_editable_get_chars (GTK_EDITABLE (entry),
@@ -924,21 +1078,16 @@
 
         if ( ! string_empty (text)) {
                 char *msg;
-                msg = g_strdup_printf (_("Will run '%s'"),
+                msg = g_strdup_printf (_("Will run command: '%s'"),
                                        text);
-                if (label)
-                        gtk_label_set_text (GTK_LABEL (label), msg);
-                
                 if (desc_label)
                         gtk_label_set_text (GTK_LABEL (desc_label), msg);
 
                 g_free (msg);
         } else {
-                if (label)
-                        gtk_label_set_text (GTK_LABEL (label), _("No program selected"));
                 
                 if (desc_label)
-                        gtk_label_set_text (GTK_LABEL (desc_label), _("No program selected"));
+                        gtk_label_set_text (GTK_LABEL (desc_label), _("No application selected"));
         }
 
         g_free (text);
@@ -972,7 +1121,6 @@
 selection_changed (GtkTreeSelection *selection,
 		   GtkWidget        *dialog)
 {
-        GtkWidget *label;
         GtkWidget *gpixmap;
         GtkWidget *desc_label;
         gchar *name;
@@ -989,7 +1137,6 @@
 	name = g_strdup (g_value_get_string (&value));
 	g_value_unset (&value);
 
-        label = g_object_get_data (G_OBJECT (dialog), "label");
         gpixmap = g_object_get_data (G_OBJECT (dialog), "pixmap");
         desc_label = g_object_get_data (G_OBJECT (dialog), "desc_label");
 
@@ -1002,11 +1149,7 @@
 		if (qitem != NULL) {
                         GdkPixbuf *pixbuf;
 			char *icon;
-
-			if (label != NULL)
-				gtk_label_set_text (GTK_LABEL (label),
-						    qitem->name);
-
+			
 			if (desc_label != NULL)
 				gtk_label_set_text (GTK_LABEL (desc_label),
 						    sure_string (qitem->comment));
@@ -1040,40 +1183,30 @@
 add_items_idle (gpointer data)
 {
 	GtkWidget *list = data;
-	add_items_idle_id = 0;
 	fill_list (list);
+	add_items_idle_id = 0;
 	return FALSE;
 }
 
 static GtkWidget*
-create_simple_contents (void)
+create_program_list_contents (void)
 {
         GtkWidget *vbox;
         GtkWidget *w;
         GtkWidget *label;
-        GtkWidget *pixmap;
         GtkWidget *list;
-        GtkWidget *hbox;
 	GtkTreeSelection *selection;
         
-        vbox = gtk_vbox_new (FALSE, 1);
+        vbox = gtk_vbox_new (FALSE, 0);
         
-        label = gtk_label_new_with_mnemonic (_("A_pplications:"));
-        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-
         list = gtk_tree_view_new ();
-        g_object_set_data (G_OBJECT (run_dialog), "dentry_list", list);
-
+        g_object_set_data (G_OBJECT (run_dialog), "program_list", list);
 	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list), FALSE);
-	gtk_label_set_mnemonic_widget (GTK_LABEL (label), list);
 
-	add_atk_name_desc (list, _("List of Applications"),
+	add_atk_name_desc (list, _("List of known applications"),
 			   _("Choose an application to run from the list"));
-	set_relation (list, GTK_LABEL (label), 0);
 
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
-
 	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
 
         g_signal_connect (selection, "changed",
@@ -1088,56 +1221,26 @@
         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w),
                                         GTK_POLICY_AUTOMATIC,
                                         GTK_POLICY_AUTOMATIC);
+
         gtk_container_add (GTK_CONTAINER (w), list);
-        
         gtk_box_pack_start (GTK_BOX (vbox), w,
-                            TRUE, TRUE, GNOME_PAD_SMALL);
-
-
-        w = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
-        gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
-        hbox = gtk_hbox_new (FALSE, 3);
-        gtk_container_add (GTK_CONTAINER (w), hbox);
-        
-        pixmap = gtk_image_new ();
-        gtk_box_pack_start (GTK_BOX (hbox), pixmap, FALSE, FALSE, 0);
-        g_object_set_data (G_OBJECT (run_dialog), "pixmap", pixmap);
-        
+                            TRUE, TRUE, 0);
+   
         label = gtk_label_new ("");
-        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+        gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-        gtk_label_set_selectable (GTK_LABEL (label), TRUE);
-        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 5);
         g_object_set_data (G_OBJECT (run_dialog), "desc_label", label);
 
-#if 0
-        label = gtk_label_new ("");
-        g_object_set_data (G_OBJECT (run_dialog), "label", label);
-        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
-#endif
-
-        unset_selected (run_dialog);
-        
         g_object_ref (G_OBJECT (vbox));
         
         g_object_set_data_full (G_OBJECT (run_dialog),
-				"simple",
+				"program_list_box",
 				vbox,
 				(GtkDestroyNotify) g_object_unref);
 
-	if (add_items_idle_id == 0)
-		add_items_idle_id =
-			g_idle_add_full (G_PRIORITY_LOW, add_items_idle,
-					 list, NULL);
+        unset_selected (run_dialog);
 
-        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (run_dialog)->vbox),
-                            vbox,
-                            TRUE, TRUE, 0);
-        
-        w = create_toggle_advanced_button ("");
-        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (run_dialog)->vbox),
-			    w, FALSE, FALSE, GNOME_PAD_SMALL);
-        
         return vbox;
 }
 
@@ -1145,61 +1248,47 @@
 static void
 update_contents (GtkWidget *dialog)
 {
-        GtkWidget *advanced = NULL;
-        GtkWidget *advanced_toggle;
-        gboolean use_advanced;
-        
-	use_advanced = gconf_client_get_bool (
-				panel_gconf_get_client (),
-				panel_gconf_general_key (
-					panel_gconf_get_profile (), "advanced_run_dialog"),
-				NULL);
-
-        advanced_toggle = g_object_get_data (G_OBJECT (dialog),
-					     "advanced_toggle_label");
-
-        
-        if (use_advanced) {
-                advanced = g_object_get_data (G_OBJECT (dialog), "advanced");
-                
-                if (advanced && advanced->parent == NULL) {
-			GtkWidget *advanced_entry;
-
-			advanced_entry =
-				g_object_get_data (G_OBJECT (dialog), "advanced-entry");
-
-                        gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox),
-                                            advanced,
-                                            FALSE, FALSE, 0);
+        GtkWidget *program_list_box = NULL;
+	GtkWidget *disclosure_button;
+        gboolean show_program_list;
+        
+	show_program_list = gconf_client_get_bool (
+				  panel_gconf_get_client (),
+				  panel_gconf_general_key (
+					panel_gconf_get_profile (), "show_program_list"),
+				  NULL);
+
+	disclosure_button = g_object_get_data (G_OBJECT (dialog), "disclosure");
+
+        if (show_program_list) {
+                program_list_box = g_object_get_data (G_OBJECT (dialog), "program_list_box");
+
+                if (program_list_box && program_list_box->parent == NULL) {
+			GtkWidget *list;
+			
+			gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE);
+
+                        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
+                                            program_list_box,
+                                            TRUE, TRUE, GNOME_PAD_SMALL);
                 
-                        gtk_widget_show_all (advanced);
+                        gtk_widget_show_all (GTK_WIDGET (GTK_DIALOG (dialog)->vbox));
 
-                        gtk_widget_grab_focus (advanced_entry);
-                }
-
-                gtk_label_set_text_with_mnemonic (GTK_LABEL (advanced_toggle),
-                                    		  _("_Advanced <<"));
-
-                gtk_tooltips_set_tip (panel_tooltips, advanced_toggle->parent,
-                                      _("Hide the advanced controls below this button."),
-                                      NULL);                
-
-        } else {                
-		GtkWidget *tree_view;
+			list = g_object_get_data (G_OBJECT (dialog), "program_list");
+			gtk_widget_grab_focus (list);
+		}
+        } else {    
+		GtkWidget *entry;           
 
-                advanced = g_object_get_data (G_OBJECT (dialog), "advanced");
+                program_list_box = g_object_get_data (G_OBJECT (dialog), "program_list_box");
                 
-                if (advanced && advanced->parent != NULL)
-                        gtk_container_remove (GTK_CONTAINER (advanced->parent), advanced);                
-                gtk_label_set_text_with_mnemonic (GTK_LABEL (advanced_toggle),
-                                    		  _("_Advanced >>"));
-
-                gtk_tooltips_set_tip (panel_tooltips, advanced_toggle->parent,
-                                      _("Allow typing in a command line instead of choosing an application from the list"),
-                                      NULL);
+                if (program_list_box && program_list_box->parent != NULL) {
+                        gtk_container_remove (GTK_CONTAINER (program_list_box->parent), program_list_box);
+			gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+		}
 
-		tree_view = g_object_get_data (G_OBJECT (dialog), "dentry_list");
-                gtk_widget_grab_focus (tree_view);
+		entry = g_object_get_data (G_OBJECT (dialog), "entry");
+                gtk_widget_grab_focus (entry);
         }
 }
 
@@ -1246,13 +1335,18 @@
 	if (add_items_idle_id)
 		g_source_remove (add_items_idle_id);
 	add_items_idle_id = 0;
+
+	if (find_icon_timeout_id)
+		g_source_remove (find_icon_timeout_id);
+	find_icon_timeout_id = 0;
 }
 
 void
 show_run_dialog (void)
 {
-        gboolean  use_advanced;          
-	char     *run_icon;
+        gboolean  enable_program_list;
+	GtkWidget *w;
+	char      *run_icon;
 
 	if (no_run_box)
 		return;
@@ -1264,36 +1358,19 @@
 
 	register_run_stock_item ();
 
-	use_advanced = gconf_client_get_bool (
-				panel_gconf_get_client (),
-				panel_gconf_general_key (
-					panel_gconf_get_profile (), "advanced_run_dialog"),
-				NULL);
-        
 	run_dialog = gtk_dialog_new_with_buttons (_("Run Program"),
 						  NULL /* parent */,
 						  0 /* flags */,
 						  GTK_STOCK_HELP,
 						  GTK_RESPONSE_HELP,
-						  GTK_STOCK_CLOSE,
-						  GTK_RESPONSE_CLOSE,
-						  PANEL_STOCK_RUN,
-						  PANEL_RESPONSE_RUN,
+						  GTK_STOCK_CANCEL,
+						  GTK_RESPONSE_CANCEL,
 						  NULL);
 
-        /* This is lame in advanced mode, but if you change it on mode
-         * toggle it creates weird effects, so always use this policy
-         */
-	g_object_set (G_OBJECT (run_dialog),
-		      "allow_grow", FALSE,
-		      "allow_shrink", TRUE,
-		      "resizable", TRUE,
-		      NULL);
-
-        /* Get some reasonable height in simple list mode */
-        if (!use_advanced)
-                gtk_window_set_default_size (GTK_WINDOW (run_dialog),
-                                             -1, 400);
+	w = gtk_dialog_add_button (GTK_DIALOG (run_dialog),
+				   PANEL_STOCK_RUN,PANEL_RESPONSE_RUN);
+	gtk_widget_set_sensitive (w, FALSE);
+	g_object_set_data (G_OBJECT (run_dialog), "run_button", w);
 
 	run_icon = gnome_program_locate_file (
 			NULL, GNOME_FILE_DOMAIN_PIXMAP, "gnome-run.png", TRUE, NULL);
@@ -1305,6 +1382,7 @@
 	g_signal_connect (G_OBJECT (run_dialog), "destroy",
 			  G_CALLBACK (run_dialog_destroyed),
 			  NULL);
+
 	gtk_window_set_position (GTK_WINDOW (run_dialog), GTK_WIN_POS_MOUSE);
 	gtk_window_set_wmclass (GTK_WINDOW (run_dialog), "run_dialog", "Panel");
 
@@ -1313,10 +1391,26 @@
         g_signal_connect (G_OBJECT (run_dialog), "response", 
 			  G_CALLBACK (run_dialog_response), NULL);
 
+
         create_simple_contents ();
-        create_advanced_contents ();
-        update_contents (run_dialog);
-        
+
+	enable_program_list = gconf_client_get_bool (
+		  	      panel_gconf_get_client (),
+			      panel_gconf_general_key (
+				   panel_gconf_get_profile (), "enable_program_list"),
+			      NULL);
+	
+	if (enable_program_list) {
+		create_program_list_contents ();
+	        update_contents (run_dialog);        
+		
+		/* start loading the list of applications */
+		w = g_object_get_data (G_OBJECT (run_dialog), "program_list");
+		add_items_idle_id =
+			g_idle_add_full (G_PRIORITY_LOW, add_items_idle,
+			 		 w, NULL);
+	}
+
 	gtk_widget_show_all (run_dialog);
 }
 
@@ -1325,15 +1419,15 @@
 {
 	GtkWidget *entry;
 
-	g_return_if_fail(text != NULL);
+	g_return_if_fail (text != NULL);
 
 	show_run_dialog ();
 
-	if(run_dialog == NULL) {
+	if (run_dialog == NULL) {
 		return;
 	}
         
 	entry = g_object_get_data (G_OBJECT (run_dialog), "entry");
 
-	gtk_entry_set_text(GTK_ENTRY(entry), text);
+	gtk_entry_set_text (GTK_ENTRY (entry), text);
 }
Index: panel-per-panel-config.schemas
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/panel-per-panel-config.schemas,v
retrieving revision 1.19
diff -u -r1.19 panel-per-panel-config.schemas
--- panel-per-panel-config.schemas	2002/03/29 14:00:12	1.19
+++ panel-per-panel-config.schemas	2002/05/07 20:21:16
@@ -21,10 +21,21 @@
 <!-- ********************************* -->
 
       <schema>
-        <key>/schemas/apps/panel/default_profiles/small/general/advanced_run_dialog</key>
+        <key>/schemas/apps/panel/default_profiles/small/general/show_program_list</key>
         <owner>panel</owner>
         <type>bool</type>
         <default>false</default>
+        <locale name="C">
+          <short></short>
+          <long></long>
+        </locale>
+      </schema>
+
+      <schema>
+        <key>/schemas/apps/panel/default_profiles/small/general/enable_program_list</key>
+        <owner>panel</owner>
+        <type>bool</type>
+        <default>true</default>
         <locale name="C">
           <short></short>
           <long></long>
Index: quick-desktop-reader.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/quick-desktop-reader.c,v
retrieving revision 1.10
diff -u -r1.10 quick-desktop-reader.c
--- quick-desktop-reader.c	2002/02/10 15:08:30	1.10
+++ quick-desktop-reader.c	2002/05/07 20:21:17
@@ -398,6 +398,9 @@
 		} else if ((val = IS_KEY ("Icon", buf)) != NULL) {
 			g_free (retval->icon);
 			retval->icon = g_strdup (val);
+		} else if ((val = IS_KEY ("Exec", buf)) != NULL) {
+			g_free (retval->exec);
+			retval->exec = g_strdup (val);
 		} else if ((val = IS_KEY ("Encoding", buf)) != NULL) {
 			if (strcmp (val, "UTF-8") == 0) {
 				encoding = ENCODING_UTF8;
@@ -515,6 +518,9 @@
 	g_free (item->sort_order);
 	item->sort_order = NULL;
 
+	g_free (item->exec);
+	item->exec = NULL;
+
 	g_free (item);
 }
 
@@ -529,6 +535,7 @@
 	newitem->icon = g_strdup (item->icon);
 	newitem->tryexec = g_strdup (item->tryexec);
 	newitem->sort_order = g_strdup (item->sort_order);
+	newitem->exec = g_strdup (item->exec);
 	return newitem;
 }
 
Index: quick-desktop-reader.h
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/quick-desktop-reader.h,v
retrieving revision 1.5
diff -u -r1.5 quick-desktop-reader.h
--- quick-desktop-reader.h	2001/12/20 03:43:40	1.5
+++ quick-desktop-reader.h	2002/05/07 20:21:17
@@ -46,6 +46,7 @@
 	char *comment;
 
 	char *icon;
+	char *exec;
 	char *tryexec;
 	char *sort_order;
 };


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