diff options
author | John Sullivan <sullivan@src.gnome.org> | 2001-04-07 18:57:37 +0000 |
---|---|---|
committer | John Sullivan <sullivan@src.gnome.org> | 2001-04-07 18:57:37 +0000 |
commit | 3104ed53fdf00c56fb6efcf81187f088ba9a14fc (patch) | |
tree | ef1adbd22ea5b73d05149b4bd0f4e3e75d15c2f4 /libnautilus-private/nautilus-bonobo-extensions.c | |
parent | 704295febe36ba8b21ffac12d106a29becdb102a (diff) | |
download | nautilus-3104ed53fdf00c56fb6efcf81187f088ba9a14fc.tar.gz |
Fixed bug 3787 (If location bar is turned off, user cannot
change viewer)
Now the "View as" choices, including "View as...", appear
at the bottom of the View menu as well as in the location bar.
* libnautilus-extensions/nautilus-bonobo-extensions.h:
* libnautilus-extensions/nautilus-bonobo-extensions.c:
(add_numbered_menu_item_internal): Handle radio item case; change
signature to support this.
(nautilus_bonobo_add_numbered_menu_item),
(nautilus_bonobo_add_numbered_toggle_menu_item):
Updated for change to add_numbered_menu_item_internal.
(nautilus_bonobo_add_numbered_radio_menu_item): New function,
just like its fellows but creates a one-of-many menu item.
(nautilus_bonobo_get_numbered_menu_item_index_from_command),
(nautilus_bonobo_get_numbered_menu_item_container_path_from_command):
New functions that return info given one of the numbered-menu-item
generated commands. Useful for callbacks when all you have in hand
is the command itself.
* src/nautilus-shell-ui.xml: Add "View as" command; add placeholders
and separators and "View as" menu item to View menu.
Also removed pixmap from Close Window menu item because it was
silly to have a pixmap on exactly one item in the File menu.
* src/nautilus-window-manage-views.c: Took "static" off of
nautilus_window_content_matches_iid so I could make it public
and use it in nautilus-window.c.
* src/nautilus-window-private.h: Added fields to Details struct
and prototypes for functions needed by View As stuff.
* src/nautilus-window-menus.c:
(view_menu_view_as_callback): New callback function used by
"View as" verb.
(nautilus_window_initialize_menus_part_1): Wire up "View as"
verb; register for Bonobo UI events to catch radio items being
selected.
* src/nautilus-window.c:
(set_dummy_initial_view_as_menu): Changed "View as ..." to
"View as...", which matches the new name of "View as Other..."
(free_stored_viewers): New function, frees and nulls out the
view identifiers stored in the Details struct for the "View as"
menus.
(nautilus_window_destroy): Call free_stored_viewers.
(activate_nth_short_list_item): New function, switches viewers
by viewer index.
(activate_extra_viewer): New function, switches to sometimes-
present extra viewer (used when current viewer isn't in short list).
(handle_view_as_item_from_bonobo_menu): If item whose state has
changed is a "View as" item, dispatch accordingly.
(nautilus_window_handle_ui_event_callback): Call
handle_view_as_item_from_bonobo_menu if UI event was state
changing to TRUE.
(view_as_menu_switch_views_callback),
(create_view_as_menu_item): Changed to store viewer index and
whether viewer is "extra viewer" rather than storing
NautilusViewIdentifier. This is used for option menu in location
bar and now closely matches the mechanism used for the View menu.
(add_view_as_bonobo_menu_item): New function used by View menu
View As items.
(replace_extra_viewer_in_view_as_menus),
(nautilus_window_synch_view_as_menus):
(load_view_as_menus_callback): Renamed and cleaned up to separate
information gathering from widget updating; now handle View As
items in View menu also.
(chose_component_callback): Added FIXME for pre-existing bug 8000.
(nautilus_window_show_view_as_dialog): New function, extracted
from view_as_menu_choose_view_callback.
(view_as_menu_choose_view_callback): Now calls extracted function.
(refresh_stored_viewers): New function, updates the list of viewers
stored in the Details struct.
Diffstat (limited to 'libnautilus-private/nautilus-bonobo-extensions.c')
-rw-r--r-- | libnautilus-private/nautilus-bonobo-extensions.c | 118 |
1 files changed, 98 insertions, 20 deletions
diff --git a/libnautilus-private/nautilus-bonobo-extensions.c b/libnautilus-private/nautilus-bonobo-extensions.c index 84f5c4536..b7da068c8 100644 --- a/libnautilus-private/nautilus-bonobo-extensions.c +++ b/libnautilus-private/nautilus-bonobo-extensions.c @@ -43,6 +43,12 @@ struct NautilusBonoboActivationHandle { guint idle_id; }; +typedef enum { + NUMBERED_MENU_ITEM_PLAIN, + NUMBERED_MENU_ITEM_TOGGLE, + NUMBERED_MENU_ITEM_RADIO +} NumberedMenuItemType; + void nautilus_bonobo_set_accelerator (BonoboUIComponent *ui, const char *path, @@ -192,13 +198,55 @@ nautilus_bonobo_get_numbered_menu_item_command (BonoboUIComponent *ui, return command_name; } +guint +nautilus_bonobo_get_numbered_menu_item_index_from_command (const char *command) +{ + char *path; + char *index_string; + int index; + gboolean got_index; + + path = gnome_vfs_unescape_string (command, NULL); + index_string = strrchr (path, '/'); + + if (index_string == NULL) { + got_index = FALSE; + } else { + got_index = eel_str_to_int (index_string + 1, &index); + } + g_free (path); + + g_return_val_if_fail (got_index, 0); + + return index; +} + +char * +nautilus_bonobo_get_numbered_menu_item_container_path_from_command (const char *command) +{ + char *path; + char *index_string; + char *container_path; + + path = gnome_vfs_unescape_string (command, NULL); + index_string = strrchr (path, '/'); + + container_path = index_string == NULL + ? NULL + : g_strndup (path, index_string - path); + g_free (path); + + return container_path; +} + static void add_numbered_menu_item_internal (BonoboUIComponent *ui, const char *container_path, guint index, const char *label, - gboolean is_toggle, - GdkPixbuf *pixbuf) + NumberedMenuItemType type, + GdkPixbuf *pixbuf, + const char *radio_group_name) { char *xml_item, *xml_command; char *encoded_label, *command_name; @@ -207,7 +255,9 @@ add_numbered_menu_item_internal (BonoboUIComponent *ui, g_assert (BONOBO_IS_UI_COMPONENT (ui)); g_assert (container_path != NULL); g_assert (label != NULL); - g_assert (!is_toggle || pixbuf == NULL); + g_assert (type == NUMBERED_MENU_ITEM_PLAIN || pixbuf == NULL); + g_assert (type == NUMBERED_MENU_ITEM_RADIO || radio_group_name == NULL); + g_assert (type != NUMBERED_MENU_ITEM_RADIO || radio_group_name != NULL); /* Because we are constructing the XML ourselves, we need to * encode the label. @@ -219,23 +269,32 @@ add_numbered_menu_item_internal (BonoboUIComponent *ui, command_name = nautilus_bonobo_get_numbered_menu_item_command (ui, container_path, index); - /* Note: we ignore the pixbuf for toggle items. This could be changed - * if we ever want a toggle item that also has a pixbuf. - */ - if (is_toggle) { + + switch (type) { + case NUMBERED_MENU_ITEM_TOGGLE: xml_item = g_strdup_printf ("<menuitem name=\"%s\" label=\"%s\" id=\"%s\" type=\"toggle\"/>\n", item_name, encoded_label, command_name); - } else if (pixbuf != NULL) { - /* Encode pixbuf type and data into XML string */ - pixbuf_data = bonobo_ui_util_pixbuf_to_xml (pixbuf); - - xml_item = g_strdup_printf ("<menuitem name=\"%s\" label=\"%s\" verb=\"%s\" pixtype=\"pixbuf\" pixname=\"%s\"/>\n", - item_name, encoded_label, command_name, pixbuf_data); - g_free (pixbuf_data); - } else { - xml_item = g_strdup_printf ("<menuitem name=\"%s\" label=\"%s\" verb=\"%s\"/>\n", - item_name, encoded_label, command_name); + break; + case NUMBERED_MENU_ITEM_RADIO: + xml_item = g_strdup_printf ("<menuitem name=\"%s\" label=\"%s\" id=\"%s\" type=\"radio\" group=\"%s\"/>\n", + item_name, encoded_label, command_name, radio_group_name); + break; + case NUMBERED_MENU_ITEM_PLAIN: + if (pixbuf != NULL) { + pixbuf_data = bonobo_ui_util_pixbuf_to_xml (pixbuf); + xml_item = g_strdup_printf ("<menuitem name=\"%s\" label=\"%s\" verb=\"%s\" pixtype=\"pixbuf\" pixname=\"%s\"/>\n", + item_name, encoded_label, command_name, pixbuf_data); + g_free (pixbuf_data); + } else { + xml_item = g_strdup_printf ("<menuitem name=\"%s\" label=\"%s\" verb=\"%s\"/>\n", + item_name, encoded_label, command_name); + } + break; + default: + g_assert_not_reached (); + xml_item = NULL; /* keep compiler happy */ } + g_free (encoded_label); g_free (item_name); @@ -269,11 +328,11 @@ nautilus_bonobo_add_numbered_menu_item (BonoboUIComponent *ui, g_return_if_fail (container_path != NULL); g_return_if_fail (label != NULL); - add_numbered_menu_item_internal (ui, container_path, index, label, FALSE, pixbuf); + add_numbered_menu_item_internal (ui, container_path, index, label, NUMBERED_MENU_ITEM_PLAIN, pixbuf, NULL); } /* Add a menu item specified by number into a given path. Used for - * dynamically creating a related series of menu items. Each index + * dynamically creating a related series of toggle menu items. Each index * must be unique (normal use is to call this in a loop, and * increment the index for each item). */ @@ -287,7 +346,26 @@ nautilus_bonobo_add_numbered_toggle_menu_item (BonoboUIComponent *ui, g_return_if_fail (container_path != NULL); g_return_if_fail (label != NULL); - add_numbered_menu_item_internal (ui, container_path, index, label, TRUE, NULL); + add_numbered_menu_item_internal (ui, container_path, index, label, NUMBERED_MENU_ITEM_TOGGLE, NULL, NULL); +} + +/* Add a menu item specified by number into a given path. Used for + * dynamically creating a related series of radio menu items. Each index + * must be unique (normal use is to call this in a loop, and + * increment the index for each item). + */ +void +nautilus_bonobo_add_numbered_radio_menu_item (BonoboUIComponent *ui, + const char *container_path, + guint index, + const char *label, + const char *radio_group_name) +{ + g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui)); + g_return_if_fail (container_path != NULL); + g_return_if_fail (label != NULL); + + add_numbered_menu_item_internal (ui, container_path, index, label, NUMBERED_MENU_ITEM_RADIO, NULL, radio_group_name); } void |