[dconf-editor] Introduce BaseHeaderBar.



commit 93e3c9241d38a2815be60fb0bcaf4b4cbb153587
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Dec 12 16:17:18 2018 +0100

    Introduce BaseHeaderBar.

 editor/{browser-headerbar.ui => base-headerbar.ui} |  48 ++--
 editor/base-headerbar.vala                         | 267 ++++++++++++++++++
 editor/browser-headerbar.vala                      | 169 +++---------
 editor/browser-window.vala                         |  62 +++--
 editor/dconf-editor.gresource.xml                  |   2 +-
 editor/dconf-headerbar.vala                        | 302 +++++++++++----------
 editor/dconf-window.vala                           |  98 +++----
 editor/meson.build                                 |   3 +-
 8 files changed, 559 insertions(+), 392 deletions(-)
---
diff --git a/editor/browser-headerbar.ui b/editor/base-headerbar.ui
similarity index 74%
rename from editor/browser-headerbar.ui
rename to editor/base-headerbar.ui
index 1c7cbc8..364d87f 100644
--- a/editor/browser-headerbar.ui
+++ b/editor/base-headerbar.ui
@@ -1,13 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="dconf-editor">
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="BrowserHeaderBar" parent="NightTimeAwareHeaderBar">
+  <template class="BaseHeaderBar" parent="NightTimeAwareHeaderBar">
     <property name="show-close-button">True</property>
     <property name="has-subtitle">False</property>
     <child>
       <object class="GtkButton" id="go_back_button">
         <property name="visible">False</property>
         <property name="valign">center</property>
+        <property name="action-name">browser.show-default-panel</property>
         <style>
           <class name="image-button"/>
         </style>
@@ -35,41 +36,34 @@
           <class name="centerwidget"/>
         </style>
         <child>
-          <object class="GtkStack" id="title_stack">
-            <property name="visible">True</property>
-            <property name="hhomogeneous">False</property>
-            <property name="hexpand">True</property>
-            <child>
-              <object class="PathWidget" id="path_widget">
-                <property name="visible">True</property>
-                <property name="hexpand">False</property>
-                <signal name="search-changed" handler="search_changed_cb"/>
-                <signal name="search-stopped" handler="search_stopped_cb"/>
-              </object>
-            </child>
-            <child>
-              <object class="GtkLabel" id="title_label">
-                <property name="visible">True</property>
-              </object>
-            </child>
+          <object class="GtkLabel" id="title_label">
+            <property name="visible">False</property>
           </object>
         </child>
       </object>
     </child>
     <child>
-      <object class="GtkMenuButton" id="quit_button">
+      <object class="GtkStack" id="quit_button_stack">
         <property name="visible">False</property>
-        <property name="valign">center</property>
-        <property name="action-name">app.quit</property>
-        <style>
-          <class name="titlebutton"/>
-        </style>
         <child>
-          <object class="GtkImage">
+          <object class="GtkButton">
             <property name="visible">True</property>
-            <property name="icon-name">window-close-symbolic</property>
-            <property name="icon-size">1</property>
+            <property name="valign">center</property>
+            <property name="action-name">app.quit</property>
+            <style>
+              <class name="titlebutton"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">window-close-symbolic</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
           </object>
+          <packing>
+            <property name="name">quit-button</property>
+          </packing>
         </child>
       </object>
       <packing>
