From 20801a94aaba0002a8adb7df3829494e4164d5bf Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Thu, 9 Aug 2001 23:37:56 +0000 Subject: Add the menu items using the EShellUserCreatableItemsHandler. * e-shell-view.c (e_shell_view_construct): Add the menu items using the EShellUserCreatableItemsHandler. * e-shell-user-creatable-items-handler.c: New. * e-shell-user-creatable-items-handler.h: New. * e-shell.c: New member `user_creatable_items_handler' in `EShellPrivate'. (init): Initialize to NULL. (destroy): Unref. (e_shell_construct): Create here. (e_shell_get_user_creatable_items_handler): New accessor. (setup_components): Add the registered components to the user_creatable_items_handler. * evolution-test-component.c (factory_fn): Add a couple sample user-creatable items. (user_create_new_item_callback): New callback for the "user_create_new_item" signal on the EvolutionShellComponent. (factory_fn): Connect. * e-shell.c (e_shell_get_component_registry): New. * evolution-shell-component.c: New enum value `USER_CREATE_NEW_ITEM'. New member `user_create_item_types' in `_EvolutionShellComponentPrivate'. (init): Init to NULL. (impl_destroy): Free it. (user_creatable_item_type_free): New helper function. (user_creatable_item_type_new): New helper function. (impl_userCreateNewItem): New, implementation for ::userCreateNewItem. (class_init): Install the "user_create_new_item" signal and the userCreateNewItem impl. (impl__get_external_uri_schemas): Renamed from `impl_ShellComponent__get_external_uri_schemas'. (impl___get_supported_types): Renamed from `impl_ShellComponent__get_supported_types'. (impl__get_user_creatable_item_types): New, implementation for the `user_creatable_item_types' attribute. (class_init): Install it. (evolution_shell_component_add_user_creatable_item): New. * evolution-shell-component.h: Added signal `user_create_new_item'. * Evolution-ShellComponent.idl: Added typedefs `UserCreatableItemType', `UserCreatableItemTypeList'. New attribute `user_creatable_item_types'. (userCreateNewItem): New. svn path=/trunk/; revision=11849 --- shell/evolution-shell-component.c | 164 ++++++++++++++++++++++++++++++++++---- 1 file changed, 148 insertions(+), 16 deletions(-) (limited to 'shell/evolution-shell-component.c') diff --git a/shell/evolution-shell-component.c b/shell/evolution-shell-component.c index bb1e7481f9..2ff908aa68 100644 --- a/shell/evolution-shell-component.c +++ b/shell/evolution-shell-component.c @@ -42,6 +42,14 @@ static GtkObjectClass *parent_class = NULL; +struct _UserCreatableItemType { + char *id; + char *description; + char *menu_description; + char menu_shortcut; +}; +typedef struct _UserCreatableItemType UserCreatableItemType; + struct _EvolutionShellComponentPrivate { GList *folder_types; /* EvolutionShellComponentFolderType */ GList *external_uri_schemas; /* char * */ @@ -55,6 +63,8 @@ struct _EvolutionShellComponentPrivate { EvolutionShellClient *owner_client; + GSList *user_creatable_item_types; /* UserCreatableItemType */ + void *closure; }; @@ -63,11 +73,42 @@ enum { OWNER_UNSET, DEBUG, HANDLE_EXTERNAL_URI, + USER_CREATE_NEW_ITEM, LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; + +/* UserCreatableItemType handling. */ + +static UserCreatableItemType * +user_creatable_item_type_new (const char *id, + const char *description, + const char *menu_description, + char menu_shortcut) +{ + UserCreatableItemType *type; + + type = g_new (UserCreatableItemType, 1); + type->id = g_strdup (id); + type->description = g_strdup (description); + type->menu_description = g_strdup (menu_description); + type->menu_shortcut = menu_shortcut; + + return type; +} + +static void +user_creatable_item_type_free (UserCreatableItemType *type) +{ + g_free (type->id); + g_free (type->description); + g_free (type->menu_description); + + g_free (type); +} + /* Helper functions. */ @@ -127,8 +168,8 @@ fill_corba_sequence_from_null_terminated_string_array (CORBA_sequence_CORBA_stri /* CORBA interface implementation. */ static GNOME_Evolution_FolderTypeList * -impl_ShellComponent__get_supported_types (PortableServer_Servant servant, - CORBA_Environment *ev) +impl__get_supported_types (PortableServer_Servant servant, + CORBA_Environment *ev) { BonoboObject *bonobo_object; EvolutionShellComponent *shell_component; @@ -168,8 +209,8 @@ impl_ShellComponent__get_supported_types (PortableServer_Servant servant, } static GNOME_Evolution_URISchemaList * -impl_ShellComponent__get_external_uri_schemas (PortableServer_Servant servant, - CORBA_Environment *ev) +impl__get_external_uri_schemas (PortableServer_Servant servant, + CORBA_Environment *ev) { EvolutionShellComponent *shell_component; EvolutionShellComponentPrivate *priv; @@ -207,6 +248,42 @@ impl_ShellComponent__get_external_uri_schemas (PortableServer_Servant servant, return uri_schema_list; } +static GNOME_Evolution_UserCreatableItemTypeList * +impl__get_user_creatable_item_types (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + EvolutionShellComponent *shell_component; + EvolutionShellComponentPrivate *priv; + GNOME_Evolution_UserCreatableItemTypeList *list; + GSList *p; + int i; + + shell_component = EVOLUTION_SHELL_COMPONENT (bonobo_object_from_servant (servant)); + priv = shell_component->priv; + + list = GNOME_Evolution_UserCreatableItemTypeList__alloc (); + list->_maximum = g_slist_length (priv->user_creatable_item_types); + list->_length = list->_maximum; + list->_buffer = CORBA_sequence_GNOME_Evolution_UserCreatableItemType_allocbuf (list->_maximum); + + for (p = priv->user_creatable_item_types, i = 0; p != NULL; p = p->next, i ++) { + GNOME_Evolution_UserCreatableItemType *corba_type; + const UserCreatableItemType *type; + + corba_type = list->_buffer + i; + type = (const UserCreatableItemType *) p->data; + + corba_type->id = CORBA_string_dup (type->id); + corba_type->description = CORBA_string_dup (type->description); + corba_type->menuDescription = CORBA_string_dup (type->menu_description); + corba_type->menuShortcut = type->menu_shortcut; + } + + CORBA_sequence_set_release (list, TRUE); + + return list; +} + static void impl_setOwner (PortableServer_Servant servant, const GNOME_Evolution_Shell shell, @@ -449,6 +526,22 @@ impl_populateFolderContextMenu (PortableServer_Servant servant, bonobo_object_unref (BONOBO_OBJECT (uic)); } +static void +impl_userCreateNewItem (PortableServer_Servant servant, + const CORBA_char *id, + CORBA_Environment *ev) +{ + EvolutionShellComponent *shell_component; + EvolutionShellComponentPrivate *priv; + + shell_component = EVOLUTION_SHELL_COMPONENT (bonobo_object_from_servant (servant)); + priv = shell_component->priv; + + /* FIXME: Check that the type is good. */ + + gtk_signal_emit (GTK_OBJECT (shell_component), signals[USER_CREATE_NEW_ITEM], id); +} + /* GtkObject methods. */ @@ -458,7 +551,7 @@ destroy (GtkObject *object) EvolutionShellComponent *shell_component; EvolutionShellComponentPrivate *priv; CORBA_Environment ev; - GList *p; + GSList *p; shell_component = EVOLUTION_SHELL_COMPONENT (object); @@ -487,6 +580,10 @@ destroy (GtkObject *object) e_free_string_list (priv->external_uri_schemas); + for (p = priv->user_creatable_item_types; p != NULL; p = p->next) + user_creatable_item_type_free ((UserCreatableItemType *) p->data); + g_slist_free (priv->user_creatable_item_types); + g_free (priv); parent_class->destroy (object); @@ -538,21 +635,32 @@ class_init (EvolutionShellComponentClass *klass) GTK_TYPE_NONE, 1, GTK_TYPE_STRING); + signals[USER_CREATE_NEW_ITEM] + = gtk_signal_new ("user_create_new_item", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (EvolutionShellComponentClass, user_create_new_item), + gtk_marshal_NONE__STRING, + GTK_TYPE_NONE, 1, + GTK_TYPE_STRING); + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); parent_class = gtk_type_class (PARENT_TYPE); - epv->_get_supported_types = impl_ShellComponent__get_supported_types; - epv->_get_external_uri_schemas = impl_ShellComponent__get_external_uri_schemas; - epv->setOwner = impl_setOwner; - epv->unsetOwner = impl_unsetOwner; - epv->debug = impl_debug; - epv->createView = impl_createView; - epv->handleExternalURI = impl_handleExternalURI; - epv->createFolderAsync = impl_createFolderAsync; - epv->removeFolderAsync = impl_removeFolderAsync; - epv->xferFolderAsync = impl_xferFolderAsync; - epv->populateFolderContextMenu = impl_populateFolderContextMenu; + epv->_get_supported_types = impl__get_supported_types; + epv->_get_external_uri_schemas = impl__get_external_uri_schemas; + epv->_get_user_creatable_item_types = impl__get_user_creatable_item_types; + epv->setOwner = impl_setOwner; + epv->unsetOwner = impl_unsetOwner; + epv->debug = impl_debug; + epv->createView = impl_createView; + epv->handleExternalURI = impl_handleExternalURI; + epv->createFolderAsync = impl_createFolderAsync; + epv->removeFolderAsync = impl_removeFolderAsync; + epv->xferFolderAsync = impl_xferFolderAsync; + epv->populateFolderContextMenu = impl_populateFolderContextMenu; + epv->userCreateNewItem = impl_userCreateNewItem; } static void @@ -676,6 +784,30 @@ evolution_shell_component_get_owner (EvolutionShellComponent *shell_component) return shell_component->priv->owner_client; } + +void +evolution_shell_component_add_user_creatable_item (EvolutionShellComponent *shell_component, + const char *id, + const char *description, + const char *menu_description, + char menu_shortcut) +{ + EvolutionShellComponentPrivate *priv; + UserCreatableItemType *type; + + g_return_if_fail (shell_component != NULL); + g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT (shell_component)); + g_return_if_fail (id != NULL); + g_return_if_fail (description != NULL); + g_return_if_fail (menu_description != NULL); + + priv = shell_component->priv; + + type = user_creatable_item_type_new (id, description, menu_description, menu_shortcut); + + priv->user_creatable_item_types = g_slist_prepend (priv->user_creatable_item_types, type); +} + E_MAKE_X_TYPE (evolution_shell_component, "EvolutionShellComponent", EvolutionShellComponent, class_init, init, PARENT_TYPE, -- cgit v1.2.3