Re: PATCH: panel run dialog redux



> This was intentional so that you could type:
> 
> gedit
> 
> And then browse for the file to edit.
> 
> Really how often do you browse for the actual application binary and how
> often for a file you wish to open.

I thought that was pretty confusing, so I changed it to always just set
the text.

A new super-neato patch is attached. Now it uses iain's disclosure
widget, always displays an icon and just generally looks nicer.

It doesn't lookup the icon when you type in a command though. I am not
sure how to best do that, since you would have to look at every entry in
"all-applications:/" and see if the EXEC value matches the command and
then load that icon. Seems kind of expensive to do.

Anyway, patch + new widget are attached. Two new screenshots are here:
http://members.shaw.ca/fworsley/screenshots

- Frank
? disclosure-widget.c
? disclosure-widget.h
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/04 00:05:56
@@ -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/04 00:05:57
@@ -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/04 00:05:57
@@ -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"
@@ -76,7 +77,6 @@
 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);
 
@@ -221,7 +221,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 +237,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;
@@ -257,13 +257,6 @@
 	const char *s;
 	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 +266,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 */
@@ -330,8 +322,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'"),
+					    s);
+					    
                         goto return_and_close;
                 }
 
@@ -387,9 +381,8 @@
                 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"),
+                        panel_error_dialog("run_error",
+					   _("Failed to execute command: '%s'\n\nDetails: %s"),
                                            s, g_strerror (errno));
                 }
         }
@@ -413,15 +406,9 @@
 
 	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);
-		}
+		gtk_entry_set_text (GTK_ENTRY (entry), fname);
 	}
+	
 	gtk_widget_destroy (GTK_WIDGET (fsel));
 }
 
@@ -430,7 +417,8 @@
 {
 	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 program to run")));
+	gtk_file_selection_set_filename (fsel, "/usr/bin/");
 	gtk_window_set_transient_for (GTK_WINDOW (fsel),
 				      GTK_WINDOW (run_dialog));
 	g_object_set_data (G_OBJECT (fsel), "entry", entry);
@@ -494,8 +482,6 @@
 static void
 sync_entry_to_list (GtkWidget *dialog)
 {
-        GtkWidget *clist;
-        GtkWidget *entry;
         gboolean blocked;
 
         blocked = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog),
@@ -503,9 +489,6 @@
         if (blocked)
                 return;
         
-        clist = g_object_get_data (G_OBJECT (dialog), "dentry_list");
-        entry = g_object_get_data (G_OBJECT (dialog), "entry");
-
         unset_selected (dialog);
 }
 
@@ -524,7 +507,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,48 +563,51 @@
 }
 
 static void
-toggle_contents (GtkWidget *button,
+toggle_contents (GtkWidget *disclosure,
                  GtkWidget *dialog)
 {
-        gboolean use_advanced;
+        gboolean show_program_list_box;
         
-	use_advanced = gconf_client_get_bool (
+	show_program_list_box = 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_box"),
 				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_box"),
+		!show_program_list_box,
 		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_box;
 
-        button = gtk_button_new_with_label (label);
+        disclosure = cddb_disclosure_new (_("Display list of known applications"),
+					  _("Hide list of known applications"));
 
-        gtk_container_add (GTK_CONTAINER (align), button);
+	show_program_list_box = gconf_client_get_bool (
+				panel_gconf_get_client (),
+				panel_gconf_general_key (
+					panel_gconf_get_profile (), "show_program_list_box"),
+				NULL);
 
-        g_signal_connect (G_OBJECT (button), "clicked",
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (disclosure), show_program_list_box);
+		
+	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
@@ -632,13 +618,6 @@
 		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 +627,46 @@
 }
 
 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;
         
         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);
+        
+	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 +675,39 @@
 			  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 (_("_Browse..."));
+        g_signal_connect(G_OBJECT(w), "clicked",
+                         G_CALLBACK (browse), entry);
+	gtk_box_pack_start (GTK_BOX (hbox2), w,
+			    FALSE, FALSE, 0);
+        
+        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;
 }
 