diff --git a/editor/base-headerbar.vala b/editor/base-headerbar.vala
new file mode 100644
index 0000000..63c8613
--- /dev/null
+++ b/editor/base-headerbar.vala
@@ -0,0 +1,267 @@
+/*
+  This file is part of Dconf Editor
+
+  Dconf Editor is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  Dconf Editor is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with Dconf Editor.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/base-headerbar.ui")]
+private class BaseHeaderBar : NightTimeAwareHeaderBar, AdaptativeWidget
+{
+    [GtkChild] protected Box center_box;
+
+    construct
+    {
+        center_box.valign = Align.FILL;
+
+        register_default_mode ();
+        register_about_mode ();
+    }
+
+    /*\
+    * * properties
+    \*/
+
+    protected bool disable_popovers = false;
+    protected bool disable_action_bar = false;
+    protected virtual void set_window_size (AdaptativeWidget.WindowSize new_size)
+    {
+        disable_popovers   = AdaptativeWidget.WindowSize.is_phone_size (new_size)
+                          || AdaptativeWidget.WindowSize.is_extra_thin (new_size);
+
+        disable_action_bar = disable_popovers
+                          || AdaptativeWidget.WindowSize.is_extra_flat (new_size);
+
+        update_hamburger_menu ();
+    }
+
+    /*\
+    * * popovers methods
+    \*/
+
+    internal virtual void close_popovers ()
+    {
+        hide_hamburger_menu ();
+    }
+
+    protected inline void hide_hamburger_menu ()
+    {
+        if (info_button.active)
+            info_button.active = false;
+    }
+
+    internal virtual bool has_popover ()
+    {
+        if (info_button.active)
+            return true;
+        return false;
+    }
+
+    /*\
+    * * keyboard calls
+    \*/
+
+    internal virtual bool previous_match ()
+    {
+        return false;
+    }
+
+    internal virtual bool next_match ()
+    {
+        return false;
+    }
+
+    internal virtual void toggle_hamburger_menu ()
+    {
+        if (info_button.visible)
+            info_button.active = !info_button.active;
+    }
+
+    /*\
+    * * hamburger menu
+    \*/
+
+    [CCode (notify = false)] public string about_action_label { private get; protected construct; }
+
+    protected override void update_hamburger_menu ()
+    {
+        GLib.Menu menu = new GLib.Menu ();
+
+/*        if (current_type == ViewType.OBJECT && !ModelUtils.is_folder_path (current_path))   // TODO a 
better way to copy various representations of a key name/value/path
+        {
+            Variant variant = new Variant.string (model.get_suggested_key_copy_text (current_path, 
browser_view.last_context_id));
+            menu.append (_("Copy descriptor"), "app.copy(" + variant.print (false) + ")");
+        }
+        else if (current_type != ViewType.SEARCH) */
+
+        populate_menu (ref menu);
+
+        append_app_actions_section (ref menu);
+
+        menu.freeze ();
+        info_button.set_menu_model ((MenuModel) menu);
+    }
+
+    protected virtual void populate_menu (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 (ref section);
+        append_or_not_keyboard_shortcuts_entry (!disable_popovers, ref section);
+        append_about_entry (about_action_label, ref section);
+        section.freeze ();
+        menu.append_section (null, section);
+    }
+
+    private static inline void append_or_not_keyboard_shortcuts_entry (bool has_keyboard_shortcuts, ref 
GLib.Menu section)
+    {
+        if (has_keyboard_shortcuts)    // FIXME is used also for hiding keyboard shortcuts in small window
+            section.append (_("Keyboard Shortcuts"), "win.show-help-overlay");
+    }
+
+    private static inline void append_about_entry (string about_action_label, ref GLib.Menu section)
+    {
+        section.append (about_action_label, "browser.about");
+    }
+
+    /*\
+    * * modes
+    \*/
+
+    protected signal void change_mode (uint8 mode_id);
+
+    private uint8 last_mode_id = 0; // 0 is default mode
+    protected uint8 register_new_mode ()
+    {
+        return ++last_mode_id;
+    }
+
+    protected bool is_not_requested_mode (uint8 mode_id, uint8 requested_mode_id, ref bool mode_is_active)
+    {
+        if (mode_id == requested_mode_id)
+        {
+            if (mode_is_active)
+                assert_not_reached ();
+            mode_is_active = true;
+            return false;
+        }
+        else
+        {
+            mode_is_active = false;
+            return true;
+        }
+    }
+
+    /*\
+    * * default widgets
+    \*/
+
+    [GtkChild] private Button       go_back_button;
+    [GtkChild] private Separator    ltr_left_separator;
+    [GtkChild] private Label        title_label;
+    [GtkChild] private MenuButton   info_button;
+
+    [GtkChild] protected Separator  ltr_right_separator;    // TODO make private
+    [GtkChild] protected Stack      quit_button_stack;
+
+    protected void set_default_widgets_states (bool     show_go_back_button,
+                                               bool     show_ltr_left_separator,
+                                               string?  title_label_text_or_null,
+                                               bool     show_info_button,
+                                               bool     show_ltr_right_separator,
+                                               bool     show_quit_button_stack)
+    {
+        go_back_button.visible = show_go_back_button;
+        ltr_left_separator.visible = show_ltr_left_separator;
+        if (title_label_text_or_null == null)
+        {
+            title_label.set_label ("");
+            title_label.hide ();
+        }
+        else
+        {
+            title_label.set_label ((!) title_label_text_or_null);
+            title_label.show ();
+        }
+        info_button.visible = show_info_button;
+        ltr_right_separator.visible = show_ltr_right_separator;
+        quit_button_stack.visible = show_quit_button_stack;
+    }
+
+    /*\
+    * * default mode
+    \*/
+
+    protected const uint8 default_mode_id = 0;
+    private bool default_mode_on = true;
+
+    internal void show_default_view ()
+    {
+        change_mode (default_mode_id);
+    }
+
+    private void register_default_mode ()
+    {
+        this.change_mode.connect (mode_changed_default);
+    }
+
+    private void mode_changed_default (uint8 requested_mode_id)
+    {
+        if (is_not_requested_mode (default_mode_id, requested_mode_id, ref default_mode_on))
+            return;
+
+        set_default_widgets_states (/* show go_back_button      */ false,
+                                    /* show ltr_left_separator  */ false,
+                                    /* title_label text or null */ null,
+                                    /* show info_button         */ true,
+                                    /* show ltr_right_separator */ disable_action_bar,
+                                    /* show quit_button_stack   */ disable_action_bar);
+    }
+
+    /*\
+    * * about mode
+    \*/
+
+    private uint8 about_mode_id = 0;
+    protected bool about_mode_on = false;   // TODO make private
+
+    internal void show_about_view ()
+        requires (about_mode_id > 0)
+    {
+        change_mode (about_mode_id);
+    }
+
+    private void register_about_mode ()
+    {
+        about_mode_id = register_new_mode ();
+
+        this.change_mode.connect (mode_changed_about);
+    }
+
+    private void mode_changed_about (uint8 requested_mode_id)
+        requires (about_mode_id > 0)
+    {
+        if (is_not_requested_mode (about_mode_id, requested_mode_id, ref about_mode_on))
+            return;
+
+        set_default_widgets_states (/* show go_back_button      */ true,
+                                    /* show ltr_left_separator  */ false,
+                                    /* title_label text or null */ _("About"),
+                                    /* show info_button         */ false,
+                                    /* show ltr_right_separator */ false,
+                                    /* show quit_button_stack   */ true);
+    }
+}
diff --git a/editor/browser-headerbar.vala b/editor/browser-headerbar.vala
index fdc048c..fa82e6b 100644
--- a/editor/browser-headerbar.vala
+++ b/editor/browser-headerbar.vala
@@ -17,51 +17,14 @@
 
 using Gtk;
 
