diff options
author | Peter Harvey <pah06@uow.edu.au> | 2005-10-17 04:29:26 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2005-10-17 04:29:26 +0800 |
commit | d21007362f8d0701d63e50fe6b219de067d95a87 (patch) | |
tree | 46326d5633d4f3c8504049476d0e72ae7ed0ca2c /lib | |
parent | 35b9deda1f37ac0cc81d926b5295983de6b55dcf (diff) | |
download | gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.gz gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.bz2 gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.lz gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.xz gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.tar.zst gsoc2013-epiphany-d21007362f8d0701d63e50fe6b219de067d95a87.zip |
H18 patch, by Peter Harvey <pah06@uow.edu.au>.
2005-10-16 Peter Harvey <pah06@uow.edu.au>
H18 patch, by Peter Harvey <pah06@uow.edu.au>.
* data/ui/epiphany-bookmark-editor-ui.xml:
* data/ui/epiphany-ui.xml:
* lib/egg/egg-editable-toolbar.c: (get_dock_position),
(get_toolbar_position), (get_toolbar_nth), (find_action),
(drag_data_delete_cb), (drag_begin_cb), (drag_end_cb),
(drag_data_get_cb), (move_item_cb), (set_dock_visible),
(remove_item_cb), (remove_toolbar_cb), (toggle_visibility_cb),
(egg_editable_toolbar_add_visibility_items),
(egg_editable_toolbar_add_popup_items), (popup_context_menu_cb),
(button_press_event_cb), (configure_item_sensitivity),
(configure_item_cursor), (connect_widget_signals),
(action_sensitive_cb), (create_item_from_action),
(create_item_from_position), (toolbar_drag_data_received_cb),
(toolbar_drag_drop_cb), (toolbar_drag_motion_cb),
(toolbar_drag_leave_cb), (configure_drag_dest), (create_dock),
(toolbar_changed_cb), (unparent_fixed), (update_fixed),
(toolbar_added_cb), (toolbar_removed_cb), (item_added_cb),
(item_removed_cb), (egg_editable_toolbar_construct),
(egg_editable_toolbar_set_ui_manager),
(egg_editable_toolbar_set_property),
(egg_editable_toolbar_get_property), (egg_editable_toolbar_init),
(egg_editable_toolbar_finalize),
(egg_editable_toolbar_get_edit_mode),
(egg_editable_toolbar_set_edit_mode),
(egg_editable_toolbar_set_fixed):
* lib/egg/egg-editable-toolbar.h:
* lib/egg/egg-toolbar-editor.c: (compare_items),
(item_added_or_removed_cb), (toolbar_removed_cb),
(egg_toolbar_editor_set_model), (egg_toolbar_editor_finalize),
(drag_begin_cb), (drag_end_cb), (drag_data_get_cb),
(editor_create_item), (editor_create_item_from_name),
(append_table), (update_editor_sheet), (egg_toolbar_editor_init):
* lib/egg/egg-toolbar-editor.h:
* lib/egg/egg-toolbars-model.c: (egg_toolbars_model_to_xml),
(egg_toolbars_model_save), (toolbar_node_new), (item_node_new),
(item_node_free), (toolbar_node_free),
(egg_toolbars_model_get_flags), (egg_toolbars_model_set_flags),
(egg_toolbars_model_get_data), (egg_toolbars_model_get_name),
(impl_add_item), (egg_toolbars_model_add_item),
(egg_toolbars_model_add_toolbar), (parse_data_list),
(parse_item_list), (parse_toolbars), (egg_toolbars_model_load),
(egg_toolbars_model_class_init), (egg_toolbars_model_init),
(egg_toolbars_model_finalize), (egg_toolbars_model_remove_toolbar),
(egg_toolbars_model_remove_item), (egg_toolbars_model_move_item),
(egg_toolbars_model_n_items), (egg_toolbars_model_item_nth),
(egg_toolbars_model_n_toolbars), (egg_toolbars_model_toolbar_nth),
(egg_toolbars_model_get_types), (egg_toolbars_model_set_types),
(fill_avail_array), (egg_toolbars_model_get_avail),
(egg_toolbars_model_get_n_avail), (egg_toolbars_model_set_n_avail):
* lib/egg/egg-toolbars-model.h:
* src/bookmarks/Makefile.am:
* src/bookmarks/ephy-bookmark-action-group.c: (smart_added_cb),
(smart_removed_cb), (node_changed_cb), (node_added_cb),
(node_removed_cb), (ephy_bookmark_group_new):
* src/bookmarks/ephy-bookmark-action-group.h:
* src/bookmarks/ephy-bookmark-action.c: (create_tool_item),
(ephy_bookmark_action_sync_icon), (show_context_menu),
(popup_menu_cb), (button_press_cb), (button_release_cb),
(connect_proxy), (ephy_bookmark_action_updated),
(ephy_bookmark_action_get_bookmark),
(ephy_bookmark_action_set_bookmark),
(ephy_bookmark_action_set_property),
(ephy_bookmark_action_get_property),
(ephy_bookmark_action_finalize), (ephy_bookmark_action_class_init),
(ephy_bookmark_action_init), (ephy_bookmark_action_name),
(ephy_bookmark_action_new):
* src/bookmarks/ephy-bookmark-action.h:
* src/bookmarks/ephy-bookmark-factory-action.c:
(ephy_bookmark_factory_action_get_type), (activate_item_cb),
(build_menu_for_topic), (build_menu), (remove_placeholder_cb),
(activate_placeholder_cb), (clicked_placeholder_cb),
(realize_placeholder_cb), (create_tool_item), (connect_proxy),
(ephy_bookmark_factory_action_class_init),
(ephy_bookmark_factory_action_new):
* src/bookmarks/ephy-bookmark-factory-action.h:
* src/bookmarks/ephy-bookmark-properties.c:
(ephy_bookmark_properties_set_property),
(ephy_bookmark_properties_get_property),
(bookmark_properties_response_cb), (update_entry),
(location_entry_changed_cb), (build_ui):
* src/bookmarks/ephy-bookmarks-editor.c: (add_entry_monitor),
(cmd_add_topic), (delete_topic_dialog_construct),
(cmd_bookmarks_import), (ephy_bookmarks_editor_finalize),
(ephy_bookmarks_editor_node_activated_cb),
(ephy_bookmarks_editor_update_menu), (view_focus_cb),
(add_focus_monitor), (remove_focus_monitor), (bookmarks_filter),
(search_entry_search_cb), (ephy_bookmarks_editor_construct),
(ephy_bookmarks_editor_set_parent),
(ephy_bookmarks_editor_set_property),
(ephy_bookmarks_editor_get_property), (ephy_bookmarks_editor_init):
* src/bookmarks/ephy-bookmarks-menu.c: (append_bookmarks),
(append_menu), (ephy_bookmarks_menu_build):
* src/bookmarks/ephy-bookmarks-menu.h:
* src/bookmarks/ephy-bookmarks-ui.c: (find_action),
(activate_bookmarks_menu), (activate_favorites_menu),
(erase_bookmarks_menu), (erase_favorites_menu), (tree_changed_cb),
(node_added_cb), (node_changed_cb), (node_removed_cb),
(ephy_bookmarks_ui_attach_window),
(ephy_bookmarks_ui_detach_window), (toolbar_node_removed_cb),
(topic_has_data), (topic_get_data), (topic_get_name),
(bookmark_has_data), (bookmark_get_data), (bookmark_get_name),
(bookmark_new_name), (ephy_bookmarks_ui_attach_toolbar_model),
(ephy_bookmarks_ui_detach_toolbar_model):
* src/bookmarks/ephy-bookmarks-ui.h:
* src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_get_type),
(ephy_bookmarks_init_defaults), (ephy_bookmarks_class_init),
(ephy_bookmarks_save_delayed), (add_to_favorites),
(update_bookmark_keywords), (ephy_bookmarks_init),
(ephy_bookmarks_finalize), (ephy_bookmarks_add),
(ephy_bookmarks_set_address), (ephy_bookmarks_set_icon),
(ephy_bookmarks_add_keyword),
(ephy_bookmarks_show_bookmark_properties),
(ephy_bookmarks_get_from_id), (ephy_bookmarks_compare_topics),
(ephy_bookmarks_compare_topic_pointers),
(ephy_bookmarks_compare_bookmarks),
(ephy_bookmarks_compare_bookmark_pointers):
* src/bookmarks/ephy-bookmarks.h:
* src/bookmarks/ephy-bookmarksbar-model.c:
* src/bookmarks/ephy-bookmarksbar-model.h:
* src/bookmarks/ephy-bookmarksbar.c:
* src/bookmarks/ephy-bookmarksbar.h:
* src/bookmarks/ephy-favorites-menu.c:
* src/bookmarks/ephy-favorites-menu.h:
* src/bookmarks/ephy-new-bookmark.c: (ephy_new_bookmark_add),
(build_editing_table), (ephy_new_bookmark_construct),
(ephy_new_bookmark_set_property), (ephy_new_bookmark_get_property):
* src/bookmarks/ephy-nodes-cover.c: (ephy_nodes_count_covered),
(ephy_nodes_remove_covered), (ephy_nodes_remove_not_covered),
(ephy_nodes_get_covered), (ephy_nodes_covered),
(ephy_nodes_get_covering):
* src/bookmarks/ephy-nodes-cover.h:
* src/bookmarks/ephy-open-tabs-action.c: (activate_cb),
(node_added_cb), (node_removed_cb), (ephy_open_tabs_group_new),
(ephy_open_tabs_action_name):
* src/bookmarks/ephy-open-tabs-action.h:
* src/bookmarks/ephy-related-action.c: (node_changed),
(node_destroyed), (open_link), (iface_init),
(ephy_related_action_get_type), (ephy_related_action_new):
* src/bookmarks/ephy-related-action.h:
* src/bookmarks/ephy-topic-action-group.c: (node_changed_cb),
(node_added_cb), (node_removed_cb), (ephy_topic_group_new):
* src/bookmarks/ephy-topic-action-group.h:
* src/bookmarks/ephy-topic-action.c: (ephy_topic_action_get_type),
(create_tool_item), (ephy_topic_action_sync_label), (get_popup),
(erase_popup), (child_added_cb), (child_changed_cb),
(child_removed_cb), (menu_destroy_cb), (menu_init_cb),
(button_deactivate_cb), (button_toggled_cb), (button_release_cb),
(button_press_cb), (connect_proxy), (ephy_topic_action_updated),
(ephy_topic_action_get_topic), (ephy_topic_action_set_topic),
(ephy_topic_action_set_property), (ephy_topic_action_get_property),
(ephy_topic_action_class_init), (ephy_topic_action_init),
(ephy_topic_action_name), (ephy_topic_action_new):
* src/bookmarks/ephy-topic-action.h:
* src/bookmarks/ephy-topic-factory-action.c:
(ephy_topic_factory_action_get_type), (sort_topics),
(activate_item_cb), (build_menu), (remove_placeholder_cb),
(activate_placeholder_cb), (clicked_placeholder_cb),
(realize_placeholder_cb), (create_tool_item), (connect_proxy),
(ephy_topic_factory_action_class_init),
(ephy_topic_factory_action_new):
* src/bookmarks/ephy-topic-factory-action.h:
* src/ephy-link-action.c: (ephy_link_action_group_get_type),
(ephy_link_action_group_new):
* src/ephy-link-action.h:
* src/ephy-lockdown.c: (find_name), (find_action_group),
(update_window):
* src/ephy-notebook.c: (move_tab_to_another_notebook),
(ephy_notebook_switch_page_cb), (ephy_notebook_init),
(tab_label_style_set_cb), (build_tab_label),
(ephy_notebook_add_tab):
* src/ephy-shell.c: (ephy_shell_get_toolbars_model):
* src/ephy-toolbar-editor.c: (ephy_toolbar_editor_constructor),
(ephy_toolbar_editor_finalize), (ephy_toolbar_editor_set_property),
(ephy_toolbar_editor_class_init):
* src/ephy-toolbar.c: (ephy_toolbar_realize),
(ephy_toolbar_unrealize), (ephy_toolbar_finalize):
* src/ephy-toolbars-model.c: (update_flags),
(ephy_toolbars_model_load):
* src/ephy-window.c: (ephy_window_get_type),
(get_chromes_visibility), (sync_chromes_visibility),
(ephy_window_key_press_event), (tool_item_enter_cb),
(tool_item_leave_cb), (tool_item_drag_begin_cb),
(connect_tool_item), (disconnect_tool_item), (disconnect_proxy_cb),
(connect_proxy_cb), (update_chromes_actions), (show_embed_popup),
(tab_added_cb), (tab_removed_cb), (ephy_window_set_chrome),
(ephy_window_dispose), (ephy_window_class_init),
(ephy_window_init), (ephy_window_finalize),
(ephy_window_remove_tab), (ephy_window_set_zoom),
(sync_prefs_with_chrome), (ephy_window_view_toolbar_cb):
* src/ephy-window.h:
Revision history:
h18, released 2005/09/23, for Epiphany 1.8.0
* Just an update for 1.8.0.
h17, released 2005/08/30, for Epiphany 1.7.6 or CVS HEAD
* Mostly just an update for 1.7.6.
* Topic menus on the toolbar now open without releasing the mouse button.
* Topic menus on the toolbar are now also hierarchical (see if you like it.
h16, released 2005/08/25, for Epiphany 1.7.5 or CVS HEAD
* Just an update for 1.7.5. Sorry, I've been busy. :)
h15, released 2005/07/19, for Epiphany 1.7.2 or CVS HEAD
* Code cleanup
h14, released 2005/07/9, for Epiphany 1.7.1 or CVS HEAD
* Improved helpful tip when adding a bookmark
* Improved toolbar context menu
* Toolbar visibility state is now saved
* Separated bookmark/topic action groups into separate files
* Topics in the overflow menu now behave as submenus
* Now importing old bookmarksbar, and saving to new filename
* Incremented toolbar file format version number to 1.1
* Fixed the 'sticky' statusbar help
* Fixed a crashing bug (dnd then open a topic on the toolbar)
h13, released 2005/05/12, for CVS HEAD
* Added middle-mouse drag-drop for the editable toolbar.
* Fixed some warnings at compile and run time.
* Added brief help for the user when adding a new bookmark.
* Cleaned up the editable toolbar code a little.
h12, released 2005/05/10, for CVS HEAD
* Added new editing facilities for the editable toolbar.
h11, released 2005/04/29, for CVS HEAD
* Fixed bug in statusbar information for toolbar items.
* Added an all-new 'Related' toolbar widget which changes to show
the most related topic whenever a bookmark is activated.
h10, released 2005/04/15, for Epiphany 1.6.2 or CVS HEAD
* Added statusbar information for all toolbar items.
* Empty toolbars are now only deleted when exiting edit mode.
* Fixed regression of middle-click for bookmarks on toolbar.
* Fixed regression of ellipsized bookmark names in menus.
h9, released 2005/04/12, for Epiphany 1.6.1
* Updated patch for 1.6.1. Long time no see.
* Now using EphyLink objects everywhere.
h7, released 2004/10/21, for Epiphany 1.4.4
* Updated patch for 1.4.4.
* Fixed bugs causing crashes when bookmarks were added (thanks Reinout).
* Added "Open in Tabs" back into bookmark menus where suitable.
h6, released 2004/09/20, for Epiphany 1.4.0
* Updated patch for 1.4.0.
* Removed the bookmarks bar.
* Generate shared XML string for bookmarks menu.
* Slightly improve performance of node-cover code.
* Delay adding bookmarks menu until it is first used.
* Fixed bug(?) in ephy-node.
h4, released 2004/08/08, for Epiphany 1.3.4
* Updated patch due to changes to topics selector.
* Removed 'Most Visited' from the min-cover calculations.
* Fixed Epiphany 1.3.4 bug where topics in selector aren't sorted.
* Updated patch due to other changes in Epiphany 1.3.4 source.
h3, released 2004/07/12, for Epiphany 1.3.2
* Simple update for Epiphany 1.3.2
h3, released 2004/05/24, for Epiphany 1.2.5
* Moved duplicated functions into a seperate file.
* Improved topic selector.
* Bookmarks toolbar topic menus now have subdivisions.
* Topic names in menu now change if modified in the bookmarks editor.
h2, released 2004/05/23, for Epiphany 1.2.5
* Significantly cleaned up the code.
* 'Most Visited' no longer appears as a submenu.
* Subtopics are selected much more intelligently, giving a better
approximation to a true minimum cover.
* Topic selector now shows suggestions with arrows, not bold font.
h1, released 2004/05/19, for Epiphany 1.2.5
* Initial release.
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/egg/egg-editable-toolbar.c | 1147 | ||||
-rwxr-xr-x | lib/egg/egg-editable-toolbar.h | 3 | ||||
-rwxr-xr-x | lib/egg/egg-toolbar-editor.c | 442 | ||||
-rwxr-xr-x | lib/egg/egg-toolbar-editor.h | 5 | ||||
-rwxr-xr-x | lib/egg/egg-toolbars-model.c | 670 | ||||
-rwxr-xr-x | lib/egg/egg-toolbars-model.h | 98 |
6 files changed, 1255 insertions, 1110 deletions
diff --git a/lib/egg/egg-editable-toolbar.c b/lib/egg/egg-editable-toolbar.c index 006df26a7..87b26b3bd 100755 --- a/lib/egg/egg-editable-toolbar.c +++ b/lib/egg/egg-editable-toolbar.c @@ -32,20 +32,27 @@ #include <gtk/gtkdnd.h> #include <gtk/gtkhbox.h> #include <gtk/gtkimage.h> +#include <gtk/gtkcheckmenuitem.h> #include <gtk/gtkimagemenuitem.h> +#include <gtk/gtkseparatormenuitem.h> #include <gtk/gtkmenu.h> #include <gtk/gtkstock.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkbutton.h> #include <gtk/gtktoolbar.h> #include <gtk/gtktoolitem.h> +#include <gtk/gtktoolbutton.h> #include <gtk/gtkseparatortoolitem.h> #include <glib/gi18n.h> #include <string.h> static void egg_editable_toolbar_class_init (EggEditableToolbarClass *klass); -static void egg_editable_toolbar_init (EggEditableToolbar *t); +static void egg_editable_toolbar_init (EggEditableToolbar *etoolbar); static void egg_editable_toolbar_finalize (GObject *object); #define MIN_TOOLBAR_HEIGHT 20 +#define EGG_ITEM_NAME "egg-item-name" +#define EGG_TOOLITEM "egg-toolitem" static const GtkTargetEntry dest_drag_types[] = { {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0}, @@ -74,13 +81,13 @@ struct _EggEditableToolbarPrivate { GtkUIManager *manager; EggToolbarsModel *model; - gboolean edit_mode; - GtkWidget *selected_toolbar; + guint edit_mode; + gboolean save_hidden; GtkWidget *fixed_toolbar; - gboolean pending; - GtkToolbar *target_toolbar; - GtkWidget *dragged_item; + guint dnd_pending; + GtkToolbar *dnd_toolbar; + GtkToolItem *dnd_toolitem; }; GType @@ -111,19 +118,25 @@ egg_editable_toolbar_get_type (void) } static int -get_toolbar_position (EggEditableToolbar *etoolbar, GtkWidget *toolbar) +get_dock_position (EggEditableToolbar *etoolbar, GtkWidget *dock) { GList *l; int result; l = gtk_container_get_children (GTK_CONTAINER (etoolbar)); - result = g_list_index (l, toolbar->parent); + result = g_list_index (l, dock); g_list_free (l); return result; } static int +get_toolbar_position (EggEditableToolbar *etoolbar, GtkWidget *toolbar) +{ + return get_dock_position (etoolbar, toolbar->parent); +} + +static int get_n_toolbars (EggEditableToolbar *etoolbar) { GList *l; @@ -159,6 +172,7 @@ get_toolbar_nth (EggEditableToolbar *etoolbar, GtkWidget *result; dock = get_dock_nth (etoolbar, position); + g_return_val_if_fail (dock != NULL, NULL); l = gtk_container_get_children (GTK_CONTAINER (dock)); result = GTK_WIDGET (l->data); @@ -168,13 +182,13 @@ get_toolbar_nth (EggEditableToolbar *etoolbar, } static GtkAction * -find_action (EggEditableToolbar *t, +find_action (EggEditableToolbar *etoolbar, const char *name) { GList *l; GtkAction *action = NULL; - l = gtk_ui_manager_get_action_groups (t->priv->manager); + l = gtk_ui_manager_get_action_groups (etoolbar->priv->manager); g_return_val_if_fail (name != NULL, NULL); @@ -197,6 +211,8 @@ drag_data_delete_cb (GtkWidget *widget, { int pos, toolbar_pos; + widget = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM); + g_return_if_fail (widget != NULL); g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar)); pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (widget->parent), @@ -212,7 +228,9 @@ drag_begin_cb (GtkWidget *widget, GdkDragContext *context, EggEditableToolbar *etoolbar) { - gtk_widget_hide (widget); + widget = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM); + g_return_if_fail (widget != NULL); + gtk_widget_hide (widget); } static void @@ -220,7 +238,9 @@ drag_end_cb (GtkWidget *widget, GdkDragContext *context, EggEditableToolbar *etoolbar) { - gtk_widget_show (widget); + widget = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM); + g_return_if_fail (widget != NULL); + gtk_widget_show (widget); } static void @@ -231,223 +251,481 @@ drag_data_get_cb (GtkWidget *widget, guint32 time, EggEditableToolbar *etoolbar) { - const char *id, *type; - char *target; + EggToolbarsModel *model; + const char *name; + char *data; + widget = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM); + g_return_if_fail (widget != NULL); + g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar)); - - type = g_object_get_data (G_OBJECT (widget), "type"); - id = g_object_get_data (G_OBJECT (widget), "id"); - if (strcmp (id, "separator") == 0) + model = egg_editable_toolbar_get_model (etoolbar); + + name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME); + if (name == NULL) { - target = g_strdup (id); + name = g_object_get_data (G_OBJECT (gtk_widget_get_parent (widget)), EGG_ITEM_NAME); + g_return_if_fail (name != NULL); } - else + + data = egg_toolbars_model_get_data (model, selection_data->target, name); + if (data != NULL) { - target = egg_toolbars_model_get_item_data (etoolbar->priv->model, - type, id); + gtk_selection_data_set (selection_data, selection_data->target, 8, (unsigned char *)data, strlen (data)); + g_free (data); } +} - gtk_selection_data_set (selection_data, - selection_data->target, 8, - (const guchar *)target, strlen (target)); - - g_free (target); +static void +move_item_cb (GtkWidget *menuitem, + EggEditableToolbar *etoolbar) +{ + GtkWidget *toolitem = g_object_get_data (G_OBJECT (menuitem), EGG_TOOLITEM); + GtkTargetList *list = gtk_target_list_new (dest_drag_types, G_N_ELEMENTS (dest_drag_types)); + gtk_drag_begin (toolitem, list, GDK_ACTION_MOVE, 1, NULL); + gtk_target_list_unref (list); } static void -set_drag_cursor (GtkWidget *widget) +set_dock_visible (EggEditableToolbar *etoolbar, + GtkWidget *dock, + gboolean visible) { - if (widget->window) + if (visible) { - GdkCursor *cursor; - GdkPixbuf *pixbuf; - - pixbuf = gdk_pixbuf_new_from_file (CURSOR_DIR "/hand-open.png", NULL); - cursor = gdk_cursor_new_from_pixbuf (gdk_display_get_default (), - pixbuf, 12, 12); - gdk_window_set_cursor (widget->window, cursor); - gdk_cursor_unref (cursor); - g_object_unref (pixbuf); + gtk_widget_show (dock); + } + else + { + gtk_widget_hide (dock); + } + + if (etoolbar->priv->save_hidden) + { + int position = get_dock_position (etoolbar, dock); + EggTbModelFlags flags = egg_toolbars_model_get_flags + (etoolbar->priv->model, position); + + if (visible) + { + flags &= ~(EGG_TB_MODEL_HIDDEN); + } + else + { + flags |= (EGG_TB_MODEL_HIDDEN); + } + + egg_toolbars_model_set_flags (etoolbar->priv->model, position, flags); } } static void -unset_drag_cursor (GtkWidget *widget) +remove_item_cb (GtkWidget *menuitem, + EggEditableToolbar *etoolbar) { - if (widget->window) + GtkWidget *toolitem = g_object_get_data (G_OBJECT (menuitem), EGG_TOOLITEM); + int pos, toolbar_pos; + + toolbar_pos = get_toolbar_position (etoolbar, toolitem->parent); + pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolitem->parent), + GTK_TOOL_ITEM (toolitem)); + + egg_toolbars_model_remove_item (etoolbar->priv->model, + toolbar_pos, pos); + + if (egg_toolbars_model_n_items (etoolbar->priv->model, toolbar_pos) == 0) { - gdk_window_set_cursor (widget->window, NULL); + egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos); } } static void -set_item_drag_source (EggToolbarsModel *model, - GtkWidget *item, - GtkAction *action, - gboolean is_separator, - const char *type) +remove_toolbar_cb (GtkWidget *menuitem, + EggEditableToolbar *etoolbar) { - GtkTargetEntry target_entry; - const char *id; + GtkWidget *toolbar = g_object_get_data (G_OBJECT (menuitem), "egg-toolbar"); + int toolbar_pos; - target_entry.target = (char *)type; - target_entry.flags = GTK_TARGET_SAME_APP; - target_entry.info = 0; + toolbar_pos = get_toolbar_position (etoolbar, toolbar); + egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos); +} - gtk_drag_source_set (item, GDK_BUTTON1_MASK, - &target_entry, 1, - GDK_ACTION_MOVE); +static void +toggle_visibility_cb (GtkWidget *menuitem, + EggEditableToolbar *etoolbar) +{ + GtkWidget *dock = g_object_get_data (G_OBJECT (menuitem), "egg-dock"); + set_dock_visible (etoolbar, dock, !GTK_WIDGET_VISIBLE (dock)); +} - if (is_separator) - { - GtkWidget *icon; - GdkPixbuf *pixbuf; +static void +egg_editable_toolbar_add_visibility_items (EggEditableToolbar *etoolbar, + GtkMenu *popup) +{ + EggToolbarsModel *model = etoolbar->priv->model; + GtkCheckMenuItem *item; + GtkWidget *dock; + int n_toolbars, n_items, n_visible = 0; + int i, j, k, l; - id = "separator"; + g_return_if_fail (model != NULL); + g_return_if_fail (etoolbar->priv->manager != NULL); - icon = _egg_editable_toolbar_new_separator_image (); - pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (icon)); - gtk_drag_source_set_icon_pixbuf (item, pixbuf); + n_toolbars = egg_toolbars_model_n_toolbars (model); + + for (i = 0; i < n_toolbars; i++) + { + dock = get_dock_nth (etoolbar, i); + if (GTK_WIDGET_VISIBLE (dock)) + n_visible++; } - else + + if (GTK_MENU_SHELL(popup)->children != NULL) { - const char *stock_id; - GValue value = { 0, }; - GdkPixbuf *pixbuf; + GtkWidget *separator = gtk_separator_menu_item_new (); + gtk_widget_show (separator); + gtk_menu_shell_append (GTK_MENU_SHELL (popup), separator); + } + + for (i = 0; i < n_toolbars; i++) + { + char buffer[40] = "Empty"; - id = gtk_action_get_name (action); + n_items = egg_toolbars_model_n_items (model, i); + for (k = 0, j = 0; j < n_items && k < sizeof(buffer)-1; j++) + { + GValue value = { 0, }; + GtkAction *action; + const char *name; + + name = egg_toolbars_model_item_nth (model, i, j); + if (name == NULL) continue; + action = find_action (etoolbar, name); + if (action == NULL) continue; + + g_value_init (&value, G_TYPE_STRING); + g_object_get_property (G_OBJECT (action), "label", &value); + name = g_value_get_string (&value); + if (name == NULL) continue; + + if (j > 0) + { + if(k<sizeof(buffer)-1) buffer[k++] = ','; + if(k<sizeof(buffer)-1) buffer[k++] = ' '; + } + + for (l = 0; name[l] && k<sizeof(buffer)-1; l++) + { + switch(name[l]) + { + case '_': + case '.': + case ',': + break; + default: + buffer[k++] = name[l]; + } + } + + if (name[l]) + { + l = k-5; + while(l>0 && buffer[l] != ',') l--; + if(buffer[l] == ',') k = l + 2; + else k = k-3; + + buffer[k++] = '.'; + buffer[k++] = '.'; + buffer[k++] = '.'; + buffer[k] = 0; + break; + } + + buffer[k] = 0; - g_value_init (&value, G_TYPE_STRING); - g_object_get_property (G_OBJECT (action), "stock_id", &value); - stock_id = g_value_get_string (&value); + g_value_unset (&value); + } + + + dock = get_dock_nth (etoolbar, i); + item = GTK_CHECK_MENU_ITEM (gtk_check_menu_item_new_with_label (buffer)); + gtk_check_menu_item_set_active (item, GTK_WIDGET_VISIBLE (dock)); + gtk_widget_set_sensitive (GTK_WIDGET (item), (n_visible > 1 || !GTK_WIDGET_VISIBLE (dock))); + gtk_widget_show (GTK_WIDGET (item)); + gtk_menu_shell_append (GTK_MENU_SHELL (popup), GTK_WIDGET (item)); + + g_object_set_data (G_OBJECT (item), "egg-dock", dock); + g_signal_connect (item, "toggled", + G_CALLBACK (toggle_visibility_cb), + etoolbar); + } +} - if (stock_id != NULL) +void +egg_editable_toolbar_add_popup_items (GtkWidget *widget, + GtkMenu *popup) +{ + EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR + (gtk_widget_get_ancestor (widget, EGG_TYPE_EDITABLE_TOOLBAR)); + GtkWidget *toolbar = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR); + GtkWidget *toolitem = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM); + GtkWidget *item, *image; + int separated; + + separated = (GTK_MENU_SHELL(popup)->children == NULL); + + if (etoolbar != NULL && toolitem != NULL) + { + if (!separated) { - pixbuf = gtk_widget_render_icon (item, stock_id, - GTK_ICON_SIZE_LARGE_TOOLBAR, NULL); + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (popup), item); + separated = 1; } - else + + item = gtk_menu_item_new_with_mnemonic (_("_Move on Toolbar")); + g_object_set_data (G_OBJECT (item), EGG_TOOLITEM, toolitem); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (popup), item); + g_signal_connect (item, "activate", + G_CALLBACK (move_item_cb), + etoolbar); + + item = gtk_image_menu_item_new_with_mnemonic (_("_Remove from Toolbar")); + g_object_set_data (G_OBJECT (item), EGG_TOOLITEM, toolitem); + gtk_widget_show (item); + image = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + gtk_menu_shell_append (GTK_MENU_SHELL (popup), item); + g_signal_connect (item, "activate", + G_CALLBACK (remove_item_cb), + etoolbar); + } + + if (etoolbar != NULL && toolbar != NULL) + { + int position; + EggTbModelFlags flags; + + position = get_toolbar_position (etoolbar, toolbar); + flags = egg_toolbars_model_get_flags (etoolbar->priv->model, position); + + if (etoolbar->priv->edit_mode > 0 && (flags & EGG_TB_MODEL_NOT_REMOVABLE)==0) { - pixbuf = gtk_widget_render_icon (item, GTK_STOCK_DND, - GTK_ICON_SIZE_LARGE_TOOLBAR, NULL); + if (!separated) + { + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (popup), item); + separated = 1; + } + + item = gtk_image_menu_item_new_with_mnemonic (_("_Remove Toolbar")); + g_object_set_data (G_OBJECT (item), "egg-toolbar", toolbar); + gtk_widget_show (item); + image = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + gtk_menu_shell_append (GTK_MENU_SHELL (popup), item); + g_signal_connect (item, "activate", + G_CALLBACK (remove_toolbar_cb), + etoolbar); } - gtk_drag_source_set_icon_pixbuf (item, pixbuf); - g_object_unref (pixbuf); - - g_value_unset (&value); + if (egg_toolbars_model_n_toolbars (etoolbar->priv->model) > 1) + { + egg_editable_toolbar_add_visibility_items (etoolbar, popup); + } } +} - g_object_set_data_full (G_OBJECT (item), "id", - g_strdup (id), g_free); - g_object_set_data_full (G_OBJECT (item), "type", - g_strdup (type), g_free); +static void +popup_context_menu_cb (GtkWidget *toolbar, + gint x, + gint y, + gint button_number, + EggEditableToolbar *etoolbar) +{ + GtkMenu *menu = GTK_MENU (gtk_menu_new ()); + egg_editable_toolbar_add_popup_items (toolbar, menu); + gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_number, + gtk_get_current_event_time ()); } -static GtkWidget * -create_item_from_action (EggEditableToolbar *t, - const char *action_name, - const char *type, - gboolean is_separator, - GtkAction **ret_action) +static gboolean +button_press_event_cb (GtkWidget *widget, + GdkEventButton *event, + EggEditableToolbar *etoolbar) +{ + if (event->button == 3) + { + GtkMenu *menu = GTK_MENU (gtk_menu_new ()); + egg_editable_toolbar_add_popup_items (widget, menu); + gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, + event->time); + return TRUE; + } + + return FALSE; +} + +static void +configure_item_sensitivity (GtkToolItem *item, EggEditableToolbar *etoolbar) { - GtkWidget *item; GtkAction *action; + char *name; + + g_return_if_fail (etoolbar != NULL); + + if (etoolbar->priv->edit_mode > 0) + { + GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (item), GTK_SENSITIVE); + gtk_tool_item_set_use_drag_window (item, TRUE); + gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE); + return; + } + + name = g_object_get_data (G_OBJECT (item), EGG_ITEM_NAME); + action = name ? find_action (etoolbar, name) : NULL; - if (is_separator) + if (action != NULL && gtk_action_is_sensitive (action)) { - item = GTK_WIDGET (gtk_separator_tool_item_new ()); - action = NULL; + GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (item), GTK_SENSITIVE); + gtk_tool_item_set_use_drag_window (item, FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE); } else { - g_return_val_if_fail (action_name != NULL, NULL); - - g_signal_emit (G_OBJECT (t), egg_editable_toolbar_signals[ACTION_REQUEST], - 0, action_name); - - action = find_action (t, action_name); - if (action) - { - item = gtk_action_create_tool_item (action); - } - else - { - return NULL; - } + gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); + gtk_tool_item_set_use_drag_window (item, TRUE); + GTK_WIDGET_SET_FLAGS (GTK_WIDGET (item), GTK_SENSITIVE); } +} - gtk_widget_show (item); +static void +configure_item_cursor (GtkToolItem *item, EggEditableToolbar *etoolbar) +{ + g_return_if_fail (etoolbar != NULL); + g_return_if_fail (GTK_WIDGET(item)->window != NULL); + + if (etoolbar->priv->edit_mode > 0) + { + GdkCursor *cursor; + GdkPixbuf *pixbuf; + + pixbuf = gdk_pixbuf_new_from_file (CURSOR_DIR "/hand-open.png", NULL); + cursor = gdk_cursor_new_from_pixbuf (gdk_display_get_default (), + pixbuf, 12, 12); + gdk_window_set_cursor (GTK_WIDGET(item)->window, cursor); + gdk_cursor_unref (cursor); + g_object_unref (pixbuf); - g_signal_connect (item, "drag_begin", - G_CALLBACK (drag_begin_cb), t); - g_signal_connect (item, "drag_end", - G_CALLBACK (drag_end_cb), t); - g_signal_connect (item, "drag_data_get", - G_CALLBACK (drag_data_get_cb), t); - g_signal_connect (item, "drag_data_delete", - G_CALLBACK (drag_data_delete_cb), t); + gtk_drag_source_set (GTK_WIDGET (item), GDK_BUTTON1_MASK, dest_drag_types, + G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE); + } + else + { + gdk_window_set_cursor (GTK_WIDGET(item)->window, NULL); + + gtk_drag_source_set (GTK_WIDGET (item), GDK_BUTTON2_MASK, dest_drag_types, + G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE); + } +} - if (t->priv->edit_mode) +static void +connect_widget_signals (GtkWidget *proxy, EggEditableToolbar *etoolbar) +{ + if (GTK_IS_CONTAINER (proxy)) { - set_drag_cursor (item); - gtk_widget_set_sensitive (item, TRUE); - set_item_drag_source (t->priv->model, item, action, - is_separator, type); - gtk_tool_item_set_use_drag_window (GTK_TOOL_ITEM (item), TRUE); + gtk_container_foreach (GTK_CONTAINER (proxy), + (GtkCallback) connect_widget_signals, + (gpointer) etoolbar); } - if (ret_action) + if (GTK_IS_BUTTON (proxy) || GTK_IS_TOOL_ITEM (proxy)) { - *ret_action = action; + g_signal_connect (proxy, "drag_begin", + G_CALLBACK (drag_begin_cb), etoolbar); + g_signal_connect (proxy, "drag_end", + G_CALLBACK (drag_end_cb), etoolbar); + g_signal_connect (proxy, "drag_data_get", + G_CALLBACK (drag_data_get_cb), etoolbar); + g_signal_connect (proxy, "drag_data_delete", + G_CALLBACK (drag_data_delete_cb), etoolbar); + g_signal_connect (proxy, "drag_data_get", + G_CALLBACK (drag_data_get_cb), etoolbar); + g_signal_connect (proxy, "button-press-event", + G_CALLBACK (button_press_event_cb), etoolbar); + gtk_drag_source_set (proxy, GDK_BUTTON2_MASK, dest_drag_types, + G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE); } +} - return item; +static void +action_sensitive_cb (GtkAction *action, + GParamSpec *pspec, + GtkToolItem *item) +{ + EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR + (gtk_widget_get_ancestor (GTK_WIDGET (item), EGG_TYPE_EDITABLE_TOOLBAR)); + configure_item_sensitivity (item, etoolbar); } -static GtkWidget * -create_item (EggEditableToolbar *t, - EggToolbarsModel *model, - int toolbar_position, - int position, - GtkAction **ret_action) +static GtkToolItem * +create_item_from_action (EggEditableToolbar *etoolbar, + const char *name) { - const char *action_name, *type; - gboolean is_separator; + GtkToolItem *item; + + g_return_val_if_fail (name != NULL, NULL); + + if (strcmp (name, "_separator") == 0) + { + item = gtk_separator_tool_item_new (); + gtk_tool_item_set_use_drag_window (item, TRUE); + } + else + { + GtkAction *action = find_action (etoolbar, name); + g_return_val_if_fail (action != NULL, NULL); + item = GTK_TOOL_ITEM (gtk_action_create_tool_item (action)); + + g_signal_connect_object (action, "notify::sensitive", + G_CALLBACK (action_sensitive_cb), item, 0); + } - egg_toolbars_model_item_nth (model, toolbar_position, position, - &is_separator, &action_name, &type); - return create_item_from_action (t, action_name, type, - is_separator, ret_action); + gtk_widget_show (GTK_WIDGET (item)); + + g_object_set_data_full (G_OBJECT (item), EGG_ITEM_NAME, + g_strdup (name), g_free); + + return item; } -static gboolean -data_is_separator (const char *data) +static GtkToolItem * +create_item_from_position (EggEditableToolbar *etoolbar, + int toolbar_position, + int position) { - return strcmp (data, "separator") == 0; + GtkToolItem *item; + const char *name; + + name = egg_toolbars_model_item_nth (etoolbar->priv->model, toolbar_position, position); + item = create_item_from_action (etoolbar, name); + + return item; } static void -drag_data_received_cb (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - EggEditableToolbar *etoolbar) +toolbar_drag_data_received_cb (GtkToolbar *toolbar, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection_data, + guint info, + guint time, + EggEditableToolbar *etoolbar) { - char *type; - char *id; - - GdkAtom target; - - target = gtk_drag_dest_find_target (widget, context, NULL); - type = egg_toolbars_model_get_item_type (etoolbar->priv->model, target); - id = egg_toolbars_model_get_item_id (etoolbar->priv->model, type, - (const char*)selection_data->data); - /* This function can be called for two reasons * * (1) drag_motion() needs an item to pass to @@ -459,113 +737,60 @@ drag_data_received_cb (GtkWidget *widget, * actually add a new item to the toolbar. */ - if (id == NULL) + GdkAtom type = selection_data->type; + const char *data = (char *)selection_data->data; + + int ipos = -1; + char *name = NULL; + + /* Find out where the drop is occuring, and the name of what is being dropped. */ + if (selection_data->length >= 0) { - etoolbar->priv->pending = FALSE; - g_free (type); - return; + ipos = gtk_toolbar_get_drop_index (toolbar, x, y); + name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, FALSE); } - if (etoolbar->priv->pending) + /* If we just want a highlight item, then . */ + if (etoolbar->priv->dnd_pending > 0) { - etoolbar->priv->pending = FALSE; - etoolbar->priv->dragged_item = - create_item_from_action (etoolbar, id, type, - data_is_separator (id), NULL); - g_object_ref (etoolbar->priv->dragged_item); - gtk_object_sink (GTK_OBJECT (etoolbar->priv->dragged_item)); - } - else - { - int pos, toolbar_pos; - - pos = gtk_toolbar_get_drop_index (GTK_TOOLBAR (widget), x, y); - toolbar_pos = get_toolbar_position (etoolbar, widget); - - if (data_is_separator ((const char*)selection_data->data)) - { - egg_toolbars_model_add_separator (etoolbar->priv->model, - toolbar_pos, pos); - } - else - { - egg_toolbars_model_add_item (etoolbar->priv->model, - toolbar_pos, pos, id, type); - } + etoolbar->priv->dnd_pending--; - gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, - time); - } - - g_free (type); - g_free (id); -} - -static void -remove_toolbar_cb (GtkWidget *menuitem, - EggEditableToolbar *etoolbar) -{ - int pos; - - pos = get_toolbar_position (etoolbar, etoolbar->priv->selected_toolbar); - egg_toolbars_model_remove_toolbar (etoolbar->priv->model, pos); -} - -static void -popup_toolbar_context_menu_cb (GtkWidget *toolbar, - gint x, - gint y, - gint button_number, - EggEditableToolbar *t) -{ - GtkWidget *menu; - GtkWidget *item; - GtkWidget *image; - - if (t->priv->edit_mode) - { - EggTbModelFlags flags; - int position; - - t->priv->selected_toolbar = toolbar; - - menu = gtk_menu_new (); - - item = gtk_image_menu_item_new_with_mnemonic (_("_Remove Toolbar")); - gtk_widget_show (item); - image = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU); - gtk_widget_show (image); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - g_signal_connect (item, "activate", - G_CALLBACK (remove_toolbar_cb), - t); - - position = get_toolbar_position (t, toolbar); - flags = egg_toolbars_model_get_flags (t->priv->model, position); - if (flags & EGG_TB_MODEL_NOT_REMOVABLE) + if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar) { - gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); + etoolbar->priv->dnd_toolitem = create_item_from_action (etoolbar, name); + gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar, + etoolbar->priv->dnd_toolitem, ipos); } - - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 2, - gtk_get_current_event_time ()); } -} - -static void -free_dragged_item (EggEditableToolbar *etoolbar) -{ - if (etoolbar->priv->dragged_item) + else { - gtk_widget_destroy (etoolbar->priv->dragged_item); - g_object_unref (etoolbar->priv->dragged_item); - etoolbar->priv->dragged_item = NULL; + gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0); + etoolbar->priv->dnd_toolbar = NULL; + etoolbar->priv->dnd_toolitem = NULL; + + /* If we don't have a name to use yet, try to create one. */ + if (name == NULL && selection_data->length >= 0) + { + name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE); + } + + if (name != NULL) + { + gint tpos = get_toolbar_position (etoolbar, GTK_WIDGET (toolbar)); + egg_toolbars_model_add_item (etoolbar->priv->model, tpos, ipos, name); + gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time); + } + else + { + gtk_drag_finish (context, FALSE, context->action == GDK_ACTION_MOVE, time); + } } + + g_free (name); } static gboolean -toolbar_drag_drop_cb (GtkWidget *widget, +toolbar_drag_drop_cb (GtkToolbar *toolbar, GdkDragContext *context, gint x, gint y, @@ -574,88 +799,46 @@ toolbar_drag_drop_cb (GtkWidget *widget, { GdkAtom target; - target = gtk_drag_dest_find_target (widget, context, NULL); + target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL); if (target != GDK_NONE) { - gtk_drag_get_data (widget, context, - target, - time); + gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time); return TRUE; } - free_dragged_item (etoolbar); - return FALSE; } static gboolean -toolbar_drag_motion_cb (GtkWidget *widget, +toolbar_drag_motion_cb (GtkToolbar *toolbar, GdkDragContext *context, gint x, gint y, guint time, EggEditableToolbar *etoolbar) { - GdkAtom target; - int index; - GtkToolbar *toolbar = GTK_TOOLBAR (widget); - GtkToolItem *item; - GtkWidget *source; - - source = gtk_drag_get_source_widget (context); - if (source) - { - EggTbModelFlags flags; - int pos; - gboolean is_item; - - pos = get_toolbar_position (etoolbar, widget); - flags = egg_toolbars_model_get_flags (etoolbar->priv->model, pos); - - is_item = etoolbar->priv->edit_mode && - (gtk_widget_get_ancestor (source, EGG_TYPE_EDITABLE_TOOLBAR) || - gtk_widget_get_ancestor (source, EGG_TYPE_TOOLBAR_EDITOR)); - - if ((flags & EGG_TB_MODEL_ACCEPT_ITEMS_ONLY) && !is_item) - { - gdk_drag_status (context, 0, time); - return FALSE; - } - - if (gtk_widget_is_ancestor (source, widget)) - { - context->suggested_action = GDK_ACTION_MOVE; - } - } - - target = gtk_drag_dest_find_target (widget, context, NULL); + GdkAtom target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL); if (target == GDK_NONE) { gdk_drag_status (context, 0, time); return FALSE; } - if (etoolbar->priv->target_toolbar != toolbar) + /* Make ourselves the current dnd toolbar, and request a highlight item. */ + if (etoolbar->priv->dnd_toolbar != toolbar) { - if (etoolbar->priv->target_toolbar) - gtk_toolbar_set_drop_highlight_item - (etoolbar->priv->target_toolbar, NULL, 0); - - free_dragged_item (etoolbar); - etoolbar->priv->pending = TRUE; - - etoolbar->priv->target_toolbar = toolbar; - - gtk_drag_get_data (widget, context, target, time); + etoolbar->priv->dnd_toolbar = toolbar; + etoolbar->priv->dnd_toolitem = NULL; + etoolbar->priv->dnd_pending++; + gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time); } - - if (etoolbar->priv->dragged_item != NULL && - etoolbar->priv->edit_mode) + + /* If a highlight item is available, use it. */ + else if (etoolbar->priv->dnd_toolitem) { - item = GTK_TOOL_ITEM (etoolbar->priv->dragged_item); - - index = gtk_toolbar_get_drop_index (toolbar, x, y); - gtk_toolbar_set_drop_highlight_item (toolbar, item, index); + gint ipos = gtk_toolbar_get_drop_index (etoolbar->priv->dnd_toolbar, x, y); + gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar, + etoolbar->priv->dnd_toolitem, ipos); } gdk_drag_status (context, context->suggested_action, time); @@ -669,53 +852,68 @@ toolbar_drag_leave_cb (GtkToolbar *toolbar, guint time, EggEditableToolbar *etoolbar) { - /* This is a workaround for bug 125557. Sometimes - * we seemingly enter another toolbar *before* leaving - * the current one. - * - * In that case etoolbar->priv->target_toolbar will - * have been set to something else and the highlighting - * will already have been turned off - */ - - if (etoolbar->priv->target_toolbar == toolbar) - { - gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0); + gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0); - etoolbar->priv->target_toolbar = NULL; - free_dragged_item (etoolbar); + /* If we were the current dnd toolbar target, remove the item. */ + if (etoolbar->priv->dnd_toolbar == toolbar) + { + etoolbar->priv->dnd_toolbar = NULL; + etoolbar->priv->dnd_toolitem = NULL; } } +static void +configure_drag_dest (EggEditableToolbar *etoolbar, + GtkToolbar *toolbar) +{ + EggToolbarsItemType *type; + GtkTargetList *targets; + GList *list; + + /* Make every toolbar able to receive drag-drops. */ + gtk_drag_dest_set (GTK_WIDGET (toolbar), 0, + dest_drag_types, G_N_ELEMENTS (dest_drag_types), + GDK_ACTION_MOVE | GDK_ACTION_COPY); + + /* Add any specialist drag-drop abilities. */ + targets = gtk_drag_dest_get_target_list (GTK_WIDGET (toolbar)); + list = egg_toolbars_model_get_types (etoolbar->priv->model); + while (list) + { + type = list->data; + if (type->new_name != NULL || type->get_name != NULL) + gtk_target_list_add (targets, type->type, 0, 0); + list = list->next; + } +} + + static GtkWidget * -create_dock (EggEditableToolbar *t) +create_dock (EggEditableToolbar *etoolbar) { GtkWidget *toolbar, *hbox; hbox = gtk_hbox_new (0, FALSE); - gtk_widget_show (hbox); toolbar = gtk_toolbar_new (); gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE); gtk_widget_show (toolbar); gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0); - gtk_drag_dest_set (toolbar, 0, - dest_drag_types, G_N_ELEMENTS (dest_drag_types), - GDK_ACTION_MOVE | GDK_ACTION_COPY); - g_signal_connect (toolbar, "drag_drop", - G_CALLBACK (toolbar_drag_drop_cb), t); + G_CALLBACK (toolbar_drag_drop_cb), etoolbar); g_signal_connect (toolbar, "drag_motion", - G_CALLBACK (toolbar_drag_motion_cb), t); + G_CALLBACK (toolbar_drag_motion_cb), etoolbar); g_signal_connect (toolbar, "drag_leave", - G_CALLBACK (toolbar_drag_leave_cb), t); + G_CALLBACK (toolbar_drag_leave_cb), etoolbar); g_signal_connect (toolbar, "drag_data_received", - G_CALLBACK (drag_data_received_cb), t); + G_CALLBACK (toolbar_drag_data_received_cb), etoolbar); g_signal_connect (toolbar, "popup_context_menu", - G_CALLBACK (popup_toolbar_context_menu_cb), t); + G_CALLBACK (popup_context_menu_cb), etoolbar); + configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar)); + return hbox; } @@ -737,14 +935,14 @@ unset_fixed_style (EggEditableToolbar *t) static void toolbar_changed_cb (EggToolbarsModel *model, int position, - EggEditableToolbar *t) + EggEditableToolbar *etoolbar) { GtkWidget *toolbar; EggTbModelFlags flags; GtkToolbarStyle style; flags = egg_toolbars_model_get_flags (model, position); - toolbar = get_toolbar_nth (t, position); + toolbar = get_toolbar_nth (etoolbar, position); if (flags & EGG_TB_MODEL_ICONS) { @@ -765,28 +963,28 @@ toolbar_changed_cb (EggToolbarsModel *model, else { gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar)); - if (position == 0 && t->priv->fixed_toolbar) + if (position == 0 && etoolbar->priv->fixed_toolbar) { - unset_fixed_style (t); + unset_fixed_style (etoolbar); } return; } gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style); - if (position == 0 && t->priv->fixed_toolbar) + if (position == 0 && etoolbar->priv->fixed_toolbar) { - set_fixed_style (t, style); + set_fixed_style (etoolbar, style); } } static void -unparent_fixed (EggEditableToolbar *t) +unparent_fixed (EggEditableToolbar *etoolbar) { GtkWidget *toolbar, *dock; - g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar)); + g_return_if_fail (GTK_IS_TOOLBAR (etoolbar->priv->fixed_toolbar)); - toolbar = t->priv->fixed_toolbar; - dock = get_dock_nth (t, 0); + toolbar = etoolbar->priv->fixed_toolbar; + dock = get_dock_nth (etoolbar, 0); if (dock && toolbar->parent != NULL) { @@ -795,13 +993,13 @@ unparent_fixed (EggEditableToolbar *t) } static void -update_fixed (EggEditableToolbar *t) +update_fixed (EggEditableToolbar *etoolbar) { GtkWidget *toolbar, *dock; - if (!t->priv->fixed_toolbar) return; + if (!etoolbar->priv->fixed_toolbar) return; - toolbar = t->priv->fixed_toolbar; - dock = get_dock_nth (t, 0); + toolbar = etoolbar->priv->fixed_toolbar; + dock = get_dock_nth (etoolbar, 0); if (dock && toolbar && toolbar->parent == NULL) { @@ -817,97 +1015,103 @@ update_fixed (EggEditableToolbar *t) static void toolbar_added_cb (EggToolbarsModel *model, int position, - EggEditableToolbar *t) + EggEditableToolbar *etoolbar) { GtkWidget *dock; - dock = create_dock (t); + dock = create_dock (etoolbar); + if ((egg_toolbars_model_get_flags (model, position) & EGG_TB_MODEL_HIDDEN) == 0) + gtk_widget_show (dock); gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT); - gtk_box_pack_start (GTK_BOX (t), dock, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0); - gtk_box_reorder_child (GTK_BOX (t), dock, position); + gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position); gtk_widget_show_all (dock); - update_fixed (t); + update_fixed (etoolbar); } static void toolbar_removed_cb (EggToolbarsModel *model, int position, - EggEditableToolbar *t) + EggEditableToolbar *etoolbar) { - GtkWidget *toolbar; + GtkWidget *dock; + int i; - if (position == 0 && t->priv->fixed_toolbar != NULL) + if (position == 0 && etoolbar->priv->fixed_toolbar != NULL) { - unparent_fixed (t); + unparent_fixed (etoolbar); } - toolbar = get_dock_nth (t, position); - gtk_widget_destroy (toolbar); + dock = get_dock_nth (etoolbar, position); + gtk_widget_destroy (dock); - update_fixed (t); + dock = NULL; + for (i = egg_toolbars_model_n_toolbars (model)-1; i >= 0; i--) + { + dock = get_dock_nth (etoolbar, i); + if (GTK_WIDGET_VISIBLE (dock)) break; + } + + if (i < 0 && dock != NULL) + { + set_dock_visible (etoolbar, dock, TRUE); + } + + update_fixed (etoolbar); } static void item_added_cb (EggToolbarsModel *model, - int toolbar_position, - int position, - EggEditableToolbar *t) + int tpos, + int ipos, + EggEditableToolbar *etoolbar) { GtkWidget *dock; GtkWidget *toolbar; - GtkWidget *item; - GtkAction *action; - - toolbar = get_toolbar_nth (t, toolbar_position); - item = create_item (t, model, toolbar_position, position, &action); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), - GTK_TOOL_ITEM (item), position); + GtkToolItem *item; - dock = get_dock_nth (t, toolbar_position); + toolbar = get_toolbar_nth (etoolbar, tpos); + item = create_item_from_position (etoolbar, tpos, ipos); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos); + + connect_widget_signals (GTK_WIDGET (item), etoolbar); + configure_item_cursor (item, etoolbar); + configure_item_sensitivity (item, etoolbar); + + dock = get_dock_nth (etoolbar, tpos); gtk_widget_set_size_request (dock, -1, -1); gtk_widget_queue_resize_no_redraw (dock); - - /* FIXME Hack to make tooltip work from gtk */ - if (action) - { - g_object_notify (G_OBJECT (action), "tooltip"); - } } static void item_removed_cb (EggToolbarsModel *model, int toolbar_position, int position, - EggEditableToolbar *t) + EggEditableToolbar *etoolbar) { GtkWidget *toolbar; GtkWidget *item; - toolbar = get_toolbar_nth (t, toolbar_position); + toolbar = get_toolbar_nth (etoolbar, toolbar_position); item = GTK_WIDGET (gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), position)); g_return_if_fail (item != NULL); gtk_container_remove (GTK_CONTAINER (toolbar), item); - - if (egg_toolbars_model_n_items (model, toolbar_position) == 0) - { - egg_toolbars_model_remove_toolbar (model, toolbar_position); - } } static void -egg_editable_toolbar_construct (EggEditableToolbar *t) +egg_editable_toolbar_construct (EggEditableToolbar *etoolbar) { int i, l, n_items, n_toolbars; - EggToolbarsModel *model = t->priv->model; + EggToolbarsModel *model = etoolbar->priv->model; g_return_if_fail (model != NULL); - g_return_if_fail (t->priv->manager != NULL); + g_return_if_fail (etoolbar->priv->manager != NULL); n_toolbars = egg_toolbars_model_n_toolbars (model); @@ -915,26 +1119,24 @@ egg_editable_toolbar_construct (EggEditableToolbar *t) { GtkWidget *toolbar, *dock; - dock = create_dock (t); - gtk_box_pack_start (GTK_BOX (t), dock, TRUE, TRUE, 0); - toolbar = get_toolbar_nth (t, i); + dock = create_dock (etoolbar); + if ((egg_toolbars_model_get_flags (model, i) & EGG_TB_MODEL_HIDDEN) == 0) + gtk_widget_show (dock); + gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0); + toolbar = get_toolbar_nth (etoolbar, i); n_items = egg_toolbars_model_n_items (model, i); for (l = 0; l < n_items; l++) { - GtkWidget *item; - GtkAction *action; + GtkToolItem *item; - item = create_item (t, model, i, l, &action); + item = create_item_from_position (etoolbar, i, l); if (item) { - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), - GTK_TOOL_ITEM (item), l); - /* FIXME Hack to make tooltip work from gtk */ - if (action) - { - g_object_notify (G_OBJECT (action), "tooltip"); - } + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l); + + connect_widget_signals (GTK_WIDGET (item), etoolbar); + configure_item_sensitivity (item, etoolbar); } else { @@ -950,12 +1152,12 @@ egg_editable_toolbar_construct (EggEditableToolbar *t) } } - update_fixed (t); + update_fixed (etoolbar); /* apply styles */ for (i = 0; i < n_toolbars; i ++) { - toolbar_changed_cb (model, i, t); + toolbar_changed_cb (model, i, etoolbar); } } @@ -1030,12 +1232,12 @@ egg_editable_toolbar_set_model (EggEditableToolbar *toolbar, } static void -egg_editable_toolbar_set_ui_manager (EggEditableToolbar *t, +egg_editable_toolbar_set_ui_manager (EggEditableToolbar *etoolbar, GtkUIManager *manager) { g_return_if_fail (GTK_IS_UI_MANAGER (manager)); - t->priv->manager = g_object_ref (manager); + etoolbar->priv->manager = g_object_ref (manager); } static void @@ -1044,15 +1246,15 @@ egg_editable_toolbar_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - EggEditableToolbar *t = EGG_EDITABLE_TOOLBAR (object); + EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object); switch (prop_id) { case PROP_UI_MANAGER: - egg_editable_toolbar_set_ui_manager (t, g_value_get_object (value)); + egg_editable_toolbar_set_ui_manager (etoolbar, g_value_get_object (value)); break; case PROP_TOOLBARS_MODEL: - egg_editable_toolbar_set_model (t, g_value_get_object (value)); + egg_editable_toolbar_set_model (etoolbar, g_value_get_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1066,15 +1268,15 @@ egg_editable_toolbar_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - EggEditableToolbar *t = EGG_EDITABLE_TOOLBAR (object); + EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object); switch (prop_id) { case PROP_UI_MANAGER: - g_value_set_object (value, t->priv->manager); + g_value_set_object (value, etoolbar->priv->manager); break; case PROP_TOOLBARS_MODEL: - g_value_set_object (value, t->priv->model); + g_value_set_object (value, etoolbar->priv->model); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1120,30 +1322,31 @@ egg_editable_toolbar_class_init (EggEditableToolbarClass *klass) } static void -egg_editable_toolbar_init (EggEditableToolbar *t) +egg_editable_toolbar_init (EggEditableToolbar *etoolbar) { - t->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (t); + etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar); + etoolbar->priv->save_hidden = TRUE; } static void egg_editable_toolbar_finalize (GObject *object) { - EggEditableToolbar *t = EGG_EDITABLE_TOOLBAR (object); + EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object); - if (t->priv->fixed_toolbar) + if (etoolbar->priv->fixed_toolbar) { - g_object_unref (t->priv->fixed_toolbar); + g_object_unref (etoolbar->priv->fixed_toolbar); } - if (t->priv->manager) + if (etoolbar->priv->manager) { - g_object_unref (t->priv->manager); + g_object_unref (etoolbar->priv->manager); } - if (t->priv->model) + if (etoolbar->priv->model) { - egg_editable_toolbar_disconnect_model (t); - g_object_unref (t->priv->model); + egg_editable_toolbar_disconnect_model (etoolbar); + g_object_unref (etoolbar->priv->model); } G_OBJECT_CLASS (parent_class)->finalize (object); @@ -1170,55 +1373,52 @@ egg_editable_toolbar_new_with_model (GtkUIManager *manager, gboolean egg_editable_toolbar_get_edit_mode (EggEditableToolbar *etoolbar) { - return etoolbar->priv->edit_mode; + return (etoolbar->priv->edit_mode > 0); } void egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar, gboolean mode) { - int i, l, n_toolbars, n_items; + int i, l, n_items; - etoolbar->priv->edit_mode = mode; - - n_toolbars = get_n_toolbars (etoolbar); - for (i = 0; i < n_toolbars; i++) + i = etoolbar->priv->edit_mode; + if (mode) { - GtkWidget *toolbar; - - toolbar = get_toolbar_nth (etoolbar, i); - n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar)); - for (l = 0; l < n_items; l++) + etoolbar->priv->edit_mode++; + } + else + { + g_return_if_fail (etoolbar->priv->edit_mode > 0); + etoolbar->priv->edit_mode--; + } + i *= etoolbar->priv->edit_mode; + + if (i == 0) + { + for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--) { - GtkToolItem *item; - const char *action_name, *type; - gboolean is_separator; - GtkAction *action = NULL; - - egg_toolbars_model_item_nth (etoolbar->priv->model, i, l, - &is_separator, &action_name, &type); - action = find_action (etoolbar, action_name); - - item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l); - gtk_tool_item_set_use_drag_window (item, mode); - - if (mode) - { - set_drag_cursor (GTK_WIDGET (item)); - gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE); - set_item_drag_source (etoolbar->priv->model, GTK_WIDGET (item), - action, is_separator, type); - } - else - { - unset_drag_cursor (GTK_WIDGET (item)); - gtk_drag_source_unset (GTK_WIDGET (item)); + GtkWidget *toolbar; + + toolbar = get_toolbar_nth (etoolbar, i); + n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar)); - if (!is_separator) + if (n_items == 0 && etoolbar->priv->edit_mode == 0) + { + egg_toolbars_model_remove_toolbar (etoolbar->priv->model, i); + } + else + { + for (l = 0; l < n_items; l++) { - g_object_notify (G_OBJECT (action), "sensitive"); + GtkToolItem *item; + + item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l); + + configure_item_cursor (item, etoolbar); + configure_item_sensitivity (item, etoolbar); } - } + } } } } @@ -1292,35 +1492,6 @@ egg_editable_toolbar_set_fixed (EggEditableToolbar *toolbar, update_fixed (toolbar); } -void -egg_editable_toolbar_set_drag_dest (EggEditableToolbar *etoolbar, - const GtkTargetEntry *targets, - gint n_targets, - const char *toolbar_name) -{ - int i, n_toolbars; - EggToolbarsModel *model = etoolbar->priv->model; - - g_return_if_fail (model != NULL); - - n_toolbars = egg_toolbars_model_n_toolbars (model); - for (i = 0; i < n_toolbars; i++) - { - const char *name; - - name = egg_toolbars_model_toolbar_nth (model, i); - if (strcmp (toolbar_name, name) == 0) - { - GtkWidget *widget = get_toolbar_nth (etoolbar, i); - - gtk_drag_dest_unset (widget); - gtk_drag_dest_set (widget, 0, - targets, n_targets, - GDK_ACTION_MOVE | GDK_ACTION_COPY); - } - } -} - #define DEFAULT_ICON_HEIGHT 20 #define DEFAULT_ICON_WIDTH 0 diff --git a/lib/egg/egg-editable-toolbar.h b/lib/egg/egg-editable-toolbar.h index 9f143da70..d91e916dd 100755 --- a/lib/egg/egg-editable-toolbar.h +++ b/lib/egg/egg-editable-toolbar.h @@ -29,6 +29,7 @@ #include <gtk/gtkvbox.h> #include <gtk/gtktoolitem.h> #include <gtk/gtktoolbar.h> +#include <gtk/gtkmenu.h> G_BEGIN_DECLS @@ -80,6 +81,8 @@ void egg_editable_toolbar_set_drag_dest (EggEditableToolbar *etoolbar, void egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar, GtkToolbar *fixed_toolbar); +void egg_editable_toolbar_add_popup_items (GtkWidget *widget, + GtkMenu *popup); /* Private Functions */ diff --git a/lib/egg/egg-toolbar-editor.c b/lib/egg/egg-toolbar-editor.c index bd79724a8..4cb7d0ccc 100755 --- a/lib/egg/egg-toolbar-editor.c +++ b/lib/egg/egg-toolbar-editor.c @@ -34,6 +34,7 @@ #include <gtk/gtktable.h> #include <gtk/gtkstock.h> #include <gtk/gtkhbox.h> +#include <gtk/gtk.h> static const GtkTargetEntry dest_drag_types[] = { {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0}, @@ -46,7 +47,6 @@ static const GtkTargetEntry source_drag_types[] = { static void egg_toolbar_editor_class_init (EggToolbarEditorClass *klass); static void egg_toolbar_editor_init (EggToolbarEditor *t); static void egg_toolbar_editor_finalize (GObject *object); -static void update_actions_list (EggToolbarEditor *editor); static void update_editor_sheet (EggToolbarEditor *editor); enum @@ -67,9 +67,8 @@ struct EggToolbarEditorPrivate GtkWidget *table; GtkWidget *scrolled_window; - - GList *default_actions_list; - GList *actions_list; + GList *actions_list; + GList *factory_list; }; GType @@ -100,27 +99,18 @@ egg_toolbar_editor_get_type (void) } static gint -compare_actions (gconstpointer a, - gconstpointer b) +compare_items (gconstpointer a, + gconstpointer b) { - GValue value_a = { 0, }, value_b = { 0, }; - const char *short_label_a, *short_label_b; - int ret; - - g_value_init (&value_a, G_TYPE_STRING); - g_object_get_property (G_OBJECT (a), "short_label", &value_a); - short_label_a = g_value_get_string (&value_a); - - g_value_init (&value_b, G_TYPE_STRING); - g_object_get_property (G_OBJECT (b), "short_label", &value_b); - short_label_b = g_value_get_string (&value_b); - - ret = g_utf8_collate (short_label_a, short_label_b); - - g_value_unset (&value_a); - g_value_unset (&value_b); - - return ret; + const GtkWidget *item1 = a; + const GtkWidget *item2 = b; + + char *key1 = g_object_get_data (G_OBJECT (item1), + "egg-collate-key"); + char *key2 = g_object_get_data (G_OBJECT (item2), + "egg-collate-key"); + + return strcmp (key1, key2); } static GtkAction * @@ -157,11 +147,19 @@ egg_toolbar_editor_set_ui_manager (EggToolbarEditor *t, } static void +item_added_or_removed_cb (EggToolbarsModel *model, + int tpos, + int ipos, + EggToolbarEditor *editor) +{ + update_editor_sheet (editor); +} + +static void toolbar_removed_cb (EggToolbarsModel *model, int position, EggToolbarEditor *editor) { - update_actions_list (editor); update_editor_sheet (editor); } @@ -172,7 +170,13 @@ egg_toolbar_editor_set_model (EggToolbarEditor *t, g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (t)); t->priv->model = g_object_ref (model); + + update_editor_sheet (t); + g_signal_connect_object (model, "item_added", + G_CALLBACK (item_added_or_removed_cb), t, 0); + g_signal_connect_object (model, "item_removed", + G_CALLBACK (item_added_or_removed_cb), t, 0); g_signal_connect_object (model, "toolbar_removed", G_CALLBACK (toolbar_removed_cb), t, 0); } @@ -261,8 +265,8 @@ egg_toolbar_editor_finalize (GObject *object) g_object_unref (editor->priv->model); } - g_list_free (editor->priv->default_actions_list); g_list_free (editor->priv->actions_list); + g_list_free (editor->priv->factory_list); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -281,66 +285,14 @@ static void drag_begin_cb (GtkWidget *widget, GdkDragContext *context) { - gtk_widget_hide (widget); + gtk_widget_hide (widget); } static void drag_end_cb (GtkWidget *widget, GdkDragContext *context) { - gtk_widget_show (widget); -} - -static void -editor_drag_data_received_cb (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time_, - EggToolbarEditor *editor) -{ - GtkAction *action; - const char *data; - - g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor)); - g_return_if_fail (selection_data != NULL); - - if (selection_data->length <= 0 || selection_data->data == NULL) return; - - data = (const char *) selection_data->data; - - if (strcmp (data, "separator") == 0) return; - - action = find_action (editor, data); - g_return_if_fail (action != NULL); - - if (g_list_find (editor->priv->default_actions_list, action)) - { - editor->priv->actions_list = g_list_insert_sorted - (editor->priv->actions_list, action, compare_actions); - } - - update_editor_sheet (editor); -} - -static void -editor_drag_data_delete_cb (GtkWidget *widget, - GdkDragContext *context, - EggToolbarEditor *editor) -{ - GtkAction *action; - g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor)); - - action = GTK_ACTION (g_object_get_data (G_OBJECT (widget), "egg-action")); - if (action) - { - editor->priv->actions_list = g_list_remove - (editor->priv->actions_list, action); - } - - update_editor_sheet (editor); + gtk_widget_show (widget); } static void @@ -351,23 +303,12 @@ drag_data_get_cb (GtkWidget *widget, guint32 time, EggToolbarEditor *editor) { - GtkAction *action; const char *target; - action = GTK_ACTION (g_object_get_data (G_OBJECT (widget), "egg-action")); - - if (action) - { - target = gtk_action_get_name (action); - } - else - { - target = "separator"; - } - - gtk_selection_data_set (selection_data, - selection_data->target, 8, - (const guchar *)target, strlen (target)); + target = g_object_get_data (G_OBJECT (widget), "egg-item-name"); + g_return_if_fail (target != NULL); + + gtk_selection_data_set (selection_data, selection_data->target, 8, target, strlen (target)); } static gchar * @@ -454,8 +395,6 @@ editor_create_item (EggToolbarEditor *editor, source_drag_types, G_N_ELEMENTS (source_drag_types), action); g_signal_connect (event_box, "drag_data_get", G_CALLBACK (drag_data_get_cb), editor); - g_signal_connect (event_box, "drag_data_delete", - G_CALLBACK (editor_drag_data_delete_cb), editor); g_signal_connect_after (event_box, "realize", G_CALLBACK (event_box_realize_cb), icon); @@ -482,80 +421,174 @@ editor_create_item (EggToolbarEditor *editor, return event_box; } -static void -update_editor_sheet (EggToolbarEditor *editor) +static GtkWidget * +editor_create_item_from_name (EggToolbarEditor *editor, + const char * name, + GdkDragAction drag_action) { - GList *l; - GList *to_drag; - int x, y, height, width; - GtkWidget *table; - GtkWidget *viewport; GtkWidget *item; - GtkWidget *icon; - - g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor)); - - viewport = GTK_BIN (editor->priv->scrolled_window)->child; - if (viewport) + const char *item_name; + const char *stock_id; + const char *short_label; + const char *collate_key; + + if (strcmp (name, "_separator") == 0) { - table = GTK_BIN (viewport)->child; - gtk_container_remove (GTK_CONTAINER (viewport), table); + GtkWidget *icon; + + icon = _egg_editable_toolbar_new_separator_image (); + short_label = _("Separator"); + item_name = strdup (name); + collate_key = g_utf8_collate_key (short_label, -1); + item = editor_create_item (editor, GTK_IMAGE (icon), + short_label, drag_action); } - table = gtk_table_new (0, 0, TRUE); - editor->priv->table = table; - gtk_container_set_border_width (GTK_CONTAINER (table), 12); - gtk_widget_show (table); - gtk_scrolled_window_add_with_viewport - (GTK_SCROLLED_WINDOW (editor->priv->scrolled_window), table); - gtk_drag_dest_set (table, GTK_DEST_DEFAULT_ALL, - dest_drag_types, G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE); - g_signal_connect (table, "drag_data_received", - G_CALLBACK (editor_drag_data_received_cb), editor); - - to_drag = editor->priv->actions_list; - - x = y = 0; - width = 4; - height = (g_list_length (to_drag)) / width + 1; - gtk_table_resize (GTK_TABLE (editor->priv->table), height, width); - - for (l = to_drag; l != NULL; l = l->next) + else { - GtkAction *action = (l->data); - const char *stock_id, *short_label; GValue value = { 0, }; + GtkAction *action; + GtkWidget *icon; + + action = find_action (editor, name); + g_return_val_if_fail (action != NULL, NULL); g_value_init (&value, G_TYPE_STRING); g_object_get_property (G_OBJECT (action), "stock_id", &value); stock_id = g_value_get_string (&value); - icon = gtk_image_new_from_stock - (stock_id ? stock_id : GTK_STOCK_DND, - GTK_ICON_SIZE_LARGE_TOOLBAR); + icon = gtk_image_new_from_stock (stock_id ? stock_id : GTK_STOCK_DND, + GTK_ICON_SIZE_LARGE_TOOLBAR); g_value_unset (&value); - + g_value_init (&value, G_TYPE_STRING); g_object_get_property (G_OBJECT (action), "short_label", &value); short_label = g_value_get_string (&value); + + item_name = strdup (name); + collate_key = g_utf8_collate_key (short_label, -1); item = editor_create_item (editor, GTK_IMAGE (icon), - short_label, GDK_ACTION_MOVE); + short_label, drag_action); g_value_unset (&value); - g_object_set_data (G_OBJECT (item), "egg-action", action); - gtk_table_attach_defaults (GTK_TABLE (editor->priv->table), - item, x, x + 1, y, y + 1); + } + + g_object_set_data_full (G_OBJECT (item), "egg-collate-key", + (gpointer) collate_key, g_free); + g_object_set_data_full (G_OBJECT (item), "egg-item-name", + (gpointer) item_name, g_free); + + return item; +} - x++; - if (x >= width) - { - x = 0; - y++; - } +static gint +append_table (GtkTable *table, GList *items, gint y, gint width) +{ + if (items != NULL) + { + gint x = 0, height; + GtkWidget *alignment; + GtkWidget *item; + + height = g_list_length (items) / width + 1; + gtk_table_resize (table, height, width); + + if (y > 0) + { + item = gtk_hseparator_new (); + alignment = gtk_alignment_new (0.5, 0.5, 1.0, 0.0); + gtk_container_add (GTK_CONTAINER (alignment), item); + gtk_widget_show (alignment); + gtk_widget_show (item); + + gtk_table_attach_defaults (table, alignment, 0, width, y-1, y+1); + } + + for (; items != NULL; items = items->next) + { + item = items->data; + alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); + gtk_container_add (GTK_CONTAINER (alignment), item); + gtk_widget_show (alignment); + gtk_widget_show (item); + + if (x >= width) + { + x = 0; + y++; + } + gtk_table_attach_defaults (table, alignment, x, x+1, y, y+1); + x++; + } + + y++; } + return y; +} + +static void +update_editor_sheet (EggToolbarEditor *editor) +{ + gint y; + GPtrArray *items; + GList *to_move = NULL, *to_copy = NULL; + GtkWidget *table; + GtkWidget *viewport; + + g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor)); + + /* Create new table. */ + table = gtk_table_new (0, 0, TRUE); + editor->priv->table = table; + gtk_container_set_border_width (GTK_CONTAINER (table), 12); + gtk_table_set_row_spacings (GTK_TABLE (table), 24); + gtk_widget_show (table); + gtk_drag_dest_set (table, GTK_DEST_DEFAULT_ALL, + dest_drag_types, G_N_ELEMENTS (dest_drag_types), + GDK_ACTION_MOVE | GDK_ACTION_COPY); + + /* Build two lists of items (one for copying, one for moving). */ + items = egg_toolbars_model_get_avail (editor->priv->model); + while (items->len > 0) + { + GtkWidget *item; + const char *name; + + name = g_ptr_array_index (items, 0); + g_ptr_array_remove_index_fast (items, 0); + + if (egg_toolbars_model_get_n_avail (editor->priv->model, name) == 1) + { + item = editor_create_item_from_name (editor, name, GDK_ACTION_MOVE); + if (item != NULL) + to_move = g_list_insert_sorted (to_move, item, compare_items); + } + else + { + item = editor_create_item_from_name (editor, name, GDK_ACTION_COPY); + if (item != NULL) + to_copy = g_list_insert_sorted (to_copy, item, compare_items); + } + } + + /* Add them to the sheet. */ + y = 0; + y = append_table (GTK_TABLE (table), to_move, y, 4); + y = append_table (GTK_TABLE (table), to_copy, y, 4); + + g_list_free (to_move); + g_list_free (to_copy); + g_ptr_array_free (items, TRUE); + + /* Delete old table. */ + viewport = GTK_BIN (editor->priv->scrolled_window)->child; + if (viewport) + { + gtk_container_remove (GTK_CONTAINER (viewport), + GTK_BIN (viewport)->child); + } + + /* Add table to window. */ + gtk_scrolled_window_add_with_viewport + (GTK_SCROLLED_WINDOW (editor->priv->scrolled_window), table); - icon = _egg_editable_toolbar_new_separator_image (); - item = editor_create_item (editor, GTK_IMAGE (icon), _("Separator"), - GDK_ACTION_COPY); - gtk_table_attach_defaults (GTK_TABLE (editor->priv->table), - item, x, x + 1, y, y + 1); } static void @@ -578,113 +611,8 @@ egg_toolbar_editor_init (EggToolbarEditor *t) t->priv = EGG_TOOLBAR_EDITOR_GET_PRIVATE (t); t->priv->manager = NULL; - t->priv->default_actions_list = NULL; t->priv->actions_list = NULL; setup_editor (t); } -void -egg_toolbar_editor_add_action (EggToolbarEditor *editor, - const char *action_name) -{ - GtkAction *action; - - action = find_action (editor, action_name); - g_return_if_fail (action != NULL); - - editor->priv->default_actions_list = g_list_insert_sorted - (editor->priv->default_actions_list, action, compare_actions); -} - -static void -parse_item_list (EggToolbarEditor *t, - xmlNodePtr child) -{ - while (child) - { - if (xmlStrEqual (child->name, (const xmlChar*) "toolitem")) - { - xmlChar *name; - - name = xmlGetProp (child, (const xmlChar*) "name"); - egg_toolbar_editor_add_action (t, (const char*)name); - xmlFree (name); - } - child = child->next; - } -} - -static gboolean -model_has_action (EggToolbarsModel *model, GtkAction *action) -{ - int i, l, n_items, n_toolbars; - - n_toolbars = egg_toolbars_model_n_toolbars (model); - for (i = 0; i < n_toolbars; i++) - { - n_items = egg_toolbars_model_n_items (model, i); - for (l = 0; l < n_items; l++) - { - const char *name; - const char *action_name; - gboolean sep; - - egg_toolbars_model_item_nth (model, i, l, &sep, &name, NULL); - action_name = gtk_action_get_name (action); - if (!sep && strcmp (name, action_name) == 0) return TRUE; - } - } - - return FALSE; -} - -static void -update_actions_list (EggToolbarEditor *editor) -{ - GList *l; - - if (editor->priv->actions_list) - g_list_free (editor->priv->actions_list); - - /* Remove the already used items */ - editor->priv->actions_list = NULL; - - for (l = editor->priv->default_actions_list; l != NULL; l = l->next) - { - GtkAction *action = GTK_ACTION (l->data); - - if (!model_has_action (editor->priv->model, action)) - { - editor->priv->actions_list = g_list_insert_sorted - (editor->priv->actions_list, action, compare_actions); - } - } -} - -void -egg_toolbar_editor_load_actions (EggToolbarEditor *editor, - const char *xml_file) -{ - xmlDocPtr doc; - xmlNodePtr root; - xmlNodePtr child; - - doc = xmlParseFile (xml_file); - root = xmlDocGetRootElement (doc); - child = root->children; - - while (child) - { - if (xmlStrEqual (child->name, (const xmlChar*) "available")) - { - parse_item_list (editor, child->children); - } - child = child->next; - } - - xmlFreeDoc (doc); - - update_actions_list (editor); - update_editor_sheet (editor); -} diff --git a/lib/egg/egg-toolbar-editor.h b/lib/egg/egg-toolbar-editor.h index e1e1f35ab..e29e5482b 100755 --- a/lib/egg/egg-toolbar-editor.h +++ b/lib/egg/egg-toolbar-editor.h @@ -56,11 +56,6 @@ struct EggToolbarEditorClass GType egg_toolbar_editor_get_type (void); GtkWidget *egg_toolbar_editor_new (GtkUIManager *manager, EggToolbarsModel *model); -void egg_toolbar_editor_load_actions (EggToolbarEditor *editor, - const char *xml_file); - -void egg_toolbar_editor_add_action (EggToolbarEditor *editor, - const char *action_name); G_END_DECLS diff --git a/lib/egg/egg-toolbars-model.c b/lib/egg/egg-toolbars-model.c index 56f4c8fbf..1d8c59476 100755 --- a/lib/egg/egg-toolbars-model.c +++ b/lib/egg/egg-toolbars-model.c @@ -31,7 +31,7 @@ #include <gdk/gdkproperty.h> static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass); -static void egg_toolbars_model_init (EggToolbarsModel *t); +static void egg_toolbars_model_init (EggToolbarsModel *model); static void egg_toolbars_model_finalize (GObject *object); enum @@ -41,9 +41,6 @@ enum TOOLBAR_ADDED, TOOLBAR_CHANGED, TOOLBAR_REMOVED, - GET_ITEM_TYPE, - GET_ITEM_ID, - GET_ITEM_DATA, LAST_SIGNAL }; @@ -55,9 +52,7 @@ typedef struct typedef struct { - char *id; - char *type; - gboolean separator; + char *name; } EggToolbarsItem; static guint signals[LAST_SIGNAL] = { 0 }; @@ -69,6 +64,8 @@ static GObjectClass *parent_class = NULL; struct EggToolbarsModelPrivate { GNode *toolbars; + GList *types; + GHashTable *avail; }; GType @@ -103,45 +100,64 @@ egg_toolbars_model_get_type (void) } static xmlDocPtr -egg_toolbars_model_to_xml (EggToolbarsModel *t) +egg_toolbars_model_to_xml (EggToolbarsModel *model) { GNode *l1, *l2, *tl; + GList *l3; xmlDocPtr doc; - g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (t), NULL); + g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), NULL); - tl = t->priv->toolbars; + tl = model->priv->toolbars; xmlIndentTreeOutput = TRUE; - doc = xmlNewDoc ((const xmlChar*) "1.0"); - doc->children = xmlNewDocNode (doc, NULL, (const xmlChar*) "toolbars", NULL); + doc = xmlNewDoc ("1.0"); + doc->children = xmlNewDocNode (doc, NULL, "toolbars", NULL); for (l1 = tl->children; l1 != NULL; l1 = l1->next) { xmlNodePtr tnode; EggToolbarsToolbar *toolbar = l1->data; - tnode = xmlNewChild (doc->children, NULL, (const xmlChar*) "toolbar", NULL); - xmlSetProp (tnode, (const xmlChar*) "name", (const xmlChar*) toolbar->name); + tnode = xmlNewChild (doc->children, NULL, "toolbar", NULL); + xmlSetProp (tnode, "name", toolbar->name); + xmlSetProp (tnode, "hidden", (toolbar->flags&EGG_TB_MODEL_HIDDEN)?"true":"false"); for (l2 = l1->children; l2 != NULL; l2 = l2->next) { xmlNodePtr node; EggToolbarsItem *item = l2->data; - if (item->separator) - { - node = xmlNewChild (tnode, NULL, (const xmlChar*) "separator", NULL); - } - else - { - char *data; - - node = xmlNewChild (tnode, NULL, (const xmlChar*) "toolitem", NULL); - data = egg_toolbars_model_get_item_data (t, item->type, item->id); - xmlSetProp (node, (const xmlChar*) "type", (const xmlChar*) item->type); - xmlSetProp (node, (const xmlChar*) "name", (const xmlChar*) data); - g_free (data); + if (strcmp (item->name, "_separator") == 0) + { + node = xmlNewChild (tnode, NULL, "separator", NULL); + continue; + } + + node = xmlNewChild (tnode, NULL, "toolitem", NULL); + xmlSetProp (node, "name", item->name); + + /* Add 'data' nodes for each data type which can be written out for this + * item. Only write types which can be used to restore the data. */ + for (l3 = model->priv->types; l3 != NULL; l3 = l3->next) + { + EggToolbarsItemType *type = l3->data; + if (type->get_name != NULL && type->get_data != NULL) + { + xmlNodePtr dnode; + char *tmp; + + tmp = type->get_data (type, item->name); + if (tmp != NULL) + { + dnode = xmlNewTextChild (node, NULL, "data", tmp); + g_free (tmp); + + tmp = gdk_atom_name (type->type); + xmlSetProp (dnode, "type", tmp); + g_free (tmp); + } + } } } } @@ -206,24 +222,24 @@ safe_save_xml (const char *xml_file, xmlDocPtr doc) } void -egg_toolbars_model_save (EggToolbarsModel *t, +egg_toolbars_model_save (EggToolbarsModel *model, const char *xml_file, const char *version) { xmlDocPtr doc; xmlNodePtr root; - g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t)); + g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model)); - doc = egg_toolbars_model_to_xml (t); + doc = egg_toolbars_model_to_xml (model); root = xmlDocGetRootElement (doc); - xmlSetProp (root, (const xmlChar*) "version", (const xmlChar*) version); + xmlSetProp (root, "version", version); safe_save_xml (xml_file, doc); xmlFreeDoc (doc); } -static EggToolbarsToolbar * -toolbars_toolbar_new (const char *name) +static GNode * +toolbar_node_new (const char *name) { EggToolbarsToolbar *toolbar; @@ -231,58 +247,67 @@ toolbars_toolbar_new (const char *name) toolbar->name = g_strdup (name); toolbar->flags = 0; - return toolbar; + return g_node_new (toolbar); } -static EggToolbarsItem * -toolbars_item_new (const char *id, - const char *type, - gboolean separator) +static GNode * +item_node_new (const char *name, EggToolbarsModel *model) { EggToolbarsItem *item; - g_return_val_if_fail (id != NULL, NULL); - g_return_val_if_fail (type != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); item = g_new (EggToolbarsItem, 1); - item->id = g_strdup (id); - item->type = g_strdup (type); - item->separator = separator; + item->name = g_strdup (name); + + gint count = (gint) g_hash_table_lookup (model->priv->avail, item->name); + if (count > G_MININT && count < G_MAXINT) + g_hash_table_insert (model->priv->avail, + g_strdup (item->name), + (gpointer) (count-1)); - return item; + return g_node_new (item); } static void -free_toolbar_node (GNode *toolbar_node) +item_node_free (GNode *item_node, EggToolbarsModel *model) { - EggToolbarsToolbar *toolbar = toolbar_node->data; + EggToolbarsItem *item = item_node->data; - g_free (toolbar->name); - g_free (toolbar); + gint count = (gint) g_hash_table_lookup (model->priv->avail, item->name); + if (count < G_MAXINT-1) + g_hash_table_insert (model->priv->avail, + g_strdup (item->name), + (gpointer) (count+1)); - g_node_destroy (toolbar_node); + g_free (item->name); + g_free (item); + + g_node_destroy (item_node); } static void -free_item_node (GNode *item_node) +toolbar_node_free (GNode *toolbar_node, EggToolbarsModel *model) { - EggToolbarsItem *item = item_node->data; + EggToolbarsToolbar *toolbar = toolbar_node->data; - g_free (item->id); - g_free (item->type); - g_free (item); + g_node_children_foreach (toolbar_node, G_TRAVERSE_ALL, + (GNodeForeachFunc) item_node_free, model); + + g_free (toolbar->name); + g_free (toolbar); - g_node_destroy (item_node); + g_node_destroy (toolbar_node); } EggTbModelFlags -egg_toolbars_model_get_flags (EggToolbarsModel *t, +egg_toolbars_model_get_flags (EggToolbarsModel *model, int toolbar_position) { GNode *toolbar_node; EggToolbarsToolbar *toolbar; - toolbar_node = g_node_nth_child (t->priv->toolbars, toolbar_position); + toolbar_node = g_node_nth_child (model->priv->toolbars, toolbar_position); g_return_val_if_fail (toolbar_node != NULL, 0); toolbar = toolbar_node->data; @@ -291,162 +316,262 @@ egg_toolbars_model_get_flags (EggToolbarsModel *t, } void -egg_toolbars_model_set_flags (EggToolbarsModel *t, +egg_toolbars_model_set_flags (EggToolbarsModel *model, int toolbar_position, EggTbModelFlags flags) { GNode *toolbar_node; EggToolbarsToolbar *toolbar; - toolbar_node = g_node_nth_child (t->priv->toolbars, toolbar_position); + toolbar_node = g_node_nth_child (model->priv->toolbars, toolbar_position); g_return_if_fail (toolbar_node != NULL); toolbar = toolbar_node->data; toolbar->flags = flags; - g_signal_emit (G_OBJECT (t), signals[TOOLBAR_CHANGED], + g_signal_emit (G_OBJECT (model), signals[TOOLBAR_CHANGED], 0, toolbar_position); } -void -egg_toolbars_model_add_separator (EggToolbarsModel *t, - int toolbar_position, - int position) + +char * +egg_toolbars_model_get_data (EggToolbarsModel *model, + GdkAtom type, + const char *name) +{ + EggToolbarsItemType *t; + char *data = NULL; + GList *l; + + if (type == GDK_NONE || type == gdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE, FALSE)) + { + g_return_val_if_fail (name != NULL, NULL); + g_return_val_if_fail (*name != 0, NULL); + return strdup (name); + } + + for (l = model->priv->types; l != NULL; l = l->next) + { + t = l->data; + if (t->type == type && t->get_data != NULL) + { + data = t->get_data (t, name); + if (data != NULL) break; + } + } + + return data; +} + +char * +egg_toolbars_model_get_name (EggToolbarsModel *model, + GdkAtom type, + const char *data, + gboolean create) +{ + EggToolbarsItemType *t; + char *name = NULL; + GList *l; + + if (type == GDK_NONE || type == gdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE, FALSE)) + { + g_return_val_if_fail (data, NULL); + g_return_val_if_fail (*data, NULL); + return strdup (data); + } + + if (create) + { + for (l = model->priv->types; name == NULL && l != NULL; l = l->next) + { + t = l->data; + if (t->type == type && t->new_name != NULL) + name = t->new_name (t, data); + } + + return name; + } + else + { + for (l = model->priv->types; name == NULL && l != NULL; l = l->next) + { + t = l->data; + if (t->type == type && t->get_name != NULL) + name = t->get_name (t, data); + } + + return name; + } +} + +static gboolean +impl_add_item (EggToolbarsModel *model, + int toolbar_position, + int position, + const char *name) { GNode *parent_node; - GNode *node; - EggToolbarsItem *item; + GNode *child_node; int real_position; - g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t)); + g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), FALSE); + g_return_val_if_fail (name != NULL, FALSE); - parent_node = g_node_nth_child (t->priv->toolbars, toolbar_position); - item = toolbars_item_new ("separator", EGG_TOOLBAR_ITEM_TYPE, TRUE); - node = g_node_new (item); - g_node_insert (parent_node, position, node); + parent_node = g_node_nth_child (model->priv->toolbars, toolbar_position); + child_node = item_node_new (name, model); + g_node_insert (parent_node, position, child_node); - real_position = g_node_child_position (parent_node, node); + real_position = g_node_child_position (parent_node, child_node); - g_signal_emit (G_OBJECT (t), signals[ITEM_ADDED], 0, + g_signal_emit (G_OBJECT (model), signals[ITEM_ADDED], 0, toolbar_position, real_position); + + return TRUE; } -static gboolean -impl_add_item (EggToolbarsModel *t, - int toolbar_position, - int position, - const char *id, - const char *type) +gboolean +egg_toolbars_model_add_item (EggToolbarsModel *model, + int toolbar_position, + int position, + const char *name) +{ + EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (model); + return klass->add_item (model, toolbar_position, position, name); +} + +int +egg_toolbars_model_add_toolbar (EggToolbarsModel *model, + int position, + const char *name) { - GNode *parent_node; GNode *node; - EggToolbarsItem *item; int real_position; - g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (t), FALSE); - g_return_val_if_fail (id != NULL, FALSE); - g_return_val_if_fail (type != NULL, FALSE); + g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), -1); - parent_node = g_node_nth_child (t->priv->toolbars, toolbar_position); - item = toolbars_item_new (id, type, FALSE); - node = g_node_new (item); - g_node_insert (parent_node, position, node); + node = toolbar_node_new (name); + g_node_insert (model->priv->toolbars, position, node); - real_position = g_node_child_position (parent_node, node); + real_position = g_node_child_position (model->priv->toolbars, node); - g_signal_emit (G_OBJECT (t), signals[ITEM_ADDED], 0, - toolbar_position, real_position); + g_signal_emit (G_OBJECT (model), signals[TOOLBAR_ADDED], + 0, real_position); - return TRUE; + return g_node_child_position (model->priv->toolbars, node); +} + +static char * +parse_data_list (EggToolbarsModel *model, + xmlNodePtr child, + gboolean create) +{ + char *name = NULL; + while (child && name == NULL) + { + if (xmlStrEqual (child->name, "data")) + { + xmlChar *type = xmlGetProp (child, "type"); + xmlChar *data = xmlNodeGetContent (child); + + if (type != NULL) + { + GdkAtom atom = gdk_atom_intern (type, TRUE); + name = egg_toolbars_model_get_name (model, atom, data, create); + } + + xmlFree (type); + xmlFree (data); + } + + child = child->next; + } + + return name; } static void -parse_item_list (EggToolbarsModel *t, +parse_item_list (EggToolbarsModel *model, xmlNodePtr child, int position) { while (child) { - if (xmlStrEqual (child->name, (const xmlChar*) "toolitem")) + if (xmlStrEqual (child->name, "toolitem")) { - xmlChar *name, *type; - char *id; + char *name; - name = xmlGetProp (child, (const xmlChar*) "name"); - type = xmlGetProp (child, (const xmlChar*) "type"); - if (type == NULL) + /* Try to get the name using the data elements first, + as they are more 'portable' or 'persistent'. */ + name = parse_data_list (model, child->children, FALSE); + if (name == NULL) { - type = xmlCharStrdup (EGG_TOOLBAR_ITEM_TYPE); + name = parse_data_list (model, child->children, TRUE); } - - if (name != NULL && name[0] != '\0' && type != NULL) - { - id = egg_toolbars_model_get_item_id (t, (const char*)type, (const char*)name); - if (id != NULL) - { - egg_toolbars_model_add_item (t, position, -1, id, (const char*)type); + + /* If that fails, try to use the name. */ + if (name == NULL) + { + xmlChar *type = xmlGetProp (child, "type"); + xmlChar *data = xmlGetProp (child, "name"); + GdkAtom atom = type ? gdk_atom_intern (type, TRUE) : GDK_NONE; + + /* If an old format, try to use it. */ + name = egg_toolbars_model_get_name (model, atom, data, FALSE); + if (name == NULL) + { + name = egg_toolbars_model_get_name (model, atom, data, TRUE); } - g_free (id); + + xmlFree (type); + xmlFree (data); + } + + if (name != NULL) + { + egg_toolbars_model_add_item (model, position, -1, name); + g_free (name); } - xmlFree (name); - xmlFree (type); } - else if (xmlStrEqual (child->name, (const xmlChar*) "separator")) + else if (xmlStrEqual (child->name, "separator")) { - egg_toolbars_model_add_separator (t, position, -1); + egg_toolbars_model_add_item (model, position, -1, "_separator"); } child = child->next; } } -int -egg_toolbars_model_add_toolbar (EggToolbarsModel *t, - int position, - const char *name) -{ - GNode *node; - int real_position; - - g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (t), -1); - - node = g_node_new (toolbars_toolbar_new (name)); - g_node_insert (t->priv->toolbars, position, node); - - real_position = g_node_child_position (t->priv->toolbars, node); - - g_signal_emit (G_OBJECT (t), signals[TOOLBAR_ADDED], - 0, real_position); - - return g_node_child_position (t->priv->toolbars, node); -} - static void -parse_toolbars (EggToolbarsModel *t, +parse_toolbars (EggToolbarsModel *model, xmlNodePtr child) { while (child) { - if (xmlStrEqual (child->name, (const xmlChar*) "toolbar")) + if (xmlStrEqual (child->name, "toolbar")) { - xmlChar *name; - xmlChar *style; + xmlChar *string; int position; - - name = xmlGetProp (child, (const xmlChar*) "name"); - position = egg_toolbars_model_add_toolbar (t, -1, (const char*) name); - xmlFree (name); - - style = xmlGetProp (child, (const xmlChar*) "style"); - if (style && xmlStrEqual (style, (const xmlChar*) "icons-only")) - { - /* FIXME: use toolbar position instead of 0 */ - egg_toolbars_model_set_flags (t, 0, EGG_TB_MODEL_ICONS); - } - xmlFree (style); - - parse_item_list (t, child->children, position); + EggTbModelFlags flags; + + string = xmlGetProp (child, "name"); + position = egg_toolbars_model_add_toolbar (model, -1, string); + flags = egg_toolbars_model_get_flags (model, position); + xmlFree (string); + + string = xmlGetProp (child, "hidden"); + if (string && xmlStrEqual (string, "true")) + flags |= EGG_TB_MODEL_HIDDEN; + xmlFree (string); + + string = xmlGetProp (child, "style"); + if (string && xmlStrEqual (string, "icons-only")) + flags |= EGG_TB_MODEL_ICONS; + xmlFree (string); + + egg_toolbars_model_set_flags (model, position, flags); + + parse_item_list (model, child->children, position); } child = child->next; @@ -454,13 +579,13 @@ parse_toolbars (EggToolbarsModel *t, } gboolean -egg_toolbars_model_load (EggToolbarsModel *t, +egg_toolbars_model_load (EggToolbarsModel *model, const char *xml_file) { xmlDocPtr doc; xmlNodePtr root; - g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (t), FALSE); + g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), FALSE); if (!xml_file || !g_file_test (xml_file, G_FILE_TEST_EXISTS)) return FALSE; @@ -472,68 +597,13 @@ egg_toolbars_model_load (EggToolbarsModel *t, } root = xmlDocGetRootElement (doc); - parse_toolbars (t, root->children); + parse_toolbars (model, root->children); xmlFreeDoc (doc); return TRUE; } -static char * -impl_get_item_id (EggToolbarsModel *t, - const char *type, - const char *data) -{ - if (strcmp (type, EGG_TOOLBAR_ITEM_TYPE) == 0) - { - return g_strdup (data); - } - - return NULL; -} - -static char * -impl_get_item_data (EggToolbarsModel *t, - const char *type, - const char *id) -{ - if (strcmp (type, EGG_TOOLBAR_ITEM_TYPE) == 0) - { - return g_strdup (id); - } - - return NULL; -} - -static char * -impl_get_item_type (EggToolbarsModel *t, - GdkAtom type) -{ - if (gdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE, FALSE) == type) - { - return g_strdup (EGG_TOOLBAR_ITEM_TYPE); - } - - return NULL; -} - -static gboolean -_egg_accumulator_STRING (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy) -{ - gboolean continue_emission; - const char *retval; - - retval = g_value_get_string (handler_return); - g_value_set_string (return_accu, retval); - continue_emission = !retval || !retval[0]; - - return continue_emission; -} - - static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass) { @@ -544,9 +614,6 @@ egg_toolbars_model_class_init (EggToolbarsModelClass *klass) object_class->finalize = egg_toolbars_model_finalize; klass->add_item = impl_add_item; - klass->get_item_id = impl_get_item_id; - klass->get_item_data = impl_get_item_data; - klass->get_item_type = impl_get_item_type; signals[ITEM_ADDED] = g_signal_new ("item_added", @@ -583,58 +650,29 @@ egg_toolbars_model_class_init (EggToolbarsModelClass *klass) G_STRUCT_OFFSET (EggToolbarsModelClass, toolbar_changed), NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); - signals[GET_ITEM_TYPE] = - g_signal_new ("get_item_type", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EggToolbarsModelClass, get_item_type), - _egg_accumulator_STRING, NULL, - _egg_marshal_STRING__POINTER, - G_TYPE_STRING, 1, G_TYPE_POINTER); - signals[GET_ITEM_ID] = - g_signal_new ("get_item_id", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EggToolbarsModelClass, get_item_id), - _egg_accumulator_STRING, NULL, - _egg_marshal_STRING__STRING_STRING, - G_TYPE_STRING, 2, G_TYPE_STRING, G_TYPE_STRING); - signals[GET_ITEM_DATA] = - g_signal_new ("get_item_data", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EggToolbarsModelClass, get_item_data), - _egg_accumulator_STRING, NULL, - _egg_marshal_STRING__STRING_STRING, - G_TYPE_STRING, 2, G_TYPE_STRING, G_TYPE_STRING); g_type_class_add_private (object_class, sizeof (EggToolbarsModelPrivate)); } static void -egg_toolbars_model_init (EggToolbarsModel *t) +egg_toolbars_model_init (EggToolbarsModel *model) { - t->priv =EGG_TOOLBARS_MODEL_GET_PRIVATE (t); - - t->priv->toolbars = g_node_new (NULL); -} + model->priv =EGG_TOOLBARS_MODEL_GET_PRIVATE (model); -static void -free_toolbar (GNode *toolbar_node) -{ - g_node_children_foreach (toolbar_node, G_TRAVERSE_ALL, - (GNodeForeachFunc) free_item_node, NULL); - free_toolbar_node (toolbar_node); + model->priv->toolbars = g_node_new (NULL); + model->priv->avail = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + egg_toolbars_model_set_n_avail (model, "_separator", G_MAXINT); } static void egg_toolbars_model_finalize (GObject *object) { - EggToolbarsModel *t = EGG_TOOLBARS_MODEL (object); + EggToolbarsModel *model = EGG_TOOLBARS_MODEL (object); - g_node_children_foreach (t->priv->toolbars, G_TRAVERSE_ALL, - (GNodeForeachFunc) free_toolbar, NULL); - g_node_destroy (t->priv->toolbars); + g_node_children_foreach (model->priv->toolbars, G_TRAVERSE_ALL, + (GNodeForeachFunc) toolbar_node_free, model); + g_node_destroy (model->priv->toolbars); + g_hash_table_destroy (model->priv->avail); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -646,51 +684,51 @@ egg_toolbars_model_new (void) } void -egg_toolbars_model_remove_toolbar (EggToolbarsModel *t, +egg_toolbars_model_remove_toolbar (EggToolbarsModel *model, int position) { GNode *node; EggTbModelFlags flags; - g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t)); + g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model)); - flags = egg_toolbars_model_get_flags (t, position); + flags = egg_toolbars_model_get_flags (model, position); if (!(flags & EGG_TB_MODEL_NOT_REMOVABLE)) { - node = g_node_nth_child (t->priv->toolbars, position); + node = g_node_nth_child (model->priv->toolbars, position); g_return_if_fail (node != NULL); - free_toolbar_node (node); + toolbar_node_free (node, model); - g_signal_emit (G_OBJECT (t), signals[TOOLBAR_REMOVED], + g_signal_emit (G_OBJECT (model), signals[TOOLBAR_REMOVED], 0, position); } } void -egg_toolbars_model_remove_item (EggToolbarsModel *t, +egg_toolbars_model_remove_item (EggToolbarsModel *model, int toolbar_position, int position) { GNode *node, *toolbar; - g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t)); + g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model)); - toolbar = g_node_nth_child (t->priv->toolbars, toolbar_position); + toolbar = g_node_nth_child (model->priv->toolbars, toolbar_position); g_return_if_fail (toolbar != NULL); node = g_node_nth_child (toolbar, position); g_return_if_fail (node != NULL); - free_item_node (node); + item_node_free (node, model); - g_signal_emit (G_OBJECT (t), signals[ITEM_REMOVED], 0, + g_signal_emit (G_OBJECT (model), signals[ITEM_REMOVED], 0, toolbar_position, position); } void -egg_toolbars_model_move_item (EggToolbarsModel *t, +egg_toolbars_model_move_item (EggToolbarsModel *model, int toolbar_position, int position, int new_toolbar_position, @@ -698,12 +736,12 @@ egg_toolbars_model_move_item (EggToolbarsModel *t, { GNode *node, *toolbar, *new_toolbar; - g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t)); + g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model)); - toolbar = g_node_nth_child (t->priv->toolbars, toolbar_position); + toolbar = g_node_nth_child (model->priv->toolbars, toolbar_position); g_return_if_fail (toolbar != NULL); - new_toolbar = g_node_nth_child (t->priv->toolbars, new_toolbar_position); + new_toolbar = g_node_nth_child (model->priv->toolbars, new_toolbar_position); g_return_if_fail (new_toolbar != NULL); node = g_node_nth_child (toolbar, position); @@ -711,74 +749,60 @@ egg_toolbars_model_move_item (EggToolbarsModel *t, g_node_unlink (node); - g_signal_emit (G_OBJECT (t), signals[ITEM_REMOVED], 0, + g_signal_emit (G_OBJECT (model), signals[ITEM_REMOVED], 0, toolbar_position, position); g_node_insert (new_toolbar, new_position, node); - g_signal_emit (G_OBJECT (t), signals[ITEM_ADDED], 0, + g_signal_emit (G_OBJECT (model), signals[ITEM_ADDED], 0, new_toolbar_position, new_position); } int -egg_toolbars_model_n_items (EggToolbarsModel *t, +egg_toolbars_model_n_items (EggToolbarsModel *model, int toolbar_position) { GNode *toolbar; - toolbar = g_node_nth_child (t->priv->toolbars, toolbar_position); + toolbar = g_node_nth_child (model->priv->toolbars, toolbar_position); g_return_val_if_fail (toolbar != NULL, -1); return g_node_n_children (toolbar); } -void -egg_toolbars_model_item_nth (EggToolbarsModel *t, +const char * +egg_toolbars_model_item_nth (EggToolbarsModel *model, int toolbar_position, - int position, - gboolean *is_separator, - const char **id, - const char **type) + int position) { GNode *toolbar; GNode *item; EggToolbarsItem *idata; - toolbar = g_node_nth_child (t->priv->toolbars, toolbar_position); - g_return_if_fail (toolbar != NULL); + toolbar = g_node_nth_child (model->priv->toolbars, toolbar_position); + g_return_val_if_fail (toolbar != NULL, NULL); item = g_node_nth_child (toolbar, position); - g_return_if_fail (item != NULL); + g_return_val_if_fail (item != NULL, NULL); idata = item->data; - - *is_separator = idata->separator; - - if (id) - { - *id = idata->id; - } - - if (type) - { - *type = idata->type; - } + return idata->name; } int -egg_toolbars_model_n_toolbars (EggToolbarsModel *t) +egg_toolbars_model_n_toolbars (EggToolbarsModel *model) { - return g_node_n_children (t->priv->toolbars); + return g_node_n_children (model->priv->toolbars); } const char * -egg_toolbars_model_toolbar_nth (EggToolbarsModel *t, +egg_toolbars_model_toolbar_nth (EggToolbarsModel *model, int position) { GNode *toolbar; EggToolbarsToolbar *tdata; - toolbar = g_node_nth_child (t->priv->toolbars, position); + toolbar = g_node_nth_child (model->priv->toolbars, position); g_return_val_if_fail (toolbar != NULL, NULL); tdata = toolbar->data; @@ -786,48 +810,40 @@ egg_toolbars_model_toolbar_nth (EggToolbarsModel *t, return tdata->name; } -gboolean -egg_toolbars_model_add_item (EggToolbarsModel *t, - int toolbar_position, - int position, - const char *id, - const char *type) +GList * +egg_toolbars_model_get_types (EggToolbarsModel *model) { - EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); - return klass->add_item (t, toolbar_position, position, id, type); + return model->priv->types; } -char * -egg_toolbars_model_get_item_id (EggToolbarsModel *t, - const char *type, - const char *name) +void +egg_toolbars_model_set_types (EggToolbarsModel *model, GList *types) { - char *retval; - - g_signal_emit (t, signals[GET_ITEM_ID], 0, type, name, &retval); - - return retval; + model->priv->types = types; } -char * -egg_toolbars_model_get_item_data (EggToolbarsModel *t, - const char *type, - const char *id) +static void +fill_avail_array (gpointer key, gpointer value, GPtrArray *array) { - char *retval; - - g_signal_emit (t, signals[GET_ITEM_DATA], 0, type, id, &retval); - - return retval; + if (GPOINTER_TO_INT (value) > 0) g_ptr_array_add (array, key); } -char * -egg_toolbars_model_get_item_type (EggToolbarsModel *t, - GdkAtom type) +GPtrArray * +egg_toolbars_model_get_avail (EggToolbarsModel *model) { - char *retval; + GPtrArray *array = g_ptr_array_new (); + g_hash_table_foreach (model->priv->avail, (GHFunc) fill_avail_array, array); + return array; +} - g_signal_emit (t, signals[GET_ITEM_TYPE], 0, type, &retval); +gint +egg_toolbars_model_get_n_avail (EggToolbarsModel *model, const char *name) +{ + return (gint) g_hash_table_lookup (model->priv->avail, name); +} - return retval; +void +egg_toolbars_model_set_n_avail (EggToolbarsModel *model, const char *name, gint count) +{ + g_hash_table_insert (model->priv->avail, g_strdup (name), (gpointer) count); } diff --git a/lib/egg/egg-toolbars-model.h b/lib/egg/egg-toolbars-model.h index aaaa2140a..fe5467aa8 100755 --- a/lib/egg/egg-toolbars-model.h +++ b/lib/egg/egg-toolbars-model.h @@ -48,7 +48,8 @@ typedef enum EGG_TB_MODEL_ICONS = 1 << 3, EGG_TB_MODEL_TEXT = 1 << 4, EGG_TB_MODEL_STYLES_MASK = 0x1F, - EGG_TB_MODEL_ACCEPT_ITEMS_ONLY = 1 << 5 + EGG_TB_MODEL_ACCEPT_ITEMS_ONLY = 1 << 5, + EGG_TB_MODEL_HIDDEN = 1 << 6 } EggTbModelFlags; struct EggToolbarsModel @@ -76,21 +77,35 @@ struct EggToolbarsModelClass int position); void (* toolbar_removed) (EggToolbarsModel *model, int position); - char * (* get_item_type) (EggToolbarsModel *model, - GdkAtom dnd_type); - char * (* get_item_id) (EggToolbarsModel *model, - const char *type, - const char *data); - char * (* get_item_data) (EggToolbarsModel *model, - const char *type, - const char *id); /* Virtual Table */ gboolean (* add_item) (EggToolbarsModel *t, int toolbar_position, int position, - const char *id, - const char *type); + const char *name); +}; + +typedef struct EggToolbarsItemType EggToolbarsItemType; + +struct EggToolbarsItemType +{ + GdkAtom type; + + gboolean (* has_data) (EggToolbarsItemType *type, + const char *name); + char * (* get_data) (EggToolbarsItemType *type, + const char *name); + + char * (* new_name) (EggToolbarsItemType *type, + const char *data); + char * (* get_name) (EggToolbarsItemType *type, + const char *data); +}; + +struct EggToolbarsItemAvailable +{ + const char * name; + guint available; }; GType egg_toolbars_model_flags_get_type (void); @@ -101,32 +116,48 @@ gboolean egg_toolbars_model_load (EggToolbarsModel *model, void egg_toolbars_model_save (EggToolbarsModel *model, const char *xml_file, const char *version); -int egg_toolbars_model_add_toolbar (EggToolbarsModel *model, - int position, - const char *name); + +/* Functions for manipulating the types of portable data this toolbar understands. */ +GList * egg_toolbars_model_get_types (EggToolbarsModel *model); +void egg_toolbars_model_set_types (EggToolbarsModel *model, + GList *types); + +/* Functions for converting between name and portable data. */ +char * egg_toolbars_model_get_name (EggToolbarsModel *model, + GdkAtom type, + const char *data, + gboolean create); +char * egg_toolbars_model_get_data (EggToolbarsModel *model, + GdkAtom type, + const char *name); + +/* Functions for retrieving what items are available for adding to the toolbars. */ +GPtrArray * egg_toolbars_model_get_avail (EggToolbarsModel *model); +gint egg_toolbars_model_get_n_avail (EggToolbarsModel *model, + const char *name); +void egg_toolbars_model_set_n_avail (EggToolbarsModel *model, + const char *name, + gint count); + +/* Functions for manipulating flags on individual toolbars. */ EggTbModelFlags egg_toolbars_model_get_flags (EggToolbarsModel *model, int toolbar_position); void egg_toolbars_model_set_flags (EggToolbarsModel *model, int toolbar_position, EggTbModelFlags flags); -void egg_toolbars_model_add_separator (EggToolbarsModel *model, - int toolbar_position, + +/* Functions for adding and removing toolbars. */ +int egg_toolbars_model_add_toolbar (EggToolbarsModel *model, + int position, + const char *name); +void egg_toolbars_model_remove_toolbar (EggToolbarsModel *model, int position); -char *egg_toolbars_model_get_item_type (EggToolbarsModel *model, - GdkAtom dnd_type); -char *egg_toolbars_model_get_item_id (EggToolbarsModel *model, - const char *type, - const char *name); -char *egg_toolbars_model_get_item_data (EggToolbarsModel *model, - const char *type, - const char *id); + +/* Functions for adding, removing and moving items. */ gboolean egg_toolbars_model_add_item (EggToolbarsModel *model, int toolbar_position, int position, - const char *id, - const char *type); -void egg_toolbars_model_remove_toolbar (EggToolbarsModel *model, - int position); + const char *name); void egg_toolbars_model_remove_item (EggToolbarsModel *model, int toolbar_position, int position); @@ -135,14 +166,15 @@ void egg_toolbars_model_move_item (EggToolbarsModel *model, int position, int new_toolbar_position, int new_position); + +/* Functions for accessing the names of items. */ int egg_toolbars_model_n_items (EggToolbarsModel *model, int toolbar_position); -void egg_toolbars_model_item_nth (EggToolbarsModel *model, +const char * egg_toolbars_model_item_nth (EggToolbarsModel *model, int toolbar_position, - int position, - gboolean *is_separator, - const char **id, - const char **type); + int position); + +/* Functions for accessing the names of toolbars. */ int egg_toolbars_model_n_toolbars (EggToolbarsModel *model); const char *egg_toolbars_model_toolbar_nth (EggToolbarsModel *model, int position); |