diff options
author | Ettore Perazzoli <ettore@src.gnome.org> | 2003-11-13 13:56:14 +0800 |
---|---|---|
committer | Ettore Perazzoli <ettore@src.gnome.org> | 2003-11-13 13:56:14 +0800 |
commit | 7a5ecfbb6c09b5350e5ce0600f42098eb6a2f5de (patch) | |
tree | 4fa518fa98738666004beb7a329560a579396227 /shell | |
parent | 35b15cb0516407c8ab0bd3ba403e04dffaaef0a1 (diff) | |
download | gsoc2013-evolution-7a5ecfbb6c09b5350e5ce0600f42098eb6a2f5de.tar gsoc2013-evolution-7a5ecfbb6c09b5350e5ce0600f42098eb6a2f5de.tar.gz gsoc2013-evolution-7a5ecfbb6c09b5350e5ce0600f42098eb6a2f5de.tar.bz2 gsoc2013-evolution-7a5ecfbb6c09b5350e5ce0600f42098eb6a2f5de.tar.lz gsoc2013-evolution-7a5ecfbb6c09b5350e5ce0600f42098eb6a2f5de.tar.xz gsoc2013-evolution-7a5ecfbb6c09b5350e5ce0600f42098eb6a2f5de.tar.zst gsoc2013-evolution-7a5ecfbb6c09b5350e5ce0600f42098eb6a2f5de.zip |
New signal "component_changed". (class_init): Install. (switch_view):
* e-shell-window.c: New signal "component_changed".
(class_init): Install.
(switch_view): Emit.
(e_shell_window_new): Call
e_user_creatable_items_handler_attach_menus() to attach the
"New..." menus.
(e_shell_window_peek_current_component_id): New.
(e_shell_window_peek_shell): Add precondition.
(e_shell_window_peek_current_component_id): Likewise.
(e_shell_window_peek_bonobo_ui_component): Likewise.
* e-user-creatable-items-handler.c: New.
* e-user-creatable-items-handler.h: New.
* e-shell-window.h: #include <bonobo/bonobo-ui-component.h>.
* e-shell.c (struct _EShellPrivate): Add member
user_creatable_items_handler.
(e_shell_get_user_creatable_items_handler): Remove.
(e_shell_peek_user_creatable_items_handler): New.
* Evolution-Component.idl (GNOME.Evolution.RequestCreateItem): New
method.
(GNOME.Evolution.creatableItems): New attribute.
* e-shell-user-creatable-items-handler.c: Remove.
* e-shell-user-creatable-items-handler.h: Remove.
svn path=/trunk/; revision=23314
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ChangeLog | 32 | ||||
-rw-r--r-- | shell/Evolution-Component.idl | 23 | ||||
-rw-r--r-- | shell/Makefile.am | 3 | ||||
-rw-r--r-- | shell/e-shell-user-creatable-items-handler.h | 74 | ||||
-rw-r--r-- | shell/e-shell-window.c | 37 | ||||
-rw-r--r-- | shell/e-shell-window.h | 8 | ||||
-rw-r--r-- | shell/e-shell.c | 28 | ||||
-rw-r--r-- | shell/e-shell.h | 6 | ||||
-rw-r--r-- | shell/e-user-creatable-items-handler.c (renamed from shell/e-shell-user-creatable-items-handler.c) | 346 | ||||
-rw-r--r-- | shell/e-user-creatable-items-handler.h | 73 |
10 files changed, 361 insertions, 269 deletions
diff --git a/shell/ChangeLog b/shell/ChangeLog index 07b908529a..93bfd273f8 100644 --- a/shell/ChangeLog +++ b/shell/ChangeLog @@ -1,3 +1,35 @@ +2003-11-13 Ettore Perazzoli <ettore@ximian.com> + + * e-shell-window.c: New signal "component_changed". + (class_init): Install. + (switch_view): Emit. + (e_shell_window_new): Call + e_user_creatable_items_handler_attach_menus() to attach the + "New..." menus. + (e_shell_window_peek_current_component_id): New. + (e_shell_window_peek_shell): Add precondition. + (e_shell_window_peek_current_component_id): Likewise. + (e_shell_window_peek_bonobo_ui_component): Likewise. + + * e-user-creatable-items-handler.c: New. + * e-user-creatable-items-handler.h: New. + + * e-shell-window.h: #include <bonobo/bonobo-ui-component.h>. + + * e-shell.c (struct _EShellPrivate): Add member + user_creatable_items_handler. + (e_shell_get_user_creatable_items_handler): Remove. + (e_shell_peek_user_creatable_items_handler): New. + + * Evolution.idl: Don't #include Evolution-ShellComponent.idl. + + * Evolution-Component.idl (GNOME.Evolution.RequestCreateItem): New + method. + (GNOME.Evolution.creatableItems): New attribute. + + * e-shell-user-creatable-items-handler.c: Remove. + * e-shell-user-creatable-items-handler.h: Remove. + 2003-11-12 Ettore Perazzoli <ettore@ximian.com> * e-shell-window.c (e_shell_window_switch_to_component): Call diff --git a/shell/Evolution-Component.idl b/shell/Evolution-Component.idl index c8159ff8fa..8c225ee357 100644 --- a/shell/Evolution-Component.idl +++ b/shell/Evolution-Component.idl @@ -13,6 +13,18 @@ module GNOME { module Evolution { + /* A type of item that the component can create when asked by the user, + e.g. a mail message or an appointment. */ + struct CreatableItemType { + string id; + string description; + string menuDescription; + string tooltip; + char menuShortcut; + string iconName; + }; + typedef sequence <CreatableItemType> CreatableItemTypeList; + interface Component : Bonobo::Unknown { exception Failed {}; @@ -34,6 +46,17 @@ module Evolution { is FALSE) */ void interactive (in boolean now_interactive, in unsigned long new_view_xid); + + + /*** The following stuff is needed to build the "New" toolbar + item as well as the "File -> New" submenu. ***/ + + /* List of creatable items. */ + readonly attribute CreatableItemTypeList userCreatableItems; + + /* Pop up a new editing dialog for the item with the specified + @item_type_name. */ + void requestCreateItem (in string item_type_name); }; }; diff --git a/shell/Makefile.am b/shell/Makefile.am index ffb11d12db..f34e837465 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -204,7 +204,6 @@ evolution_SOURCES = \ e-shell-settings-dialog.h \ e-shell-startup-wizard.c \ e-shell-startup-wizard.h \ - e-shell-user-creatable-items-handler.h \ e-shell-view.h \ e-shell-window-commands.c \ e-shell-window-commands.h \ @@ -214,6 +213,8 @@ evolution_SOURCES = \ e-shell.h \ e-sidebar.c \ e-sidebar.h \ + e-user-creatable-items-handler.c \ + e-user-creatable-items-handler.h \ e-task-bar.c \ e-task-bar.h \ e-task-widget.c \ diff --git a/shell/e-shell-user-creatable-items-handler.h b/shell/e-shell-user-creatable-items-handler.h deleted file mode 100644 index 228603573a..0000000000 --- a/shell/e-shell-user-creatable-items-handler.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-shell-user-creatable-items-handler.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifndef _E_SHELL_USER_CREATABLE_ITEMS_HANDLER_H_ -#define _E_SHELL_USER_CREATABLE_ITEMS_HANDLER_H_ - -#include "evolution-shell-component-client.h" - -#include <glib-object.h> -#include <bonobo/bonobo-ui-component.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define E_TYPE_SHELL_USER_CREATABLE_ITEMS_HANDLER (e_shell_user_creatable_items_handler_get_type ()) -#define E_SHELL_USER_CREATABLE_ITEMS_HANDLER(obj) (GTK_CHECK_CAST ((obj), E_TYPE_SHELL_USER_CREATABLE_ITEMS_HANDLER, EShellUserCreatableItemsHandler)) -#define E_SHELL_USER_CREATABLE_ITEMS_HANDLER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_SHELL_USER_CREATABLE_ITEMS_HANDLER, EShellUserCreatableItemsHandlerClass)) -#define E_IS_SHELL_USER_CREATABLE_ITEMS_HANDLER(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_SHELL_USER_CREATABLE_ITEMS_HANDLER)) -#define E_IS_SHELL_USER_CREATABLE_ITEMS_HANDLER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_SHELL_USER_CREATABLE_ITEMS_HANDLER)) - - -typedef struct _EShellUserCreatableItemsHandler EShellUserCreatableItemsHandler; -typedef struct _EShellUserCreatableItemsHandlerPrivate EShellUserCreatableItemsHandlerPrivate; -typedef struct _EShellUserCreatableItemsHandlerClass EShellUserCreatableItemsHandlerClass; - -#include "e-shell-view.h" - -struct _EShellUserCreatableItemsHandler { - GObject parent; - - EShellUserCreatableItemsHandlerPrivate *priv; -}; - -struct _EShellUserCreatableItemsHandlerClass { - GObjectClass parent_class; -}; - - -GtkType e_shell_user_creatable_items_handler_get_type (void); -EShellUserCreatableItemsHandler *e_shell_user_creatable_items_handler_new (void); - -void e_shell_user_creatable_items_handler_add_component (EShellUserCreatableItemsHandler *handler, - const char *id, - EvolutionShellComponentClient *shell_component_client); - -void e_shell_user_creatable_items_handler_attach_menus (EShellUserCreatableItemsHandler *handler, - EShellView *shell_view); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_SHELL_USER_CREATABLE_ITEMS_HANDLER_H_ */ diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c index 586f7e6419..903c091447 100644 --- a/shell/e-shell-window.c +++ b/shell/e-shell-window.c @@ -28,6 +28,7 @@ #include "e-component-registry.h" #include "e-shell-window-commands.h" +#include "e-shell-marshal.h" #include "e-sidebar.h" #include "e-util/e-lang-utils.h" @@ -91,6 +92,14 @@ struct _EShellWindowPrivate { }; +enum { + COMPONENT_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + + /* ComponentView handling. */ static ComponentView * @@ -253,6 +262,8 @@ switch_view (EShellWindow *window, ComponentView *component_view) NULL); g_object_unref (gconf_client); + + g_signal_emit (window, signals[COMPONENT_CHANGED], 0); } @@ -375,6 +386,14 @@ class_init (EShellWindowClass *class) object_class->finalize = impl_finalize; parent_class = g_type_class_peek_parent (class); + + signals[COMPONENT_CHANGED] = g_signal_new ("component_changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EShellWindowClass, component_changed), + NULL, NULL, + e_shell_marshal_NONE__NONE, + G_TYPE_NONE, 0); } static void @@ -447,6 +466,8 @@ e_shell_window_new (EShell *shell, } } + e_user_creatable_items_handler_attach_menus (e_shell_peek_user_creatable_items_handler (shell), window); + return GTK_WIDGET (window); } @@ -482,9 +503,23 @@ e_shell_window_switch_to_component (EShellWindow *window, const char *component_ } +const char * +e_shell_window_peek_current_component_id (EShellWindow *window) +{ + g_return_val_if_fail (E_IS_SHELL_WINDOW (window), NULL); + + if (window->priv->current_view == NULL) + return NULL; + + return window->priv->current_view->component_id; +} + + EShell * e_shell_window_peek_shell (EShellWindow *window) { + g_return_val_if_fail (E_IS_SHELL_WINDOW (window), NULL); + return window->priv->shell; } @@ -492,6 +527,8 @@ e_shell_window_peek_shell (EShellWindow *window) BonoboUIComponent * e_shell_window_peek_bonobo_ui_component (EShellWindow *window) { + g_return_val_if_fail (E_IS_SHELL_WINDOW (window), NULL); + return window->priv->ui_component; } diff --git a/shell/e-shell-window.h b/shell/e-shell-window.h index 2d1848b034..01c231c329 100644 --- a/shell/e-shell-window.h +++ b/shell/e-shell-window.h @@ -24,6 +24,7 @@ #define _E_SHELL_WINDOW_H_ #include <bonobo/bonobo-window.h> +#include <bonobo/bonobo-ui-component.h> #define E_TYPE_SHELL_WINDOW (e_shell_window_get_type ()) #define E_SHELL_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_SHELL_WINDOW, EShellWindow)) @@ -44,6 +45,8 @@ struct _EShellWindow { struct _EShellWindowClass { BonoboWindowClass parent_class; + + void (* component_changed) (EShellWindow *window); }; @@ -55,8 +58,9 @@ GType e_shell_window_get_type (void); GtkWidget *e_shell_window_new (EShell *shell, const char *component_id); -void e_shell_window_switch_to_component (EShellWindow *shell, - const char *component_id); +void e_shell_window_switch_to_component (EShellWindow *shell, + const char *component_id); +const char *e_shell_window_peek_current_component_id (EShellWindow *shell); EShell *e_shell_window_peek_shell (EShellWindow *window); BonoboUIComponent *e_shell_window_peek_bonobo_ui_component (EShellWindow *window); diff --git a/shell/e-shell.c b/shell/e-shell.c index d4b8fdf131..e69b04a0a3 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -78,6 +78,7 @@ struct _EShellPrivate { GList *windows; + EUserCreatableItemsHandler *user_creatable_items_handler; EUriSchemaRegistry *uri_schema_registry; EComponentRegistry *component_registry; @@ -354,6 +355,11 @@ impl_dispose (GObject *object) priv->is_initialized = FALSE; + if (priv->user_creatable_items_handler != NULL) { + g_object_unref (priv->user_creatable_items_handler); + priv->user_creatable_items_handler = NULL; + } + if (priv->uri_schema_registry != NULL) { g_object_unref (priv->uri_schema_registry); priv->uri_schema_registry = NULL; @@ -460,8 +466,9 @@ e_shell_init (EShell *shell) EShellPrivate *priv; priv = g_new0 (EShellPrivate, 1); - priv->line_status = E_SHELL_LINE_STATUS_OFFLINE; - priv->component_registry = e_component_registry_new (); + priv->line_status = E_SHELL_LINE_STATUS_OFFLINE; + priv->component_registry = e_component_registry_new (); + priv->user_creatable_items_handler = e_user_creatable_items_handler_new (priv->component_registry); shell->priv = priv; } @@ -866,14 +873,6 @@ e_shell_show_settings (EShell *shell, } -EShellUserCreatableItemsHandler * -e_shell_get_user_creatable_items_handler (EShell *shell) -{ - g_assert_not_reached (); /* FIXME */ - return NULL; -} - - const char * e_shell_construct_result_to_string (EShellConstructResult result) { @@ -954,4 +953,13 @@ e_shell_prepare_for_quit (EShell *shell) } +EUserCreatableItemsHandler * +e_shell_peek_user_creatable_items_handler (EShell *shell) +{ + g_return_val_if_fail (E_IS_SHELL (shell), NULL); + + return shell->priv->user_creatable_items_handler; +} + + BONOBO_TYPE_FUNC_FULL (EShell, GNOME_Evolution_Shell, PARENT_TYPE, e_shell) diff --git a/shell/e-shell.h b/shell/e-shell.h index add8c3e425..9d75a86baa 100644 --- a/shell/e-shell.h +++ b/shell/e-shell.h @@ -38,9 +38,9 @@ typedef struct _EShellClass EShellClass; #include "Evolution.h" #include "e-component-registry.h" -#include "e-shell-user-creatable-items-handler.h" #include "e-shell-window.h" #include "e-uri-schema-registry.h" +#include "e-user-creatable-items-handler.h" #define E_TYPE_SHELL (e_shell_get_type ()) @@ -124,12 +124,12 @@ void e_shell_show_settings (EShell *shell, const char *type, EShellWindow *shell_window); -EShellUserCreatableItemsHandler *e_shell_get_user_creatable_items_handler (EShell *shell); - gboolean e_shell_prepare_for_quit (EShell *shell); const char *e_shell_construct_result_to_string (EShellConstructResult result); +EUserCreatableItemsHandler *e_shell_peek_user_creatable_items_handler (EShell *shell); + #ifdef __cplusplus } diff --git a/shell/e-shell-user-creatable-items-handler.c b/shell/e-user-creatable-items-handler.c index 73747eb3a2..a524886993 100644 --- a/shell/e-shell-user-creatable-items-handler.c +++ b/shell/e-user-creatable-items-handler.c @@ -24,9 +24,9 @@ #include <config.h> #endif -#include "e-shell-user-creatable-items-handler.h" +#include "e-user-creatable-items-handler.h" -#include "e-shell-corba-icon-utils.h" +#include "e-shell-utils.h" #include "widgets/misc/e-combo-button.h" @@ -46,23 +46,23 @@ #include <ctype.h> #include <string.h> - + #define PARENT_TYPE G_TYPE_OBJECT static GObjectClass *parent_class = NULL; - + #define VERB_PREFIX "ShellUserCreatableItemVerb" #define EVOLUTION_MAIL_OAFIID "OAFIID:GNOME_Evolution_Mail_ShellComponent" -#define SHELL_VIEW_KEY "EShellUserCreatableItemsHandler:shell_view" -#define COMBO_BUTTON_WIDGET_KEY "EShellUserCreatableItemsHandler:combo_button" -#define TOOLTIPS_KEY "EShellUserCreatableItemsHandler:tooltips" +#define SHELL_WINDOW_KEY "EUserCreatableItemsHandler:shell_window" +#define COMBO_BUTTON_WIDGET_KEY "EUserCreatableItemsHandler:combo_button" +#define TOOLTIPS_KEY "EUserCreatableItemsHandler:tooltips" struct _Component { - EvolutionShellComponentClient *component_client; - - GNOME_Evolution_UserCreatableItemTypeList *type_list; + char *id; + GNOME_Evolution_Component component; + GNOME_Evolution_CreatableItemTypeList *type_list; }; typedef struct _Component Component; @@ -72,13 +72,12 @@ struct _MenuItem { char shortcut; char *verb; char *tooltip; - GdkPixbuf *icon; char *component_id; - char *folder_type; + GdkPixbuf *icon; }; typedef struct _MenuItem MenuItem; -struct _EShellUserCreatableItemsHandlerPrivate { +struct _EUserCreatableItemsHandlerPrivate { /* The components that register user creatable items. */ GSList *components; /* Component */ @@ -92,26 +91,27 @@ struct _EShellUserCreatableItemsHandlerPrivate { const MenuItem *default_menu_item; }; - + /* Component struct handling. */ static Component * component_new (const char *id, - EvolutionShellComponentClient *client) + GNOME_Evolution_Component component) { CORBA_Environment ev; Component *new; - GNOME_Evolution_ShellComponent objref; - new = g_new (Component, 1); + CORBA_exception_init (&ev); - new->component_client = client; - g_object_ref (client); + new = g_new (Component, 1); + new->id = g_strdup (id); - CORBA_exception_init (&ev); + new->type_list = GNOME_Evolution_Component__get_userCreatableItems (component, &ev); + if (BONOBO_EX (&ev)) + new->type_list = NULL; - objref = evolution_shell_component_client_corba_objref (client); - new->type_list = GNOME_Evolution_ShellComponent__get_userCreatableItemTypes (objref, &ev); + new->component = component; + Bonobo_Unknown_ref (new->component, &ev); if (ev._major != CORBA_NO_EXCEPTION) new->type_list = NULL; @@ -124,32 +124,52 @@ component_new (const char *id, static void component_free (Component *component) { - g_object_unref (component->component_client); + CORBA_Environment ev; + + CORBA_exception_init (&ev); + + Bonobo_Unknown_unref (component->component, &ev); + + g_free (component->id); if (component->type_list != NULL) CORBA_free (component->type_list); + CORBA_exception_free (&ev); + g_free (component); } - +static void +get_components_from_registry (EUserCreatableItemsHandler *handler, + EComponentRegistry *registry) +{ + GSList *registry_list = e_component_registry_peek_list (registry); + GSList *p; + + for (p = registry_list; p != NULL; p = p->next) { + EComponentInfo *info = p->data; + Component *component; + + e_component_registry_activate (registry, info->id, NULL); + + if (info->iface != CORBA_OBJECT_NIL) + component = component_new (info->id, info->iface); + + handler->priv->components = g_slist_prepend (handler->priv->components, component); + } +} + + /* Helper functions. */ static gboolean item_is_default (const MenuItem *item, - const char *folder_type, const char *component_id) { - if (component_id == NULL || folder_type == NULL) + if (component_id == NULL) return FALSE; - if (item->folder_type != NULL && *item->folder_type != 0) { - if (strcmp (item->folder_type, folder_type) == 0) - return TRUE; - else - return FALSE; - } - if (strcmp (item->component_id, component_id) == 0) return TRUE; else @@ -163,14 +183,14 @@ create_verb_from_component_number_and_type_id (int component_num, return g_strdup_printf (VERB_PREFIX ":%d:%s", component_num, type_id); } - + /* Setting up menu items for the "File -> New" submenu and the "New" toolbar button. */ static void -ensure_menu_items (EShellUserCreatableItemsHandler *handler) +ensure_menu_items (EUserCreatableItemsHandler *handler) { - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandlerPrivate *priv; GSList *menu_items; GSList *p; int component_num; @@ -190,27 +210,29 @@ ensure_menu_items (EShellUserCreatableItemsHandler *handler) component = (const Component *) p->data; if (component->type_list != NULL) { for (i = 0; i < component->type_list->_length; i ++) { - const GNOME_Evolution_UserCreatableItemType *type; + const GNOME_Evolution_CreatableItemType *type; MenuItem *item; - type = (const GNOME_Evolution_UserCreatableItemType *) component->type_list->_buffer + i; + type = (const GNOME_Evolution_CreatableItemType *) component->type_list->_buffer + i; item = g_new (MenuItem, 1); item->label = type->menuDescription; item->shortcut = type->menuShortcut; item->verb = create_verb_from_component_number_and_type_id (component_num, type->id); item->tooltip = type->tooltip; - item->component_id = g_strdup (evolution_shell_component_client_get_id (component->component_client)); - item->folder_type = g_strdup (type->folderType); + item->component_id = g_strdup (component->id); if (strcmp (item->component_id, EVOLUTION_MAIL_OAFIID) == 0 && strcmp (type->id, "message") == 0) default_verb = item->verb; - if (type->icon.width == 0 || type->icon.height == 0) + if (type->iconName == "") { item->icon = NULL; - else - item->icon = e_new_gdk_pixbuf_from_corba_icon (& type->icon, 16, 16); + } else { + char *icon_path = e_shell_get_icon_path (type->iconName, TRUE); + item->icon = gdk_pixbuf_new_from_file (icon_path, NULL); + g_free (icon_path); + } menu_items = g_slist_prepend (menu_items, item); } @@ -251,8 +273,6 @@ free_menu_items (GSList *menu_items) g_object_unref (item->icon); g_free (item->component_id); - g_free (item->folder_type); - g_free (item); } @@ -260,33 +280,31 @@ free_menu_items (GSList *menu_items) } static const MenuItem * -get_default_action_for_view (EShellUserCreatableItemsHandler *handler, - EShellView *shell_view) +get_default_action_for_view (EUserCreatableItemsHandler *handler, + EShellWindow *window) { - EShellUserCreatableItemsHandlerPrivate *priv; - const char *view_component_id; + EUserCreatableItemsHandlerPrivate *priv; + const char *window_component_id; const GSList *p; priv = handler->priv; - view_component_id = e_shell_view_get_current_component_id (shell_view); - if (view_component_id == NULL) + window_component_id = e_shell_window_peek_current_component_id (window); + if (window_component_id == NULL) return priv->default_menu_item; for (p = priv->menu_items; p != NULL; p = p->next) { const MenuItem *item; item = (const MenuItem *) p->data; - if (item_is_default (item, - e_shell_view_get_current_folder_type (shell_view), - e_shell_view_get_current_component_id (shell_view))) + if (item_is_default (item, window_component_id)) return item; } return priv->default_menu_item; } - + /* The XML description for "File -> New". */ /* This adds a menu item for @item. If @first is true, the keyboard shortcut @@ -369,11 +387,10 @@ item_types_sort_func (const void *a, } static char * -create_menu_xml (EShellUserCreatableItemsHandler *handler, - const char *folder_type, +create_menu_xml (EUserCreatableItemsHandler *handler, const char *component_id) { - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandlerPrivate *priv; GString *xml; GSList *p; GSList *non_default_items; @@ -386,7 +403,7 @@ create_menu_xml (EShellUserCreatableItemsHandler *handler, xml = g_string_new (""); g_string_append (xml, "<placeholder name=\"ComponentItems\">"); - g_string_append (xml, "<placeholder name=\"EShellUserCreatableItemsPlaceholder\">"); + g_string_append (xml, "<placeholder name=\"EUserCreatableItemsPlaceholder\">"); /* 1. Add all the elements that are default for this component. (Note that we don't need to do any sorting since the items are already @@ -399,7 +416,7 @@ create_menu_xml (EShellUserCreatableItemsHandler *handler, const MenuItem *item; item = (const MenuItem *) p->data; - if (item_is_default (item, folder_type, component_id)) { + if (item_is_default (item, component_id)) { append_xml_for_menu_item (xml, item, first); first = FALSE; } @@ -410,7 +427,7 @@ create_menu_xml (EShellUserCreatableItemsHandler *handler, if (component_id != NULL) g_string_append_printf (xml, - "<separator f=\"\" name=\"EShellUserCreatableItemsHandlerSeparator\"/>"); + "<separator f=\"\" name=\"EUserCreatableItemsHandlerSeparator\"/>"); /* 3. Add the elements that are not default for this component. */ @@ -419,7 +436,7 @@ create_menu_xml (EShellUserCreatableItemsHandler *handler, const MenuItem *item; item = (const MenuItem *) p->data; - if (! item_is_default (item, folder_type, component_id)) + if (! item_is_default (item, component_id)) non_default_items = g_slist_prepend (non_default_items, (void *) item); } @@ -430,7 +447,7 @@ create_menu_xml (EShellUserCreatableItemsHandler *handler, /* Done... */ - g_string_append (xml, "</placeholder>"); /* EShellUserCreatableItemsPlaceholder */ + g_string_append (xml, "</placeholder>"); /* EUserCreatableItemsPlaceholder */ g_string_append (xml, "</placeholder>"); /* ComponentItems */ retval = xml->str; @@ -439,15 +456,15 @@ create_menu_xml (EShellUserCreatableItemsHandler *handler, return retval; } - + /* Verb handling. */ static void -execute_verb (EShellUserCreatableItemsHandler *handler, - EShellView *shell_view, +execute_verb (EUserCreatableItemsHandler *handler, + EShellWindow *window, const char *verb_name) { - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandlerPrivate *priv; const Component *component; int component_number; const char *p; @@ -479,15 +496,10 @@ execute_verb (EShellUserCreatableItemsHandler *handler, CORBA_exception_init (&ev); - GNOME_Evolution_ShellComponent_userCreateNewItem - (evolution_shell_component_client_corba_objref (component->component_client), - id, - e_safe_corba_string (e_shell_view_get_current_physical_uri (shell_view)), - e_safe_corba_string (e_shell_view_get_current_folder_type (shell_view)), - &ev); + GNOME_Evolution_Component_requestCreateItem (component->component, id, &ev); if (ev._major != CORBA_NO_EXCEPTION) - g_warning ("Error in userCreateNewItem -- %s", BONOBO_EX_REPOID (&ev)); + g_warning ("Error in requestCreateItem -- %s", BONOBO_EX_REPOID (&ev)); CORBA_exception_free (&ev); return; @@ -500,30 +512,30 @@ verb_fn (BonoboUIComponent *ui_component, void *data, const char *verb_name) { - EShellUserCreatableItemsHandler *handler; - EShellView *shell_view; + EUserCreatableItemsHandler *handler; + EShellWindow *shell_window; - shell_view = g_object_get_data (G_OBJECT (ui_component), SHELL_VIEW_KEY); - g_assert (E_IS_SHELL_VIEW (shell_view)); + shell_window = g_object_get_data (G_OBJECT (ui_component), SHELL_WINDOW_KEY); + g_assert (E_IS_SHELL_WINDOW (shell_window)); - handler = E_SHELL_USER_CREATABLE_ITEMS_HANDLER (data); + handler = E_USER_CREATABLE_ITEMS_HANDLER (data); - execute_verb (handler, shell_view, verb_name); + execute_verb (handler, shell_window, verb_name); } static void -add_verbs (EShellUserCreatableItemsHandler *handler, - EShellView *shell_view) +add_verbs (EUserCreatableItemsHandler *handler, + EShellWindow *window) { - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandlerPrivate *priv; BonoboUIComponent *ui_component; int component_num; GSList *p; priv = handler->priv; - ui_component = e_shell_view_get_bonobo_ui_component (shell_view); - g_object_set_data (G_OBJECT (ui_component), SHELL_VIEW_KEY, shell_view); + ui_component = e_shell_window_peek_bonobo_ui_component (window); + g_object_set_data (G_OBJECT (ui_component), SHELL_WINDOW_KEY, window); component_num = 0; for (p = priv->components; p != NULL; p = p->next) { @@ -549,29 +561,29 @@ add_verbs (EShellUserCreatableItemsHandler *handler, } } - + /* The "New" button in the toolbar. */ static void combo_button_activate_default_callback (EComboButton *combo_button, void *data) { - EShellView *shell_view; - EShellUserCreatableItemsHandler *handler; + EShellWindow *shell_window; + EUserCreatableItemsHandler *handler; const MenuItem *menu_item; - shell_view = E_SHELL_VIEW (data); - handler = e_shell_get_user_creatable_items_handler (e_shell_view_get_shell (shell_view)); + shell_window = E_SHELL_WINDOW (data); + handler = e_shell_peek_user_creatable_items_handler (e_shell_window_peek_shell (shell_window)); - menu_item = get_default_action_for_view (handler, shell_view); - execute_verb (handler, shell_view, menu_item->verb); + menu_item = get_default_action_for_view (handler, shell_window); + execute_verb (handler, shell_window, menu_item->verb); } static void -setup_toolbar_button (EShellUserCreatableItemsHandler *handler, - EShellView *shell_view) +setup_toolbar_button (EUserCreatableItemsHandler *handler, + EShellWindow *window) { - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandlerPrivate *priv; BonoboUIComponent *ui_component; GtkWidget *combo_button; GtkWidget *menu; @@ -587,12 +599,10 @@ setup_toolbar_button (EShellUserCreatableItemsHandler *handler, e_combo_button_set_label (E_COMBO_BUTTON (combo_button), _("New")); gtk_widget_show (combo_button); - g_signal_connect (combo_button, "activate_default", - G_CALLBACK (combo_button_activate_default_callback), - shell_view); + g_signal_connect (combo_button, "activate_default", G_CALLBACK (combo_button_activate_default_callback), window); - ui_component = e_shell_view_get_bonobo_ui_component (shell_view); - bonobo_window_add_popup (BONOBO_WINDOW (shell_view), GTK_MENU (menu), "/popups/NewPopup"); + ui_component = e_shell_window_peek_bonobo_ui_component (window); + bonobo_window_add_popup (BONOBO_WINDOW (window), GTK_MENU (menu), "/popups/NewPopup"); control = bonobo_control_new (combo_button); @@ -601,43 +611,30 @@ setup_toolbar_button (EShellUserCreatableItemsHandler *handler, bonobo_object_unref (control); - g_object_set_data (G_OBJECT (shell_view), COMBO_BUTTON_WIDGET_KEY, combo_button); + g_object_set_data (G_OBJECT (window), COMBO_BUTTON_WIDGET_KEY, combo_button); tooltips = gtk_tooltips_new (); g_object_set_data (G_OBJECT (combo_button), TOOLTIPS_KEY, tooltips); } - -/* This handles the menus for a given EShellView. We have to rebuild the menu - and set the toolbar button every time the view changes, and clean up when - the view is destroyed. */ static void -shell_view_view_changed_callback (EShellView *shell_view, - const char *evolution_path, - const char *physical_uri, - const char *folder_type, - const char *component_id, - void *data) +update_for_window (EUserCreatableItemsHandler *handler, + EShellWindow *window) { - EShellUserCreatableItemsHandler *handler; - EShellUserCreatableItemsHandlerPrivate *priv; GtkWidget *combo_button_widget; GtkTooltips *tooltips; BonoboUIComponent *ui_component; const MenuItem *default_menu_item; char *menu_xml; - handler = E_SHELL_USER_CREATABLE_ITEMS_HANDLER (data); - priv = handler->priv; - - combo_button_widget = g_object_get_data (G_OBJECT (shell_view), COMBO_BUTTON_WIDGET_KEY); + combo_button_widget = g_object_get_data (G_OBJECT (window), COMBO_BUTTON_WIDGET_KEY); g_assert (E_IS_COMBO_BUTTON (combo_button_widget)); tooltips = g_object_get_data (G_OBJECT (combo_button_widget), TOOLTIPS_KEY); g_assert (tooltips != NULL); - default_menu_item = get_default_action_for_view (handler, shell_view); + default_menu_item = get_default_action_for_view (handler, window); if (default_menu_item == NULL) { gtk_widget_set_sensitive (combo_button_widget, FALSE); e_combo_button_set_label (E_COMBO_BUTTON (combo_button_widget), _("New")); @@ -651,29 +648,40 @@ shell_view_view_changed_callback (EShellView *shell_view, e_combo_button_set_icon (E_COMBO_BUTTON (combo_button_widget), default_menu_item->icon); gtk_tooltips_set_tip (tooltips, combo_button_widget, default_menu_item->tooltip, NULL); - ui_component = e_shell_view_get_bonobo_ui_component (shell_view); - bonobo_ui_component_rm (ui_component, "/menu/File/New/ComponentItems/EShellUserCreatableItemsPlaceholder", NULL); - bonobo_ui_component_rm (ui_component, "/popups/NewPopup/ComponentItems/EShellUserCreatableItemsPlaceholder", NULL); + ui_component = e_shell_window_peek_bonobo_ui_component (window); + bonobo_ui_component_rm (ui_component, "/menu/File/New/ComponentItems/EUserCreatableItemsPlaceholder", NULL); + bonobo_ui_component_rm (ui_component, "/popups/NewPopup/ComponentItems/EUserCreatableItemsPlaceholder", NULL); + + menu_xml = create_menu_xml (handler, e_shell_window_peek_current_component_id (window)); - menu_xml = create_menu_xml (handler, - e_shell_view_get_current_folder_type (shell_view), - e_shell_view_get_current_component_id (shell_view)); bonobo_ui_component_set (ui_component, "/menu/File/New", menu_xml, NULL); bonobo_ui_component_set (ui_component, "/popups/NewPopup", menu_xml, NULL); g_free (menu_xml); } - + +/* This handles the menus for a given EShellWindow. We have to rebuild the menu + and set the toolbar button every time the view changes, and clean up when + the view is destroyed. */ + +static void +shell_window_component_changed_callback (EShellWindow *shell_window, + EUserCreatableItemsHandler *handler) +{ + update_for_window (handler, shell_window); +} + + /* GObject methods. */ static void impl_dispose (GObject *object) { - EShellUserCreatableItemsHandler *handler; - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandler *handler; + EUserCreatableItemsHandlerPrivate *priv; GSList *p; - handler = E_SHELL_USER_CREATABLE_ITEMS_HANDLER (object); + handler = E_USER_CREATABLE_ITEMS_HANDLER (object); priv = handler->priv; for (p = priv->components; p != NULL; p = p->next) @@ -689,10 +697,10 @@ impl_dispose (GObject *object) static void impl_finalize (GObject *object) { - EShellUserCreatableItemsHandler *handler; - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandler *handler; + EUserCreatableItemsHandlerPrivate *priv; - handler = E_SHELL_USER_CREATABLE_ITEMS_HANDLER (object); + handler = E_USER_CREATABLE_ITEMS_HANDLER (object); priv = handler->priv; free_menu_items (priv->menu_items); @@ -702,7 +710,7 @@ impl_finalize (GObject *object) (* G_OBJECT_CLASS (parent_class)->finalize) (object); } - + static void class_init (GObjectClass *object_class) { @@ -713,11 +721,11 @@ class_init (GObjectClass *object_class) } static void -init (EShellUserCreatableItemsHandler *shell_user_creatable_items_handler) +init (EUserCreatableItemsHandler *shell_user_creatable_items_handler) { - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandlerPrivate *priv; - priv = g_new (EShellUserCreatableItemsHandlerPrivate, 1); + priv = g_new (EUserCreatableItemsHandlerPrivate, 1); priv->components = NULL; priv->menu_items = NULL; priv->default_menu_item = NULL; @@ -725,76 +733,56 @@ init (EShellUserCreatableItemsHandler *shell_user_creatable_items_handler) shell_user_creatable_items_handler->priv = priv; } - -EShellUserCreatableItemsHandler * -e_shell_user_creatable_items_handler_new (void) -{ - EShellUserCreatableItemsHandler *new; - - new = g_object_new (e_shell_user_creatable_items_handler_get_type (), NULL); - return new; -} - -void -e_shell_user_creatable_items_handler_add_component (EShellUserCreatableItemsHandler *handler, - const char *id, - EvolutionShellComponentClient *shell_component_client) +EUserCreatableItemsHandler * +e_user_creatable_items_handler_new (EComponentRegistry *registry) { - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandler *new; - g_return_if_fail (handler != NULL); - g_return_if_fail (E_IS_SHELL_USER_CREATABLE_ITEMS_HANDLER (handler)); - g_return_if_fail (shell_component_client != NULL); - g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client)); + new = g_object_new (e_user_creatable_items_handler_get_type (), NULL); - priv = handler->priv; + get_components_from_registry (new, registry); - priv->components = g_slist_prepend (priv->components, component_new (id, shell_component_client)); + return new; } - + /** - * e_shell_user_creatable_items_handler_attach_menus: + * e_user_creatable_items_handler_attach_menus: * @handler: - * @shell_view: + * @shell_window: * - * Set up the menus and toolbar items for @shell_view. When the shell changes + * Set up the menus and toolbar items for @shell_window. When the shell changes * view, the menu and the toolbar item will update automatically (i.e. the * actions for the current folder will go on top etc.). **/ void -e_shell_user_creatable_items_handler_attach_menus (EShellUserCreatableItemsHandler *handler, - EShellView *shell_view) +e_user_creatable_items_handler_attach_menus (EUserCreatableItemsHandler *handler, + EShellWindow *window) { BonoboUIComponent *ui_component; - EShellUserCreatableItemsHandlerPrivate *priv; + EUserCreatableItemsHandlerPrivate *priv; char *menu_xml; - g_return_if_fail (handler != NULL); - g_return_if_fail (E_IS_SHELL_USER_CREATABLE_ITEMS_HANDLER (handler)); - g_return_if_fail (shell_view != NULL); - g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); + g_return_if_fail (E_IS_USER_CREATABLE_ITEMS_HANDLER (handler)); + g_return_if_fail (E_IS_SHELL_WINDOW (window)); priv = handler->priv; - setup_toolbar_button (handler, shell_view); - g_signal_connect (shell_view, "view_changed", - G_CALLBACK (shell_view_view_changed_callback), handler); + setup_toolbar_button (handler, window); + g_signal_connect (window, "component_changed", G_CALLBACK (shell_window_component_changed_callback), handler); - add_verbs (handler, shell_view); - menu_xml = create_menu_xml (handler, - e_shell_view_get_current_component_id (shell_view), - e_shell_view_get_current_folder_type (shell_view)); + add_verbs (handler, window); + menu_xml = create_menu_xml (handler, e_shell_window_peek_current_component_id (window)); - ui_component = e_shell_view_get_bonobo_ui_component (shell_view); + ui_component = e_shell_window_peek_bonobo_ui_component (window); bonobo_ui_component_set (ui_component, "/menu/File/New", menu_xml, NULL); bonobo_ui_component_set (ui_component, "/popups/NewPopup", menu_xml, NULL); g_free (menu_xml); + + update_for_window (handler, window); } - -E_MAKE_TYPE (e_shell_user_creatable_items_handler, - "EShellUserCreatableItemsHandler", EShellUserCreatableItemsHandler, - class_init, init, PARENT_TYPE) + +E_MAKE_TYPE (e_user_creatable_items_handler, "EUserCreatableItemsHandler", EUserCreatableItemsHandler, class_init, init, PARENT_TYPE) diff --git a/shell/e-user-creatable-items-handler.h b/shell/e-user-creatable-items-handler.h new file mode 100644 index 0000000000..d6f12e3973 --- /dev/null +++ b/shell/e-user-creatable-items-handler.h @@ -0,0 +1,73 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-shell-user-creatable-items-handler.h + * + * Copyright (C) 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli <ettore@ximian.com> + */ + +#ifndef _E_USER_CREATABLE_ITEMS_HANDLER_H_ +#define _E_USER_CREATABLE_ITEMS_HANDLER_H_ + +#include <glib-object.h> +#include <bonobo/bonobo-ui-component.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define E_TYPE_USER_CREATABLE_ITEMS_HANDLER (e_user_creatable_items_handler_get_type ()) +#define E_USER_CREATABLE_ITEMS_HANDLER(obj) (GTK_CHECK_CAST ((obj), E_TYPE_USER_CREATABLE_ITEMS_HANDLER, EUserCreatableItemsHandler)) +#define E_USER_CREATABLE_ITEMS_HANDLER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_USER_CREATABLE_ITEMS_HANDLER, EUserCreatableItemsHandlerClass)) +#define E_IS_USER_CREATABLE_ITEMS_HANDLER(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_USER_CREATABLE_ITEMS_HANDLER)) +#define E_IS_USER_CREATABLE_ITEMS_HANDLER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_USER_CREATABLE_ITEMS_HANDLER)) + + +typedef struct _EUserCreatableItemsHandler EUserCreatableItemsHandler; +typedef struct _EUserCreatableItemsHandlerPrivate EUserCreatableItemsHandlerPrivate; +typedef struct _EUserCreatableItemsHandlerClass EUserCreatableItemsHandlerClass; + + +#include "e-shell-window.h" + + +struct _EUserCreatableItemsHandler { + GObject parent; + + EUserCreatableItemsHandlerPrivate *priv; +}; + +struct _EUserCreatableItemsHandlerClass { + GObjectClass parent_class; +}; + + +GtkType e_user_creatable_items_handler_get_type (void); +EUserCreatableItemsHandler *e_user_creatable_items_handler_new (EComponentRegistry *registry); + +void e_user_creatable_items_handler_add_component (EUserCreatableItemsHandler *handler, + const char *id, + GNOME_Evolution_Component component); +void e_user_creatable_items_handler_attach_menus (EUserCreatableItemsHandler *handler, + EShellWindow *window); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _E_USER_CREATABLE_ITEMS_HANDLER_H_ */ |