[libgda] GdaBrowser: improvements to query exection perspective's favorites



commit 8ed75143268cd7b7f5f4b3c52aa5aacacad734d3
Author: Vivien Malerba <malerba gnome-db org>
Date:   Mon Jan 17 19:26:18 2011 +0100

    GdaBrowser: improvements to query exection perspective's favorites

 tools/browser/data-manager/data-console.c          |   16 +-
 tools/browser/query-exec/query-console.c           |  166 ++++++++++++++++++--
 tools/browser/query-exec/query-console.h           |    4 +-
 tools/browser/query-exec/query-exec-perspective.c  |    6 +-
 tools/browser/query-exec/query-favorite-selector.c |   65 +++++---
 tools/browser/support.c                            |   14 ++-
 tools/browser/support.h                            |    7 +-
 7 files changed, 223 insertions(+), 55 deletions(-)
---
diff --git a/tools/browser/data-manager/data-console.c b/tools/browser/data-manager/data-console.c
index 3a03202..af03ae0 100644
--- a/tools/browser/data-manager/data-console.c
+++ b/tools/browser/data-manager/data-console.c
@@ -386,33 +386,33 @@ data_console_new (BrowserConnection *bcnc)
 	gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
 	gtk_box_pack_start (GTK_BOX (hbox), bbox, FALSE, FALSE, 5);
 
-	button = browser_make_small_button (FALSE, _("Reset"), GTK_STOCK_CLEAR,
+	button = browser_make_small_button (FALSE, FALSE, _("Reset"), GTK_STOCK_CLEAR,
 					    _("Reset the editor's\ncontents"));
 	dconsole->priv->clear_xml_button = button;
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (editor_clear_clicked_cb), dconsole);
 
-	button = browser_make_small_button (FALSE, _("Add"), GTK_STOCK_ADD,
+	button = browser_make_small_button (FALSE, TRUE, _("Add"), GTK_STOCK_ADD,
 					    _("Add a new data source"));
 	dconsole->priv->add_source_button = button;
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (add_source_clicked_cb), dconsole);
 
