[dconf-editor] Introduce AdaptativeHeaderBar.



commit 895cfd411ba9c6c4381514960a17ffb8b7034dd3
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Dec 6 16:11:17 2018 +0100

    Introduce AdaptativeHeaderBar.

 editor/adaptative-window.vala | 101 +++++++++++++++++++++++++++++++++++++++++-
 editor/browser-headerbar.ui   |   2 +-
 editor/browser-headerbar.vala |  38 +++++-----------
 editor/browser-window.ui      |  13 ------
 editor/browser-window.vala    |  54 +++++-----------------
 editor/dconf-window.vala      |   3 +-
 6 files changed, 125 insertions(+), 86 deletions(-)
---
diff --git a/editor/adaptative-window.vala b/editor/adaptative-window.vala
index 402b38e..1556236 100644
--- a/editor/adaptative-window.vala
+++ b/editor/adaptative-window.vala
@@ -68,8 +68,72 @@ private interface AdaptativeWidget : Object
     internal abstract void set_window_size (WindowSize new_size);
 }
 
-private class AdaptativeWindow : ApplicationWindow
+private abstract class AdaptativeHeaderBar : HeaderBar
 {
+    /*\
+    * * manage night mode
+    \*/
+
+    private bool night_time = false;   // no need to use NightTime here (that allows an "Unknown" value)
+    internal void set_night_time (bool _night_time)
+    {
+        night_time = _night_time;
+        update_hamburger_menu ();
+    }
+    private bool dark_theme = false;
+    internal void set_dark_theme (bool _dark_theme)
+    {
+        dark_theme = _dark_theme;
+        update_hamburger_menu ();
+    }
+    private bool automatic_night_mode = false;
+    internal void set_automatic_night_mode (bool _automatic_night_mode)
+    {
+        automatic_night_mode = _automatic_night_mode;
+        // menu update not needed
+    }
+
+    internal void init_night_mode (bool _night_time, bool _dark_theme, bool _automatic_night_mode)
+    {
+        night_time           = _night_time;
+        dark_theme           = _dark_theme;
+        automatic_night_mode = _automatic_night_mode;
+        // menu is already updated three times at startup, let's not add one
+    }
+
+    /*\
+    * * hamburger menu
+    \*/
+
+    protected abstract void update_hamburger_menu ();
+
+    protected void append_or_not_night_mode_entry (ref GLib.Menu section)
+    {
+        _append_or_not_night_mode_entry (night_time, dark_theme, automatic_night_mode, ref section);
+    }
+    private static void _append_or_not_night_mode_entry (bool night_time, bool dark_theme, bool auto_night, 
ref GLib.Menu section)
+    {
+        if (!night_time)
+            return;
+
+        if (dark_theme)
+            /* Translators: there are three related actions: "use", "reuse" and "pause" */
+            section.append (_("Pause night mode"), "app.set-use-night-mode(false)");
+
+        else if (auto_night)
+            /* Translators: there are three related actions: "use", "reuse" and "pause" */
+            section.append (_("Reuse night mode"), "app.set-use-night-mode(true)");
+
+        else
+            /* Translators: there are three related actions: "use", "reuse" and "pause" */
+            section.append (_("Use night mode"), "app.set-use-night-mode(true)");
+    }
+}
+
+private abstract class AdaptativeWindow : ApplicationWindow
+{
+    public AdaptativeHeaderBar adaptative_headerbar { protected get; protected construct; }
+
     private StyleContext context;
 
     construct
@@ -77,6 +141,11 @@ private class AdaptativeWindow : ApplicationWindow
         context = get_style_context ();
         context.add_class ("startup");
 
+        adaptative_headerbar.show ();
+        set_titlebar (adaptative_headerbar);
+
+        init_night_mode ();
+
         manage_high_contrast ();
 
         window_state_event.connect (on_window_state_event);
@@ -271,4 +340,34 @@ private class AdaptativeWindow : ApplicationWindow
         else
             context.remove_class ("hc-theme");
     }
+
+    /*\
+    * * manage night mode
+    \*/
+
+    // for construct only
+    public bool initial_night_time           { private get; protected construct; }
+    public bool initial_dark_theme           { private get; protected construct; }
+    public bool initial_automatic_night_mode { private get; protected construct; }
+
+    private void init_night_mode ()
+    {
+        adaptative_headerbar.init_night_mode (initial_night_time, initial_dark_theme, 
initial_automatic_night_mode);
+    }
+
+    // for updates
+    internal void night_time_changed (Object nlm, ParamSpec thing)
+    {
+        adaptative_headerbar.set_night_time (NightLightMonitor.NightTime.should_use_dark_theme 
(((NightLightMonitor) nlm).night_time));
+    }
+
+    internal void dark_theme_changed (Object nlm, ParamSpec thing)
+    {
+        adaptative_headerbar.set_dark_theme (((NightLightMonitor) nlm).dark_theme);
+    }
+
+    internal void automatic_night_mode_changed (Object nlm, ParamSpec thing)
+    {
+        adaptative_headerbar.set_automatic_night_mode (((NightLightMonitor) nlm).automatic_night_mode);
+    }
 }
