[gthumb] started work to use the header bar instead of the menu bar



commit 78b9ba32a8c7d13de75065704db74256e673585c
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Oct 14 18:34:48 2013 +0200

    started work to use the header bar instead of the menu bar

 extensions/gstreamer_tools/gth-media-viewer-page.c |    9 ++
 gthumb/gth-browser.c                               |  131 +++++++++++++++++++-
 gthumb/gth-browser.h                               |   17 +++
 gthumb/gth-window.c                                |   64 ++++++++++-
 gthumb/gth-window.h                                |    4 +
 5 files changed, 218 insertions(+), 7 deletions(-)
---
diff --git a/extensions/gstreamer_tools/gth-media-viewer-page.c 
b/extensions/gstreamer_tools/gth-media-viewer-page.c
index e19e754..387872b 100644
--- a/extensions/gstreamer_tools/gth-media-viewer-page.c
+++ b/extensions/gstreamer_tools/gth-media-viewer-page.c
@@ -736,6 +736,15 @@ gth_media_viewer_page_real_activate (GthViewerPage *base,
        /* video area */
 
        self->priv->area = gtk_drawing_area_new ();
+
+       /* do not use the rgba visual on the drawing area */
+       {
+               GdkVisual *visual;
+               visual = gdk_screen_get_system_visual (gtk_widget_get_screen (GTK_WIDGET (self->priv->area)));
+               if (visual != NULL)
+                       gtk_widget_set_visual (GTK_WIDGET (self->priv->area), visual);
+       }
+
        gtk_widget_set_double_buffered (self->priv->area, FALSE);
        gtk_widget_add_events (self->priv->area, (gtk_widget_get_events (self->priv->area)
                                                  | GDK_EXPOSURE_MASK
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 42cd59d..7ad4852 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -118,6 +118,7 @@ struct _GthBrowserPrivate {
        GtkWidget         *list_extra_widget_container;
        GtkWidget         *list_extra_widget;
        GtkWidget         *file_properties;
+       GtkWidget         *header_sections[GTH_BROWSER_N_HEADER_SECTIONS];
 
        GtkWidget         *thumbnail_list;
 
@@ -545,10 +546,12 @@ void
 gth_browser_update_title (GthBrowser *browser)
 {
        GString      *title;
+       GString      *subtitle;
        const char   *name = NULL;
        GthFileStore *file_store;
 
        title = g_string_new (NULL);
+       subtitle = g_string_new (NULL);
 
        if (browser->priv->current_file != NULL)
                name = g_file_info_get_display_name (browser->priv->current_file->info);
@@ -573,17 +576,17 @@ gth_browser_update_title (GthBrowser *browser)
                pos = gth_file_store_get_pos (file_store, browser->priv->current_file->file);
                if (pos >= 0) {
                        browser->priv->current_file_position = pos;
-                       g_string_append_printf (title, " - %d/%d", browser->priv->current_file_position + 1, 
browser->priv->n_visibles);
+                       g_string_append_printf (subtitle, "%d/%d", browser->priv->current_file_position + 1, 
browser->priv->n_visibles);
                }
        }
 
-       if (title->len > 0)
-               g_string_append (title, " - ");
-       g_string_append (title, _("gThumb"));
+       if (title->len == 0)
+               g_string_append (title, _("gThumb"));
 
-       gtk_window_set_title (GTK_WINDOW (browser), title->str);
+       _gth_window_set_title (GTH_WINDOW (browser), title->str, subtitle->str);
 
        g_string_free (title, TRUE);
+       g_string_free (subtitle, TRUE);
 }
 
 
@@ -2553,6 +2556,18 @@ _gth_browser_get_browser_file_properties_container (GthBrowser *browser)
 
 
 static void
+_gth_browser_update_header_section_visibility (GthBrowser              *browser,
+                                              GthBrowserHeaderSection  section,
+                                              gboolean                 visible)
+{
+       GtkWidget *header_section;
+
+       header_section = browser->priv->header_sections[section];
+       gtk_widget_set_visible (header_section, visible && (_gtk_container_get_n_children (GTK_CONTAINER 
(header_section)) > 0));
+}
+
+
+static void
 _gth_browser_real_set_current_page (GthWindow *window,
                                    int        page)
 {
@@ -2573,6 +2588,19 @@ _gth_browser_real_set_current_page (GthWindow *window,
        _gth_browser_update_browser_ui (browser, page);
        _gth_browser_hide_infobar (browser);
 
+       _gth_browser_update_header_section_visibility (browser, 
GTH_BROWSER_HEADER_SECTION_BROWSER_NAVIGATION, page == GTH_BROWSER_PAGE_BROWSER);
+       _gth_browser_update_header_section_visibility (browser, GTH_BROWSER_HEADER_SECTION_BROWSER_COMMANDS, 
page == GTH_BROWSER_PAGE_BROWSER);
+       _gth_browser_update_header_section_visibility (browser, GTH_BROWSER_HEADER_SECTION_BROWSER_VIEW, page 
== GTH_BROWSER_PAGE_BROWSER);
+       _gth_browser_update_header_section_visibility (browser, GTH_BROWSER_HEADER_SECTION_BROWSER_EDIT, page 
== GTH_BROWSER_PAGE_BROWSER);
+       _gth_browser_update_header_section_visibility (browser, GTH_BROWSER_HEADER_SECTION_BROWSER_TOOLS, 
page == GTH_BROWSER_PAGE_BROWSER);
+       _gth_browser_update_header_section_visibility (browser, 
GTH_BROWSER_HEADER_SECTION_BROWSER_PROPERTIES, page == GTH_BROWSER_PAGE_BROWSER);
+
+       _gth_browser_update_header_section_visibility (browser, GTH_BROWSER_HEADER_SECTION_VIEWER_NAVIGATION, 
page == GTH_BROWSER_PAGE_VIEWER);
+       _gth_browser_update_header_section_visibility (browser, GTH_BROWSER_HEADER_SECTION_VIEWER_VIEW, page 
== GTH_BROWSER_PAGE_VIEWER);
+       _gth_browser_update_header_section_visibility (browser, GTH_BROWSER_HEADER_SECTION_VIEWER_EDIT, page 
== GTH_BROWSER_PAGE_VIEWER);
+       _gth_browser_update_header_section_visibility (browser, GTH_BROWSER_HEADER_SECTION_VIEWER_TOOLS, page 
== GTH_BROWSER_PAGE_VIEWER);
+       _gth_browser_update_header_section_visibility (browser, GTH_BROWSER_HEADER_SECTION_VIEWER_PROPERTIES, 
page == GTH_BROWSER_PAGE_VIEWER);
+
        /* move the sidebar from the browser to the viewer and vice-versa */
 
        gtk_widget_unrealize (browser->priv->file_properties);
@@ -4303,7 +4331,10 @@ gth_browser_init (GthBrowser *browser)
        char           *caption;
        int             i;
 
-       g_object_set (browser, "n-pages", GTH_BROWSER_N_PAGES, NULL);
+       g_object_set (browser,
+                     "n-pages", GTH_BROWSER_N_PAGES,
+                     "use-header-bar", TRUE,
+                     NULL);
 
        browser->priv = G_TYPE_INSTANCE_GET_PRIVATE (browser, GTH_TYPE_BROWSER, GthBrowserPrivate);
        browser->priv->viewer_pages = NULL;
@@ -4412,6 +4443,11 @@ gth_browser_init (GthBrowser *browser)
 
        /* ui actions */
 
+       g_action_map_add_action_entries (G_ACTION_MAP (browser),
+                                        gth_browser_actions,
+                                        G_N_ELEMENTS (gth_browser_actions),
+                                        browser);
+
        browser->priv->actions = gtk_action_group_new ("Actions");
        gtk_action_group_set_translation_domain (browser->priv->actions, NULL);
        gtk_action_group_add_actions (browser->priv->actions,
@@ -4537,6 +4573,73 @@ gth_browser_init (GthBrowser *browser)
                          G_CALLBACK (folder_popup_hide_cb),
                          browser);
 
+       /* headerbar */
+
+       {
+               GtkWidget *header_bar;
+               GtkWidget *button;
+
+               header_bar = gth_window_get_header_bar (GTH_WINDOW (browser));
+
+               /* dynamic sections */
+
+               for (i = 0; i < GTH_BROWSER_N_HEADER_SECTIONS; i++) {
+                       browser->priv->header_sections[i] = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+                       gtk_style_context_add_class (gtk_widget_get_style_context 
(browser->priv->header_sections[i]), GTK_STYLE_CLASS_LINKED);
+               }
+
+               gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_BROWSER_NAVIGATION]);
+               gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_BROWSER_COMMANDS]);
+               gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_BROWSER_VIEW]);
+               gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_BROWSER_EDIT]);
+               gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_BROWSER_TOOLS]);
+               gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_BROWSER_PROPERTIES]);
+
+               gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_NAVIGATION]);
+               gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_VIEW]);
+               gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_EDIT]);
+               gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_TOOLS]);
+               gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), 
browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_PROPERTIES]);
+
+               /* browser navigation */
+
+               button = gtk_button_new_from_icon_name ("go-previous-symbolic", GTK_ICON_SIZE_MENU);
+               gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), FALSE);
+               gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), gtk_action_group_get_action 
(browser->priv->actions, "Go_Back"));
+               gtk_widget_show (button);
+               gtk_box_pack_start (GTK_BOX 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_BROWSER_NAVIGATION]), button, FALSE, FALSE, 0);
+
+               button = gtk_button_new_from_icon_name ("go-next-symbolic", GTK_ICON_SIZE_MENU);
+               gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), FALSE);
+               gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), gtk_action_group_get_action 
(browser->priv->actions, "Go_Forward"));
+               gtk_widget_show (button);
+               gtk_box_pack_start (GTK_BOX 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_BROWSER_NAVIGATION]), button, FALSE, FALSE, 0);
+
+               /* browser commands */
+
+               button = gtk_button_new_from_icon_name ("view-fullscreen-symbolic", GTK_ICON_SIZE_MENU);
+               gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), FALSE);
+               gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), gtk_action_group_get_action 
(browser->priv->actions, "View_Fullscreen"));
+               gtk_widget_show (button);
+               gtk_box_pack_start (GTK_BOX 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_BROWSER_VIEW]), button, FALSE, FALSE, 0);
+
+               /* viewer navigation */
+
+               button = gtk_button_new_from_icon_name ("go-previous-symbolic", GTK_ICON_SIZE_MENU);
+               gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), FALSE);
+               gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), gtk_action_group_get_action 
(browser->priv->actions, "View_BrowserMode"));
+               gtk_widget_show (button);
+               gtk_box_pack_start (GTK_BOX 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_NAVIGATION]), button, FALSE, FALSE, 0);
+
+               /* viewer view */
+
+               button = gtk_button_new_from_icon_name ("view-fullscreen-symbolic", GTK_ICON_SIZE_MENU);
+               gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), FALSE);
+               gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), gtk_action_group_get_action 
(browser->priv->actions, "View_Fullscreen"));
+               gtk_widget_show (button);
+               gtk_box_pack_start (GTK_BOX 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_VIEW]), button, FALSE, FALSE, 0);
+       }
+
        /* toolbar */
 
        browser->priv->browser_toolbar = gtk_ui_manager_get_widget (browser->priv->ui, "/ToolBar");
