[gedit] Readd bus interface to extend the filebrowser context menu
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Readd bus interface to extend the filebrowser context menu
- Date: Mon, 3 Mar 2014 13:18:03 +0000 (UTC)
commit 22bdaaae18596b603e09b98f6e3bc0152c5a5275
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Mar 1 12:58:30 2014 +0100
Readd bus interface to extend the filebrowser context menu
https://bugzilla.gnome.org/show_bug.cgi?id=725424
plugins/filebrowser/Makefile.am | 4 +-
plugins/filebrowser/gedit-file-browser-menus.ui | 3 +
plugins/filebrowser/gedit-file-browser-messages.c | 22 +++
plugins/filebrowser/gedit-file-browser-widget.c | 26 +++
plugins/filebrowser/gedit-file-browser-widget.h | 4 +-
plugins/filebrowser/messages.xml | 8 +-
.../gedit-file-browser-message-add-context-item.c | 171 --------------------
.../gedit-file-browser-message-add-context-item.h | 69 --------
...edit-file-browser-message-extend-context-menu.c | 129 +++++++++++++++
...edit-file-browser-message-extend-context-menu.h | 69 ++++++++
plugins/filebrowser/messages/messages.h | 2 +-
11 files changed, 258 insertions(+), 249 deletions(-)
---
diff --git a/plugins/filebrowser/Makefile.am b/plugins/filebrowser/Makefile.am
index 2471a9b..7a662d8 100644
--- a/plugins/filebrowser/Makefile.am
+++ b/plugins/filebrowser/Makefile.am
@@ -20,8 +20,8 @@ plugins_filebrowser_BUILTSOURCES = \
plugins_filebrowser_messages_NOINST_H_FILES = \
plugins/filebrowser/messages/gedit-file-browser-message-activation.h \
- plugins/filebrowser/messages/gedit-file-browser-message-add-context-item.h \
plugins/filebrowser/messages/gedit-file-browser-message-add-filter.h \
+ plugins/filebrowser/messages/gedit-file-browser-message-extend-context-menu.h \
plugins/filebrowser/messages/gedit-file-browser-message-get-root.h \
plugins/filebrowser/messages/gedit-file-browser-message-get-view.h \
plugins/filebrowser/messages/gedit-file-browser-message-id.h \
@@ -44,8 +44,8 @@ plugins_filebrowser_libfilebrowser_la_NOINST_H_FILES = \
plugins_filebrowser_messages_sources = \
plugins/filebrowser/messages/gedit-file-browser-message-activation.c \
- plugins/filebrowser/messages/gedit-file-browser-message-add-context-item.c \
plugins/filebrowser/messages/gedit-file-browser-message-add-filter.c \
+ plugins/filebrowser/messages/gedit-file-browser-message-extend-context-menu.c \
plugins/filebrowser/messages/gedit-file-browser-message-get-root.c \
plugins/filebrowser/messages/gedit-file-browser-message-get-view.c \
plugins/filebrowser/messages/gedit-file-browser-message-id.c \
diff --git a/plugins/filebrowser/gedit-file-browser-menus.ui b/plugins/filebrowser/gedit-file-browser-menus.ui
index 3fabd1d..e57ac1d 100644
--- a/plugins/filebrowser/gedit-file-browser-menus.ui
+++ b/plugins/filebrowser/gedit-file-browser-menus.ui
@@ -69,6 +69,9 @@
</item>
</section>
</submenu>
+ <section>
+ <attribute name="id">extension-section</attribute>
+ </section>
</menu>
<menu id="bookmarks-menu">
<section>
diff --git a/plugins/filebrowser/gedit-file-browser-messages.c
b/plugins/filebrowser/gedit-file-browser-messages.c
index 7bfa4c5..1054c2b 100644
--- a/plugins/filebrowser/gedit-file-browser-messages.c
+++ b/plugins/filebrowser/gedit-file-browser-messages.c
@@ -533,6 +533,22 @@ message_remove_filter_cb (GeditMessageBus *bus,
}
static void
+message_extend_context_menu_cb (GeditMessageBus *bus,
+ GeditMessage *message,
+ GeditWindow *window)
+{
+ WindowData *data;
+ GeditMenuExtension *ext;
+
+ data = get_window_data (window);
+
+ ext = gedit_file_browser_widget_extend_context_menu (data->widget);
+
+ g_object_set (message, "extension", ext, NULL);
+ g_object_unref (ext);
+}
+
+static void
message_up_cb (GeditMessageBus *bus,
GeditMessage *message,
WindowData *data)
@@ -676,6 +692,11 @@ register_methods (GeditWindow *window,
"remove_filter");
gedit_message_bus_register (bus,
+ GEDIT_TYPE_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU,
+ MESSAGE_OBJECT_PATH,
+ "extend_context_menu");
+
+ gedit_message_bus_register (bus,
GEDIT_TYPE_MESSAGE,
MESSAGE_OBJECT_PATH,
"up");
@@ -726,6 +747,7 @@ register_methods (GeditWindow *window,
BUS_CONNECT (bus, set_markup, data);
BUS_CONNECT (bus, add_filter, window);
BUS_CONNECT (bus, remove_filter, data);
+ BUS_CONNECT (bus, extend_context_menu, window);
BUS_CONNECT (bus, up, data);
BUS_CONNECT (bus, history_back, data);
diff --git a/plugins/filebrowser/gedit-file-browser-widget.c b/plugins/filebrowser/gedit-file-browser-widget.c
index ee5cb92..9ac88b2 100644
--- a/plugins/filebrowser/gedit-file-browser-widget.c
+++ b/plugins/filebrowser/gedit-file-browser-widget.c
@@ -2221,6 +2221,32 @@ gedit_file_browser_widget_refresh (GeditFileBrowserWidget *obj)
}
}
+GeditMenuExtension *
+gedit_file_browser_widget_extend_context_menu (GeditFileBrowserWidget *obj)
+{
+ gint i, n_items;
+ GMenuModel *section = NULL;
+
+ g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_WIDGET (obj), NULL);
+
+ n_items = g_menu_model_get_n_items (obj->priv->dir_menu);
+
+ for (i = 0; i < n_items && !section; i++)
+ {
+ gchar *id = NULL;
+
+ if (g_menu_model_get_item_attribute (obj->priv->dir_menu, i, "id", "s", &id) &&
+ strcmp (id, "extension-section") == 0)
+ {
+ section = g_menu_model_get_item_link (obj->priv->dir_menu, i, G_MENU_LINK_SECTION);
+ }
+
+ g_free (id);
+ }
+
+ return section != NULL ? gedit_menu_extension_new (G_MENU (section)) : NULL;
+}
+
void
gedit_file_browser_widget_history_back (GeditFileBrowserWidget *obj)
{
diff --git a/plugins/filebrowser/gedit-file-browser-widget.h b/plugins/filebrowser/gedit-file-browser-widget.h
index 6c5c313..67c14be 100644
--- a/plugins/filebrowser/gedit-file-browser-widget.h
+++ b/plugins/filebrowser/gedit-file-browser-widget.h
@@ -22,6 +22,7 @@
#define __GEDIT_FILE_BROWSER_WIDGET_H__
#include <gtk/gtk.h>
+#include <gedit/gedit-menu-extension.h>
#include "gedit-file-browser-store.h"
#include "gedit-file-bookmarks-store.h"
#include "gedit-file-browser-view.h"
@@ -111,7 +112,8 @@ void gedit_file_browser_widget_remove_filter
(GeditFileBrowserWidget *obj,
gulong id);
void gedit_file_browser_widget_set_filter_pattern (GeditFileBrowserWidget *obj,
gchar const *pattern);
-
+GeditMenuExtension *
+ gedit_file_browser_widget_extend_context_menu (GeditFileBrowserWidget *obj);
void gedit_file_browser_widget_refresh (GeditFileBrowserWidget *obj);
void gedit_file_browser_widget_history_back (GeditFileBrowserWidget *obj);
void gedit_file_browser_widget_history_forward (GeditFileBrowserWidget *obj);
diff --git a/plugins/filebrowser/messages.xml b/plugins/filebrowser/messages.xml
index 0aebd99..e2b7137 100644
--- a/plugins/filebrowser/messages.xml
+++ b/plugins/filebrowser/messages.xml
@@ -25,11 +25,9 @@
<message namespace="Gedit" name="FileBrowserMessageId">
<property name="id" type="uint"/>
</message>
- <message namespace="Gedit" name="FileBrowserMessageAddContextItem">
- <include system="yes">gtk/gtk.h</include>
- <property name="action" type="object" gtype="GTK_TYPE_ACTION"/>
- <property name="path" type="string"/>
- <property name="id" type="uint"/>
+ <message namespace="Gedit" name="FileBrowserMessageExtendContextMenu">
+ <include system="yes">gedit/gedit-menu-extension.h</include>
+ <property name="extension" type="object" gtype="GEDIT_TYPE_MENU_EXTENSION"/>
</message>
<message namespace="Gedit" name="FileBrowserMessageActivation">
<property name="active" type="boolean"/>
diff --git a/plugins/filebrowser/messages/gedit-file-browser-message-extend-context-menu.c
b/plugins/filebrowser/messages/gedit-file-browser-message-extend-context-menu.c
new file mode 100644
index 0000000..b4dc47d
--- /dev/null
+++ b/plugins/filebrowser/messages/gedit-file-browser-message-extend-context-menu.c
@@ -0,0 +1,129 @@
+
+/*
+ * gedit-file-browser-message-extend-context-menu.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2014 - Paolo Borelli
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gedit-file-browser-message-extend-context-menu.h"
+#include <gedit/gedit-menu-extension.h>
+
+#define
GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object),
GEDIT_TYPE_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU, GeditFileBrowserMessageExtendContextMenuPrivate))
+
+enum
+{
+ PROP_0,
+
+ PROP_EXTENSION,
+};
+
+struct _GeditFileBrowserMessageExtendContextMenuPrivate
+{
+ GeditMenuExtension *extension;
+};
+
+G_DEFINE_TYPE (GeditFileBrowserMessageExtendContextMenu, gedit_file_browser_message_extend_context_menu,
GEDIT_TYPE_MESSAGE)
+
+static void
+gedit_file_browser_message_extend_context_menu_finalize (GObject *obj)
+{
+ GeditFileBrowserMessageExtendContextMenu *msg = GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU (obj);
+
+ if (msg->priv->extension)
+ {
+ g_object_unref (msg->priv->extension);
+ }
+
+ G_OBJECT_CLASS (gedit_file_browser_message_extend_context_menu_parent_class)->finalize (obj);
+}
+
+static void
+gedit_file_browser_message_extend_context_menu_get_property (GObject *obj,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GeditFileBrowserMessageExtendContextMenu *msg;
+
+ msg = GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU (obj);
+
+ switch (prop_id)
+ {
+ case PROP_EXTENSION:
+ g_value_set_object (value, msg->priv->extension);
+ break;
+ }
+}
+
+static void
+gedit_file_browser_message_extend_context_menu_set_property (GObject *obj,
+ guint prop_id,
+ GValue const *value,
+ GParamSpec *pspec)
+{
+ GeditFileBrowserMessageExtendContextMenu *msg;
+
+ msg = GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU (obj);
+
+ switch (prop_id)
+ {
+ case PROP_EXTENSION:
+ {
+ if (msg->priv->extension)
+ {
+ g_object_unref (msg->priv->extension);
+ }
+ msg->priv->extension = g_value_dup_object (value);
+ break;
+ }
+ }
+}
+
+static void
+gedit_file_browser_message_extend_context_menu_class_init (GeditFileBrowserMessageExtendContextMenuClass
*klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->finalize = gedit_file_browser_message_extend_context_menu_finalize;
+
+ object_class->get_property = gedit_file_browser_message_extend_context_menu_get_property;
+ object_class->set_property = gedit_file_browser_message_extend_context_menu_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_EXTENSION,
+ g_param_spec_object ("extension",
+ "Extension",
+ "Extension",
+ GEDIT_TYPE_MENU_EXTENSION,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
+ g_type_class_add_private (object_class, sizeof (GeditFileBrowserMessageExtendContextMenuPrivate));
+}
+
+static void
+gedit_file_browser_message_extend_context_menu_init (GeditFileBrowserMessageExtendContextMenu *message)
+{
+ message->priv = GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU_GET_PRIVATE (message);
+}
diff --git a/plugins/filebrowser/messages/gedit-file-browser-message-extend-context-menu.h
b/plugins/filebrowser/messages/gedit-file-browser-message-extend-context-menu.h
new file mode 100644
index 0000000..dc363ab
--- /dev/null
+++ b/plugins/filebrowser/messages/gedit-file-browser-message-extend-context-menu.h
@@ -0,0 +1,69 @@
+
+/*
+ * gedit-file-browser-message-extend-context-menu.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2014 - Paolo Borelli
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifndef __GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU_H__
+#define __GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU_H__
+
+#include <gedit/gedit-message.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU
(gedit_file_browser_message_extend_context_menu_get_type ())
+#define GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
+
GEDIT_TYPE_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU,\
+
GeditFileBrowserMessageExtendContextMenu))
+#define GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
+
GEDIT_TYPE_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU,\
+
GeditFileBrowserMessageExtendContextMenu const))
+#define GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
+
GEDIT_TYPE_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU,\
+
GeditFileBrowserMessageExtendContextMenuClass))
+#define GEDIT_IS_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
+
GEDIT_TYPE_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU))
+#define GEDIT_IS_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
+
GEDIT_TYPE_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU))
+#define GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
+
GEDIT_TYPE_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU,\
+
GeditFileBrowserMessageExtendContextMenuClass))
+
+typedef struct _GeditFileBrowserMessageExtendContextMenu GeditFileBrowserMessageExtendContextMenu;
+typedef struct _GeditFileBrowserMessageExtendContextMenuClass
GeditFileBrowserMessageExtendContextMenuClass;
+typedef struct _GeditFileBrowserMessageExtendContextMenuPrivate
GeditFileBrowserMessageExtendContextMenuPrivate;
+
+struct _GeditFileBrowserMessageExtendContextMenu
+{
+ GeditMessage parent;
+
+ GeditFileBrowserMessageExtendContextMenuPrivate *priv;
+};
+
+struct _GeditFileBrowserMessageExtendContextMenuClass
+{
+ GeditMessageClass parent_class;
+};
+
+GType gedit_file_browser_message_extend_context_menu_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __GEDIT_FILE_BROWSER_MESSAGE_EXTEND_CONTEXT_MENU_H__ */
diff --git a/plugins/filebrowser/messages/messages.h b/plugins/filebrowser/messages/messages.h
index fb8acfb..e470e82 100644
--- a/plugins/filebrowser/messages/messages.h
+++ b/plugins/filebrowser/messages/messages.h
@@ -2,8 +2,8 @@
#define __GEDIT_FILE_BROWER_MESSAGES_MESSAGES_H__
#include "gedit-file-browser-message-activation.h"
-#include "gedit-file-browser-message-add-context-item.h"
#include "gedit-file-browser-message-add-filter.h"
+#include "gedit-file-browser-message-extend-context-menu.h"
#include "gedit-file-browser-message-get-root.h"
#include "gedit-file-browser-message-get-view.h"
#include "gedit-file-browser-message-id.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]