From 443b71cb6849f0676a6fdce11b957fae7cc06d8b Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Fri, 15 Apr 2005 17:09:05 +0000 Subject: [PATCH] plug-ins/helpbrowser/dialog.c added menu toolbar buttons; not functional 2005-04-15 Sven Neumann * plug-ins/helpbrowser/dialog.c * plug-ins/helpbrowser/queue.[ch]: added menu toolbar buttons; not functional yet. --- ChangeLog | 6 ++ plug-ins/helpbrowser/dialog.c | 89 +++++++++++++++++++---- plug-ins/helpbrowser/queue.c | 128 +++++++++++++++++++++++++++++----- plug-ins/helpbrowser/queue.h | 8 ++- 4 files changed, 199 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 83902fdd0b..599333d8bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-04-15 Sven Neumann + + * plug-ins/helpbrowser/dialog.c + * plug-ins/helpbrowser/queue.[ch]: added menu toolbar buttons; not + functional yet. + 2005-04-15 Michael Natterer Added loading of Photoshop brushes. Fixes bug #163047: diff --git a/plug-ins/helpbrowser/dialog.c b/plug-ins/helpbrowser/dialog.c index d8eadc9200..c83594366f 100644 --- a/plug-ins/helpbrowser/dialog.c +++ b/plug-ins/helpbrowser/dialog.c @@ -118,13 +118,15 @@ static gchar * filename_from_uri (const gchar *uri); /* private variables */ -static const gchar *eek_png_tag = "

Eeek!

"; +static const gchar *eek_png_tag = "

Eeek!