-[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/browser-headerbar.ui")]
-private abstract class BrowserHeaderBar : NightTimeAwareHeaderBar, AdaptativeWidget
+private abstract class BrowserHeaderBar : BaseHeaderBar
 {
-    [GtkChild] protected MenuButton info_button;
-    [GtkChild] protected PathWidget path_widget;
-
-    [GtkChild] protected Box        center_box;
-    [GtkChild] protected Stack      title_stack;
-    [GtkChild] protected Label      title_label;
-
-    [GtkChild] protected Button     go_back_button;
-    [GtkChild] protected Separator  ltr_left_separator;
-    [GtkChild] protected Separator  ltr_right_separator;
-
-    [GtkChild] protected Button     quit_button;
-
     protected ViewType current_type = ViewType.FOLDER;
     protected string current_path = "/";
 
     internal signal void search_changed ();
     internal signal void search_stopped ();
 
-    protected bool disable_popovers = false;
-    protected bool disable_action_bar = false;
-    private void set_window_size (AdaptativeWidget.WindowSize new_size)
-    {
-        bool _disable_popovers = AdaptativeWidget.WindowSize.is_phone_size (new_size)
-                              || AdaptativeWidget.WindowSize.is_extra_thin (new_size);
-        if (disable_popovers != _disable_popovers)
-        {
-            disable_popovers = _disable_popovers;
-            disable_popovers_changed ();
-        }
-
-        disable_action_bar = _disable_popovers
-                          || AdaptativeWidget.WindowSize.is_extra_flat (new_size);
-
-        update_hamburger_menu ();
-        update_modifications_button ();
-
-        path_widget.set_window_size (new_size);
-    }
-    protected virtual void disable_popovers_changed () {}
-    protected abstract void update_modifications_button ();
-
     [CCode (notify = false)] internal bool search_mode_enabled   { get { return 
path_widget.search_mode_enabled; }}
     [CCode (notify = false)] internal bool entry_has_focus       { get { return path_widget.entry_has_focus; 
}}
     [CCode (notify = false)] internal string text                { get { return path_widget.text; }}
@@ -90,134 +53,80 @@ private abstract class BrowserHeaderBar : NightTimeAwareHeaderBar, AdaptativeWid
         return path_widget.handle_event (event);
     }
 
-    construct
-    {
-        center_box.valign = Align.FILL;
-    }
-
     /*\
-    * * in-window about
+    * * path widget
     \*/
 
-    protected bool in_window_about = false;
-
-    protected virtual void close_in_window_panels () {}
-    internal void show_in_window_about ()
-    {
-        close_in_window_panels ();
-
-        in_window_about = true;
-        update_modifications_button ();
-        info_button.hide ();
-        go_back_button.set_action_name ("browser.hide-in-window-about");
-        go_back_button.show ();
-        title_label.set_label (_("About"));
-        title_stack.set_visible_child (title_label);
-    }
+    protected PathWidget path_widget;
 
-    internal void hide_in_window_about ()
-        requires (in_window_about == true)
+    construct
     {
-        go_back_button.hide ();
-        in_window_about = false;
-        title_stack.set_visible_child (path_widget);
-        if (disable_action_bar)
-            ltr_right_separator.show ();
-        info_button.show ();
-        if (path_widget.search_mode_enabled)
-            path_widget.entry_grab_focus_without_selecting ();
-    }
+        add_path_widget ();
 
-    /*\
-    * * hamburger menu
-    \*/
-
-    protected inline void hide_hamburger_menu ()
-    {
-        if (info_button.active)
-            info_button.active = false;
+        this.change_mode.connect (mode_changed_browser);
     }
 
-    protected override void update_hamburger_menu ()
+    private void add_path_widget ()
     {
-        GLib.Menu menu = new GLib.Menu ();
-
-/*        if (current_type == ViewType.OBJECT && !ModelUtils.is_folder_path (current_path))   // TODO a 
better way to copy various representations of a key name/value/path
-        {
-            Variant variant = new Variant.string (model.get_suggested_key_copy_text (current_path, 
browser_view.last_context_id));
-            menu.append (_("Copy descriptor"), "app.copy(" + variant.print (false) + ")");
-        }
-        else if (current_type != ViewType.SEARCH) */
-
-        populate_menu (ref menu);
+        path_widget = new PathWidget ();
+        path_widget.hexpand = false;
 
-        append_app_actions_section (ref menu);
+        path_widget.search_changed.connect (search_changed_cb);
+        path_widget.search_stopped.connect (search_stopped_cb);
 
-        menu.freeze ();
-        info_button.set_menu_model ((MenuModel) menu);
+        path_widget.visible = true;
+        center_box.add (path_widget);
     }
 
-    protected virtual void populate_menu (ref GLib.Menu menu) {}
-
-    private void append_app_actions_section (ref GLib.Menu menu)
+    private void search_changed_cb ()
     {
-        GLib.Menu section = new GLib.Menu ();
-        append_or_not_night_mode_entry (ref section);
-        _append_app_actions_section (!disable_popovers, ref section);
-        section.freeze ();
-        menu.append_section (null, section);
+        search_changed ();
     }
-    private static void _append_app_actions_section (bool has_keyboard_shortcuts, ref GLib.Menu section)
+
+    private void search_stopped_cb ()
     {
-        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");
+        search_stopped ();
     }
 
-    /*\
-    * * proxy callbacks
-    \*/
-
-    [GtkCallback]
-    private void search_changed_cb ()
+    protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
     {
-        search_changed ();
+        base.set_window_size (new_size);
+        path_widget.set_window_size (new_size);
     }
-    [GtkCallback]
-    private void search_stopped_cb ()
+
+    private void mode_changed_browser (uint8 mode_id)
     {
-        search_stopped ();
+        if (mode_id == default_mode_id)
+        {
+            path_widget.show ();
+            if (path_widget.search_mode_enabled)
+                path_widget.entry_grab_focus_without_selecting ();
+        }
+        else
+        {
+            path_widget.hide ();
+        }
     }
 
     /*\
     * *
     \*/
 
-    internal virtual void close_popovers ()
+    internal override void close_popovers ()
     {
         hide_hamburger_menu ();
         path_widget.close_popovers ();
     }
 
-    internal virtual bool has_popover ()
+    internal override bool has_popover ()
     {
-        if (info_button.active)
+        if (base.has_popover ())
             return true;
         if (path_widget.has_popover ())
             return true;
         return false;
     }
 
-    internal virtual bool previous_match ()
-    {
-        return false;
-    }
-
-    internal virtual bool next_match ()
-    {
-        return false;
-    }
-
     internal virtual void set_path (ViewType type, string path)
     {
         current_type = type;
@@ -227,10 +136,4 @@ private abstract class BrowserHeaderBar : NightTimeAwareHeaderBar, AdaptativeWid
 
         update_hamburger_menu ();
     }
-
-    internal virtual void toggle_hamburger_menu ()
-    {
-        if (info_button.visible)
-            info_button.active = !info_button.active;
-    }
 }
