[gthumb] Use custom actions for the navigation tool buttons
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] Use custom actions for the navigation tool buttons
- Date: Tue, 25 Oct 2011 14:56:30 +0000 (UTC)
commit 835727014f6915efcc9ba1895f4a6445bcce1616
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Oct 22 22:05:46 2011 +0200
Use custom actions for the navigation tool buttons
gthumb/Makefile.am | 2 +
gthumb/gth-browser-ui.h | 3 +
gthumb/gth-browser.c | 119 ++++++++++++++---------------
gthumb/gth-menu-action.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++
gthumb/gth-menu-action.h | 54 +++++++++++++
5 files changed, 303 insertions(+), 63 deletions(-)
---
diff --git a/gthumb/Makefile.am b/gthumb/Makefile.am
index db5da68..2b6f48a 100644
--- a/gthumb/Makefile.am
+++ b/gthumb/Makefile.am
@@ -78,6 +78,7 @@ PUBLIC_HEADER_FILES = \
gth-load-file-data-task.h \
gth-location-chooser.h \
gth-main.h \
+ gth-menu-action.h \
gth-menu-button.h \
gth-metadata.h \
gth-metadata-chooser.h \
@@ -206,6 +207,7 @@ gthumb_SOURCES = \
gth-main-default-sort-types.c \
gth-main-default-tests.c \
gth-main-default-types.c \
+ gth-menu-action.c \
gth-menu-button.c \
gth-metadata.c \
gth-metadata-chooser.c \
diff --git a/gthumb/gth-browser-ui.h b/gthumb/gth-browser-ui.h
index 4c89058..9aa5673 100644
--- a/gthumb/gth-browser-ui.h
+++ b/gthumb/gth-browser-ui.h
@@ -107,6 +107,9 @@ static const char *fixed_ui_info =
" </menubar>"
" <toolbar name='ToolBar'>"
+" <toolitem action='Toolbar_Go_Back'/>"
+" <toolitem action='Toolbar_Go_Forward'/>"
+" <toolitem action='Toolbar_Go_Up'/>"
" <toolitem action='View_Stop'/>"
" <separator/>"
" <placeholder name='Export_Actions'/>"
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 781bfe9..e9c2ab9 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -48,6 +48,7 @@
#include "gth-location-chooser.h"
#include "gth-main.h"
#include "gth-marshal.h"
+#include "gth-menu-action.h"
#include "gth-metadata-provider.h"
#include "gth-preferences.h"
#include "gth-progress-dialog.h"
@@ -61,9 +62,6 @@
#include "main.h"
#define GTH_BROWSER_CALLBACK(f) ((GthBrowserCallback) (f))
-#define GO_BACK_HISTORY_POPUP "/GoBackHistoryPopup"
-#define GO_FORWARD_HISTORY_POPUP "/GoForwardHistoryPopup"
-#define GO_PARENT_POPUP "/GoParentPopup"
#define MAX_HISTORY_LENGTH 15
#define GCONF_NOTIFICATIONS 13
#define DEF_SIDEBAR_WIDTH 255
@@ -185,6 +183,9 @@ struct _GthBrowserPrivateData {
GList *history;
GList *history_current;
+ GtkWidget *back_history_menu;
+ GtkWidget *forward_history_menu;
+ GtkWidget *go_parent_menu;
};
@@ -455,7 +456,7 @@ _gth_browser_update_parent_list (GthBrowser *browser)
int i;
GFile *parent;
- menu = gtk_ui_manager_get_widget (browser->priv->ui, GO_PARENT_POPUP);
+ menu = browser->priv->go_parent_menu;
_gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);
if (browser->priv->location == NULL)
@@ -707,7 +708,7 @@ _gth_browser_update_history_list (GthBrowser *browser)
/* Update the back history menu. */
- menu = gtk_ui_manager_get_widget (browser->priv->ui, GO_BACK_HISTORY_POPUP);
+ menu = browser->priv->back_history_menu;
_gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);
if ((browser->priv->history != NULL)
@@ -732,7 +733,7 @@ _gth_browser_update_history_list (GthBrowser *browser)
/* Update the forward history menu. */
- menu = gtk_ui_manager_get_widget (browser->priv->ui, GO_FORWARD_HISTORY_POPUP);
+ menu = browser->priv->forward_history_menu;
_gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);
if ((browser->priv->history != NULL)
@@ -2517,6 +2518,10 @@ gth_browser_finalize (GObject *object)
g_hash_table_unref (browser->priv->named_dialogs);
g_free (browser->priv->list_attributes);
_g_object_unref (browser->priv->folder_popup_file_data);
+ _g_object_unref (browser->priv->back_history_menu);
+ _g_object_unref (browser->priv->forward_history_menu);
+ _g_object_unref (browser->priv->go_parent_menu);
+
g_free (browser->priv);
browser->priv = NULL;
}
@@ -3630,76 +3635,64 @@ gth_file_list_key_press_cb (GtkWidget *widget,
static void
-add_browser_toolbar_menu_buttons (GthBrowser *browser)
+_gth_browser_add_custom_actions (GthBrowser *browser,
+ GtkActionGroup *actions)
{
- int tool_pos;
- GtkToolItem *tool_item;
- GtkAction *action;
-
- tool_pos = 0;
-
- /* toolbar back button */
-
- tool_item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_BACK);
- gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item),
- gtk_ui_manager_get_widget (browser->priv->ui, GO_BACK_HISTORY_POPUP));
- gtk_tool_item_set_homogeneous (tool_item, FALSE);
- gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), _("Go to the previous visited location"));
- gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (tool_item), _("View the list of visited locations"));
+ GtkAction *action;
- action = gtk_action_new ("Toolbar_Go_Back", NULL, NULL, GTK_STOCK_GO_BACK);
- g_object_set (action, "is_important", TRUE, NULL);
+ /* Go Back */
+
+ browser->priv->back_history_menu = gtk_menu_new ();
+ action = g_object_new (GTH_TYPE_MENU_ACTION,
+ "name", "Toolbar_Go_Back",
+ "stock-id", GTK_STOCK_GO_BACK,
+ "button-tooltip", _("Go to the previous visited location"),
+ "arrow-tooltip", _("View the list of visited locations"),
+ "is-important", TRUE,
+ "menu", browser->priv->back_history_menu,
+ NULL);
g_signal_connect (action,
"activate",
G_CALLBACK (gth_browser_activate_action_go_back),
browser);
- gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_item), action);
- gtk_action_group_add_action (browser->priv->actions, action);
-
- gtk_widget_show (GTK_WIDGET (tool_item));
- gtk_toolbar_insert (GTK_TOOLBAR (browser->priv->browser_toolbar), tool_item, tool_pos++);
-
- /* toolbar forward button */
-
- tool_item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD);
- gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item),
- gtk_ui_manager_get_widget (browser->priv->ui, GO_FORWARD_HISTORY_POPUP));
- gtk_tool_item_set_homogeneous (tool_item, FALSE);
- gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), _("Go to the next visited location"));
- gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (tool_item), _("View the list of visited locations"));
-
- action = gtk_action_new ("Toolbar_Go_Forward", NULL, NULL, GTK_STOCK_GO_FORWARD);
- g_object_set (action, "is_important", TRUE, NULL);
+ gtk_action_group_add_action (actions, action);
+ g_object_unref (action);
+
+ /* Go Forward */
+
+ browser->priv->forward_history_menu = gtk_menu_new ();
+ action = g_object_new (GTH_TYPE_MENU_ACTION,
+ "name", "Toolbar_Go_Forward",
+ "stock-id", GTK_STOCK_GO_FORWARD,
+ "button-tooltip", _("Go to the next visited location"),
+ "arrow-tooltip", _("View the list of visited locations"),
+ "is-important", TRUE,
+ "menu", browser->priv->forward_history_menu,
+ NULL);
g_signal_connect (action,
"activate",
G_CALLBACK (gth_browser_activate_action_go_forward),
browser);
- gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_item), action);
- gtk_action_group_add_action (browser->priv->actions, action);
-
- gtk_widget_show (GTK_WIDGET (tool_item));
- gtk_toolbar_insert (GTK_TOOLBAR (browser->priv->browser_toolbar), tool_item, tool_pos++);
-
- /* toolbar up button */
-
- tool_item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_UP);
- gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item),
- gtk_ui_manager_get_widget (browser->priv->ui, GO_PARENT_POPUP));
- gtk_tool_item_set_homogeneous (tool_item, FALSE);
- gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), _("Go up one level"));
- gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (tool_item), _("View the list of upper locations"));
-
- action = gtk_action_new ("Toolbar_Go_Up", NULL, NULL, GTK_STOCK_GO_UP);
- g_object_set (action, "is_important", FALSE, NULL);
+ gtk_action_group_add_action (actions, action);
+ g_object_unref (action);
+
+ /* Go Up */
+
+ browser->priv->go_parent_menu = gtk_menu_new ();
+ action = g_object_new (GTH_TYPE_MENU_ACTION,
+ "name", "Toolbar_Go_Up",
+ "stock-id", GTK_STOCK_GO_UP,
+ "button-tooltip", _("Go up one level"),
+ "arrow-tooltip", _("View the list of upper locations"),
+ "is-important", FALSE,
+ "menu", browser->priv->go_parent_menu,
+ NULL);
g_signal_connect (action,
"activate",
G_CALLBACK (gth_browser_activate_action_go_up),
browser);
- gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_item), action);
- gtk_action_group_add_action (browser->priv->actions, action);
-
- gtk_widget_show (GTK_WIDGET (tool_item));
- gtk_toolbar_insert (GTK_TOOLBAR (browser->priv->browser_toolbar), tool_item, tool_pos++);
+ gtk_action_group_add_action (actions, action);
+ g_object_unref (action);
}
@@ -4163,6 +4156,7 @@ _gth_browser_construct (GthBrowser *browser)
gth_browser_action_toggle_entries,
G_N_ELEMENTS (gth_browser_action_toggle_entries),
browser);
+ _gth_browser_add_custom_actions (browser, browser->priv->actions);
browser->priv->ui = gtk_ui_manager_new ();
g_signal_connect (browser->priv->ui,
@@ -4274,7 +4268,6 @@ _gth_browser_construct (GthBrowser *browser)
browser->priv->browser_toolbar = gtk_ui_manager_get_widget (browser->priv->ui, "/ToolBar");
gtk_toolbar_set_show_arrow (GTK_TOOLBAR (browser->priv->browser_toolbar), TRUE);
gth_window_attach_toolbar (GTH_WINDOW (browser), GTH_BROWSER_PAGE_BROWSER, browser->priv->browser_toolbar);
- add_browser_toolbar_menu_buttons (browser);
/* infobar */
diff --git a/gthumb/gth-menu-action.c b/gthumb/gth-menu-action.c
new file mode 100644
index 0000000..0600733
--- /dev/null
+++ b/gthumb/gth-menu-action.c
@@ -0,0 +1,188 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include "gth-menu-action.h"
+
+
+/* Properties */
+enum {
+ PROP_0,
+ PROP_BUTTON_TOOLTIP,
+ PROP_ARROW_TOOLTIP,
+ PROP_MENU
+};
+
+
+static gpointer parent_class = NULL;
+
+
+struct _GthMenuActionPrivate {
+ char *button_tooltip;
+ char *arrow_tooltip;
+ GtkWidget *menu;
+};
+
+
+static void
+gth_menu_action_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GthMenuAction *self = GTH_MENU_ACTION (object);
+
+ switch (property_id) {
+ case PROP_BUTTON_TOOLTIP:
+ g_free (self->priv->button_tooltip);
+ self->priv->button_tooltip = g_strdup (g_value_get_string (value));
+ break;
+
+ case PROP_ARROW_TOOLTIP:
+ g_free (self->priv->arrow_tooltip);
+ self->priv->arrow_tooltip = g_strdup (g_value_get_string (value));
+ break;
+
+ case PROP_MENU:
+ if (self->priv->menu != NULL)
+ g_object_unref (self->priv->menu);
+ self->priv->menu = g_value_dup_object (value);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+static void
+gth_menu_action_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GthMenuAction *self = GTH_MENU_ACTION (object);
+
+ switch (property_id) {
+ case PROP_BUTTON_TOOLTIP:
+ g_value_set_string (value, self->priv->button_tooltip);
+ break;
+
+ case PROP_ARROW_TOOLTIP:
+ g_value_set_string (value, self->priv->arrow_tooltip);
+ break;
+
+ case PROP_MENU:
+ g_value_set_object (value, self->priv->menu);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+static void
+gth_menu_action_init (GthMenuAction *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_MENU_ACTION, GthMenuActionPrivate);
+ self->priv->menu = NULL;
+ self->priv->arrow_tooltip = NULL;
+ self->priv->button_tooltip = NULL;
+}
+
+
+static void
+gth_menu_action_finalize (GObject *base)
+{
+ GthMenuAction *self = GTH_MENU_ACTION (base);
+
+ g_free (self->priv->arrow_tooltip);
+ g_free (self->priv->button_tooltip);
+
+ G_OBJECT_CLASS (parent_class)->finalize (base);
+}
+
+
+static GtkWidget *
+gth_menu_action_create_tool_item (GtkAction *base)
+{
+ GthMenuAction *self = GTH_MENU_ACTION (base);
+ GtkWidget *tool_item;
+
+ tool_item = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON, NULL);
+ gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), FALSE);
+ gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), self->priv->button_tooltip);
+ gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (tool_item), self->priv->arrow_tooltip);
+ gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item), self->priv->menu);
+
+ return tool_item;
+}
+
+
+static void
+gth_menu_action_class_init (GthMenuActionClass *klass)
+{
+ GObjectClass *object_class;
+ GtkActionClass *action_class;
+
+ parent_class = g_type_class_peek_parent (klass);
+ g_type_class_add_private (klass, sizeof (GthMenuActionPrivate));
+
+ object_class = (GObjectClass*) klass;
+ object_class->set_property = gth_menu_action_set_property;
+ object_class->get_property = gth_menu_action_get_property;
+ object_class->finalize = gth_menu_action_finalize;
+
+ action_class = (GtkActionClass *) klass;
+ action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
+ action_class->create_tool_item = gth_menu_action_create_tool_item;
+
+ /* properties */
+
+ g_object_class_install_property (object_class,
+ PROP_BUTTON_TOOLTIP,
+ g_param_spec_string ("button-tooltip",
+ "Button Tooltip",
+ "The tooltip for the button",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_ARROW_TOOLTIP,
+ g_param_spec_string ("arrow-tooltip",
+ "Arrow Tooltip",
+ "The tooltip for the arrow",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_MENU,
+ g_param_spec_object ("menu",
+ "Menu",
+ "The menu to show",
+ GTK_TYPE_MENU,
+ G_PARAM_READWRITE));
+}
+
+
+G_DEFINE_TYPE (GthMenuAction, gth_menu_action, GTK_TYPE_ACTION)
diff --git a/gthumb/gth-menu-action.h b/gthumb/gth-menu-action.h
new file mode 100644
index 0000000..231e78f
--- /dev/null
+++ b/gthumb/gth-menu-action.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTH_MENU_ACTION_H
+#define GTH_MENU_ACTION_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_MENU_ACTION (gth_menu_action_get_type ())
+#define GTH_MENU_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_MENU_ACTION, GthMenuAction))
+#define GTH_MENU_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_MENU_ACTION, GthMenuActionClass))
+#define GTH_IS_MENU_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_MENU_ACTION))
+#define GTH_IS_MENU_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTH_TYPE_MENU_ACTION))
+#define GTH_MENU_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTH_TYPE_MENU_ACTION, GthMenuActionClass))
+
+typedef struct _GthMenuAction GthMenuAction;
+typedef struct _GthMenuActionClass GthMenuActionClass;
+typedef struct _GthMenuActionPrivate GthMenuActionPrivate;
+
+struct _GthMenuAction {
+ GtkAction parent;
+ GthMenuActionPrivate *priv;
+};
+
+struct _GthMenuActionClass {
+ GtkActionClass parent_class;
+};
+
+GType gth_menu_action_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* GTH_MENU_ACTION_H */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]