@@ -902,18 +892,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 +912,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 +955,6 @@
 selection_changed (GtkTreeSelection *selection,
 		   GtkWidget        *dialog)
 {
-        GtkWidget *label;
         GtkWidget *gpixmap;
         GtkWidget *desc_label;
         gchar *name;
@@ -989,7 +971,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,14 +983,10 @@
 		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));
+						    qitem->comment);
 
 			icon = gnome_desktop_item_find_icon (qitem->icon,
 							     48 /* desired size */,
@@ -1040,40 +1017,29 @@
 add_items_idle (gpointer data)
 {
 	GtkWidget *list = data;
-	add_items_idle_id = 0;
 	fill_list (list);
 	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 +1054,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 +1081,54 @@
 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_box;
+        
+	show_program_list_box = gconf_client_get_bool (
+				  panel_gconf_get_client (),
+				  panel_gconf_general_key (
+					panel_gconf_get_profile (), "show_program_list_box"),
+				  NULL);
+
+	disclosure_button = g_object_get_data (G_OBJECT (dialog), "disclosure");
+
+        if (show_program_list_box) {
+                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_grab_focus (advanced_entry);
-                }
+                        gtk_widget_show_all (GTK_WIDGET (GTK_DIALOG (dialog)->vbox));
 
-                gtk_label_set_text_with_mnemonic (GTK_LABEL (advanced_toggle),
-                                    		  _("_Advanced <<"));
+			list = g_object_get_data (G_OBJECT (dialog), "program_list");
+			gtk_widget_grab_focus (list);
 
-                gtk_tooltips_set_tip (panel_tooltips, advanced_toggle->parent,
-                                      _("Hide the advanced controls below this button."),
-                                      NULL);                
-
-        } else {                
-		GtkWidget *tree_view;
+			/* start loading the list of applications */
+			if (add_items_idle_id == 0) {
+				add_items_idle_id =
+					g_idle_add_full (G_PRIORITY_LOW, add_items_idle,
+					 		 list, NULL);
+			}
+		}
+        } 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);
         }
 }
 
@@ -1251,7 +1180,7 @@
 void
 show_run_dialog (void)
 {
-        gboolean  use_advanced;          
+        gboolean  show_program_list_box;          
 	char     *run_icon;
 
 	if (no_run_box)
@@ -1264,10 +1193,10 @@
 
 	register_run_stock_item ();
 
-	use_advanced = gconf_client_get_bool (
+	show_program_list_box = 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_box"),
 				NULL);
         
 	run_dialog = gtk_dialog_new_with_buttons (_("Run Program"),
@@ -1281,20 +1210,6 @@
 						  PANEL_RESPONSE_RUN,
 						  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);
-
 	run_icon = gnome_program_locate_file (
 			NULL, GNOME_FILE_DOMAIN_PIXMAP, "gnome-run.png", TRUE, NULL);
 	if (run_icon) {
@@ -1305,6 +1220,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");
 
@@ -1314,7 +1230,7 @@
 			  G_CALLBACK (run_dialog_response), NULL);
 
         create_simple_contents ();
-        create_advanced_contents ();
+	create_program_list_contents ();
         update_contents (run_dialog);
         
 	gtk_widget_show_all (run_dialog);
@@ -1325,15 +1241,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);
 }
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 *  Authors: Iain Holmes <iain ximian com>
 *
 *  Copyright 2002 Iain Holmes
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gtk/gtktogglebutton.h>
#include <libgnome/gnome-i18n.h>

#include "disclosure-widget.h"

static GtkCheckButtonClass *parent_class = NULL;

struct _CDDBDisclosurePrivate {
	GtkWidget *container;
	char *shown;
	char *hidden;
	
	guint32 expand_id;
	GtkExpanderStyle style;

	int expander_size;
	int direction;
};