diff --git a/editor/browser-window.vala b/editor/browser-window.vala
index d873a49..8dc31c4 100644
--- a/editor/browser-window.vala
+++ b/editor/browser-window.vala
@@ -91,29 +91,29 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
 
     private const GLib.ActionEntry [] browser_action_entries =
     {
-        { "empty",          empty, "*" },
-        { "empty-null",     empty },
-        { "disabled-state", empty, "(sq)", "('',uint16 65535)" },
+        { "empty",              empty, "*" },
+        { "empty-null",         empty },
+        { "disabled-state",     empty, "(sq)", "('',uint16 65535)" },
 
-        { "open-folder", open_folder, "s" },
-        { "open-object", open_object, "(sq)" },
-        { "open-config", open_config, "s" },
-        { "open-search", open_search, "s" },
-        { "next-search", next_search, "s" },
-        { "open-parent", open_parent, "s" },
+        { "open-folder",        open_folder, "s" },
+        { "open-object",        open_object, "(sq)" },
+        { "open-config",        open_config, "s" },
+        { "open-search",        open_search, "s" },
+        { "next-search",        next_search, "s" },
+        { "open-parent",        open_parent, "s" },
 
-        { "open-path", open_path, "(sq)", "('/',uint16 " + ModelUtils.folder_context_id_string + ")" },
+        { "open-path",          open_path, "(sq)", "('/',uint16 " + ModelUtils.folder_context_id_string + 
")" },
 
-        { "reload-folder", reload_folder },
-        { "reload-object", reload_object },
-        { "reload-search", reload_search },
+        { "reload-folder",      reload_folder },
+        { "reload-object",      reload_object },
+        { "reload-search",      reload_search },
 
-        { "hide-search",   hide_search },
-        { "show-search",   show_search },
-        { "toggle-search", toggle_search, "b", "false" },
+        { "hide-search",        hide_search },
+        { "show-search",        show_search },
+        { "toggle-search",      toggle_search, "b", "false" },
 
-        { "hide-in-window-about",           hide_in_window_about },
-        { "about",                          about }
+        { "show-default-panel", show_default_view },
+        { "about",              about }
     };
 
     private void empty (/* SimpleAction action, Variant? variant */) {}
@@ -263,7 +263,7 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
         {
             disable_popovers = _disable_popovers;
             if (in_window_about)
-                hide_in_window_about ();
+                show_default_view ();
         }
 
         chain_set_window_size (new_size);
@@ -356,7 +356,7 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
         hide_notification ();
         headerbar.close_popovers ();
         if (in_window_about)
-            hide_in_window_about ();
+            show_default_view ();
     }
 
     /*\
@@ -748,27 +748,31 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
     private void toggle_in_window_about ()
     {
         if (in_window_about)
-            hide_in_window_about ();
+            show_default_view ();
         else
-            show_in_window_about ();
+            show_about_view ();
     }
 
-    private inline void show_in_window_about ()
+    private inline void show_about_view ()
         requires (in_window_about == false)
     {
         close_in_window_panels ();
 
         in_window_about = true;
-        headerbar.show_in_window_about ();
+        headerbar.show_about_view ();
         browser_view.show_in_window_about ();
     }
 
-    protected void hide_in_window_about (/* SimpleAction action, Variant? path_variant */)
-        requires (in_window_about == true)
+    protected virtual void show_default_view (/* SimpleAction action, Variant? path_variant */)
     {
-        in_window_about = false;
-        headerbar.hide_in_window_about ();
-        browser_view.hide_in_window_about ();
+        if (in_window_about)
+        {
+            in_window_about = false;
+            headerbar.show_default_view ();
+            browser_view.hide_in_window_about ();
+        }
+        else
+            assert_not_reached ();
     }
 
     /*\
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 6264462..31e132b 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/ca/desrt/dconf-editor/ui">
+    <file preprocess="xml-stripblanks">base-headerbar.ui</file>
     <file preprocess="xml-stripblanks">bookmark.ui</file>
     <file preprocess="xml-stripblanks">bookmarks.ui</file>
     <file preprocess="xml-stripblanks">bookmarks-controller.ui</file>
-    <file preprocess="xml-stripblanks">browser-headerbar.ui</file>
     <file preprocess="xml-stripblanks">browser-infobar.ui</file>
     <file preprocess="xml-stripblanks">browser-stack.ui</file>
     <file preprocess="xml-stripblanks">browser-view.ui</file>
diff --git a/editor/dconf-headerbar.vala b/editor/dconf-headerbar.vala
index d904770..cca497b 100644
--- a/editor/dconf-headerbar.vala
+++ b/editor/dconf-headerbar.vala
@@ -44,11 +44,41 @@ private class DConfHeaderBar : BrowserHeaderBar
         add_show_modifications_button ();
         add_modifications_actions_button ();
         construct_modifications_actions_button_menu ();
+
+        register_bookmarks_modes ();
+        register_modifications_mode ();
     }
 
     internal DConfHeaderBar (NightLightMonitor _night_light_monitor)
     {
-        Object (night_light_monitor: _night_light_monitor);
+        Object (night_light_monitor: _night_light_monitor, about_action_label: _("About Dconf Editor"));
+    }
+
+    protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
+    {
+        bool _disable_popovers = disable_popovers;
+
+        base.set_window_size (new_size);
+
+        if (disable_popovers != _disable_popovers)
+            update_bookmarks_button_visibility ();
+        update_modifications_button ();
+    }
+
+    private void update_bookmarks_button_visibility ()
+    {
+        if (disable_popovers || modifications_mode_on)
+        {
+            bookmarks_button.active = false;
+
+            bookmarks_button.sensitive = false;
+            bookmarks_revealer.set_reveal_child (false);
+        }
+        else
+        {
+            bookmarks_button.sensitive = true;
+            bookmarks_revealer.set_reveal_child (true);
+        }
     }
 
     /*\
@@ -99,52 +129,75 @@ private class DConfHeaderBar : BrowserHeaderBar
     }
 
     /*\
-    * * in-window bookmarks
+    * * use-bookmarks mode
     \*/
 