-	button = browser_make_small_button (TRUE, _("Variables"), NULL, _("Show variables needed"));
+	button = browser_make_small_button (TRUE, FALSE, _("Variables"), NULL, _("Show variables needed"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	dconsole->priv->params_toggle = GTK_TOGGLE_BUTTON (button);
 	g_signal_connect (button, "toggled",
 			  G_CALLBACK (variables_clicked_cb), dconsole);
 
-	button = browser_make_small_button (FALSE, _("Execute"), GTK_STOCK_EXECUTE, _("Execute specified\n"
+	button = browser_make_small_button (FALSE, FALSE, _("Execute"), GTK_STOCK_EXECUTE, _("Execute specified\n"
 										      "data manager"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (execute_clicked_cb), dconsole);
 
-	button = browser_make_small_button (TRUE, _("View XML"), NULL, _("View specifications\n"
+	button = browser_make_small_button (TRUE, FALSE, _("View XML"), NULL, _("View specifications\n"
 									 "as XML (advanced)"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	spec_editor_toggled_cb (GTK_TOGGLE_BUTTON (button), dconsole);
@@ -420,7 +420,7 @@ data_console_new (BrowserConnection *bcnc)
 			  G_CALLBACK (spec_editor_toggled_cb), dconsole);
 
 #ifdef HAVE_GDU
-	button = browser_make_small_button (FALSE, _("Help"), GTK_STOCK_HELP, _("Help"));
+	button = browser_make_small_button (FALSE, FALSE, _("Help"), GTK_STOCK_HELP, _("Help"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (help_clicked_cb), dconsole);
@@ -779,8 +779,8 @@ add_source_clicked_cb (G_GNUC_UNUSED GtkButton *button, DataConsole *dconsole)
 								    dconsole->priv->mgr,
 								    current_source, GTK_WIDGET (dconsole));
 		gtk_menu_popup (GTK_MENU (dconsole->priv->add_source_menu), NULL, NULL,
-			NULL, NULL, 0,
-			gtk_get_current_event_time ());
+				NULL, NULL, 0,
+				gtk_get_current_event_time ());
 		return;
 	}
 
diff --git a/tools/browser/query-exec/query-console.c b/tools/browser/query-exec/query-console.c
index e87095d..9ab9b26 100644
--- a/tools/browser/query-exec/query-console.c
+++ b/tools/browser/query-exec/query-console.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 - 2010 The GNOME Foundation
+ * Copyright (C) 2009 - 2011 The GNOME Foundation
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -122,6 +122,9 @@ struct _QueryConsolePrivate {
 
 	ExecutionBatch *current_exec;
 	guint current_exec_id; /* timout ID to fetch execution results */
+
+	gint fav_id;
+	GtkWidget *favorites_menu;
 };
 
 static void query_console_class_init (QueryConsoleClass *klass);
@@ -183,6 +186,7 @@ query_console_init (QueryConsole *tconsole, G_GNUC_UNUSED QueryConsoleClass *kla
 	tconsole->priv->params = NULL;
 	tconsole->priv->params_popup = NULL;
 	tconsole->priv->agroup = NULL;
+	tconsole->priv->fav_id = -1;
 }
 static void connection_busy_cb (BrowserConnection *bcnc, gboolean is_busy,
 				gchar *reason, QueryConsole *tconsole);
@@ -212,6 +216,8 @@ query_console_dispose (GObject *object)
 			gtk_widget_destroy (tconsole->priv->params_popup);
 		if (tconsole->priv->agroup)
 			g_object_unref (tconsole->priv->agroup);
+		if (tconsole->priv->favorites_menu)
+			gtk_widget_destroy (tconsole->priv->favorites_menu);
 
 		g_free (tconsole->priv);
 		tconsole->priv = NULL;
@@ -355,32 +361,36 @@ query_console_new (BrowserConnection *bcnc)
 	gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
 	gtk_box_pack_start (GTK_BOX (hbox), bbox, FALSE, FALSE, 5);
 
-	button = browser_make_small_button (FALSE, _("Clear"), GTK_STOCK_CLEAR, _("Clear the editor's\ncontents"));
+	button = browser_make_small_button (FALSE, FALSE, _("Clear"),
+					    GTK_STOCK_CLEAR, _("Clear the editor's\ncontents"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (sql_clear_clicked_cb), tconsole);
 
-	button = browser_make_small_button (TRUE, _("Variables"), NULL, _("Show variables needed\nto execute SQL"));
+	button = browser_make_small_button (TRUE, FALSE, _("Variables"), NULL,
+					    _("Show variables needed\nto execute SQL"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	tconsole->priv->params_toggle = GTK_TOGGLE_BUTTON (button);
 	g_signal_connect (button, "toggled",
 			  G_CALLBACK (sql_variables_clicked_cb), tconsole);
 
-	button = browser_make_small_button (FALSE, _("Execute"), GTK_STOCK_EXECUTE, _("Execute SQL in editor"));
+	button = browser_make_small_button (FALSE, FALSE, _("Execute"), GTK_STOCK_EXECUTE, _("Execute SQL in editor"));
 	tconsole->priv->exec_button = button;
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (sql_execute_clicked_cb), tconsole);
 	
-	button = browser_make_small_button (FALSE, _("Indent"), GTK_STOCK_INDENT, _("Indent SQL in editor\n"
-									    "and make the code more readable\n"
-									    "(removes comments)"));
+	button = browser_make_small_button (FALSE, FALSE, _("Indent"),
+					    GTK_STOCK_INDENT, _("Indent SQL in editor\n"
+								"and make the code more readable\n"
+								"(removes comments)"));
 	tconsole->priv->indent_button = button;
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (sql_indent_clicked_cb), tconsole);
 
-	button = browser_make_small_button (FALSE, _("Favorite"), STOCK_ADD_BOOKMARK, _("Add SQL to favorite"));
+	button = browser_make_small_button (FALSE, TRUE, _("Favorite"),
+					    STOCK_ADD_BOOKMARK, _("Add SQL to favorite"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (sql_favorite_clicked_cb), tconsole);
@@ -412,14 +422,16 @@ query_console_new (BrowserConnection *bcnc)
 	gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
 	gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
 
-	button = browser_make_small_button (FALSE, _("Copy"), GTK_STOCK_COPY, _("Copy selected history\nto editor"));
+	button = browser_make_small_button (FALSE, FALSE, _("Copy"), GTK_STOCK_COPY,
+					    _("Copy selected history\nto editor"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (history_copy_clicked_cb), tconsole);
 	tconsole->priv->history_copy_button = button;
 	gtk_widget_set_sensitive (button, FALSE);
 
-	button = browser_make_small_button (FALSE, _("Clear"), GTK_STOCK_CLEAR, _("Clear history"));
+	button = browser_make_small_button (FALSE, FALSE, _("Clear"),
+					    GTK_STOCK_CLEAR, _("Clear history"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (history_clear_clicked_cb), tconsole);
@@ -526,6 +538,7 @@ history_copy_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsole *tconsole
         }
 
 	query_editor_set_text (tconsole->priv->editor, string->str);
+	tconsole->priv->fav_id = -1;
 	g_string_free (string, TRUE);
 }
 
@@ -630,6 +643,7 @@ static void
 sql_clear_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsole *tconsole)
 {
 	query_editor_set_text (tconsole->priv->editor, NULL);
+	tconsole->priv->fav_id = -1;
 	gtk_widget_grab_focus (GTK_WIDGET (tconsole->priv->editor));
 }
 
@@ -668,18 +682,144 @@ sql_indent_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsole *tconsole)
 	}
 }
 
+static void sql_favorite_new_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsole *tconsole);
+static void sql_favorite_modify_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsole *tconsole);
+
 static void
 sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsole *tconsole)
 {
+	GtkWidget *menu, *mitem;
+	BrowserFavorites *bfav;
+
+	if (tconsole->priv->favorites_menu)
+		gtk_widget_destroy (tconsole->priv->favorites_menu);
+
+	menu = gtk_menu_new ();
+	tconsole->priv->favorites_menu = menu;
+	mitem = gtk_menu_item_new_with_label (_("New favorite"));
+	g_signal_connect (mitem, "activate",
+			  G_CALLBACK (sql_favorite_new_mitem_cb), tconsole);
+	gtk_widget_show (mitem);
+	gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
+
+	bfav = browser_connection_get_favorites (tconsole->priv->bcnc);
+	if (tconsole->priv->fav_id >= 0) {
+		BrowserFavoritesAttributes fav;
+		if (browser_favorites_get (bfav, tconsole->priv->fav_id, &fav, NULL)) {
+			gchar *str;
+			str = g_strdup_printf (_("Modify favorite '%s'"), fav.name);
+			mitem = gtk_menu_item_new_with_label (str);
+			g_free (str);
+			g_signal_connect (mitem, "activate",
+					  G_CALLBACK (sql_favorite_modify_mitem_cb), tconsole);
+			g_object_set_data_full (G_OBJECT (mitem), "favname",
+						g_strdup (fav.name), g_free);
+			g_object_set_data (G_OBJECT (mitem), "favid",
+					   GINT_TO_POINTER (tconsole->priv->fav_id));
+			gtk_widget_show (mitem);
+			gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
+			browser_favorites_reset_attributes (&fav);
+		}
+	}
+
+	GSList *allfav;
+	allfav = browser_favorites_list (bfav, 0, BROWSER_FAVORITES_QUERIES, ORDER_KEY_QUERIES, NULL);
+	if (allfav) {
+		GtkWidget *submenu;
+		GSList *list;
+
+		mitem = gtk_menu_item_new_with_label (_("Modify a favorite"));
+		gtk_widget_show (mitem);
+		gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
+
+		submenu = gtk_menu_new ();
+		gtk_menu_item_set_submenu (GTK_MENU_ITEM (mitem), submenu);
+		for (list = allfav; list; list = list->next) {
+			BrowserFavoritesAttributes *fav;
+			fav = (BrowserFavoritesAttributes*) list->data;
+			if (fav->id == tconsole->priv->fav_id)
+				continue;
+			gchar *str;
+			str = g_strdup_printf (_("Modify favorite '%s'"), fav->name);
+			mitem = gtk_menu_item_new_with_label (str);
+			g_free (str);
+			g_signal_connect (mitem, "activate",
+					  G_CALLBACK (sql_favorite_modify_mitem_cb), tconsole);
+			g_object_set_data_full (G_OBJECT (mitem), "favname",
+						g_strdup (fav->name), g_free);
+			g_object_set_data (G_OBJECT (mitem), "favid",
+					   GINT_TO_POINTER (fav->id));
+			gtk_widget_show (mitem);
+			gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mitem);
+		}
+		browser_favorites_free_list (allfav);
+	}
+
+	gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+			NULL, NULL, 0,
+			gtk_get_current_event_time ());
+}
+
+static void
+sql_favorite_new_mitem_cb (GtkMenuItem *mitem, QueryConsole *tconsole)
+{
 	BrowserFavorites *bfav;
 	BrowserFavoritesAttributes fav;
 	GError *error = NULL;
 
+	GdaSet *set;
+	GtkWidget *dlg;
+	gint response;
+	const GValue *cvalue;
+	set = gda_set_new_inline (1, _("Favorite's name"),
+				  G_TYPE_STRING, _("Unnamed query"));
+	dlg = gdaui_basic_form_new_in_dialog (set,
+					      (GtkWindow*) gtk_widget_get_toplevel (GTK_WIDGET (tconsole)),
+					      _("Name of the favorite to create"),
+					      _("Enter the name of the favorite to create"));
+	response = gtk_dialog_run (GTK_DIALOG (dlg));
+	if (response == GTK_RESPONSE_REJECT) {
+		g_object_unref (set);
+		gtk_widget_destroy (dlg);
+		return;
+	}
+
 	memset (&fav, 0, sizeof (fav));
 	fav.id = -1;
 	fav.type = BROWSER_FAVORITES_QUERIES;
 	fav.contents = query_editor_get_all_text (tconsole->priv->editor);
-	fav.name = _("Unnamed query");
+	cvalue = gda_set_get_holder_value (set, _("Favorite's name"));
+	fav.name = (gchar*) g_value_get_string (cvalue);
+
+	bfav = browser_connection_get_favorites (tconsole->priv->bcnc);
+
+	if (! browser_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
+		browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
+                                    _("Could not add favorite: %s"),
+                                    error && error->message ? error->message : _("No detail"));
+                if (error)
+                        g_error_free (error);
+	}
+	else
+		tconsole->priv->fav_id = fav.id;
+	g_free (fav.contents);
+
+	g_object_unref (set);
+	gtk_widget_destroy (dlg);
+}
+
+static void
+sql_favorite_modify_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsole *tconsole)
+{
+	BrowserFavorites *bfav;
+	BrowserFavoritesAttributes fav;
+	GError *error = NULL;
+
+	memset (&fav, 0, sizeof (fav));
+	fav.id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (mitem), "favid"));
+	fav.type = BROWSER_FAVORITES_QUERIES;
+	fav.contents = query_editor_get_all_text (tconsole->priv->editor);
+	fav.name = g_object_get_data (G_OBJECT (mitem), "favname");
 
 	bfav = browser_connection_get_favorites (tconsole->priv->bcnc);
 