diff --git a/editor/browser-headerbar.ui b/editor/browser-headerbar.ui
index 886bb2a..e96cfa9 100644
--- a/editor/browser-headerbar.ui
+++ b/editor/browser-headerbar.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="dconf-editor">
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="BrowserHeaderBar" parent="GtkHeaderBar">
+  <template class="BrowserHeaderBar" parent="AdaptativeHeaderBar">
     <property name="show-close-button">True</property>
     <property name="has-subtitle">False</property>
     <child>
diff --git a/editor/browser-headerbar.vala b/editor/browser-headerbar.vala
index 24254af..29383ec 100644
--- a/editor/browser-headerbar.vala
+++ b/editor/browser-headerbar.vala
@@ -18,7 +18,7 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/browser-headerbar.ui")]
-private class BrowserHeaderBar : HeaderBar, AdaptativeWidget
+private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
 {
     [GtkChild] private MenuButton   info_button;
     [GtkChild] private PathWidget   path_widget;
@@ -433,10 +433,6 @@ private class BrowserHeaderBar : HeaderBar, AdaptativeWidget
     * * hamburger menu
     \*/
 
-    internal bool night_time            { private get; internal set; default = false; }    // no need to use 
NightTime here (that allows an "Unknown" value)
-    internal bool dark_theme            { private get; internal set; default = false; }
-    internal bool automatic_night_mode  { private get; internal set; default = false; }
-
     private inline void hide_hamburger_menu ()
     {
         if (info_button.active)
@@ -451,7 +447,7 @@ private class BrowserHeaderBar : HeaderBar, AdaptativeWidget
             info_button.active = !info_button.active;
     }
 
-    internal void update_hamburger_menu ()
+    protected override void update_hamburger_menu ()
     {
         GLib.Menu menu = new GLib.Menu ();
 
@@ -468,7 +464,7 @@ private class BrowserHeaderBar : HeaderBar, AdaptativeWidget
         if (!in_window_bookmarks)
             append_or_not_delay_mode_section (delay_mode, current_type == ViewType.FOLDER, current_path, ref 
menu);
 
-        append_app_actions_section (night_time, dark_theme, automatic_night_mode, disable_popovers, ref 
menu);
+        append_app_actions_section (ref menu);
 
         menu.freeze ();
         info_button.set_menu_model ((MenuModel) menu);
@@ -511,33 +507,19 @@ private class BrowserHeaderBar : HeaderBar, AdaptativeWidget
         menu.append_section (null, section);
     }
 
-    private static void append_app_actions_section (bool night_time, bool dark_theme, bool auto_night, bool 
disable_popovers, ref GLib.Menu menu)
+    private void append_app_actions_section (ref GLib.Menu menu)
     {
         GLib.Menu section = new GLib.Menu ();
-        append_or_not_night_mode_entry (night_time, dark_theme, auto_night, ref section);
-        if (!disable_popovers)    // TODO else...
-            section.append (_("Keyboard Shortcuts"), "win.show-help-overlay");
-        section.append (_("About Dconf Editor"), "browser.about");
+        append_or_not_night_mode_entry (ref section);
+        _append_app_actions_section (!disable_popovers, ref section);
         section.freeze ();
         menu.append_section (null, section);
     }
-
-    private static void append_or_not_night_mode_entry (bool night_time, bool dark_theme, bool auto_night, 
ref GLib.Menu section)
+    private static void _append_app_actions_section (bool has_keyboard_shortcuts, ref GLib.Menu section)
     {
-        if (!night_time)
-            return;
-
-        if (dark_theme)
-            /* Translators: there are three related actions: "use", "reuse" and "pause" */
-            section.append (_("Pause night mode"), "app.set-use-night-mode(false)");
-
-        else if (auto_night)
-            /* Translators: there are three related actions: "use", "reuse" and "pause" */
-            section.append (_("Reuse night mode"), "app.set-use-night-mode(true)");
-
-        else
-            /* Translators: there are three related actions: "use", "reuse" and "pause" */
-            section.append (_("Use night mode"), "app.set-use-night-mode(true)");
+        if (has_keyboard_shortcuts)    // FIXME is used also for hiding keyboard shortcuts in small window
+            section.append (_("Keyboard Shortcuts"), "win.show-help-overlay");
+        section.append (_("About Dconf Editor"), "browser.about");
     }
 
     /*\
diff --git a/editor/browser-window.ui b/editor/browser-window.ui
index 153d78d..5a8f81b 100644
--- a/editor/browser-window.ui
+++ b/editor/browser-window.ui
@@ -8,13 +8,6 @@
     <signal name="key-press-event" handler="on_key_press_event"/>
     <signal name="button-press-event" handler="on_button_press_event"/>
     <signal name="destroy" handler="on_destroy"/>
-    <child type="titlebar">
-      <object class="BrowserHeaderBar" id="headerbar">
-        <property name="visible">True</property>
-        <signal name="search-changed" handler="search_changed_cb"/>
-        <signal name="search-stopped" handler="search_stopped_cb"/>
-      </object>
-    </child>
     <child>
       <object class="GtkOverlay">
         <property name="visible">True</property>
@@ -22,12 +15,6 @@
           <object class="GtkGrid" id="main_grid">
             <property name="visible">True</property>
             <property name="orientation">vertical</property>
-            <child>
-              <object class="BrowserView" id="browser_view">
-                <property name="visible">True</property>
-                <property name="vexpand">True</property>
-              </object>
-            </child>
           </object>
         </child>
         <child type="overlay">
diff --git a/editor/browser-window.vala b/editor/browser-window.vala
index 48825fb..f70844e 100644
--- a/editor/browser-window.vala
+++ b/editor/browser-window.vala
@@ -28,16 +28,24 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
     protected string    saved_view      = "/";
     protected string    saved_selection = "";
 
-    [GtkChild] protected BrowserHeaderBar headerbar;
-    [GtkChild] protected BrowserView      browser_view;
-    [GtkChild] protected Grid             main_grid;
+    [GtkChild] protected Grid main_grid;
+               protected BrowserHeaderBar headerbar;
+               protected BrowserView      browser_view;
 
     construct
     {
+        headerbar = (BrowserHeaderBar) adaptative_headerbar;
+        headerbar.search_changed.connect (search_changed_cb);
+        headerbar.search_stopped.connect (search_stopped_cb);
+
+        browser_view = new BrowserView ();
+        browser_view.vexpand = true;
+        browser_view.visible = true;
+        main_grid.add (browser_view);
+
         install_browser_action_entries ();
         install_key_action_entries ();
 
-        init_night_mode ();
         bind_mouse_config ();
 
         add_adaptative_child (headerbar);
@@ -344,13 +352,11 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
     * * search callbacks
     \*/
 
-    [GtkCallback]
     private void search_changed_cb ()
     {
         request_search (reload_search_next);
     }
 
-    [GtkCallback]
     private void search_stopped_cb ()
     {
         browser_view.row_grab_focus ();
@@ -875,42 +881,6 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
         return false;
     }
 
-    /*\
-    * * night mode
-    \*/
-
-    // for construct only
-    public bool initial_night_time           { private get; protected construct; }
-    public bool initial_dark_theme           { private get; protected construct; }
-    public bool initial_automatic_night_mode { private get; protected construct; }
-
-    private void init_night_mode ()
-    {
-        headerbar.night_time           = initial_night_time;
-        headerbar.dark_theme           = initial_dark_theme;
-        headerbar.automatic_night_mode = initial_automatic_night_mode;
-        // menu is already updated three times at startup, let's not add one
-    }
-
-    // for updates
-    internal void night_time_changed (Object nlm, ParamSpec thing)
-    {
-        headerbar.night_time = NightLightMonitor.NightTime.should_use_dark_theme (((NightLightMonitor) 
nlm).night_time);
-        headerbar.update_hamburger_menu ();
-    }
-
-    internal void dark_theme_changed (Object nlm, ParamSpec thing)
-    {
-        headerbar.dark_theme = ((NightLightMonitor) nlm).dark_theme;
-        headerbar.update_hamburger_menu ();
-    }
-
-    internal void automatic_night_mode_changed (Object nlm, ParamSpec thing)
-    {
-        headerbar.automatic_night_mode = ((NightLightMonitor) nlm).automatic_night_mode;
-        // update menu not needed
-    }
-
     /*\
     * * notifications
     \*/
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 20a5486..f5ee82e 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -119,7 +119,8 @@ private class DConfWindow : BrowserWindow
 
     internal DConfWindow (bool disable_warning, string? schema, string? path, string? key_name, bool 
night_time, bool dark_theme, bool automatic_night_mode)
     {
-        Object (initial_night_time: night_time, initial_dark_theme: dark_theme, 
initial_automatic_night_mode: automatic_night_mode);
+        BrowserHeaderBar headerbar = new BrowserHeaderBar ();
+        Object (initial_night_time: night_time, initial_dark_theme: dark_theme, 
initial_automatic_night_mode: automatic_night_mode, adaptative_headerbar: (AdaptativeHeaderBar) headerbar);
 
         headerbar_update_bookmarks_icons_handler = headerbar.update_bookmarks_icons.connect 
(update_bookmarks_icons_from_variant);
         browserview_update_bookmarks_icons_handler = browser_view.update_bookmarks_icons.connect 
(update_bookmarks_icons_from_variant);


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