-    bool in_window_bookmarks = false;
+    private uint8 use_bookmarks_mode_id = 0;
+    private bool use_bookmarks_mode_on = false;
 
-    internal void show_in_window_bookmarks ()
+    internal void show_use_bookmarks_view ()
+        requires (use_bookmarks_mode_id > 0)
     {
-        if (in_window_modifications)
-            hide_in_window_modifications ();
-        else if (in_window_about)
-            hide_in_window_about ();
+        change_mode (use_bookmarks_mode_id);
+    }
 
-        in_window_bookmarks = true;
-        update_modifications_button ();
-        info_button.hide ();
-        bookmarks_controller.hide ();
-        ltr_left_separator.hide ();
-        title_label.set_label (_("Bookmarks"));
-        title_stack.show ();
-        title_stack.set_visible_child (title_label);
-        go_back_button.set_action_name ("ui.hide-in-window-bookmarks");
-        go_back_button.show ();
-    }
-
-    internal void hide_in_window_bookmarks ()
-        requires (in_window_bookmarks == true)
-    {
-        bookmarks_controller.hide ();
-        ltr_left_separator.hide ();
-        go_back_button.hide ();
-        in_window_bookmarks = false;
-        title_stack.show ();
-        title_stack.set_visible_child (path_widget);
-        update_modifications_button ();
-        info_button.show ();
-        update_hamburger_menu ();
-        if (path_widget.search_mode_enabled)
-            path_widget.entry_grab_focus_without_selecting ();
+    private void register_bookmarks_modes ()
+    {
+        use_bookmarks_mode_id = register_new_mode ();
+        edit_bookmarks_mode_id = register_new_mode ();
+
+        this.change_mode.connect (mode_changed_bookmarks);
     }
 
-    internal void edit_in_window_bookmarks ()
-        requires (in_window_bookmarks == true)
+    private void mode_changed_bookmarks (uint8 requested_mode_id)
     {
-        ltr_left_separator.show ();
+        mode_changed_use_bookmarks (requested_mode_id);
+        mode_changed_edit_bookmarks (requested_mode_id);
+    }
+
+    private void mode_changed_use_bookmarks (uint8 requested_mode_id)
+        requires (use_bookmarks_mode_id > 0)
+    {
+        if (is_not_requested_mode (use_bookmarks_mode_id, requested_mode_id, ref use_bookmarks_mode_on))
+            return;
+
+        set_default_widgets_states (/* show go_back_button      */ true,
+                                    /* show ltr_left_separator  */ false,
+                                    /* title_label text or null */ _("Bookmarks"),
+                                    /* show info_button         */ false,
+                                    /* show ltr_right_separator */ false,
+                                    /* show quit_button_stack   */ true);
+    }
+
+    /*\
+    * * edit-bookmarks mode
+    \*/
+
+    private uint8 edit_bookmarks_mode_id = 0;
+    private bool edit_bookmarks_mode_on = false;
+
+    internal void show_edit_bookmarks_view ()
+        requires (edit_bookmarks_mode_id > 0)
+    {
+        change_mode (edit_bookmarks_mode_id);
+    }
+
+    private void mode_changed_edit_bookmarks (uint8 requested_mode_id)
+        requires (edit_bookmarks_mode_id > 0)
+    {
+        if (is_not_requested_mode (edit_bookmarks_mode_id, requested_mode_id, ref edit_bookmarks_mode_on))
+        {
+            bookmarks_controller.hide ();
+            return;
+        }
+
+        set_default_widgets_states (/* show go_back_button      */ true,
+                                    /* show ltr_left_separator  */ true,
+                                    /* title_label text or null */ null,
+                                    /* show info_button         */ false,
+                                    /* show ltr_right_separator */ false,
+                                    /* show quit_button_stack   */ true);
         bookmarks_controller.show ();
-        title_stack.hide ();
     }
 
     /*\
@@ -160,9 +213,8 @@ private class DConfHeaderBar : BrowserHeaderBar
         show_modifications_button.action_name = "ui.show-in-window-modifications";
         show_modifications_button.get_style_context ().add_class ("titlebutton");
 
-        show_modifications_button.visible = false;
-        pack_end (show_modifications_button);
-        child_set_property (show_modifications_button, "position", 3);
+        show_modifications_button.visible = true;
+        quit_button_stack.add (show_modifications_button);
     }
 
     /*\
@@ -183,28 +235,6 @@ private class DConfHeaderBar : BrowserHeaderBar
         pack_end (modifications_actions_button);
     }
 
-    /*\
-    * * adaptative stuff
-    \*/
-
-    protected override void disable_popovers_changed ()
-    {
-        if (disable_popovers)
-        {
-            bookmarks_button.active = false;
-
-            bookmarks_button.sensitive = false;
-            bookmarks_revealer.set_reveal_child (false);
-        }
-        else
-        {
-            bookmarks_button.sensitive = true;
-            if (!in_window_modifications)
-                bookmarks_button.show ();
-            bookmarks_revealer.set_reveal_child (true);
-        }
-    }
-
     /*\
     * *
     \*/
@@ -230,11 +260,9 @@ private class DConfHeaderBar : BrowserHeaderBar
 
     internal override bool has_popover ()
     {
-        if (bookmarks_button.active)
+        if (base.has_popover ())
             return true;
-        if (info_button.active)
-            return true;
-        if (path_widget.has_popover ())
+        if (bookmarks_button.active)
             return true;
         return false;
     }
@@ -243,22 +271,16 @@ private class DConfHeaderBar : BrowserHeaderBar
 
     internal override bool next_match ()
     {
-        if (info_button.active)
-            return false;
         if (bookmarks_button.active)
             return bookmarks_button.next_match ();
-        else
-            return false;
+        return false;
     }
 
     internal override bool previous_match ()
     {
-        if (info_button.active)
-            return false;
         if (bookmarks_button.active)
             return bookmarks_button.previous_match ();
-        else
-            return false;
+        return false;
     }
 
     internal override void close_popovers ()
@@ -298,25 +320,27 @@ private class DConfHeaderBar : BrowserHeaderBar
     {
         if (modifications_actions_button.visible)
             modifications_actions_button.active = !modifications_actions_button.active;
-        else if (info_button.visible)
-            info_button.active = !info_button.active;
+        else
+            base.toggle_hamburger_menu ();
     }
 
     protected override void populate_menu (ref GLib.Menu menu)
     {
+        bool bookmarks_mode_on = use_bookmarks_mode_on || edit_bookmarks_mode_on;
+
         if (disable_popovers)
-            append_bookmark_section (current_type, current_path, BookmarksList.get_bookmark_name 
(current_path, current_type) in get_bookmarks (), in_window_bookmarks, ref menu);
+            append_bookmark_section (current_type, current_path, BookmarksList.get_bookmark_name 
(current_path, current_type) in get_bookmarks (), bookmarks_mode_on, ref menu);
 
-        if (!in_window_bookmarks)
+        if (!bookmarks_mode_on)
             append_or_not_delay_mode_section (delay_mode, current_type == ViewType.FOLDER, current_path, ref 
menu);
     }
 
-    private static void append_bookmark_section (ViewType current_type, string current_path, bool 
is_in_bookmarks, bool in_window_bookmarks, ref GLib.Menu menu)
+    private static void append_bookmark_section (ViewType current_type, string current_path, bool 
is_in_bookmarks, bool bookmarks_mode_on, ref GLib.Menu menu)
     {
         GLib.Menu section = new GLib.Menu ();
 
-        if (in_window_bookmarks)
-            section.append (_("Hide bookmarks"), "ui.hide-in-window-bookmarks");    // button hidden in 
current design
+        if (bookmarks_mode_on)
+            section.append (_("Hide bookmarks"), "ui.empty");    // button hidden in current design
         else
         {
             if (is_in_bookmarks)
@@ -351,7 +375,47 @@ private class DConfHeaderBar : BrowserHeaderBar
     * * in-window modifications
     \*/
 
-    bool in_window_modifications = false;
+    private uint8 modifications_mode_id = 0;
+    private bool modifications_mode_on = false;
+
+    internal void show_modifications_view ()
+        requires (modifications_mode_id > 0)
+    {
+        change_mode (modifications_mode_id);
+    }
+
+    private void register_modifications_mode ()
+    {
+        modifications_mode_id = register_new_mode ();
+
+        this.change_mode.connect (mode_changed_modifications);
+    }
+
+    private void mode_changed_modifications (uint8 requested_mode_id)
+    {
+        if (is_not_requested_mode (modifications_mode_id, requested_mode_id, ref modifications_mode_on))
+        {
+            modifications_actions_button.hide ();
+            bookmarks_revealer.show ();
+            update_bookmarks_button_visibility ();
+            // if (path_widget.search_mode_enabled)
+            //    path_widget.entry_grab_focus_without_selecting ();
+            return;
+        }
+
+        set_default_widgets_states (/* show go_back_button      */ true,
+                                    /* show ltr_left_separator  */ false,
+                                    /* title_label text or null */ _("Pending"),
+                                    /* show info_button         */ false,
+                                    /* show ltr_right_separator */ false,
+                                    /* show quit_button_stack   */ false);
+        if (disable_action_bar && !disable_popovers)
+        {
+            bookmarks_button.sensitive = false;
+            bookmarks_revealer.hide ();
+        }
+        modifications_actions_button.show ();
+    }
 
     GLib.Menu changes_pending_menu;
     GLib.Menu quit_delayed_mode_menu;
@@ -369,39 +433,25 @@ private class DConfHeaderBar : BrowserHeaderBar
         modifications_actions_button.set_menu_model (changes_pending_menu);
     }
 
-    protected override void close_in_window_panels ()
-    {
-        if (in_window_bookmarks)
-            hide_in_window_bookmarks ();
-        else if (in_window_modifications)
-            hide_in_window_modifications ();
-    }
-
-    protected override void update_modifications_button ()
+    private void update_modifications_button ()
     {
         if (disable_action_bar)
         {
             set_show_close_button (false);
-            if (in_window_modifications)
+            if (modifications_mode_on)
             {
-                quit_button.hide ();
-                show_modifications_button.hide ();
                 ltr_right_separator.hide ();
+                quit_button_stack.hide ();
             }
             else
             {
+                quit_button_stack.show ();
                 if (delay_mode)
-                {
-                    quit_button.hide ();
-                    show_modifications_button.show ();
-                }
+                    quit_button_stack.set_visible_child (show_modifications_button);
                 else
-                {
-                    show_modifications_button.hide ();
-                    quit_button.show ();
-                }
+                    quit_button_stack.set_visible_child_name ("quit-button");
 
-                if (in_window_bookmarks || in_window_about)
+                if (use_bookmarks_mode_on || edit_bookmarks_mode_on || about_mode_on)
                     ltr_right_separator.hide ();
                 else
                     ltr_right_separator.show ();
@@ -409,54 +459,12 @@ private class DConfHeaderBar : BrowserHeaderBar
         }
         else
         {
-            if (in_window_modifications)
-                hide_in_window_modifications ();
-            quit_button.hide ();
-            show_modifications_button.hide ();
+            quit_button_stack.hide ();
             ltr_right_separator.hide ();
             set_show_close_button (true);
         }
     }
 
-    internal void show_in_window_modifications ()
-    {
-        if (in_window_bookmarks)
-            hide_in_window_bookmarks ();
-        else if (in_window_about)
-            hide_in_window_about ();
-
-        in_window_modifications = true;
-        info_button.hide ();
-        ltr_right_separator.hide ();
-        show_modifications_button.hide ();
-        if (disable_action_bar && !disable_popovers)
-            bookmarks_button.hide ();
-        modifications_actions_button.show ();
-        go_back_button.set_action_name ("ui.hide-in-window-modifications");
-        go_back_button.show ();
-        title_label.set_label (_("Pending"));
-        title_stack.set_visible_child (title_label);
-    }
-
-    internal void hide_in_window_modifications ()
-        requires (in_window_modifications == true)
-    {
-        go_back_button.hide ();
-        modifications_actions_button.hide ();
-        if (disable_action_bar)
-        {
-            show_modifications_button.show ();
-            ltr_right_separator.show ();
-        }
-        if (!disable_popovers)
-            bookmarks_button.show ();
-        in_window_modifications = false;
-        title_stack.set_visible_child (path_widget);
-        info_button.show ();
-        if (path_widget.search_mode_enabled)
-            path_widget.entry_grab_focus_without_selecting ();
-    }
-
     internal void set_apply_modifications_button_sensitive (bool new_value)
     {
         if (new_value)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 58a5b6b..516df8f 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -419,11 +419,9 @@ private class DConfWindow : BrowserWindow
         { "dismiss-change", dismiss_change, "s" },  // here because needs to be accessed from 
DelayedSettingView rows
         { "erase", erase_dconf_key, "s" },          // here because needs a reload_view as we enter 
delay_mode
 
-        { "show-in-window-bookmarks",       show_in_window_bookmarks },
-        { "hide-in-window-bookmarks",       hide_in_window_bookmarks },
+        { "show-in-window-bookmarks",       show_use_bookmarks_view },
 
-        { "show-in-window-modifications",   show_in_window_modifications },
-        { "hide-in-window-modifications",   hide_in_window_modifications },
+        { "show-in-window-modifications",   show_modifications_view },
 
         { "update-bookmarks-icons", update_bookmarks_icons, "as" },
 
@@ -458,7 +456,7 @@ private class DConfWindow : BrowserWindow
     private void apply_delayed_settings (/* SimpleAction action, Variant? path_variant */)
     {
         if (browser_view.in_window_modifications)
-            hide_in_window_modifications ();
+            show_default_view ();
         modifications_handler.apply_delayed_settings ();
         invalidate_popovers_with_ui_reload ();
     }
@@ -466,7 +464,7 @@ private class DConfWindow : BrowserWindow
     private void dismiss_delayed_settings (/* SimpleAction action, Variant? path_variant */)
     {
         if (browser_view.in_window_modifications)
-            hide_in_window_modifications ();
+            show_default_view ();
         modifications_handler.dismiss_delayed_settings ();
         invalidate_popovers_with_ui_reload ();
     }
@@ -498,46 +496,44 @@ private class DConfWindow : BrowserWindow
     * * showing or hiding panels
     \*/
 
-    private void show_in_window_bookmarks (/* SimpleAction action, Variant? path_variant */)
+    protected override void show_default_view ()
     {
-        if (browser_view.in_window_modifications == true)
-            hide_in_window_modifications ();
-        else if (in_window_about)
-            hide_in_window_about ();
+        if (browser_view.in_window_bookmarks)
+        {
+            if (browser_view.in_window_bookmarks_edit_mode)
+                leave_edit_mode ();     // TODO place after
+            headerbar.show_default_view ();
+            browser_view.hide_in_window_bookmarks ();
+        }
+        else if (browser_view.in_window_modifications)
+        {
+            headerbar.show_default_view ();
+            browser_view.hide_in_window_modifications ();
+        }
+        else
+            base.show_default_view ();
+    }
+
+    private void show_use_bookmarks_view (/* SimpleAction action, Variant? path_variant */)
+    {
+        if (browser_view.in_window_modifications || in_window_about)
+            show_default_view ();
 
-        headerbar.show_in_window_bookmarks ();
+        headerbar.show_use_bookmarks_view ();
         string [] bookmarks = headerbar.get_bookmarks ();
         browser_view.show_in_window_bookmarks (bookmarks);
         update_bookmarks_icons_from_array (bookmarks);
     }
 
-    private void hide_in_window_bookmarks (/* SimpleAction action, Variant? path_variant */)
-        requires (browser_view.in_window_bookmarks == true)
+    private void show_modifications_view (/* SimpleAction action, Variant? path_variant */)
     {
-        if (browser_view.in_window_bookmarks_edit_mode)
-            leave_edit_mode ();     // TODO place after
-        headerbar.hide_in_window_bookmarks ();
-        browser_view.hide_in_window_bookmarks ();
-    }
+        if (browser_view.in_window_bookmarks || in_window_about)
+            show_default_view ();
 
-    private void show_in_window_modifications (/* SimpleAction action, Variant? path_variant */)
-    {
-        if (browser_view.in_window_bookmarks == true)
-            hide_in_window_bookmarks ();
-        else if (in_window_about)
-            hide_in_window_about ();
-
-        headerbar.show_in_window_modifications ();
+        headerbar.show_modifications_view ();
         browser_view.show_in_window_modifications ();
     }
 
-    private void hide_in_window_modifications (/* SimpleAction action, Variant? path_variant */)
-        requires (browser_view.in_window_modifications == true)
-    {
-        headerbar.hide_in_window_modifications ();
-        browser_view.hide_in_window_modifications ();
-    }
-
     /*\
     * * updating bookmarks icons
     \*/
@@ -622,7 +618,7 @@ private class DConfWindow : BrowserWindow
         {
             disable_popovers = _disable_popovers;
             if (browser_view.in_window_bookmarks)
-                hide_in_window_bookmarks ();
+                show_default_view ();
         }
 
         bool _disable_action_bar = _disable_popovers
@@ -631,7 +627,7 @@ private class DConfWindow : BrowserWindow
         {
             disable_action_bar = _disable_action_bar;
             if (browser_view.in_window_modifications)
-                hide_in_window_modifications ();
+                show_default_view ();
         }
     }
 
@@ -698,7 +694,7 @@ private class DConfWindow : BrowserWindow
 
         update_actions ();
 
-        headerbar.edit_in_window_bookmarks ();
+        headerbar.show_edit_bookmarks_view ();
         browser_view.enter_bookmarks_edit_mode ();
     }
 
@@ -707,7 +703,7 @@ private class DConfWindow : BrowserWindow
         edit_mode_state_action.set_state (false);
 
         bool give_focus_to_info_button = browser_view.leave_bookmarks_edit_mode ();
-        headerbar.show_in_window_bookmarks ();
+        headerbar.show_use_bookmarks_view ();
 
 /*        if (give_focus_to_info_button)
             info_button.grab_focus (); */
@@ -775,13 +771,13 @@ private class DConfWindow : BrowserWindow
          && !AdaptativeWidget.WindowSize.is_extra_thin (window_size))
         {
             if (browser_view.in_window_modifications)
-                hide_in_window_modifications ();
+                show_default_view ();
             headerbar.click_bookmarks_button ();
         }
         else if (browser_view.in_window_bookmarks)
-            hide_in_window_bookmarks ();
+            show_default_view ();
         else
-            show_in_window_bookmarks ();
+            show_use_bookmarks_view ();
     }
 
     private void bookmark                               (/* SimpleAction action, Variant? variant */)