static void
finalize (GObject *object)
{
	CDDBDisclosure *disclosure;

	disclosure = CDDB_DISCLOSURE (object);
	if (disclosure->priv == NULL) {
		return;
	}

	if (disclosure->priv->container != NULL) {
		g_object_unref (G_OBJECT (disclosure->priv->container));
	}
	
	g_free (disclosure->priv);
	disclosure->priv = NULL;

	G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
get_x_y (CDDBDisclosure *disclosure,
	 int *x,
	 int *y,
	 GtkStateType *state_type)
{
	GtkCheckButton *check_button;
	GdkRectangle new_area, restrict_area;
	int indicator_size, indicator_spacing;
	int focus_width;
	int focus_pad;
	gboolean interior_focus;
	GtkWidget *widget = GTK_WIDGET (disclosure);
	GtkAllocation *area = &widget->allocation;
	GtkBin *bin = GTK_BIN (disclosure);
	GtkRequisition child_requisition;
	int width, height;
	
	if (GTK_WIDGET_VISIBLE (disclosure) &&
	    GTK_WIDGET_MAPPED (disclosure)) {
		check_button = GTK_CHECK_BUTTON (disclosure);
		
		gtk_widget_style_get (widget,
				      "interior_focus", &interior_focus,
				      "focus-line-width", &focus_width,
				      "focus-padding", &focus_pad,
				      NULL);
		
		*state_type = GTK_WIDGET_STATE (widget);
		if ((*state_type != GTK_STATE_NORMAL) &&
		    (*state_type != GTK_STATE_PRELIGHT)) {
			*state_type = GTK_STATE_NORMAL;
		}

		if (bin->child) {
			width = bin->child->allocation.x - widget->allocation.x - (2 * GTK_CONTAINER (widget)->border_width);
		} else {
			width = widget->allocation.width;
		}
		
		*x = widget->allocation.x + (width) / 2;
		*y = widget->allocation.y + widget->allocation.height / 2;

		if (interior_focus == FALSE) {
			*x += focus_width + focus_pad;
		}

		*state_type = GTK_WIDGET_STATE (widget) == GTK_STATE_ACTIVE ? GTK_STATE_NORMAL : GTK_WIDGET_STATE (widget);

		if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) {
			*x = widget->allocation.x + widget->allocation.width - (indicator_size + *x - widget->allocation.x);
		}
	} else {
		*x = 0;
		*y = 0;
		*state_type = GTK_STATE_NORMAL;
	}
}

static gboolean
expand_collapse_timeout (gpointer data)
{
	GdkRectangle area;
	GtkWidget *widget = data;
	CDDBDisclosure *disclosure = data;
	GtkStateType state_type;
	int x, y;
	
	gdk_window_invalidate_rect (widget->window, &widget->allocation, TRUE);
	get_x_y (disclosure, &x, &y, &state_type);
	
	gtk_paint_expander (widget->style,
			    widget->window,
			    state_type,
			    &widget->allocation,
			    widget,
			    "disclosure",
			    x, y,
			    disclosure->priv->style);

	disclosure->priv->style += disclosure->priv->direction;
	if ((int) disclosure->priv->style > (int) GTK_EXPANDER_EXPANDED) {
		disclosure->priv->style = GTK_EXPANDER_EXPANDED;

		if (disclosure->priv->container != NULL) {
			gtk_widget_show (disclosure->priv->container);
		}

		g_object_set (G_OBJECT (disclosure),
			      "label", disclosure->priv->hidden,
			      NULL);
		return FALSE;
	} else if ((int) disclosure->priv->style < (int) GTK_EXPANDER_COLLAPSED) {
		disclosure->priv->style = GTK_EXPANDER_COLLAPSED;

		if (disclosure->priv->container != NULL) {
			gtk_widget_hide (disclosure->priv->container);
		}

		g_object_set (G_OBJECT (disclosure),
			      "label", disclosure->priv->shown,
			      NULL);

		return FALSE;
	} else {
		return TRUE;
	}
}

static void
do_animation (CDDBDisclosure *disclosure,
	      gboolean opening)
{
	if (disclosure->priv->expand_id > 0) {
		gtk_timeout_remove (disclosure->priv->expand_id);
	}

	disclosure->priv->direction = opening ? 1 : -1;
	disclosure->priv->expand_id = g_timeout_add (50, expand_collapse_timeout, disclosure);
}

static void
toggled (GtkToggleButton *tb)
{
	CDDBDisclosure *disclosure;

	disclosure = CDDB_DISCLOSURE (tb);
	do_animation (disclosure, gtk_toggle_button_get_active (tb));

	if (disclosure->priv->container == NULL) {
		return;
	}
}

