gedit r6780 - in trunk: . plugins/filebrowser
- From: jessevdk svn gnome org
- To: svn-commits-list gnome org
- Subject: gedit r6780 - in trunk: . plugins/filebrowser
- Date: Thu, 1 Jan 2009 18:30:41 +0000 (UTC)
Author: jessevdk
Date: Thu Jan 1 18:30:41 2009
New Revision: 6780
URL: http://svn.gnome.org/viewvc/gedit?rev=6780&view=rev
Log:
* plugins/filebrowser/gedit-file-browser-messages.c: added
add_context_item and remove_context_item messages (for extending the
context menu)
Modified:
trunk/ChangeLog
trunk/plugins/filebrowser/gedit-file-browser-messages.c
Modified: trunk/plugins/filebrowser/gedit-file-browser-messages.c
==============================================================================
--- trunk/plugins/filebrowser/gedit-file-browser-messages.c (original)
+++ trunk/plugins/filebrowser/gedit-file-browser-messages.c Thu Jan 1 18:30:41 2009
@@ -20,6 +20,9 @@
guint root_changed_id;
guint begin_loading_id;
guint end_loading_id;
+
+ GList *merge_ids;
+ GtkActionGroup *merged_actions;
GeditMessageBus *bus;
GeditFileBrowserWidget *widget;
@@ -41,6 +44,8 @@
GeditFileBrowserWidget *widget)
{
WindowData *data = g_slice_new (WindowData);
+ GtkUIManager *manager;
+ GList *groups;
data->bus = gedit_window_get_message_bus (window);
data->widget = widget;
@@ -48,11 +53,21 @@
g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)gtk_tree_row_reference_free);
+
data->filters = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify)g_free,
NULL);
-
+
+ manager = gedit_file_browser_widget_get_ui_manager (widget);
+
+ data->merge_ids = NULL;
+ data->merged_actions = gtk_action_group_new ("MessageMergedActions");
+
+ groups = gtk_ui_manager_get_action_groups (manager);
+ gtk_ui_manager_insert_action_group (manager, data->merged_actions, g_list_length (groups));
+ g_list_free (groups);
+
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, data);
return data;
@@ -68,10 +83,21 @@
window_data_free (GeditWindow *window)
{
WindowData *data = get_window_data (window);
-
+ GtkUIManager *manager;
+ GList *item;
+
g_hash_table_destroy (data->row_tracking);
g_hash_table_destroy (data->filters);
+ manager = gedit_file_browser_widget_get_ui_manager (data->widget);
+ gtk_ui_manager_remove_action_group (manager, data->merged_actions);
+
+ for (item = data->merge_ids; item; item = item->next)
+ gtk_ui_manager_remove_ui (manager, GPOINTER_TO_INT (item->data));
+
+ g_list_free (data->merge_ids);
+ g_object_unref (data->merged_actions);
+
g_slice_free (WindowData, data);
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
@@ -529,6 +555,78 @@
}
static void
+message_add_context_item_cb (GeditMessageBus *bus,
+ GeditMessage *message,
+ WindowData *data)
+{
+ GtkAction *action = NULL;
+ gchar *path = NULL;
+ gchar *name;
+ GtkUIManager *manager;
+ guint merge_id;
+
+ gedit_message_get (message,
+ "action", &action,
+ "path", &path,
+ NULL);
+
+ if (!action || !path)
+ {
+ if (action)
+ g_object_unref (action);
+
+ g_free (path);
+ return;
+ }
+
+ gtk_action_group_add_action (data->merged_actions, action);
+ manager = gedit_file_browser_widget_get_ui_manager (data->widget);
+ name = g_strconcat (gtk_action_get_name (action), "MenuItem", NULL);
+ merge_id = gtk_ui_manager_new_merge_id (manager);
+
+ gtk_ui_manager_add_ui (manager,
+ merge_id,
+ path,
+ name,
+ gtk_action_get_name (action),
+ GTK_UI_MANAGER_AUTO,
+ FALSE);
+
+ if (gtk_ui_manager_get_widget (manager, path))
+ {
+ data->merge_ids = g_list_prepend (data->merge_ids, GINT_TO_POINTER (merge_id));
+ gedit_message_set (message, "id", merge_id, NULL);
+ }
+ else
+ {
+ gedit_message_set (message, "id", 0, NULL);
+ }
+
+ g_object_unref (action);
+ g_free (path);
+ g_free (name);
+}
+
+static void
+message_remove_context_item_cb (GeditMessageBus *bus,
+ GeditMessage *message,
+ WindowData *data)
+{
+ guint merge_id = 0;
+ GtkUIManager *manager;
+
+ gedit_message_get (message, "id", &merge_id, NULL);
+
+ if (merge_id == 0)
+ return;
+
+ manager = gedit_file_browser_widget_get_ui_manager (data->widget);
+
+ data->merge_ids = g_list_remove (data->merge_ids, GINT_TO_POINTER (merge_id));
+ gtk_ui_manager_remove_ui (manager, merge_id);
+}
+
+static void
register_methods (GeditWindow *window,
GeditFileBrowserWidget *widget)
{
@@ -570,6 +668,19 @@
"id", G_TYPE_ULONG,
NULL);
+ gedit_message_bus_register (bus,
+ MESSAGE_OBJECT_PATH, "add_context_item",
+ 1,
+ "action", GTK_TYPE_ACTION,
+ "id", G_TYPE_UINT,
+ NULL);
+
+ gedit_message_bus_register (bus,
+ MESSAGE_OBJECT_PATH, "remove_context_item",
+ 0,
+ "id", G_TYPE_UINT,
+ NULL);
+
gedit_message_bus_register (bus, MESSAGE_OBJECT_PATH, "up", 0, NULL);
gedit_message_bus_register (bus, MESSAGE_OBJECT_PATH, "history_back", 0, NULL);
@@ -597,6 +708,9 @@
BUS_CONNECT (bus, add_filter, window);
BUS_CONNECT (bus, remove_filter, data);
+ BUS_CONNECT (bus, add_context_item, data);
+ BUS_CONNECT (bus, remove_context_item, data);
+
BUS_CONNECT (bus, up, data);
BUS_CONNECT (bus, history_back, data);
BUS_CONNECT (bus, history_forward, data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]