diff options
author | Ettore Perazzoli <ettore@src.gnome.org> | 2002-08-01 04:36:16 +0800 |
---|---|---|
committer | Ettore Perazzoli <ettore@src.gnome.org> | 2002-08-01 04:36:16 +0800 |
commit | ec3f54257d3d3ddcd22779547f543ba9a9716f89 (patch) | |
tree | 5fc3f964d9adc7032c3484cec0e09fc0bce3cec4 /shell | |
parent | 6135f6ad4544f68ef23bdf9dca698a93cfae7067 (diff) | |
download | gsoc2013-evolution-ec3f54257d3d3ddcd22779547f543ba9a9716f89.tar.gz gsoc2013-evolution-ec3f54257d3d3ddcd22779547f543ba9a9716f89.tar.zst gsoc2013-evolution-ec3f54257d3d3ddcd22779547f543ba9a9716f89.zip |
Pass "contacts" as the @folder_type to
* gui/component/addressbook-component.c (add_creatable_item): Pass
"contacts" as the @folder_type to
evolution_shell_component_add_user_creatable_item().
* gui/component-factory.c (add_creatable_item): New arg
@folder_type, pass it to
evolution_shell_component_add_user_creatable_item().
(create_object): Set the right folder types for the various
user-creatable items.
* component-factory.c (create_component): Pass "mail" as
@folder_type to
evolution_shell_component_add_user_creatable_item().
* evolution-test-component.c (register_component): Pass NULL for
@folder_type to
evolution_shell_component_add_user_creatable_item().
* e-shell-user-creatable-items-handler.c: New member folder_type
in struct MenuItem.
(ensure_menu_items): Initialize ->folder_type.
(item_is_default): New helper function.
(create_menu_xml): New arg @folder_type. Put the items on the top
using item_is_default().
(shell_view_view_changed_callback): Pass the folder type to
create_menu_xml().
* evolution-shell-component.c: New member folder_type in
UserCreatableItemType.
(user_creatable_item_type_new): New arg @folder_type.
(user_creatable_item_type_free): Free ->folder_type.
(evolution_shell_component_add_user_creatable_item): New arg
@folder_type.
(impl__get_userCreatableItemTypes): Set ->folderType in the
returned CORBA structs.
* Evolution-ShellComponent.idl: New member folderType in struct
UserCreatableItemType.
* e-shell-user-creatable-items-handler.c: New member component_id
in struct MenuItem. Removed member menu_xml from
EShellUserCreatableItemsHandlerPrivate.
(init): No need to initialize menu_xml here anymore.
(impl_destroy): ...And no need to free here, either.
(setup_menu_xml): New, derived from ensure_menu_xml(). This
orders the menu so that the items for the current component go at
the top.
(create_menu_xml): Removed.
(e_shell_user_creatable_items_handler_attach_menus): Set up
properly for the current component ID, using setup_menu_xml().
svn path=/trunk/; revision=17658
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ChangeLog | 39 | ||||
-rw-r--r-- | shell/Evolution-ShellComponent.idl | 36 | ||||
-rw-r--r-- | shell/e-shell-user-creatable-items-handler.c | 162 | ||||
-rw-r--r-- | shell/evolution-shell-component.c | 8 | ||||
-rw-r--r-- | shell/evolution-shell-component.h | 1 | ||||
-rw-r--r-- | shell/evolution-test-component.c | 3 |
6 files changed, 190 insertions, 59 deletions
diff --git a/shell/ChangeLog b/shell/ChangeLog index 64624a4ac6..81133e81e3 100644 --- a/shell/ChangeLog +++ b/shell/ChangeLog @@ -1,3 +1,42 @@ +2002-07-31 Ettore Perazzoli <ettore@ximian.com> + + * evolution-test-component.c (register_component): Pass NULL for + @folder_type to + evolution_shell_component_add_user_creatable_item(). + + * e-shell-user-creatable-items-handler.c: New member folder_type + in struct MenuItem. + (ensure_menu_items): Initialize ->folder_type. + (item_is_default): New helper function. + (create_menu_xml): New arg @folder_type. Put the items on the top + using item_is_default(). + (shell_view_view_changed_callback): Pass the folder type to + create_menu_xml(). + + * evolution-shell-component.c: New member folder_type in + UserCreatableItemType. + (user_creatable_item_type_new): New arg @folder_type. + (user_creatable_item_type_free): Free ->folder_type. + (evolution_shell_component_add_user_creatable_item): New arg + @folder_type. + (impl__get_userCreatableItemTypes): Set ->folderType in the + returned CORBA structs. + + * Evolution-ShellComponent.idl: New member folderType in struct + UserCreatableItemType. + + * e-shell-user-creatable-items-handler.c: New member component_id + in struct MenuItem. Removed member menu_xml from + EShellUserCreatableItemsHandlerPrivate. + (init): No need to initialize menu_xml here anymore. + (impl_destroy): ...And no need to free here, either. + (setup_menu_xml): New, derived from ensure_menu_xml(). This + orders the menu so that the items for the current component go at + the top. + (create_menu_xml): Removed. + (e_shell_user_creatable_items_handler_attach_menus): Set up + properly for the current component ID, using setup_menu_xml(). + 2002-07-29 Jeffrey Stedfast <fejj@ximian.com> * evolution-folder-selector-button.c diff --git a/shell/Evolution-ShellComponent.idl b/shell/Evolution-ShellComponent.idl index 18118b4359..96557353b9 100644 --- a/shell/Evolution-ShellComponent.idl +++ b/shell/Evolution-ShellComponent.idl @@ -14,21 +14,6 @@ module GNOME { module Evolution { interface Shell; - /* Definition for a folder type. */ - struct FolderType { - string name; - string iconName; - - string displayName; - string description; - - boolean userCreatable; - - sequence<string> acceptedDndTypes; - sequence<string> exportedDndTypes; - }; - typedef sequence<FolderType> FolderTypeList; - /* URI schemas, e.g. mailto:. */ typedef string URISchema; typedef sequence<URISchema> URISchemaList; @@ -42,9 +27,30 @@ module Evolution { string tooltip; char menuShortcut; Icon icon; + + // This specifies the folder type for which this user creatable + // type is a default type. + string folderType; }; typedef sequence<UserCreatableItemType> UserCreatableItemTypeList; + /* Definition for a folder type. */ + struct FolderType { + string name; + string iconName; + + string displayName; + string description; + + boolean userCreatable; + + sequence<string> acceptedDndTypes; + sequence<string> exportedDndTypes; + + UserCreatableItemTypeList userCreatableItemTypes; + }; + typedef sequence<FolderType> FolderTypeList; + interface ShellComponentListener; interface ShellComponent : Bonobo::Unknown { diff --git a/shell/e-shell-user-creatable-items-handler.c b/shell/e-shell-user-creatable-items-handler.c index 36791623de..a10b755329 100644 --- a/shell/e-shell-user-creatable-items-handler.c +++ b/shell/e-shell-user-creatable-items-handler.c @@ -71,6 +71,8 @@ struct _MenuItem { char *verb; char *tooltip; GdkPixbuf *icon; + char *component_id; + char *folder_type; }; typedef struct _MenuItem MenuItem; @@ -86,9 +88,6 @@ struct _EShellUserCreatableItemsHandlerPrivate { creatable type. This pointer always points to one of the menu items in ->menu_items. */ const MenuItem *default_menu_item; - - /* XML to describe the menu. */ - char *menu_xml; }; @@ -217,13 +216,14 @@ ensure_menu_items (EShellUserCreatableItemsHandler *handler) type = (const GNOME_Evolution_UserCreatableItemType *) 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; - - if (strcmp (evolution_shell_component_client_get_id (component->component_client), - EVOLUTION_MAIL_OAFIID) == 0 + 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); + + if (strcmp (item->component_id, EVOLUTION_MAIL_OAFIID) == 0 && strcmp (type->id, "message") == 0) default_verb = item->verb; @@ -273,6 +273,8 @@ free_menu_items (GSList *menu_items) if (item->icon != NULL) gdk_pixbuf_unref (item->icon); + g_free (item->component_id); + g_free (item); } @@ -348,54 +350,115 @@ get_default_action_for_view (EShellUserCreatableItemsHandler *handler, /* The XML description for "File -> New". */ +/* This adds a menu item for @item. If @first is true, the keyboard shortcut + is going to be "Control-N" instead of whatever the component defines. */ static void -ensure_menu_xml (EShellUserCreatableItemsHandler *handler) +append_xml_for_menu_item (GString *xml, + const MenuItem *item, + gboolean first) +{ + char *encoded_label; + char *encoded_tooltip; + + encoded_label = bonobo_ui_util_encode_str (item->label); + g_string_sprintfa (xml, "<menuitem name=\"New:%s\" verb=\"%s\" label=\"%s\"", + item->verb, item->verb, encoded_label); + + if (first) + g_string_sprintfa (xml, " accel=\"*Control*N\""); + else if (item->shortcut != '\0') + g_string_sprintfa (xml, " accel=\"*Control**Shift*%c\"", item->shortcut); + + if (item->icon != NULL) + g_string_sprintfa (xml, " pixtype=\"pixbuf\" pixname=\"%s\"", + bonobo_ui_util_pixbuf_to_xml (item->icon)); + + encoded_tooltip = bonobo_ui_util_encode_str (item->tooltip); + g_string_sprintfa (xml, " tip=\"%s\"", encoded_tooltip); + + g_string_append (xml, "/> "); + + g_free (encoded_label); + g_free (encoded_tooltip); +} + +static gboolean +item_is_default (const MenuItem *item, + const char *folder_type, + const char *component_id) +{ + if (component_id == NULL || folder_type == 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 + return FALSE; +} + +static char * +create_menu_xml (EShellUserCreatableItemsHandler *handler, + const char *folder_type, + const char *component_id) { EShellUserCreatableItemsHandlerPrivate *priv; GString *xml; GSList *p; + char *retval; priv = handler->priv; - if (priv->menu_xml != NULL) - return; ensure_menu_items (handler); xml = g_string_new (""); g_string_append (xml, "<placeholder name=\"ComponentItems\">"); + g_string_append (xml, "<placeholder name=\"EShellUserCreatableItemsPlaceholder\">"); - for (p = priv->menu_items; p != NULL; p = p->next) { - const MenuItem *item; - char *encoded_label; - char *encoded_tooltip; - - item = (const MenuItem *) p->data; + /* 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 + sorted alphabetically.) */ + if (component_id != NULL) { + gboolean first = TRUE; - encoded_label = bonobo_ui_util_encode_str (item->label); - g_string_sprintfa (xml, "<menuitem name=\"New:%s\" verb=\"%s\" label=\"%s\"", - item->verb, item->verb, encoded_label); - - if (item->shortcut != '\0') - g_string_sprintfa (xml, " accel=\"*Control**Shift*%c\"", item->shortcut); + for (p = priv->menu_items; p != NULL; p = p->next) { + const MenuItem *item; - if (item->icon != NULL) - g_string_sprintfa (xml, " pixtype=\"pixbuf\" pixname=\"%s\"", - bonobo_ui_util_pixbuf_to_xml (item->icon)); + item = (const MenuItem *) p->data; + if (item_is_default (item, folder_type, component_id)) { + append_xml_for_menu_item (xml, item, first); + first = FALSE; + } + } + } - encoded_tooltip = bonobo_ui_util_encode_str (item->tooltip); - g_string_sprintfa (xml, " tip=\"%s\"", encoded_tooltip); + /* 2. Add a separator. */ + if (component_id != NULL) + g_string_sprintfa (xml, "<separator f=\"\" name=\"EShellUserCreatableItemsHandlerSeparator\"/>"); - g_string_append (xml, "/> "); + /* 3. Add the elements that are not default for this component. */ + for (p = priv->menu_items; p != NULL; p = p->next) { + const MenuItem *item; - g_free (encoded_label); - g_free (encoded_tooltip); + item = (const MenuItem *) p->data; + if (! item_is_default (item, folder_type, component_id)) + append_xml_for_menu_item (xml, item, FALSE); } - g_string_append (xml, "</placeholder>"); + g_string_append (xml, "</placeholder>"); /* EShellUserCreatableItemsPlaceholder */ + g_string_append (xml, "</placeholder>"); /* ComponentItems */ - priv->menu_xml = xml->str; + retval = xml->str; g_string_free (xml, FALSE); + + return retval; } @@ -581,7 +644,9 @@ shell_view_view_changed_callback (EShellView *shell_view, 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; @@ -605,6 +670,17 @@ 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); + + 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); } @@ -625,8 +701,6 @@ impl_destroy (GtkObject *object) g_slist_free (priv->components); - g_free (priv->menu_xml); - free_menu_items (priv->menu_items); g_free (priv); @@ -650,7 +724,6 @@ init (EShellUserCreatableItemsHandler *shell_user_creatable_items_handler) priv = g_new (EShellUserCreatableItemsHandlerPrivate, 1); priv->components = NULL; - priv->menu_xml = NULL; priv->menu_items = NULL; priv->default_menu_item = NULL; @@ -681,7 +754,6 @@ e_shell_user_creatable_items_handler_add_component (EShellUserCreatableItemsHan g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client)); priv = handler->priv; - g_return_if_fail (priv->menu_xml == NULL); priv->components = g_slist_prepend (priv->components, component_new (id, shell_component_client)); } @@ -702,6 +774,7 @@ e_shell_user_creatable_items_handler_attach_menus (EShellUserCreatableItemsHandl { BonoboUIComponent *ui_component; EShellUserCreatableItemsHandlerPrivate *priv; + char *menu_xml; g_return_if_fail (handler != NULL); g_return_if_fail (E_IS_SHELL_USER_CREATABLE_ITEMS_HANDLER (handler)); @@ -714,13 +787,16 @@ e_shell_user_creatable_items_handler_attach_menus (EShellUserCreatableItemsHandl gtk_signal_connect (GTK_OBJECT (shell_view), "view_changed", GTK_SIGNAL_FUNC (shell_view_view_changed_callback), handler); - ensure_menu_xml (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)); ui_component = e_shell_view_get_bonobo_ui_component (shell_view); - bonobo_ui_component_set (ui_component, "/menu/File/New", priv->menu_xml, NULL); - bonobo_ui_component_set (ui_component, "/popups/NewPopup", priv->menu_xml, NULL); + 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); } diff --git a/shell/evolution-shell-component.c b/shell/evolution-shell-component.c index cee0ee7f60..cfe318b610 100644 --- a/shell/evolution-shell-component.c +++ b/shell/evolution-shell-component.c @@ -52,6 +52,7 @@ struct _UserCreatableItemType { char *tooltip; char menu_shortcut; GdkPixbuf *icon; + char *folder_type; }; typedef struct _UserCreatableItemType UserCreatableItemType; @@ -98,6 +99,7 @@ user_creatable_item_type_new (const char *id, const char *description, const char *menu_description, const char *tooltip, + const char *folder_type, char menu_shortcut, GdkPixbuf *icon) { @@ -109,6 +111,7 @@ user_creatable_item_type_new (const char *id, type->menu_description = g_strdup (menu_description); type->tooltip = g_strdup (tooltip); type->menu_shortcut = menu_shortcut; + type->folder_type = g_strdup (folder_type); if (icon == NULL) type->icon = NULL; @@ -124,6 +127,7 @@ user_creatable_item_type_free (UserCreatableItemType *type) g_free (type->id); g_free (type->description); g_free (type->menu_description); + g_free (type->folder_type); if (type->icon != NULL) gdk_pixbuf_unref (type->icon); @@ -369,6 +373,7 @@ impl__get_userCreatableItemTypes (PortableServer_Servant servant, corba_type->description = CORBA_string_dup (type->description); corba_type->menuDescription = CORBA_string_dup (type->menu_description); corba_type->tooltip = CORBA_string_dup (type->tooltip != NULL ? type->tooltip : ""); + corba_type->folderType = CORBA_string_dup (type->folder_type != NULL ? type->folder_type : ""); corba_type->menuShortcut = type->menu_shortcut; e_store_corba_icon_from_pixbuf (type->icon, & corba_type->icon); @@ -1054,6 +1059,7 @@ evolution_shell_component_add_user_creatable_item (EvolutionShellComponent *she const char *description, const char *menu_description, const char *tooltip, + const char *folder_type, char menu_shortcut, GdkPixbuf *icon) { @@ -1068,7 +1074,7 @@ evolution_shell_component_add_user_creatable_item (EvolutionShellComponent *she priv = shell_component->priv; - type = user_creatable_item_type_new (id, description, menu_description, tooltip, menu_shortcut, icon); + type = user_creatable_item_type_new (id, description, menu_description, tooltip, folder_type, menu_shortcut, icon); priv->user_creatable_item_types = g_slist_prepend (priv->user_creatable_item_types, type); } diff --git a/shell/evolution-shell-component.h b/shell/evolution-shell-component.h index a38f87eb99..fafa489c8e 100644 --- a/shell/evolution-shell-component.h +++ b/shell/evolution-shell-component.h @@ -194,6 +194,7 @@ void evolution_shell_component_add_user_creatable_item (EvolutionShellComponen const char *description, const char *menu_description, const char *tooltip, + const char *folder_type, char menu_shortcut, GdkPixbuf *icon); diff --git a/shell/evolution-test-component.c b/shell/evolution-test-component.c index 9464b44b92..eb9b670c02 100644 --- a/shell/evolution-test-component.c +++ b/shell/evolution-test-component.c @@ -588,14 +588,17 @@ register_component (void) evolution_shell_component_add_user_creatable_item (shell_component, "Stuff", "New Stuff", "New _Stuff", "Create some new stuff", + NULL, '\0', NULL); evolution_shell_component_add_user_creatable_item (shell_component, "MoreStuff", "New More Stuff", "New _More Stuff", "Create more stuff", + NULL, 'n', NULL); evolution_shell_component_add_user_creatable_item (shell_component, "FolderSelector", "Folder Selector", "New Folder _Selector", "Show a folder selector", + NULL, 's', NULL); gtk_signal_connect (GTK_OBJECT (shell_component), "user_create_new_item", |