@@ -5105,6 +5208,22 @@ gth_browser_get_filterbar (GthBrowser *browser)
 
 
 GtkWidget *
+gth_browser_get_headerbar_section (GthBrowser                  *browser,
+                                  GthBrowserHeaderSection       section)
+{
+       return browser->priv->header_sections[section];
+}
+
+
+GthMenuManager *
+gth_browser_get_menu_manager (GthBrowser               *browser,
+                             GthBrowserMenuManager      manager)
+{
+       return browser->priv->menu_managers[manager];
+}
+
+
+GtkWidget *
 gth_browser_get_file_list (GthBrowser *browser)
 {
        return browser->priv->file_list;
diff --git a/gthumb/gth-browser.h b/gthumb/gth-browser.h
index babb964..09f71e5 100644
--- a/gthumb/gth-browser.h
+++ b/gthumb/gth-browser.h
@@ -50,6 +50,21 @@ typedef enum { /*< skip >*/
        GTH_BROWSER_N_PAGES
 } GthBrowserPage;
 
+typedef enum { /*< skip >*/
+       GTH_BROWSER_HEADER_SECTION_BROWSER_NAVIGATION,
+       GTH_BROWSER_HEADER_SECTION_BROWSER_COMMANDS,
+       GTH_BROWSER_HEADER_SECTION_BROWSER_VIEW,
+       GTH_BROWSER_HEADER_SECTION_BROWSER_EDIT,
+       GTH_BROWSER_HEADER_SECTION_BROWSER_TOOLS,
+       GTH_BROWSER_HEADER_SECTION_BROWSER_PROPERTIES,
+       GTH_BROWSER_HEADER_SECTION_VIEWER_NAVIGATION,
+       GTH_BROWSER_HEADER_SECTION_VIEWER_VIEW,
+       GTH_BROWSER_HEADER_SECTION_VIEWER_EDIT,
+       GTH_BROWSER_HEADER_SECTION_VIEWER_TOOLS,
+       GTH_BROWSER_HEADER_SECTION_VIEWER_PROPERTIES,
+       GTH_BROWSER_N_HEADER_SECTIONS
+} GthBrowserHeaderSection;
+
 typedef enum {
        GTH_ACTION_GO_TO,
        GTH_ACTION_GO_BACK,
@@ -106,6 +121,8 @@ GtkWidget *      gth_browser_get_browser_toolbar    (GthBrowser       *browser);
 GtkWidget *      gth_browser_get_infobar            (GthBrowser       *browser);
 GtkWidget *      gth_browser_get_statusbar          (GthBrowser       *browser);
 GtkWidget *      gth_browser_get_filterbar          (GthBrowser       *browser);
+GtkWidget *      gth_browser_get_headerbar_section  (GthBrowser       *browser,
+                                                    GthBrowserHeaderSection section);
 GtkWidget *      gth_browser_get_file_list          (GthBrowser       *browser);
 GtkWidget *      gth_browser_get_file_list_view     (GthBrowser       *browser);
 GtkWidget *      gth_browser_get_thumbnail_list     (GthBrowser       *browser);
diff --git a/gthumb/gth-window.c b/gthumb/gth-window.c
index a2cce99..43489f4 100644
--- a/gthumb/gth-window.c
+++ b/gthumb/gth-window.c
@@ -31,15 +31,18 @@ G_DEFINE_TYPE (GthWindow, gth_window, GTK_TYPE_APPLICATION_WINDOW)
 
 enum  {
        PROP_0,
-       PROP_N_PAGES
+       PROP_N_PAGES,
+       PROP_USE_HEADER_BAR
 };
 
 
 struct _GthWindowPrivate {
        int              n_pages;
+       gboolean         use_header_bar;
        int              current_page;
        GtkWidget       *grid;
        GtkWidget       *notebook;
+       GtkWidget       *headerbar;
        GtkWidget       *menubar;
        GtkWidget       *toolbar;
        GtkWidget       *infobar;
@@ -106,6 +109,16 @@ gth_window_set_n_pages (GthWindow *self,
 
 
 static void
+_gth_window_add_header_bar (GthWindow *self)
+{
+       self->priv->headerbar = gtk_header_bar_new ();
+       gtk_widget_show (self->priv->headerbar);
+       gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (self->priv->headerbar), TRUE);
+       gtk_window_set_titlebar (GTK_WINDOW (self), self->priv->headerbar);
+}
+
+
+static void
 gth_window_set_property (GObject      *object,
                         guint         property_id,
                         const GValue *value,
@@ -119,6 +132,11 @@ gth_window_set_property (GObject      *object,
        case PROP_N_PAGES:
                gth_window_set_n_pages (self, g_value_get_int (value));
                break;
+       case PROP_USE_HEADER_BAR:
+               self->priv->use_header_bar = g_value_get_boolean (value);
+               if (self->priv->use_header_bar)
+                       _gth_window_add_header_bar (self);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
@@ -140,6 +158,9 @@ gth_window_get_property (GObject    *object,
        case PROP_N_PAGES:
                g_value_set_int (value, self->priv->n_pages);
                break;
+       case PROP_USE_HEADER_BAR:
+               g_value_set_boolean (value, self->priv->use_header_bar);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                break;
@@ -262,6 +283,13 @@ gth_window_class_init (GthWindowClass *klass)
                                                           G_MAXINT,
                                                           1,
                                                           G_PARAM_READWRITE));
+       g_object_class_install_property (G_OBJECT_CLASS (klass),
+                                        PROP_USE_HEADER_BAR,
+                                        g_param_spec_boolean ("use-header-bar",
+                                                              "use-header-bar",
+                                                              "use-header-bar",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE));
 }
 
 
@@ -277,6 +305,9 @@ gth_window_init (GthWindow *window)
        window->priv->toolbar = NULL;
        window->priv->infobar = NULL;
        window->priv->statusbar = NULL;
+       window->priv->headerbar = NULL;
+       window->priv->use_header_bar = FALSE;
+
        window->priv->window_group = gtk_window_group_new ();
        gtk_window_group_add_window (window->priv->window_group, GTK_WINDOW (window));
 
@@ -447,6 +478,13 @@ gth_window_get_area (GthWindow     *window,
 }
 
 
+GtkWidget *
+gth_window_get_header_bar (GthWindow *window)
+{
+       return window->priv->headerbar;
+}
+
+
 void
 gth_window_save_page_size (GthWindow *window,
                           int        page,
@@ -512,3 +550,27 @@ gth_window_get_page_size (GthWindow *window,
 
        return TRUE;
 }
+
+
+void
+_gth_window_set_title (GthWindow  *window,
+                      const char *title,
+                      const char *subtitle)
+{
+       if (window->priv->use_header_bar) {
+               gtk_header_bar_set_title (GTK_HEADER_BAR (window->priv->headerbar), title);
+               gtk_header_bar_set_subtitle (GTK_HEADER_BAR (window->priv->headerbar), subtitle);
+       }
+       else {
+               GString *complete_title;
+
+               complete_title = g_string_new (title);
+               if (subtitle != NULL) {
+                       g_string_append (complete_title, " - ");
+                       g_string_append (complete_title, subtitle);
+               }
+               gtk_window_set_title (GTK_WINDOW (window), complete_title->str);
+
+               g_string_free (complete_title, TRUE);
+       }
+}
diff --git a/gthumb/gth-window.h b/gthumb/gth-window.h
index 83bc5cd..6f83b7d 100644
--- a/gthumb/gth-window.h
+++ b/gthumb/gth-window.h
@@ -87,6 +87,7 @@ void           gth_window_show_only_content  (GthWindow     *window,
                                              gboolean       only_content);
 GtkWidget *    gth_window_get_area           (GthWindow     *window,
                                              GthWindowArea  area);
+GtkWidget *    gth_window_get_header_bar     (GthWindow     *window);
 void           gth_window_save_page_size     (GthWindow     *window,
                                              int            page,
                                              int            width,
@@ -99,6 +100,9 @@ gboolean       gth_window_get_page_size      (GthWindow     *window,
                                              int           *height);
 void           gth_window_clear_saved_size   (GthWindow     *window,
                                              int            page);
+void           _gth_window_set_title         (GthWindow     *window,
+                                             const char    *title,
+                                             const char    *subtitle);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]