diff options
-rw-r--r-- | ChangeLog | 26 | ||||
-rw-r--r-- | data/ui/epiphany-toolbar.xml.in | 5 | ||||
-rw-r--r-- | data/ui/epiphany-ui.xml.in | 1 | ||||
-rwxr-xr-x | lib/egg/egg-editable-toolbar.c | 51 | ||||
-rwxr-xr-x | lib/egg/egg-editable-toolbar.h | 23 | ||||
-rw-r--r-- | src/bookmarks/ephy-topic-action.c | 2 | ||||
-rw-r--r-- | src/ephy-shell.c | 21 | ||||
-rwxr-xr-x | src/ephy-toolbars-model.c | 40 | ||||
-rwxr-xr-x | src/ephy-toolbars-model.h | 3 | ||||
-rw-r--r-- | src/ephy-window.c | 20 | ||||
-rwxr-xr-x | src/toolbar.c | 162 | ||||
-rw-r--r-- | src/toolbar.h | 4 | ||||
-rw-r--r-- | src/window-commands.c | 37 |
13 files changed, 320 insertions, 75 deletions
@@ -1,3 +1,29 @@ +2003-04-25 Marco Pesenti Gritti <marco@it.gnome.org> + + * data/ui/epiphany-toolbar.xml.in: + * data/ui/epiphany-ui.xml.in: + * lib/egg/egg-editable-toolbar.c: (egg_editable_toolbar_hide), + (egg_editable_toolbar_set_drag_dest): + * lib/egg/egg-editable-toolbar.h: + * src/bookmarks/ephy-topic-action.c: (create_tool_item): + * src/ephy-shell.c: (save_toolbars), (ephy_shell_finalize), + (ephy_shell_get_toolbars_model): + * src/ephy-toolbars-model.c: (impl_add_item), + (ephy_toolbars_model_class_init): + * src/ephy-toolbars-model.h: + * src/ephy-window.c: (ephy_window_set_chrome): + * src/toolbar.c: (ensure_bookmark_action), (toolbar_ensure_action), + (action_added_cb), (init_bookmarks_toolbar), (toolbar_set_window), + (toolbar_new), (toolbar_set_visibility): + * src/toolbar.h: + * src/window-commands.c: (toolbar_editor_destroy_cb), + (window_cmd_edit_toolbar): + + Get back toolbar editing functionalities. + More work on the bookmarks toolbars implementation. + The toolbars context menus are regressed but it's not my fault :/ + The signal on EggToolbar is borked. + 2003-04-25 David Bordoley <bordoley@msu.edu> * src/bookmarks/ephy-topic-action.c: (button_toggled_cb), diff --git a/data/ui/epiphany-toolbar.xml.in b/data/ui/epiphany-toolbar.xml.in index 43c800ad3..c0680a827 100644 --- a/data/ui/epiphany-toolbar.xml.in +++ b/data/ui/epiphany-toolbar.xml.in @@ -21,7 +21,7 @@ <toolitem verb="Spinner"/> <toolitem verb="ToolbarGo"/> </available> -<toolbar> +<toolbar name="DefaultToolbar"> <toolitem verb="NavigationBack"/> <toolitem verb="NavigationForward"/> <toolitem verb="ViewStop"/> @@ -33,5 +33,8 @@ <toolitem verb="Location"/> <toolitem verb="Spinner"/> </toolbar> +<toolbar name="BookmarksToolbar"> + <toolitem verb="GoTopicId0"/> +</toolbar> </editabletoolbar> diff --git a/data/ui/epiphany-ui.xml.in b/data/ui/epiphany-ui.xml.in index dc8e97242..0da96aa19 100644 --- a/data/ui/epiphany-ui.xml.in +++ b/data/ui/epiphany-ui.xml.in @@ -33,6 +33,7 @@ <submenu name="ViewMenu" verb="View"> <menuitem name="ViewToolbarMenu" verb="ViewToolbar"/> + <menuitem name="ViewBookmarksToolbarMenu" verb="ViewBookmarksToolbar"/> <menuitem name="ViewStatusbarMenu" verb="ViewStatusbar"/> <menuitem name="ViewFullscreenMenu" verb="ViewFullscreen"/> <separator name="ViewSep1"/> diff --git a/lib/egg/egg-editable-toolbar.c b/lib/egg/egg-editable-toolbar.c index 5220629a5..b024bf7df 100755 --- a/lib/egg/egg-editable-toolbar.c +++ b/lib/egg/egg-editable-toolbar.c @@ -585,3 +585,54 @@ egg_editable_toolbar_show (EggEditableToolbar *etoolbar, } } } + +void +egg_editable_toolbar_hide (EggEditableToolbar *etoolbar, + const char *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 *toolbar_name; + + toolbar_name = egg_toolbars_model_toolbar_nth (model, i); + if (strcmp (toolbar_name, name) == 0) + { + gtk_widget_hide (get_toolbar_nth (etoolbar, i)); + } + } +} + +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, GTK_DEST_DEFAULT_DROP, + targets, n_targets, + GDK_ACTION_MOVE | GDK_ACTION_COPY); + } + } +} + diff --git a/lib/egg/egg-editable-toolbar.h b/lib/egg/egg-editable-toolbar.h index d528ca4a4..5a73d4205 100755 --- a/lib/egg/egg-editable-toolbar.h +++ b/lib/egg/egg-editable-toolbar.h @@ -53,17 +53,18 @@ struct EggEditableToolbarClass }; GType egg_editable_toolbar_get_type (void); -GtkWidget *egg_editable_toolbar_new (EggMenuMerge *merge, - EggToolbarsModel *model); -void egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar, - gboolean mode); -void egg_editable_toolbar_show (EggEditableToolbar *etoolbar, - const char *name); -void egg_editable_toolbar_hide (EggEditableToolbar *etoolbar, - const char *name); -void egg_editable_toolbar_add_drag_type (EggEditableToolbar *etoolbar, - const char *drag_type, - const char *toolbar_name); +GtkWidget *egg_editable_toolbar_new (EggMenuMerge *merge, + EggToolbarsModel *model); +void egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar, + gboolean mode); +void egg_editable_toolbar_show (EggEditableToolbar *etoolbar, + const char *name); +void egg_editable_toolbar_hide (EggEditableToolbar *etoolbar, + const char *name); +void egg_editable_toolbar_set_drag_dest (EggEditableToolbar *etoolbar, + const GtkTargetEntry *targets, + gint n_targets, + const char *toolbar_name); G_END_DECLS diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c index 4c6319c75..b8d8ab9ee 100644 --- a/src/bookmarks/ephy-topic-action.c +++ b/src/bookmarks/ephy-topic-action.c @@ -94,7 +94,7 @@ create_tool_item (EggAction *action) gtk_widget_show (button); gtk_container_add (GTK_CONTAINER (hbox), button); g_object_set_data (G_OBJECT (item), "button", button); - + arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); gtk_widget_show (arrow); diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 9d71bfcef..2f21091ac 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -294,6 +294,18 @@ ephy_shell_init (EphyShell *gs) } static void +save_toolbars (EggToolbarsModel *model) +{ + char *xml_file; + + xml_file = g_build_filename (ephy_dot_dir (), + "toolbar.xml", + NULL); + egg_toolbars_model_save (model, xml_file); + g_free (xml_file); +} + +static void ephy_shell_finalize (GObject *object) { EphyShell *gs; @@ -307,6 +319,13 @@ ephy_shell_finalize (GObject *object) g_assert (ephy_shell == NULL); + LOG ("Unref toolbars model") + if (gs->priv->toolbars_model) + { + save_toolbars (EGG_TOOLBARS_MODEL (gs->priv->toolbars_model)); + g_object_unref (G_OBJECT (gs->priv->toolbars_model)); + } + LOG ("Unref session") if (gs->priv->session) { @@ -648,8 +667,6 @@ ephy_shell_get_toolbars_model (EphyShell *gs) if (gs->priv->toolbars_model == NULL) { gs->priv->toolbars_model = ephy_toolbars_model_new (); - egg_toolbars_model_load (EGG_TOOLBARS_MODEL (gs->priv->toolbars_model), - ephy_file ("epiphany-toolbar.xml")); } return gs->priv->toolbars_model; diff --git a/src/ephy-toolbars-model.c b/src/ephy-toolbars-model.c index da842e719..c67d427e3 100755 --- a/src/ephy-toolbars-model.c +++ b/src/ephy-toolbars-model.c @@ -26,6 +26,14 @@ static void ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass); static void ephy_toolbars_model_init (EphyToolbarsModel *t); static void ephy_toolbars_model_finalize (GObject *object); +enum +{ + ACTION_ADDED, + LAST_SIGNAL +}; + +static guint ephy_toolbars_model_signals[LAST_SIGNAL] = { 0 }; + static GObjectClass *parent_class = NULL; struct EphyToolbarsModelPrivate @@ -68,7 +76,10 @@ impl_add_item (EggToolbarsModel *t, const char *name) { EphyBookmarks *bookmarks; - char *res = NULL; + char *action_name = NULL; + const char *res; + + LOG ("Add item %s", name) bookmarks = ephy_shell_get_bookmarks (ephy_shell); @@ -79,24 +90,27 @@ impl_add_item (EggToolbarsModel *t, nodes = ephy_dnd_node_list_extract_nodes (name); id = ephy_node_get_id (EPHY_NODE (nodes->data)); - res = g_strdup_printf ("GoTopicId%d", id); + action_name = g_strdup_printf ("GoTopicId%d", id); g_list_free (nodes); } - else if (gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) == type) + else if (gdk_atom_intern (EPHY_DND_BOOKMARK_TYPE, FALSE) == type) { GList *nodes; int id; nodes = ephy_dnd_node_list_extract_nodes (name); id = ephy_node_get_id (EPHY_NODE (nodes->data)); - res = g_strdup_printf ("GoBookmarkId%d", id); + action_name = g_strdup_printf ("GoBookmarkId%d", id); g_list_free (nodes); } - else - { - EGG_TOOLBARS_MODEL_CLASS (parent_class)->add_item - (t, toolbar_position, position, type, name); - } + + res = action_name ? action_name : name; + + g_signal_emit (G_OBJECT (t), + ephy_toolbars_model_signals[ACTION_ADDED], 0, res); + + EGG_TOOLBARS_MODEL_CLASS (parent_class)->add_item + (t, toolbar_position, position, type, res); return res; } @@ -114,6 +128,14 @@ ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass) object_class->finalize = ephy_toolbars_model_finalize; etm_class->add_item = impl_add_item; + + ephy_toolbars_model_signals[ACTION_ADDED] = + g_signal_new ("action_added", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyToolbarsModelClass, action_added), + NULL, NULL, g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); } static void diff --git a/src/ephy-toolbars-model.h b/src/ephy-toolbars-model.h index 4ebf48057..f01230494 100755 --- a/src/ephy-toolbars-model.h +++ b/src/ephy-toolbars-model.h @@ -44,6 +44,9 @@ struct EphyToolbarsModel struct EphyToolbarsModelClass { EggToolbarsModelClass parent_class; + + void (* action_added) (EggToolbarsModel *group, + char *action_name); }; GType ephy_toolbars_model_get_type (void); diff --git a/src/ephy-window.c b/src/ephy-window.c index 357c4e84d..8152b0019 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -821,23 +821,9 @@ ephy_window_set_chrome (EphyWindow *window, gtk_widget_hide (window->priv->menubar); } - if (flags & EMBED_CHROME_PERSONALTOOLBARON) - { - } - else - { - } - - if (flags & EMBED_CHROME_TOOLBARON) - { -/* egg_editable_toolbar_show - (EGG_EDITABLE_TOOLBAR (window->priv->toolbar));*/ - } - else - { -/* egg_editable_toolbar_hide - (EGG_EDITABLE_TOOLBAR (window->priv->toolbar));*/ - } + toolbar_set_visibility (window->priv->toolbar, + flags & EMBED_CHROME_TOOLBARON, + flags & EMBED_CHROME_PERSONALTOOLBARON); if (flags & EMBED_CHROME_STATUSBARON) { diff --git a/src/toolbar.c b/src/toolbar.c index 1525edddc..4f4203874 100755 --- a/src/toolbar.c +++ b/src/toolbar.c @@ -35,7 +35,6 @@ #include "ephy-string.h" #include "ephy-debug.h" #include "ephy-new-bookmark.h" -/*#include "egg-toolbars-group.h"*/ #include "ephy-stock-icons.h" #include <string.h> @@ -55,6 +54,11 @@ toolbar_get_property (GObject *object, GValue *value, GParamSpec *pspec); +static GtkTargetEntry drag_targets[] = { + { EPHY_DND_TOPIC_TYPE, 0, 0 }, + { EPHY_DND_BOOKMARK_TYPE, 0, 1 }, +}; +static int n_drag_targets = G_N_ELEMENTS (drag_targets); enum { @@ -115,9 +119,10 @@ go_location_cb (EggAction *action, char *location, EphyWindow *window) ephy_embed_load_url (embed, location); } -/* + + static EggAction * -get_bookmark_action (Toolbar *t, EphyBookmarks *bookmarks, gulong id, const char *action_name) +ensure_bookmark_action (Toolbar *t, EphyBookmarks *bookmarks, gulong id, const char *action_name) { EggAction *action; @@ -129,43 +134,40 @@ get_bookmark_action (Toolbar *t, EphyBookmarks *bookmarks, gulong id, const char G_CALLBACK (go_location_cb), t->priv->window); egg_action_group_add_action (t->priv->action_group, action); g_object_unref (action); - - return action; } -static EggAction * -toolbar_get_action (EggEditableToolbar *etoolbar, - const char *name) +static void +toolbar_ensure_action (Toolbar *t, + const char *name) { - Toolbar *t = TOOLBAR (etoolbar); EggAction *action = NULL; gulong id = 0; EphyBookmarks *bookmarks; + LOG ("Ensure action %s", name) + bookmarks = ephy_shell_get_bookmarks (ephy_shell); - if (action) - { - return action; - } - else if (g_str_has_prefix (name, "GoBookmarkId")) + if (g_str_has_prefix (name, "GoBookmarkId")) { - LOG ("Create action %s", name) if (!ephy_str_to_int (name + strlen ("GoBookmarkId"), &id)) { - return NULL; + return; } - action = get_bookmark_action (t, bookmarks, id, name); + LOG ("Create action %s", name) + + action = ensure_bookmark_action (t, bookmarks, id, name); } else if (g_str_has_prefix (name, "GoTopicId")) { - LOG ("Create action %s", name) if (!ephy_str_to_int (name + strlen ("GoTopicId"), &id)) { - return NULL; + return; } + LOG ("Create action %s", name) + action = ephy_topic_action_new (name, id); g_signal_connect (action, "go_location", G_CALLBACK (go_location_cb), @@ -173,10 +175,8 @@ toolbar_get_action (EggEditableToolbar *etoolbar, egg_action_group_add_action (t->priv->action_group, action); g_object_unref (action); } - - return action; } -*/ + static void toolbar_class_init (ToolbarClass *klass) { @@ -311,8 +311,47 @@ toolbar_setup_actions (Toolbar *t) } static void +action_added_cb (EphyToolbarsModel *model, + char *action_name, + Toolbar *t) +{ + toolbar_ensure_action (t, action_name); +} + +static void +init_bookmarks_toolbar (Toolbar *t) +{ + EphyToolbarsModel *model; + int i, n_toolbars; + + model = ephy_shell_get_toolbars_model (ephy_shell); + n_toolbars = egg_toolbars_model_n_toolbars + (EGG_TOOLBARS_MODEL (model)); + + for (i = 0; i < n_toolbars; i++) + { + const char *t_name; + + t_name = egg_toolbars_model_toolbar_nth + (EGG_TOOLBARS_MODEL (model), i); + g_return_if_fail (t_name != NULL); + + if (strcmp (t_name, "BookmarksToolbar") == 0) + { + egg_editable_toolbar_set_drag_dest + (EGG_EDITABLE_TOOLBAR (t), + drag_targets, n_drag_targets, + t_name); + } + } +} + +static void toolbar_set_window (Toolbar *t, EphyWindow *window) { + EphyToolbarsModel *model; + char *xml_file; + g_return_if_fail (t->priv->window == NULL); t->priv->window = window; @@ -322,7 +361,32 @@ toolbar_set_window (Toolbar *t, EphyWindow *window) egg_menu_merge_insert_action_group (t->priv->ui_merge, t->priv->action_group, 1); - g_object_set (G_OBJECT (t), "MenuMerge", t->priv->ui_merge, NULL); + model = ephy_shell_get_toolbars_model (ephy_shell); + g_return_if_fail (model != NULL); + g_signal_connect_object (model, "action_added", + G_CALLBACK (action_added_cb), + t, 0); + + xml_file = g_build_filename (ephy_dot_dir (), + "toolbar.xml", + NULL); + if (g_file_test (xml_file, G_FILE_TEST_EXISTS)) + { + egg_toolbars_model_load + (EGG_TOOLBARS_MODEL (model), xml_file); + } + else + { + egg_toolbars_model_load (EGG_TOOLBARS_MODEL (model), + ephy_file ("epiphany-toolbar.xml")); + } + g_free (xml_file); + + g_object_set (G_OBJECT (t), + "ToolbarsModel", model, + "MenuMerge", t->priv->ui_merge, + NULL); + init_bookmarks_toolbar (t); } static void @@ -411,13 +475,8 @@ Toolbar * toolbar_new (EphyWindow *window) { Toolbar *t; - EphyToolbarsModel *model; - - model = ephy_shell_get_toolbars_model (ephy_shell); - g_return_val_if_fail (model != NULL, NULL); t = TOOLBAR (g_object_new (TOOLBAR_TYPE, - "ToolbarsModel", model, "EphyWindow", window, NULL)); @@ -558,3 +617,50 @@ toolbar_update_navigation_actions (Toolbar *t, gboolean back, gboolean forward, g_object_set (action, "sensitive", !up, NULL); } +void +toolbar_set_visibility (Toolbar *t, + gboolean normal_toolbars, + gboolean bmk_toolbars) +{ + EphyToolbarsModel *model; + int i, n_toolbars; + + model = ephy_shell_get_toolbars_model (ephy_shell); + n_toolbars = egg_toolbars_model_n_toolbars + (EGG_TOOLBARS_MODEL (model)); + + for (i = 0; i < n_toolbars; i++) + { + const char *t_name; + + t_name = egg_toolbars_model_toolbar_nth + (EGG_TOOLBARS_MODEL (model), i); + g_return_if_fail (t_name != NULL); + if (strcmp (t_name, "BookmarksToolbar") == 0) + { + if (bmk_toolbars) + { + egg_editable_toolbar_show + (EGG_EDITABLE_TOOLBAR (t), t_name); + } + else + { + egg_editable_toolbar_hide + (EGG_EDITABLE_TOOLBAR (t), t_name); + } + } + else + { + if (normal_toolbars) + { + egg_editable_toolbar_show + (EGG_EDITABLE_TOOLBAR (t), t_name); + } + else + { + egg_editable_toolbar_hide + (EGG_EDITABLE_TOOLBAR (t), t_name); + } + } + } +} diff --git a/src/toolbar.h b/src/toolbar.h index 9f4404b8a..98d6790a4 100644 --- a/src/toolbar.h +++ b/src/toolbar.h @@ -74,6 +74,10 @@ void toolbar_update_navigation_actions (Toolbar *t, gboolean forward, gboolean up); +void toolbar_set_visibility (Toolbar *t, + gboolean normal_toolbars, + gboolean bmk_toolbars); + G_END_DECLS #endif diff --git a/src/window-commands.c b/src/window-commands.c index 28c2f725b..8e128e775 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -36,7 +36,10 @@ #include "ephy-new-bookmark.h" #include "egg-toggle-action.h" #include "egg-editable-toolbar.h" +#include "egg-toolbar-editor.h" +#include "ephy-file-helpers.h" #include "toolbar.h" +#include "ephy-state.h" #include <string.h> #include <libgnomevfs/gnome-vfs-uri.h> @@ -638,19 +641,41 @@ window_cmd_edit_prefs (EggAction *action, gtk_widget_show (GTK_WIDGET(dialog)); } +static void +toolbar_editor_destroy_cb (GtkWidget *tbe, + Toolbar *t) +{ + egg_editable_toolbar_set_edit_mode (EGG_EDITABLE_TOOLBAR (t), FALSE); +} + void window_cmd_edit_toolbar (EggAction *action, EphyWindow *window) { - Toolbar *toolbar; + GtkWidget *editor; + EphyToolbarsModel *model; + Toolbar *t; - toolbar = ephy_window_get_toolbar (window); -/* - egg_editable_toolbar_edit (EGG_EDITABLE_TOOLBAR (toolbar), - GTK_WIDGET (window));*/ + model = ephy_shell_get_toolbars_model (ephy_shell); + t = ephy_window_get_toolbar (window); + + editor = egg_toolbar_editor_new + (EGG_MENU_MERGE (window->ui_merge), + EGG_TOOLBARS_MODEL (model)); + ephy_state_add_window (editor, + "toolbar_editor", + 500, 330); + g_signal_connect (editor, "destroy", + G_CALLBACK (toolbar_editor_destroy_cb), + t); + egg_toolbar_editor_load_actions (EGG_TOOLBAR_EDITOR (editor), + ephy_file ("epiphany-toolbar.xml")); + gtk_widget_show (editor); + + egg_editable_toolbar_set_edit_mode (EGG_EDITABLE_TOOLBAR (t), TRUE); } -void +void window_cmd_help_contents (EggAction *action, EphyWindow *window) { |