@@ -1003,13 +1143,15 @@ query_exec_fetch_cb (QueryConsole *tconsole)
  * query_console_set_text
  * @console: a #QueryConsole
  * @text: the new text
+ * @fav_id: the favorite ID or -1 if not a favorite.
  *
  * Replaces the edited SQL with @text in @console
  */
 void
-query_console_set_text (QueryConsole *console, const gchar *text)
+query_console_set_text (QueryConsole *console, const gchar *text, gint fav_id)
 {
 	g_return_if_fail (IS_QUERY_CONSOLE (console));
+	console->priv->fav_id = fav_id;
 	query_editor_set_text (console->priv->editor, text);
 }
 
diff --git a/tools/browser/query-exec/query-console.h b/tools/browser/query-exec/query-console.h
index 6f86e66..491d44e 100644
--- a/tools/browser/query-exec/query-console.h
+++ b/tools/browser/query-exec/query-console.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The GNOME Foundation
+ * Copyright (C) 2009 - 2011 The GNOME Foundation
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -50,7 +50,7 @@ struct _QueryConsoleClass {
 GType                    query_console_get_type (void) G_GNUC_CONST;
 
 GtkWidget               *query_console_new      (BrowserConnection *bcnc);
-void                     query_console_set_text (QueryConsole *console, const gchar *text);
+void                     query_console_set_text (QueryConsole *console, const gchar *text, gint fav_id);
 
 G_END_DECLS
 
diff --git a/tools/browser/query-exec/query-exec-perspective.c b/tools/browser/query-exec/query-exec-perspective.c
index 0613e75..ba78259 100644
--- a/tools/browser/query-exec/query-exec-perspective.c
+++ b/tools/browser/query-exec/query-exec-perspective.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 - 2010 Vivien Malerba
+ * Copyright (C) 2009 - 2011 Vivien Malerba
  *
  * This Library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public License as
@@ -224,7 +224,7 @@ query_exec_perspective_new (BrowserWindow *bwin)
 }
 
 static void
-fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED gint fav_id,
+fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id,
 			  G_GNUC_UNUSED BrowserFavoritesType fav_type, const gchar *selection,
 			  QueryExecPerspective *perspective)
 {
@@ -236,7 +236,7 @@ fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED gint fa
 	if (!page)
 		return;
 	if (IS_QUERY_CONSOLE (page)) {
-		query_console_set_text (QUERY_CONSOLE (page), selection);
+		query_console_set_text (QUERY_CONSOLE (page), selection, fav_id);
 		gtk_widget_grab_focus (page);
 	}
 	else {
diff --git a/tools/browser/query-exec/query-favorite-selector.c b/tools/browser/query-exec/query-favorite-selector.c
index fcb1005..848ed5b 100644
--- a/tools/browser/query-exec/query-favorite-selector.c
+++ b/tools/browser/query-exec/query-favorite-selector.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The GNOME Foundation
+ * Copyright (C) 2009 - 2011 The GNOME Foundation
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -168,33 +168,38 @@ query_favorite_selector_get_type (void)
 	return type;
 }
 
+static void
+favorite_delete_selected (QueryFavoriteSelector *tsel)
+{
+	GtkTreeModel *model;
+	GtkTreeSelection *select;
+	GtkTreeIter iter;
+	
+	select = gtk_tree_view_get_selection (GTK_TREE_VIEW (tsel->priv->treeview));
+	if (gtk_tree_selection_get_selected (select, &model, &iter)) {
+		BrowserFavorites *bfav;
+		BrowserFavoritesAttributes fav;
+		GError *lerror = NULL;
+		
+		memset (&fav, 0, sizeof (BrowserFavoritesAttributes));
+		gtk_tree_model_get (model, &iter,
+				    COLUMN_ID, &(fav.id), -1);
+		bfav = browser_connection_get_favorites (tsel->priv->bcnc);
+		if (!browser_favorites_delete (bfav, 0, &fav, NULL)) {
+			browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
+					    _("Could not remove favorite: %s"),
+					    lerror && lerror->message ? lerror->message : _("No detail"));
+			if (lerror)
+				g_error_free (lerror);
+		}
+	}
+}
+
 static gboolean
 key_press_event_cb (GtkTreeView *treeview, GdkEventKey *event, QueryFavoriteSelector *tsel)
 {
 	if (event->keyval == GDK_Delete) {
-		GtkTreeModel *model;
-		GtkTreeSelection *select;
-		GtkTreeIter iter;
-		
-		select = gtk_tree_view_get_selection (treeview);
-		if (gtk_tree_selection_get_selected (select, &model, &iter)) {
-			BrowserFavorites *bfav;
-			BrowserFavoritesAttributes fav;
-			GError *lerror = NULL;
-
-			memset (&fav, 0, sizeof (BrowserFavoritesAttributes));
-			gtk_tree_model_get (model, &iter,
-					    COLUMN_ID, &(fav.id), -1);
-			bfav = browser_connection_get_favorites (tsel->priv->bcnc);
-			if (!browser_favorites_delete (bfav, 0, &fav, NULL)) {
-				browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
-						    _("Could not remove favorite: %s"),
-						    lerror && lerror->message ? lerror->message : _("No detail"));
-				if (lerror)
-					g_error_free (lerror);
-			}
-		}
-		
+		favorite_delete_selected (tsel);
 		return TRUE;
 	}
 	return FALSE; /* not handled */