static void
draw_indicator (GtkCheckButton *check,
		GdkRectangle *area)
{
	GtkWidget *widget = GTK_WIDGET (check);
	CDDBDisclosure *disclosure = CDDB_DISCLOSURE (check);
	GtkStateType state_type;
	int x, y;

	get_x_y (disclosure, &x, &y, &state_type);
	gtk_paint_expander (widget->style,
			    widget->window,
			    state_type,
			    area,
			    widget,
			    "treeview",
			    x, y,
			    disclosure->priv->style);
}

static void
class_init (CDDBDisclosureClass *klass)
{
	GObjectClass *object_class;
	GtkWidgetClass *widget_class;
	GtkCheckButtonClass *button_class;
	GtkToggleButtonClass *toggle_class;
	
	object_class = G_OBJECT_CLASS (klass);
	widget_class = GTK_WIDGET_CLASS (klass);
	button_class = GTK_CHECK_BUTTON_CLASS (klass);
	toggle_class = GTK_TOGGLE_BUTTON_CLASS (klass);
	
	toggle_class->toggled = toggled;
	button_class->draw_indicator = draw_indicator;

	object_class->finalize = finalize;

	parent_class = g_type_class_peek_parent (klass);

	gtk_widget_class_install_style_property (widget_class,
						 g_param_spec_int ("expander_size",
								   _("Expander Size"),
								   _("Size of the expander arrow"),
								   0, G_MAXINT,
								   10, G_PARAM_READABLE));
}

static void
init (CDDBDisclosure *disclosure)
{
	disclosure->priv = g_new0 (CDDBDisclosurePrivate, 1);
	disclosure->priv->expander_size = 10;
}

GType
cddb_disclosure_get_type (void)
{
	static GType type = 0;

	if (type == 0) {
		GTypeInfo info = {
			sizeof (CDDBDisclosureClass),
			NULL, NULL, (GClassInitFunc) class_init, NULL, NULL,
			sizeof (CDDBDisclosure), 0, (GInstanceInitFunc) init
		};

		type = g_type_register_static (GTK_TYPE_CHECK_BUTTON, "CDDBDisclosure", &info, 0);
	}

	return type;
}

GtkWidget *
cddb_disclosure_new (const char *shown,
		     const char *hidden)
{
	CDDBDisclosure *disclosure;

	disclosure = g_object_new (cddb_disclosure_get_type (), "label", shown, NULL);

	disclosure->priv->shown = g_strdup (shown);
	disclosure->priv->hidden = g_strdup (hidden);
	return GTK_WIDGET (disclosure);
}

void
cddb_disclosure_set_container (CDDBDisclosure *disclosure,
			       GtkWidget *container)
{
	g_object_ref (G_OBJECT (container));
	disclosure->priv->container = container;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 *  Authors: Iain Holmes <iain ximian com>
 *
 *  Copyright 2002 Iain Holmes
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 *
 */

#ifndef __DISCLOSURE_WIDGET_H__
#define __DISCLOSURE_WIDGET_H__

#include <gtk/gtkcheckbutton.h>

G_BEGIN_DECLS

#define CDDB_DISCLOSURE_TYPE (cddb_disclosure_get_type ())
#define CDDB_DISCLOSURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDDB_DISCLOSURE_TYPE, CDDBDisclosure))
#define CDDB_DISCLOSURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CDDB_DISCLOSURE_TYPE, CDDBDisclosureClass))
#define IS_CDDB_DISCLOSURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDDB_DISCLOSURE_TYPE))
#define IS_CDDB_DISCLOSURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDDB_DISCLOSURE_TYPE))

typedef struct _CDDBDisclosure CDDBDisclosure;
typedef struct _CDDBDisclosureClass CDDBDisclosureClass;
typedef struct _CDDBDisclosurePrivate CDDBDisclosurePrivate;

struct _CDDBDisclosure {
	GtkCheckButton parent;

	CDDBDisclosurePrivate *priv;
};

struct _CDDBDisclosureClass {
	GtkCheckButtonClass parent_class;
};

GType cddb_disclosure_get_type (void);
GtkWidget *cddb_disclosure_new (const char *shown,
				const char *hidden);


G_END_DECLS

#endif


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