[gthumb] added a GthToggleMenuAction to add menu buttons to the toolbar
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] added a GthToggleMenuAction to add menu buttons to the toolbar
- Date: Tue, 25 Oct 2011 14:56:20 +0000 (UTC)
commit c9c9c2d68d56318d90ca946b854b7cdea55d68c3
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Oct 22 15:22:02 2011 +0200
added a GthToggleMenuAction to add menu buttons to the toolbar
extensions/export_tools/callbacks.c | 58 ++++++++++++----
extensions/list_tools/callbacks.c | 49 +++++++------
gthumb/Makefile.am | 2 +
gthumb/gth-browser-ui.h | 3 +
gthumb/gth-toggle-menu-action.c | 129 ++++++++++++++++++++++++++++++++++
gthumb/gth-toggle-menu-action.h | 55 ++++++++++++++
gthumb/gth-toggle-menu-tool-button.c | 24 ++++++
7 files changed, 283 insertions(+), 37 deletions(-)
---
diff --git a/extensions/export_tools/callbacks.c b/extensions/export_tools/callbacks.c
index a8e1433..7346793 100644
--- a/extensions/export_tools/callbacks.c
+++ b/extensions/export_tools/callbacks.c
@@ -27,8 +27,16 @@
#include "callbacks.h"
+#define BROWSER_DATA_KEY "export-tools-browser-data"
+
+
static const char *ui_info =
"<ui>"
+" <toolbar name='ToolBar'>"
+" <placeholder name='Edit_Actions_2'>"
+" <toolitem action='ExportTools'/>"
+" </placeholder>"
+" </toolbar>"
" <popup name='ExportPopup'>"
" <placeholder name='Web_Services'/>"
" <separator/>"
@@ -37,31 +45,55 @@ static const char *ui_info =
"</ui>";
+typedef struct {
+ GthBrowser *browser;
+ GtkActionGroup *action_group;
+} BrowserData;
+
+
+static void
+browser_data_free (BrowserData *data)
+{
+ g_free (data);
+}
+
+
void
export_tools__gth_browser_construct_cb (GthBrowser *browser)
{
+ BrowserData *data;
+ GtkAction *action;
GError *error = NULL;
guint merge_id;
- GtkToolItem *tool_item;
g_return_if_fail (GTH_IS_BROWSER (browser));
+ data = g_new0 (BrowserData, 1);
+ data->browser = browser;
+ data->action_group = gtk_action_group_new ("Export Tools Actions");
+ gtk_action_group_set_translation_domain (data->action_group, NULL);
+
+ /* tools menu action */
+
+ action = g_object_new (GTH_TYPE_TOGGLE_MENU_ACTION,
+ "name", "ExportTools",
+ "icon-name", "share",
+ "label", _("Share"),
+ /*"tooltip", _("Export files"),*/
+ "is-important", TRUE,
+ NULL);
+ gtk_action_group_add_action (data->action_group, action);
+
+ gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->action_group, 0);
+
merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), ui_info, -1, &error);
if (merge_id == 0) {
g_warning ("building ui failed: %s", error->message);
g_clear_error (&error);
}
- /* export tools menu button */
-
- tool_item = g_object_new (GTH_TYPE_TOGGLE_MENU_TOOL_BUTTON,
- "icon-name", "share",
- "label", _("Share"),
- NULL);
- /*gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), _("Export files"));*/
- gth_toggle_menu_tool_button_set_menu (GTH_TOGGLE_MENU_TOOL_BUTTON (tool_item),
- gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/ExportPopup"));
- gtk_tool_item_set_is_important (GTK_TOOL_ITEM (tool_item), TRUE);
- gtk_widget_show (GTK_WIDGET (tool_item));
- gtk_toolbar_insert (GTK_TOOLBAR (gth_browser_get_browser_toolbar (browser)), tool_item, -1);
+ g_object_set (action, "menu", gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/ExportPopup"), NULL);
+ g_object_unref (action);
+
+ g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
}
diff --git a/extensions/list_tools/callbacks.c b/extensions/list_tools/callbacks.c
index d961fd7..21ed87d 100644
--- a/extensions/list_tools/callbacks.c
+++ b/extensions/list_tools/callbacks.c
@@ -35,6 +35,16 @@
static const char *fixed_ui_info =
"<ui>"
+" <toolbar name='ToolBar'>"
+" <placeholder name='Edit_Actions_2'>"
+" <toolitem action='ListTools'/>"
+" </placeholder>"
+" </toolbar>"
+" <toolbar name='ViewerToolBar'>"
+" <placeholder name='Edit_Actions_2'>"
+" <toolitem action='ListTools'/>"
+" </placeholder>"
+" </toolbar>"
/*
" <popup name='FileListPopup'>"
" <placeholder name='Open_Actions'>"
@@ -211,8 +221,8 @@ void
list_tools__gth_browser_construct_cb (GthBrowser *browser)
{
BrowserData *data;
+ GtkAction *action;
GError *error = NULL;
- GtkToolItem *tool_item;
g_return_if_fail (GTH_IS_BROWSER (browser));
@@ -224,6 +234,18 @@ list_tools__gth_browser_construct_cb (GthBrowser *browser)
action_entries,
G_N_ELEMENTS (action_entries),
browser);
+
+ /* tools menu action */
+
+ action = g_object_new (GTH_TYPE_TOGGLE_MENU_ACTION,
+ "name", "ListTools",
+ "stock-id", GTK_STOCK_EXECUTE,
+ "label", _("Tools"),
+ "tooltip", _("Batch tools for multiple files"),
+ "is-important", TRUE,
+ NULL);
+ gtk_action_group_add_action (data->action_group, action);
+
gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->action_group, 0);
if (! gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), fixed_ui_info, -1, &error)) {
@@ -231,29 +253,8 @@ list_tools__gth_browser_construct_cb (GthBrowser *browser)
g_clear_error (&error);
}
- /* tools menu button */
-
- tool_item = g_object_new (GTH_TYPE_TOGGLE_MENU_TOOL_BUTTON,
- "stock-id", GTK_STOCK_EXECUTE,
- "label", _("Tools"),
- NULL);
- gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), _("Batch tools for multiple files"));
- gth_toggle_menu_tool_button_set_menu (GTH_TOGGLE_MENU_TOOL_BUTTON (tool_item),
- gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/ListToolsPopup"));
- gtk_tool_item_set_is_important (GTK_TOOL_ITEM (tool_item), TRUE);
- gtk_widget_show (GTK_WIDGET (tool_item));
- gtk_toolbar_insert (GTK_TOOLBAR (gth_browser_get_browser_toolbar (browser)), tool_item, -1);
-
- tool_item = g_object_new (GTH_TYPE_TOGGLE_MENU_TOOL_BUTTON,
- "stock-id", GTK_STOCK_EXECUTE,
- "label", _("Tools"),
- NULL);
- gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item), _("Batch tools for multiple files"));
- gth_toggle_menu_tool_button_set_menu (GTH_TOGGLE_MENU_TOOL_BUTTON (tool_item),
- gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/ListToolsPopup"));
- gtk_tool_item_set_is_important (GTK_TOOL_ITEM (tool_item), TRUE);
- gtk_widget_show (GTK_WIDGET (tool_item));
- gtk_toolbar_insert (GTK_TOOLBAR (gth_browser_get_viewer_toolbar (browser)), tool_item, 9);
+ g_object_set (action, "menu", gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), "/ListToolsPopup"), NULL);
+ g_object_unref (action);
g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
diff --git a/gthumb/Makefile.am b/gthumb/Makefile.am
index 4739efc..db5da68 100644
--- a/gthumb/Makefile.am
+++ b/gthumb/Makefile.am
@@ -109,6 +109,7 @@ PUBLIC_HEADER_FILES = \
gth-thumb-loader.h \
gth-time.h \
gth-time-selector.h \
+ gth-toggle-menu-action.h \
gth-toggle-menu-tool-button.h \
gth-toolbox.h \
gth-uri-list.h \
@@ -236,6 +237,7 @@ gthumb_SOURCES = \
gth-thumb-loader.c \
gth-time.c \
gth-time-selector.c \
+ gth-toggle-menu-action.c \
gth-toggle-menu-tool-button.c \
gth-toolbox.c \
gth-uri-list.c \
diff --git a/gthumb/gth-browser-ui.h b/gthumb/gth-browser-ui.h
index 0c00e0f..4c89058 100644
--- a/gthumb/gth-browser-ui.h
+++ b/gthumb/gth-browser-ui.h
@@ -115,6 +115,7 @@ static const char *fixed_ui_info =
" <placeholder name='BrowserCommands'/>"
" <separator/>"
" <placeholder name='Edit_Actions'/>"
+" <placeholder name='Edit_Actions_2'/>"
" </toolbar>"
" <toolbar name='ViewerToolBar'>"
@@ -126,6 +127,7 @@ static const char *fixed_ui_info =
" <placeholder name='ViewerCommands'/>"
" <separator/>"
" <placeholder name='Edit_Actions'/>"
+" <placeholder name='Edit_Actions_2'/>"
" <separator expand='true'/>"
" <placeholder name='ViewerCommandsSecondary'/>"
" <toolitem action='Viewer_Properties'/>"
@@ -140,6 +142,7 @@ static const char *fixed_ui_info =
" <placeholder name='ViewerCommands'/>"
" <separator/>"
" <placeholder name='Edit_Actions'/>"
+" <placeholder name='Edit_Actions_2'/>"
" <separator expand='true'/>"
" <placeholder name='ViewerCommandsSecondary'/>"
" <toolitem action='Viewer_Properties'/>"
diff --git a/gthumb/gth-toggle-menu-action.c b/gthumb/gth-toggle-menu-action.c
new file mode 100644
index 0000000..abb6985
--- /dev/null
+++ b/gthumb/gth-toggle-menu-action.c
@@ -0,0 +1,129 @@
+/* -*- 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-toggle-menu-action.h"
+#include "gth-toggle-menu-tool-button.h"
+
+
+/* Properties */
+enum {
+ PROP_0,
+ PROP_MENU
+};
+
+
+static gpointer parent_class = NULL;
+
+
+struct _GthToggleMenuActionPrivate {
+ GtkWidget *menu;
+};
+
+
+static void
+gth_toggle_menu_action_init (GthToggleMenuAction *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_TOGGLE_MENU_ACTION, GthToggleMenuActionPrivate);
+ self->priv->menu = NULL;
+}
+
+
+
+static void
+gth_toggle_menu_action_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GthToggleMenuAction *self = GTH_TOGGLE_MENU_ACTION (object);
+
+ switch (property_id) {
+ 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_toggle_menu_action_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GthToggleMenuAction *self = GTH_TOGGLE_MENU_ACTION (object);
+
+ switch (property_id) {
+ 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_toggle_menu_action_class_init (GthToggleMenuActionClass *klass)
+{
+ GObjectClass *object_class;
+ GtkActionClass *action_class;
+
+ parent_class = g_type_class_peek_parent (klass);
+ g_type_class_add_private (klass, sizeof (GthToggleMenuActionPrivate));
+
+ object_class = (GObjectClass *) klass;
+ object_class->set_property = gth_toggle_menu_action_set_property;
+ object_class->get_property = gth_toggle_menu_action_get_property;
+
+ action_class = (GtkActionClass *) klass;
+ action_class->toolbar_item_type = GTH_TYPE_TOGGLE_MENU_TOOL_BUTTON;
+
+ /* properties */
+
+ 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 (GthToggleMenuAction, gth_toggle_menu_action, GTK_TYPE_TOGGLE_ACTION)
+
+
+GtkWidget *
+gth_toggle_menu_action_get_menu (GthToggleMenuAction *self)
+{
+ return self->priv->menu;
+}
diff --git a/gthumb/gth-toggle-menu-action.h b/gthumb/gth-toggle-menu-action.h
new file mode 100644
index 0000000..f23ce9c
--- /dev/null
+++ b/gthumb/gth-toggle-menu-action.h
@@ -0,0 +1,55 @@
+/* -*- 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_TOGGLE_MENU_ACTION_H
+#define GTH_TOGGLE_MENU_ACTION_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_TOGGLE_MENU_ACTION (gth_toggle_menu_action_get_type ())
+#define GTH_TOGGLE_MENU_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_TOGGLE_MENU_ACTION, GthToggleMenuAction))
+#define GTH_TOGGLE_MENU_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_TOGGLE_MENU_ACTION, GthToggleMenuActionClass))
+#define GTH_IS_TOGGLE_MENU_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_TOGGLE_MENU_ACTION))
+#define GTH_IS_TOGGLE_MENU_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GTH_TYPE_TOGGLE_MENU_ACTION))
+#define GTH_TOGGLE_MENU_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTH_TYPE_TOGGLE_MENU_ACTION, GthToggleMenuActionClass))
+
+typedef struct _GthToggleMenuAction GthToggleMenuAction;
+typedef struct _GthToggleMenuActionClass GthToggleMenuActionClass;
+typedef struct _GthToggleMenuActionPrivate GthToggleMenuActionPrivate;
+
+struct _GthToggleMenuAction {
+ GtkToggleAction parent;
+ GthToggleMenuActionPrivate *priv;
+};
+
+struct _GthToggleMenuActionClass {
+ GtkToggleActionClass parent_class;
+};
+
+GType gth_toggle_menu_action_get_type (void) G_GNUC_CONST;
+GtkWidget * gth_toggle_menu_action_get_menu (GthToggleMenuAction *action);
+
+G_END_DECLS
+
+#endif /* GTH_TOGGLE_MENU_ACTION_H */
+
diff --git a/gthumb/gth-toggle-menu-tool-button.c b/gthumb/gth-toggle-menu-tool-button.c
index 9a9c54f..626e309 100644
--- a/gthumb/gth-toggle-menu-tool-button.c
+++ b/gthumb/gth-toggle-menu-tool-button.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <gtk/gtk.h>
+#include "gth-toggle-menu-action.h"
#include "gth-toggle-menu-tool-button.h"
#define MENU_ID "gth-toggle-menu-tool-button-menu-id"
@@ -803,6 +804,20 @@ gth_toggle_menu_tool_button_update (GtkActivatable *activatable,
gth_toggle_menu_tool_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
gtk_action_unblock_activate (action);
}
+ else if ((strcmp (property_name, "menu") == 0) && GTH_IS_TOGGLE_MENU_ACTION (action)) {
+ gth_toggle_menu_tool_button_set_menu (button, gth_toggle_menu_action_get_menu (GTH_TOGGLE_MENU_ACTION (action)));
+ }
+ else if (gtk_activatable_get_use_action_appearance (activatable)) {
+ if (strcmp (property_name, "label") == 0) {
+ gth_toggle_menu_tool_button_set_label (button, gtk_action_get_label (action));
+ }
+ else if (strcmp (property_name, "stock-id") == 0) {
+ gth_toggle_menu_tool_button_set_stock_id (button, gtk_action_get_stock_id (action));
+ }
+ else if (strcmp (property_name, "icon-name") == 0) {
+ gth_toggle_menu_tool_button_set_icon_name (button, gtk_action_get_icon_name (action));
+ }
+ }
}
@@ -822,6 +837,15 @@ gth_toggle_menu_tool_button_sync_action_properties (GtkActivatable *activatable,
gtk_action_block_activate (action);
gth_toggle_menu_tool_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
gtk_action_unblock_activate (action);
+
+ if (GTH_IS_TOGGLE_MENU_ACTION (action))
+ gth_toggle_menu_tool_button_set_menu (button, gth_toggle_menu_action_get_menu (GTH_TOGGLE_MENU_ACTION (action)));
+
+ if (gtk_activatable_get_use_action_appearance (activatable)) {
+ gth_toggle_menu_tool_button_set_label (button, gtk_action_get_label (action));
+ gth_toggle_menu_tool_button_set_stock_id (button, gtk_action_get_stock_id (action));
+ gth_toggle_menu_tool_button_set_icon_name (button, gtk_action_get_icon_name (action));
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]