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/egg/egg-toolbar-editor.c | |
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/egg/egg-toolbar-editor.c')
-rwxr-xr-x | lib/egg/egg-toolbar-editor.c | 442 |
1 files changed, 185 insertions, 257 deletions
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); -} |