"; -static Queue *queue = NULL; -static gchar *current_ref = NULL; +static Queue *queue = NULL; +static gchar *current_ref = NULL; -static GtkWidget *html = NULL; -static GtkUIManager *ui_manager = NULL; +static GtkWidget *html = NULL; +static GtkUIManager *ui_manager = NULL; +static GtkWidget *button_prev = NULL; +static GtkWidget *button_next = NULL; static GtkTargetEntry help_dnd_target_table[] = { @@ -145,6 +147,8 @@ browser_dialog_open (void) GtkWidget *drag_source; GtkWidget *image; GtkWidget *combo; + GtkToolItem *item; + GtkAction *action; GtkListStore *history; GtkCellRenderer *cell; gchar *eek_png_path; @@ -181,6 +185,28 @@ browser_dialog_open (void) gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0); gtk_widget_show (toolbar); + item = gtk_separator_tool_item_new (); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, 0); + gtk_widget_show (GTK_WIDGET (item)); + + item = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON, NULL); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, 0); + gtk_widget_show (GTK_WIDGET (item)); + + action = gtk_ui_manager_get_action (ui_manager, + "/ui/help-browser-popup/forward"); + gtk_action_connect_proxy (action, GTK_WIDGET (item)); + button_next = GTK_WIDGET (item); + + item = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON, NULL); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, 0); + gtk_widget_show (GTK_WIDGET (item)); + + action = gtk_ui_manager_get_action (ui_manager, + "/ui/help-browser-popup/back"); + gtk_action_connect_proxy (action, GTK_WIDGET (item)); + button_prev = GTK_WIDGET (item); + hbox = gtk_hbox_new (FALSE, 2); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); @@ -394,6 +420,7 @@ ui_manager_new (GtkWidget *window) GtkUIManager *ui_manager = gtk_ui_manager_new (); GtkActionGroup *group = gtk_action_group_new ("Actions"); + GError *error = NULL; gtk_action_group_set_translation_domain (group, NULL); gtk_action_group_add_actions (group, actions, G_N_ELEMENTS (actions), window); @@ -408,15 +435,15 @@ ui_manager_new (GtkWidget *window) gtk_ui_manager_add_ui_from_string (ui_manager, "" " " - " " - " " - " " " " " " " " " " "", - -1, NULL); + -1, &error); + + if (error) + g_warning ("error parsing ui: %s", error->message); gtk_ui_manager_add_ui_from_string (ui_manager, "" @@ -503,18 +530,51 @@ close_callback (GtkAction *action, gtk_widget_destroy (GTK_WIDGET (data)); } +static GtkWidget * +build_menu (GList *list) +{ + GtkMenuShell *menu; + + if (! list) + return NULL; + + menu = GTK_MENU_SHELL (gtk_menu_new ()); + + for (; list; list = g_list_next (list)) + { + GtkWidget *menu_item = gtk_menu_item_new_with_label (list->data); + + gtk_menu_shell_append (menu, menu_item); + gtk_widget_show (menu_item); + } + + g_list_free (list); + + return GTK_WIDGET (menu); +} + static void update_toolbar (void) { GtkAction *action; - action = gtk_ui_manager_get_action (ui_manager, - "/ui/help-browser-toolbar/back"); - gtk_action_set_sensitive (action, queue_has_prev (queue)); + /* update the back button and its menu */ action = gtk_ui_manager_get_action (ui_manager, - "/ui/help-browser-toolbar/forward"); + "/ui/help-browser-popup/back"); + gtk_action_set_sensitive (action, queue_has_prev (queue)); + + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (button_prev), + build_menu (queue_list_prev (queue))); + + /* update the forward button and its menu */ + + action = gtk_ui_manager_get_action (ui_manager, + "/ui/help-browser-popup/forward"); gtk_action_set_sensitive (action, queue_has_next (queue)); + + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (button_prev), + build_menu (queue_list_next (queue))); } static void @@ -603,6 +663,9 @@ title_changed (HtmlDocument *doc, history_add (GTK_COMBO_BOX (data), current_ref, title ? title : _("Untitled")); + if (title) + queue_set_title (queue, title); + g_free (title); } diff --git a/plug-ins/helpbrowser/queue.c b/plug-ins/helpbrowser/queue.c index 6e8c848257..2bfd9403ef 100644 --- a/plug-ins/helpbrowser/queue.c +++ b/plug-ins/helpbrowser/queue.c @@ -34,17 +34,37 @@ struct _Queue GList *current; }; +typedef struct +{ + gchar *uri; + gchar *title; +} Item; + + +static Item * +item_new (const gchar *uri) +{ + Item *item = g_new0 (Item, 1); + + item->uri = g_strdup (uri); + + return item; +} + +static void +item_free (Item *item) +{ + g_free (item->uri); + g_free (item->title); + + g_free (item); +} + + Queue * queue_new (void) { - Queue *h; - - h = g_malloc (sizeof (Queue)); - - h->queue = NULL; - h->current = NULL; - - return (h); + return g_new0 (Queue, 1); } void @@ -84,36 +104,42 @@ const gchar * queue_prev (Queue *h) { GList *p; + Item *item; if (!h || !h->queue || (h->current == g_list_first (h->queue))) return NULL; p = g_list_previous (h->current); - return (const gchar *) p->data; + item = p->data; + + return (const gchar *) item->uri; } const gchar * queue_next (Queue *h) { GList *p; + Item *item; if (!h || !h->queue || (h->current == g_list_last(h->queue))) return NULL; p = g_list_next (h->current); - return (const gchar *) p->data; + item = p->data; + + return (const gchar *) item->uri; } -void +void queue_add (Queue *h, - const gchar *ref) + const gchar *uri) { GList *trash = NULL; g_return_if_fail (h != NULL); - g_return_if_fail (ref != NULL); + g_return_if_fail (uri != NULL); if (h->current) { @@ -121,14 +147,34 @@ queue_add (Queue *h, h->current->next = NULL; } - h->queue = g_list_append (h->queue, g_strdup (ref)); + h->queue = g_list_append (h->queue, item_new (uri)); h->current = g_list_last (h->queue); if (trash) { - g_list_foreach (trash, (GFunc) g_free, NULL); + g_list_foreach (trash, (GFunc) item_free, NULL); g_list_free (trash); - } + } +} + +void +queue_set_title (Queue *h, + const gchar *title) +{ + Item *item; + + g_return_if_fail (h != NULL); + g_return_if_fail (title != NULL); + + if (! h->current || ! h->current->data) + return; + + item = h->current->data; + + if (item->title) + g_free (item->title); + + item->title = g_strdup (title); } gboolean @@ -136,7 +182,7 @@ queue_has_next (Queue *h) { if (!h || !h->queue || (h->current == g_list_last (h->queue))) return FALSE; - + return (g_list_next (h->current) != NULL); } @@ -145,6 +191,52 @@ queue_has_prev (Queue *h) { if (!h || !h->queue || (h->current == g_list_first (h->queue))) return FALSE; - + return (g_list_previous (h->current) != NULL); } + +GList * +queue_list_next (Queue *h) +{ + GList *result = NULL; + + if (queue_has_next) + { + GList *list; + + for (list = g_list_next (h->current); + list; + list = g_list_next (list)) + { + Item *item = list->data; + + result = g_list_prepend (result, + item->title ? item->title : item->uri); + } + } + + return g_list_reverse (result); +} + +GList * +queue_list_prev (Queue *h) +{ + GList *result = NULL; + + if (queue_has_prev) + { + GList *list; + + for (list = g_list_previous (h->current); + list; + list = g_list_previous (list)) + { + Item *item = list->data; + + result = g_list_prepend (result, + item->title ? item->title : item->uri); + } + } + + return g_list_reverse (result); +} diff --git a/plug-ins/helpbrowser/queue.h b/plug-ins/helpbrowser/queue.h index 8ece944326..acf45c6a91 100644 --- a/plug-ins/helpbrowser/queue.h +++ b/plug-ins/helpbrowser/queue.h @@ -25,17 +25,23 @@ #ifndef _GIMP_HELP_QUEUE_H_ #define _GIMP_HELP_QUEUE_H_ + typedef struct _Queue Queue; Queue * queue_new (void); void queue_free (Queue *queue); void queue_add (Queue *queue, - const gchar *ref); + const gchar *uri); +void queue_set_title (Queue *queue, + const gchar *title); const gchar * queue_prev (Queue *queue); const gchar * queue_next (Queue *queue); void queue_move_prev (Queue *queue); void queue_move_next (Queue *queue); gboolean queue_has_next (Queue *queue); gboolean queue_has_prev (Queue *queue); +GList * queue_list_prev (Queue *queue); +GList * queue_list_next (Queue *queue); + #endif /* _GIMP_HELP_QUEUE_H_ */