@@ -811,9 +807,9 @@ private class DConfWindow : BrowserWindow
          && !AdaptativeWidget.WindowSize.is_extra_flat (window_size))
             revealer.toggle_modifications_list ();
         else if (browser_view.in_window_modifications)
-            hide_in_window_modifications ();
+            show_default_view ();
         else
-            show_in_window_modifications ();
+            show_modifications_view ();
     }
 
     private void escape_pressed                         (/* SimpleAction action, Variant? variant */)
@@ -823,12 +819,10 @@ private class DConfWindow : BrowserWindow
             if (browser_view.in_window_bookmarks_edit_mode)
                 leave_edit_mode ();
             else
-                hide_in_window_bookmarks ();
+                show_default_view ();
         }
-        else if (browser_view.in_window_modifications)
-            hide_in_window_modifications ();
-        else if (in_window_about)
-            hide_in_window_about ();
+        else if (browser_view.in_window_modifications || in_window_about)
+            show_default_view ();
         else if (headerbar.search_mode_enabled)
             stop_search ();
         else if (current_type == ViewType.CONFIG)
@@ -907,12 +901,8 @@ private class DConfWindow : BrowserWindow
         hide_notification ();
         headerbar.close_popovers ();
         revealer.hide_modifications_list ();
-        if (browser_view.in_window_bookmarks)
-            hide_in_window_bookmarks ();
-        else if (browser_view.in_window_modifications)
-            hide_in_window_modifications ();
-        else if (in_window_about)
-            hide_in_window_about ();
+        if (browser_view.in_window_bookmarks || browser_view.in_window_modifications || in_window_about)
+            show_default_view ();
     }
 
     public static bool is_path_invalid (string path)
diff --git a/editor/meson.build b/editor/meson.build
index e483105..d48ff5a 100644
--- a/editor/meson.build
+++ b/editor/meson.build
@@ -69,6 +69,7 @@ sources = files(
   'about-list.vala',
   'adaptative-pathbar.vala',
   'adaptative-window.vala',
+  'base-headerbar.vala',
   'bookmarks.vala',
   'bookmarks-controller.vala',
   'bookmarks-list.vala',
@@ -106,10 +107,10 @@ sources = files(
 )
 
 resource_data = files(
+  'base-headerbar.ui',
   'bookmarks.ui',
   'bookmarks-controller.ui',
   'bookmark.ui',
-  'browser-headerbar.ui',
   'browser-infobar.ui',
   'browser-stack.ui',
   'browser-view.ui',


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