diff options
author | Martin Wehner <martin.wehner@gmail.com> | 2006-07-24 21:38:26 +0000 |
---|---|---|
committer | Martin Wehner <mwehner@src.gnome.org> | 2006-07-24 21:38:26 +0000 |
commit | 0a9fe18765d0376c3dcf544b1ca521300d76b7e1 (patch) | |
tree | daa6ea05f83829acbe843cff74ad0f37eb112a87 | |
parent | 8fa38099a1028f6904325c47d7960fcde9788159 (diff) | |
download | nautilus-0a9fe18765d0376c3dcf544b1ca521300d76b7e1.tar.gz |
Add extension versioning infrastructure and add nautilus-menu.[ch].
2006-07-24 Martin Wehner <martin.wehner@gmail.com>
* configure.in:
* libnautilus-extension/Makefile.am:
Add extension versioning infrastructure and add nautilus-menu.[ch].
* libnautilus-extension/nautilus-menu-item.[ch]:
Add and handle a 'menu' property and add a function
nautilus_menu_item_set_submenu.
* libnautilus-extension/nautilus-menu.[ch]:
New files implementing a submenu item.
* src/file-manager/fm-directory-view.c: (add_extension_menu_items),
(reset_extension_actions_menu):
Add extension menu items recursively.
* libnautilus-extension/nautilus-menu-provider.h:
Update include.
Extend extension API to support submenus. (#314579)
Patch from Raffaele Sandrini <rasa@gmx.ch>
-rw-r--r-- | ChangeLog | 24 | ||||
-rw-r--r-- | configure.in | 9 | ||||
-rw-r--r-- | libnautilus-extension/Makefile.am | 4 | ||||
-rw-r--r-- | libnautilus-extension/nautilus-menu-item.c | 31 | ||||
-rw-r--r-- | libnautilus-extension/nautilus-menu-item.h | 49 | ||||
-rw-r--r-- | libnautilus-extension/nautilus-menu-provider.h | 2 | ||||
-rw-r--r-- | libnautilus-extension/nautilus-menu.c | 132 | ||||
-rw-r--r-- | libnautilus-extension/nautilus-menu.h | 117 | ||||
-rw-r--r-- | src/file-manager/fm-directory-view.c | 40 |
9 files changed, 350 insertions, 58 deletions
@@ -1,3 +1,27 @@ +2006-07-24 Martin Wehner <martin.wehner@gmail.com> + + * configure.in: + * libnautilus-extension/Makefile.am: + Add extension versioning infrastructure and add nautilus-menu.[ch]. + + * libnautilus-extension/nautilus-menu-item.[ch]: + Add and handle a 'menu' property and add a function + nautilus_menu_item_set_submenu. + + * libnautilus-extension/nautilus-menu.[ch]: + New files implementing a submenu item. + + * src/file-manager/fm-directory-view.c: (add_extension_menu_items), + (reset_extension_actions_menu): + Add extension menu items recursively. + + * libnautilus-extension/nautilus-menu-provider.h: + Update include. + + Extend extension API to support submenus. (#314579) + + Patch from Raffaele Sandrini <rasa@gmx.ch> + 2006-07-11 Martin Wehner <martin.wehner@gmail.com> * configure.in: diff --git a/configure.in b/configure.in index d8dd9f103..d25871db9 100644 --- a/configure.in +++ b/configure.in @@ -22,6 +22,12 @@ m4_define(exif_minver, 0.5.12) m4_define(beagle_minver, 0.0.12) m4_define(tracker_minver, 0.0.1) +dnl 1. If the library code has changed at all since last release, then increment revision. +dnl 2. If any interfaces have been added, then increment current and set revision to 0. +dnl Interface break is not allowed. +m4_define(nautilus_extension_current, 2) +m4_define(nautilus_extension_revision, 0) + AC_INIT(nautilus, 2.15.90, [http://bugzilla.gnome.org/enter_bug.cgi?product=nautilus]) @@ -51,6 +57,9 @@ AC_SUBST(RSVG_REQUIRED, [rsvg_minver]) AC_SUBST(XML_REQUIRED, [xml_minver]) AC_SUBST(STARTUP_NOTIFICATION_REQUIRED, [startup_notification_minver]) +dnl We need to decrement current by one in the calculation of the age because +dnl the library was started with version "1:0:0" instead of "0:0:0" +AC_SUBST(NAUTILUS_EXTENSION_VERSION_INFO, [nautilus_extension_current]:[nautilus_extension_revision]:`expr [nautilus_extension_current] - 1`) AC_C_BIGENDIAN AC_C_CONST diff --git a/libnautilus-extension/Makefile.am b/libnautilus-extension/Makefile.am index 6ce5c7a78..4ddca7b12 100644 --- a/libnautilus-extension/Makefile.am +++ b/libnautilus-extension/Makefile.am @@ -11,7 +11,7 @@ INCLUDES=\ $(NULL) libnautilus_extension_la_LDFLAGS=\ - -version-info 1:0:0 \ + -version-info @NAUTILUS_EXTENSION_VERSION_INFO@ \ -no-undefined \ $(NULL) @@ -30,6 +30,7 @@ libnautilus_extension_include_HEADERS= \ nautilus-menu-provider.h \ nautilus-property-page-provider.h \ nautilus-property-page.h \ + nautilus-menu.h \ $(NULL) libnautilus_extension_la_SOURCES= \ @@ -44,6 +45,7 @@ libnautilus_extension_la_SOURCES= \ nautilus-menu-provider.c \ nautilus-property-page-provider.c \ nautilus-property-page.c \ + nautilus-menu.c \ $(NULL) pkgconfigdir=$(libdir)/pkgconfig diff --git a/libnautilus-extension/nautilus-menu-item.c b/libnautilus-extension/nautilus-menu-item.c index 714562751..7012301d4 100644 --- a/libnautilus-extension/nautilus-menu-item.c +++ b/libnautilus-extension/nautilus-menu-item.c @@ -23,7 +23,7 @@ */ #include <config.h> -#include "nautilus-menu-item.h" +#include "nautilus-menu.h" #include "nautilus-extension-i18n.h" enum { @@ -39,6 +39,7 @@ enum { PROP_ICON, PROP_SENSITIVE, PROP_PRIORITY, + PROP_MENU, LAST_PROP }; @@ -47,6 +48,7 @@ struct _NautilusMenuItemDetails { char *label; char *tip; char *icon; + NautilusMenu *menu; gboolean sensitive; gboolean priority; }; @@ -83,6 +85,12 @@ nautilus_menu_item_activate (NautilusMenuItem *item) g_signal_emit (item, signals[ACTIVATE], 0); } +void +nautilus_menu_item_set_submenu (NautilusMenuItem *item, NautilusMenu *menu) +{ + g_object_set (item, "menu", menu, NULL); +} + static void nautilus_menu_item_get_property (GObject *object, guint param_id, @@ -112,6 +120,9 @@ nautilus_menu_item_get_property (GObject *object, case PROP_PRIORITY : g_value_set_boolean (value, item->details->priority); break; + case PROP_MENU : + g_value_set_object (value, item->details->menu); + break; default : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -157,6 +168,13 @@ nautilus_menu_item_set_property (GObject *object, item->details->priority = g_value_get_boolean (value); g_object_notify (object, "priority"); break; + case PROP_MENU : + if (item->details->menu) { + g_object_unref (item->details->menu); + } + item->details->menu = g_object_ref (g_value_get_object (value)); + g_object_notify (object, "menu"); + break; default : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -174,6 +192,9 @@ nautilus_menu_item_finalize (GObject *object) g_free (item->details->label); g_free (item->details->tip); g_free (item->details->icon); + if (item->details->menu) { + g_object_unref (item->details->menu); + } g_free (item->details); @@ -185,6 +206,7 @@ nautilus_menu_item_instance_init (NautilusMenuItem *item) { item->details = g_new0 (NautilusMenuItemDetails, 1); item->details->sensitive = TRUE; + item->details->menu = NULL; } static void @@ -249,6 +271,13 @@ nautilus_menu_item_class_init (NautilusMenuItemClass *class) "Show priority text in toolbars", TRUE, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (class), + PROP_MENU, + g_param_spec_object ("menu", + "Menu", + "The menu belonging to this item. May be null.", + NAUTILUS_TYPE_MENU, + G_PARAM_READWRITE)); } GType diff --git a/libnautilus-extension/nautilus-menu-item.h b/libnautilus-extension/nautilus-menu-item.h index be443d0b3..883bacf26 100644 --- a/libnautilus-extension/nautilus-menu-item.h +++ b/libnautilus-extension/nautilus-menu-item.h @@ -25,53 +25,6 @@ #ifndef NAUTILUS_MENU_ITEM_H #define NAUTILUS_MENU_ITEM_H -#include <glib-object.h> -#include "nautilus-extension-types.h" - -G_BEGIN_DECLS - -#define NAUTILUS_TYPE_MENU_ITEM (nautilus_menu_item_get_type()) -#define NAUTILUS_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_MENU_ITEM, NautilusMenuItem)) -#define NAUTILUS_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_MENU_ITEM, NautilusMenuItemClass)) -#define NAUTILUS_MENU_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_MENU_ITEM)) -#define NAUTILUS_MENU_IS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NAUTILUS_TYPE_MENU_ITEM)) -#define NAUTILUS_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NAUTILUS_TYPE_MENU_ITEM, NautilusMenuItemClass)) - -typedef struct _NautilusMenuItem NautilusMenuItem; -typedef struct _NautilusMenuItemDetails NautilusMenuItemDetails; -typedef struct _NautilusMenuItemClass NautilusMenuItemClass; - -struct _NautilusMenuItem { - GObject parent; - - NautilusMenuItemDetails *details; -}; - -struct _NautilusMenuItemClass { - GObjectClass parent; - - void (*activate) (NautilusMenuItem *item); -}; - -GType nautilus_menu_item_get_type (void); -NautilusMenuItem *nautilus_menu_item_new (const char *name, - const char *label, - const char *tip, - const char *icon); - -void nautilus_menu_item_activate (NautilusMenuItem *item); - -/* NautilusMenuItem has the following properties: - * name (string) - the identifier for the menu item - * label (string) - the user-visible label of the menu item - * tip (string) - the tooltip of the menu item - * icon (string) - the name of the icon to display in the menu item - * sensitive (boolean) - whether the menu item is sensitive or not - * priority (boolean) - used for toolbar items, whether to show priority - * text. - */ - - -G_END_DECLS +#include "nautilus-menu.h" #endif diff --git a/libnautilus-extension/nautilus-menu-provider.h b/libnautilus-extension/nautilus-menu-provider.h index da335fb6a..d23a18172 100644 --- a/libnautilus-extension/nautilus-menu-provider.h +++ b/libnautilus-extension/nautilus-menu-provider.h @@ -34,7 +34,7 @@ #include <gtk/gtkwidget.h> #include "nautilus-extension-types.h" #include "nautilus-file-info.h" -#include "nautilus-menu-item.h" +#include "nautilus-menu.h" G_BEGIN_DECLS diff --git a/libnautilus-extension/nautilus-menu.c b/libnautilus-extension/nautilus-menu.c new file mode 100644 index 000000000..ad1c55c60 --- /dev/null +++ b/libnautilus-extension/nautilus-menu.c @@ -0,0 +1,132 @@ +/* + * nautilus-menu.h - Menus exported by NautilusMenuProvider objects. + * + * Copyright (C) 2005 Raffaele Sandrini + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Raffaele Sandrini <rasa@gmx.ch> + * + */ + +#include <config.h> +#include "nautilus-menu.h" +#include "nautilus-extension-i18n.h" + +#include <glib/glist.h> + +#define NAUTILUS_MENU_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_MENU, NautilusMenuPrivate)) + +struct _NautilusMenuPrivate { + GList *item_list; +}; + +void +nautilus_menu_append_item (NautilusMenu *this, NautilusMenuItem *item) +{ + g_return_if_fail (this != NULL); + g_return_if_fail (item != NULL); + + this->private->item_list = g_list_append (this->private->item_list, g_object_ref (item)); +} + +GList * +nautilus_menu_get_items (NautilusMenu *this) +{ + g_return_val_if_fail (this != NULL, NULL); + + GList *item_list = g_list_copy (this->private->item_list); + g_list_foreach (item_list, (GFunc)g_object_ref, NULL); + + return item_list; +} + +void +nautilus_menu_item_list_free (GList *item_list) +{ + g_return_if_fail (item_list != NULL); + + g_list_foreach (item_list, (GFunc)g_object_unref, NULL); + g_list_free (item_list); +} + +/* Type initialization */ + +static void +nautilus_menu_finalize (GObject *object) +{ + NautilusMenu *this = NAUTILUS_MENU (object); + GObjectClass *parent_class = g_type_class_peek_parent (NAUTILUS_MENU_GET_CLASS (object)); + + if (this->private->item_list) { + g_list_free (this->private->item_list); + } + + parent_class->finalize (object); +} + +static void +nautilus_menu_init (NautilusMenu *this) +{ + this->private = NAUTILUS_MENU_GET_PRIVATE (this); + + this->private->item_list = NULL; +} + +static void +nautilus_menu_class_init (NautilusMenuClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (NautilusMenuPrivate)); + + object_class->finalize = nautilus_menu_finalize; +} + +GType +nautilus_menu_get_type (void) +{ + static GType type = 0; + + if(type == 0) { + static const GTypeInfo info = { + sizeof (NautilusMenuClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) nautilus_menu_class_init, + (GClassFinalizeFunc) NULL, + NULL, + sizeof (NautilusMenu), + 0, + (GInstanceInitFunc) nautilus_menu_init, + }; + + type = g_type_register_static (G_TYPE_OBJECT, "NautilusMenu", &info, 0); + } + + return type; +} + +/* public constructors */ + +NautilusMenu * +nautilus_menu_new (void) +{ + NautilusMenu *obj; + + obj = NAUTILUS_MENU (g_object_new (NAUTILUS_TYPE_MENU, NULL)); + + return obj; +} diff --git a/libnautilus-extension/nautilus-menu.h b/libnautilus-extension/nautilus-menu.h new file mode 100644 index 000000000..d1511bd1d --- /dev/null +++ b/libnautilus-extension/nautilus-menu.h @@ -0,0 +1,117 @@ +/* + * nautilus-menu.h - Menus exported by NautilusMenuProvider objects. + * + * Copyright (C) 2005 Raffaele Sandrini + * Copyright (C) 2003 Novell, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Dave Camp <dave@ximian.com> + * Raffaele Sandrini <rasa@gmx.ch> + * + */ + +#ifndef NAUTILUS_MENU_H +#define NAUTILUS_MENU_H + +#include <glib-object.h> +#include "nautilus-extension-types.h" + + +G_BEGIN_DECLS + +/* NautilusMenu defines */ +#define NAUTILUS_TYPE_MENU (nautilus_menu_get_type ()) +#define NAUTILUS_MENU(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NAUTILUS_TYPE_MENU, NautilusMenu)) +#define NAUTILUS_MENU_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NAUTILUS_TYPE_MENU, NautilusMenuClass)) +#define NAUTILUS_IS_MENU(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NAUTILUS_TYPE_MENU)) +#define NAUTILUS_IS_MENU_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NAUTILUS_TYPE_MENU)) +#define NAUTILUS_MENU_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NAUTILUS_TYPE_MENU, NautilusMenuClass)) +/* NautilusMenuItem defines */ +#define NAUTILUS_TYPE_MENU_ITEM (nautilus_menu_item_get_type()) +#define NAUTILUS_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_MENU_ITEM, NautilusMenuItem)) +#define NAUTILUS_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_MENU_ITEM, NautilusMenuItemClass)) +#define NAUTILUS_MENU_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_MENU_ITEM)) +#define NAUTILUS_MENU_IS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NAUTILUS_TYPE_MENU_ITEM)) +#define NAUTILUS_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NAUTILUS_TYPE_MENU_ITEM, NautilusMenuItemClass)) + + +/* NautilusMenu types */ +typedef struct _NautilusMenu NautilusMenu; +typedef struct _NautilusMenuPrivate NautilusMenuPrivate; +typedef struct _NautilusMenuClass NautilusMenuClass; +/* NautilusMenuItem types */ +typedef struct _NautilusMenuItem NautilusMenuItem; +typedef struct _NautilusMenuItemDetails NautilusMenuItemDetails; +typedef struct _NautilusMenuItemClass NautilusMenuItemClass; + + +/* NautilusMenu structs */ +struct _NautilusMenu { + GObject parent; + NautilusMenuPrivate *private; +}; + +struct _NautilusMenuClass { + GObjectClass parent_class; +}; + +/* NautilusMenuItem structs */ +struct _NautilusMenuItem { + GObject parent; + + NautilusMenuItemDetails *details; +}; + +struct _NautilusMenuItemClass { + GObjectClass parent; + + void (*activate) (NautilusMenuItem *item); +}; + + +/* NautilusMenu methods */ +GType nautilus_menu_get_type (void); +NautilusMenu * nautilus_menu_new (void); + +void nautilus_menu_append_item (NautilusMenu *this, + NautilusMenuItem *item); +GList* nautilus_menu_get_items (NautilusMenu *this); +void nautilus_menu_item_list_free (GList *item_list); + +/* NautilusMenuItem methods */ +GType nautilus_menu_item_get_type (void); +NautilusMenuItem *nautilus_menu_item_new (const char *name, + const char *label, + const char *tip, + const char *icon); + +void nautilus_menu_item_activate (NautilusMenuItem *item); +void nautilus_menu_item_set_submenu (NautilusMenuItem *item, + NautilusMenu *menu); +/* NautilusMenuItem has the following properties: + * name (string) - the identifier for the menu item + * label (string) - the user-visible label of the menu item + * tip (string) - the tooltip of the menu item + * icon (string) - the name of the icon to display in the menu item + * sensitive (boolean) - whether the menu item is sensitive or not + * priority (boolean) - used for toolbar items, whether to show priority + * text. + * menu (NautilusMenu) - The menu belonging to this item. May be null. + */ + +G_END_DECLS + +#endif /* NAUTILUS_MENU_H */ diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c index 1856d619f..f7bc9fe8d 100644 --- a/src/file-manager/fm-directory-view.c +++ b/src/file-manager/fm-directory-view.c @@ -5042,7 +5042,8 @@ activate_check_mime_types (FMDirectoryView *view, static void add_extension_menu_items (FMDirectoryView *view, GList *files, - GList *menu_items) + GList *menu_items, + const char *subdirectory) { GtkUIManager *ui_manager; GList *l; @@ -5051,27 +5052,52 @@ add_extension_menu_items (FMDirectoryView *view, for (l = menu_items; l; l = l->next) { NautilusMenuItem *item; + NautilusMenu *menu; GtkAction *action; + char *path; item = NAUTILUS_MENU_ITEM (l->data); + g_object_get (item, "menu", &menu, NULL); + action = add_extension_action_for_files (view, item, files); - + + path = g_build_path ("/", FM_DIRECTORY_VIEW_POPUP_PATH_EXTENSION_ACTIONS, subdirectory, NULL); gtk_ui_manager_add_ui (ui_manager, view->details->extensions_menu_merge_id, - FM_DIRECTORY_VIEW_POPUP_PATH_EXTENSION_ACTIONS, + path, gtk_action_get_name (action), gtk_action_get_name (action), - GTK_UI_MANAGER_MENUITEM, + (menu != NULL) ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM, FALSE); + g_free (path); + path = g_build_path ("/", FM_DIRECTORY_VIEW_MENU_PATH_EXTENSION_ACTIONS_PLACEHOLDER, subdirectory, NULL); gtk_ui_manager_add_ui (ui_manager, view->details->extensions_menu_merge_id, - FM_DIRECTORY_VIEW_MENU_PATH_EXTENSION_ACTIONS_PLACEHOLDER, + path, gtk_action_get_name (action), gtk_action_get_name (action), - GTK_UI_MANAGER_MENUITEM, + (menu != NULL) ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM, FALSE); + g_free (path); + + /* recursively fill the menu */ + if (menu != NULL) { + char *subdir; + GList *children; + + children = nautilus_menu_get_items (menu); + + subdir = g_build_path ("/", subdirectory, gtk_action_get_name (action), NULL); + add_extension_menu_items (view, + files, + children, + subdir); + + nautilus_menu_item_list_free (children); + g_free (subdir); + } } } @@ -5097,7 +5123,7 @@ reset_extension_actions_menu (FMDirectoryView *view, GList *selection) items = get_all_extension_menu_items (gtk_widget_get_toplevel (GTK_WIDGET (view)), selection); if (items != NULL) { - add_extension_menu_items (view, selection, items); + add_extension_menu_items (view, selection, items, ""); for (l = items; l != NULL; l = l->next) { g_object_unref (l->data); |