@@ -350,6 +355,12 @@ properties_activated_cb (GtkMenuItem *mitem, QueryFavoriteSelector *tsel)
 }
 
 static void
+delete_activated_cb (GtkMenuItem *mitem, QueryFavoriteSelector *tsel)
+{
+	favorite_delete_selected (tsel);
+}
+
+static void
 do_popup_menu (G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event, QueryFavoriteSelector *tsel)
 {
 	int button, event_time;
@@ -367,6 +378,12 @@ do_popup_menu (G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event, QueryFavo
 		g_signal_connect (mitem, "activate",
 				  G_CALLBACK (properties_activated_cb), tsel);
 
+		mitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
+		gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
+		gtk_widget_show (mitem);
+		g_signal_connect (mitem, "activate",
+				  G_CALLBACK (delete_activated_cb), tsel);
+
 		tsel->priv->popup_menu = menu;
 	}
 		
diff --git a/tools/browser/support.c b/tools/browser/support.c
index b0d3b32..bf9bcaf 100644
--- a/tools/browser/support.c
+++ b/tools/browser/support.c
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2009 - 2010The GNOME Foundation.
+ * Copyright (C) 2009 - 2011 The GNOME Foundation.
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -470,7 +470,8 @@ connection_removed_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc
  * Returns: a new #GtkWidget
  */
 GtkWidget *
-browser_make_small_button (gboolean is_toggle, const gchar *label, const gchar *stock_id, const gchar *tooltip)
+browser_make_small_button (gboolean is_toggle, gboolean with_arrow,
+			   const gchar *label, const gchar *stock_id, const gchar *tooltip)
 {
 	GtkWidget *button, *hbox = NULL;
 
@@ -478,7 +479,7 @@ browser_make_small_button (gboolean is_toggle, const gchar *label, const gchar *
 		button = gtk_toggle_button_new ();
 	else
 		button = gtk_button_new ();
-	if (label && stock_id) {
+	if ((label && stock_id) || with_arrow) {
 		hbox = gtk_hbox_new (FALSE, 0);
 		gtk_container_add (GTK_CONTAINER (button), hbox);
 		gtk_widget_show (hbox);
@@ -503,6 +504,13 @@ browser_make_small_button (gboolean is_toggle, const gchar *label, const gchar *
 			gtk_container_add (GTK_CONTAINER (button), wid);
 		gtk_widget_show (wid);
 	}
+	if (with_arrow) {
+		GtkWidget *arrow;
+		arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
+		gtk_box_pack_start (GTK_BOX (hbox), arrow, TRUE, TRUE, 0);
+		gtk_misc_set_alignment (GTK_MISC (arrow), 1, .5);
+		gtk_widget_show (arrow);
+	}
 
 	if (tooltip)
 		gtk_widget_set_tooltip_text (button, tooltip);
diff --git a/tools/browser/support.h b/tools/browser/support.h
index f6c7100..667739b 100644
--- a/tools/browser/support.h
+++ b/tools/browser/support.h
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2009 - 2010 The GNOME Foundation.
+ * Copyright (C) 2009 - 2011 The GNOME Foundation.
  *
  * AUTHORS:
  * 	Vivien Malerba <malerba gnome-db org>
@@ -47,8 +47,9 @@ GtkWidget*         browser_make_tab_label_with_pixbuf (const gchar *label,
 						       GdkPixbuf *pixbuf, gboolean with_close,
 						       GtkWidget **out_close_button);
 
-GtkWidget          *browser_make_small_button (gboolean is_toggle,
-					       const gchar *label, const gchar *stock_id, const gchar *tooltip);
+GtkWidget          *browser_make_small_button (gboolean is_toggle, gboolean with_arrow,
+					       const gchar *label, const gchar *stock_id,
+					       const gchar *tooltip);
 GtkWidget          *browser_make_tree_view (GtkTreeModel *model);
 
 /*



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