[dconf-editor] Introduce DConfHeaderBar.



commit b5caf36b5bb974e01afd767204681c29648848d9
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Dec 7 12:46:09 2018 +0100

    Introduce DConfHeaderBar.

 editor/bookmarks-controller.vala |   5 +
 editor/bookmarks.vala            |   5 +
 editor/browser-headerbar.ui      | 104 +--------
 editor/browser-headerbar.vala    | 435 ++++++----------------------------
 editor/browser-window.vala       |   4 +-
 editor/dconf-headerbar.vala      | 489 +++++++++++++++++++++++++++++++++++++++
 editor/dconf-window.vala         |   7 +-
 editor/meson.build               |   1 +
 8 files changed, 577 insertions(+), 473 deletions(-)
---
diff --git a/editor/bookmarks-controller.vala b/editor/bookmarks-controller.vala
index eeed446..b818bad 100644
--- a/editor/bookmarks-controller.vala
+++ b/editor/bookmarks-controller.vala
@@ -52,6 +52,11 @@ private class BookmarksController : Grid
             rows_size_button.hide ();
     }
 
+    internal BookmarksController (string _controller_action_prefix, bool _show_rows_size_button)
+    {
+        Object (controller_action_prefix: _controller_action_prefix, show_rows_size_button: 
_show_rows_size_button);
+    }
+
     internal void update_rows_size_button_icon (bool small_bookmarks_rows)
     {
         if (small_bookmarks_rows)
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index d32861d..97f820f 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -91,6 +91,11 @@ private class Bookmarks : MenuButton
         clicked.connect (() => { if (active) bookmarked_switch.grab_focus (); });
     }
 
+    internal Bookmarks (string _schema_path)
+    {
+        Object (schema_path: _schema_path);
+    }
+
     [GtkCallback]
     private void on_bookmarks_changed (Variant bookmarks_variant, bool writable)
     {
diff --git a/editor/browser-headerbar.ui b/editor/browser-headerbar.ui
index b8bcbe1..fb8532c 100644
--- a/editor/browser-headerbar.ui
+++ b/editor/browser-headerbar.ui
@@ -25,44 +25,12 @@
         <property name="visible">False</property>
       </object>
     </child>
-    <!-- child>
-      <object class="GtkButton" id="apply_modifications_button">
-        <property name="visible">False</property>
-        <property name="action-name">ui.apply-modifications</property>
-        <style>
-          <class name="image-button"/>
-          <class name="suggested-action"/>
-        </style>
-        <child>
-          <object class="GtkImage">
-            <property name="visible">True</property>
-            <property name="icon-name">object-select-symbolic</property>
-            <property name="icon-size">1</property>
-          </object>
-        </child>
-      </object>
-    </child -->
-    <!-- child>
-      <object class="GtkButton" id="dismiss_modification_button">
-        <property name="visible">False</property>
-        <property name="action-name">ui.dismiss-modifications</property>
-        <style>
-          <class name="image-button"/>
-        </style>
-        <child>
-          <object class="GtkImage">
-            <property name="visible">True</property>
-            <property name="icon-name">list-remove-symbolic</property>
-            <property name="icon-size">1</property>
-          </object>
-        </child>
-      </object>
-    </child -->
     <child type="title">
       <object class="GtkBox" id="center_box">
         <property name="visible">True</property>
         <property name="valign">fill</property>
         <property name="spacing">6</property>
+        <property name="hexpand">False</property> <!-- or "hexpand-set">true... that's horrible -->
         <style>
           <class name="centerwidget"/>
         </style>
@@ -70,6 +38,7 @@
           <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>
@@ -83,36 +52,6 @@
                 <property name="visible">True</property>
               </object>
             </child>
-            <child>
-              <object class="BookmarksController" id="bookmarks_controller">
-                <property name="visible">True</property>
-                <property name="hexpand">True</property>
-                <property name="show-rows-size-button">False</property>
-                <property name="controller-action-prefix">bmk</property>
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkRevealer" id="bookmarks_revealer">
-            <property name="visible">True</property>
-            <property name="transition-type">slide-left</property>
-            <property name="reveal-child">True</property>
-            <style>
-              <class name="headerbar-revealer"/>
-            </style>
-            <child>
-              <object class="Bookmarks" id="bookmarks_button">
-                <property name="visible">True</property>
-                <property name="valign">center</property>
-                <property name="focus-on-click">False</property>
-                <property name="schema-path">/ca/desrt/dconf-editor/</property>
-                <signal name="update-bookmarks-icons" handler="update_bookmarks_icons_cb"/>
-                <style>
-                  <class name="image-button"/> <!-- TODO https://bugzilla.gnome.org/show_bug.cgi?id=756731 
-->
-                </style>
-              </object>
-            </child>
           </object>
         </child>
       </object>
@@ -137,26 +76,6 @@
         <property name="pack-type">end</property>
       </packing>
     </child>
-    <child>
-      <object class="GtkButton" id="show_modifications_button">
-        <property name="visible">False</property>
-        <property name="valign">center</property>
-        <property name="action-name">ui.show-in-window-modifications</property>
-        <style>
-          <class name="titlebutton"/>
-        </style>
-        <child>
-          <object class="GtkImage">
-            <property name="visible">True</property>
-            <property name="icon-name">document-open-recent-symbolic</property>
-            <property name="icon-size">1</property>
-          </object>
-        </child>
-      </object>
-      <packing>
-        <property name="pack-type">end</property>
-      </packing>
-    </child>
     <child>
       <object class="GtkSeparator" id="ltr_right_separator">
         <property name="visible">False</property>
@@ -169,25 +88,6 @@
         <property name="pack-type">end</property>
       </packing>
     </child>
-    <child>
-      <object class="GtkMenuButton" id="modifications_actions_button">
-        <property name="visible">False</property>
-        <property name="valign">center</property>
-        <style>
-          <class name="image-button"/>
-        </style>
-        <child>
-          <object class="GtkImage">
-            <property name="visible">True</property>
-            <property name="icon-name">view-more-symbolic</property>
-            <property name="icon-size">1</property>
-          </object>
-        </child>
-      </object>
-      <packing>
-        <property name="pack-type">end</property>
-      </packing>
-    </child>
     <child>
       <object class="GtkMenuButton" id="info_button">
         <property name="visible">True</property>
diff --git a/editor/browser-headerbar.vala b/editor/browser-headerbar.vala
index b131fba..e4f3918 100644
--- a/editor/browser-headerbar.vala
+++ b/editor/browser-headerbar.vala
@@ -18,45 +18,29 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/browser-headerbar.ui")]
-private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
+private abstract class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
 {
-    [GtkChild] private MenuButton   info_button;
-    [GtkChild] private PathWidget   path_widget;
+    [GtkChild] protected MenuButton info_button;
+    [GtkChild] protected PathWidget path_widget;
 
-    [GtkChild] private Revealer     bookmarks_revealer;
-    [GtkChild] private Bookmarks    bookmarks_button;
+    [GtkChild] protected Box        center_box;
+    [GtkChild] protected Stack      title_stack;
+    [GtkChild] protected Label      title_label;
 
-    [GtkChild] private Box          center_box;
-    [GtkChild] private Stack        title_stack;
-    [GtkChild] private Label        title_label;
+    [GtkChild] protected Button     go_back_button;
+    [GtkChild] protected Separator  ltr_left_separator;
+    [GtkChild] protected Separator  ltr_right_separator;
 
-    [GtkChild] private Button       go_back_button;
-    [GtkChild] private Separator    ltr_left_separator;
-    [GtkChild] private Separator    ltr_right_separator;
+    [GtkChild] protected Button     quit_button;
 
-    private ViewType current_type = ViewType.FOLDER;
-    private string current_path = "/";
-
-    private bool _delay_mode = false;
-    internal bool delay_mode
-    {
-        private  get { return _delay_mode; }
-        internal set
-        {
-            if (_delay_mode == value)
-                return;
-            _delay_mode = value;
-            update_modifications_button ();
-            update_hamburger_menu ();
-        }
-    }
+    protected ViewType current_type = ViewType.FOLDER;
+    protected string current_path = "/";
 
     internal signal void search_changed ();
     internal signal void search_stopped ();
-    internal signal void update_bookmarks_icons (Variant bookmarks_variant);
 
-    private bool disable_popovers = false;
-    private bool disable_action_bar = false;
+    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)
@@ -64,20 +48,7 @@ private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
         if (disable_popovers != _disable_popovers)
         {
             disable_popovers = _disable_popovers;
-            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);
-            }
+            disable_popovers_changed ();
         }
 
         disable_action_bar = _disable_popovers
@@ -88,6 +59,8 @@ private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
 
         path_widget.set_window_size (new_size);
     }
+    protected virtual void disable_popovers_changed () {}
+    protected abstract void update_modifications_button ();
 
     internal bool search_mode_enabled   { get { return path_widget.search_mode_enabled; }}
     internal bool entry_has_focus       { get { return path_widget.entry_has_focus; }}
@@ -99,9 +72,7 @@ private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
         path_widget.get_fallback_path_and_complete_path (out fallback_path, out complete_path);
     }
     internal void toggle_pathbar_menu ()    { path_widget.toggle_pathbar_menu (); }
-    internal string [] get_bookmarks ()     { return bookmarks_button.get_bookmarks (); }
 
-    internal void update_bookmark_icon (string bookmark, BookmarkIcon icon) { 
bookmarks_button.update_bookmark_icon (bookmark, icon); }
     internal void update_ghosts (string fallback_path)                      { path_widget.update_ghosts 
(fallback_path); }
     internal void prepare_search (PathEntry.SearchMode mode, string? search){ path_widget.prepare_search 
(mode, search); }
     internal string get_selected_child (string fallback_path)               { return 
path_widget.get_selected_child (fallback_path); }
@@ -114,101 +85,26 @@ private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
             path_widget.entry_grab_focus_without_selecting ();
     }
 
-    internal void set_path (ViewType type, string path)
-    {
-        current_type = type;
-        current_path = path;
-
-        path_widget.set_path (type, path);
-        bookmarks_button.set_path (type, path);
-
-        update_hamburger_menu ();
-    }
-
-    internal bool has_popover ()
-    {
-        if (bookmarks_button.active)
-            return true;
-        if (info_button.active)
-            return true;
-        if (path_widget.has_popover ())
-            return true;
-        return false;
-    }
-
     internal bool handle_event (Gdk.EventKey event)
     {
         return path_widget.handle_event (event);
     }
 
-    internal bool next_match ()
-    {
-        if (info_button.active)
-            return false;
-        if (bookmarks_button.active)
-            return bookmarks_button.next_match ();
-        else
-            return false;
-    }
-
-    internal bool previous_match ()
-    {
-        if (info_button.active)
-            return false;
-        if (bookmarks_button.active)
-            return bookmarks_button.previous_match ();
-        else
-            return false;
-    }
-
-    internal void close_popovers ()
-    {
-        hide_hamburger_menu ();
-        if (bookmarks_button.active)
-            bookmarks_button.active = false;
-        path_widget.close_popovers ();
-    }
-
-    internal void click_bookmarks_button ()
-    {
-        hide_hamburger_menu ();
-        if (bookmarks_button.sensitive)
-            bookmarks_button.clicked ();
-    }
-
-    internal void bookmark_current_path ()
-    {
-        hide_hamburger_menu ();
-        bookmarks_button.bookmark_current_path ();
-        update_hamburger_menu ();
-    }
-
-    internal void unbookmark_current_path ()
-    {
-        hide_hamburger_menu ();
-        bookmarks_button.unbookmark_current_path ();
-        update_hamburger_menu ();
-    }
-
     construct
     {
         center_box.valign = Align.FILL;
-        install_action_entries ();
-        construct_modifications_actions_button_menu ();
     }
 
     /*\
     * * in-window about
     \*/
 
-    bool in_window_about = false;
+    protected bool in_window_about = false;
 
+    protected virtual void close_in_window_panels () {}
     internal void show_in_window_about ()
     {
-        if (in_window_bookmarks)
-            hide_in_window_bookmarks ();
-        else if (in_window_modifications)
-            hide_in_window_modifications ();
+        close_in_window_panels ();
 
         in_window_about = true;
         update_modifications_button ();
@@ -232,211 +128,16 @@ private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
             path_widget.entry_grab_focus_without_selecting ();
     }
 
-    /*\
-    * * in-window modifications
-    \*/
-
-    [GtkChild] private Button       show_modifications_button;
-    [GtkChild] private Button       quit_button;
-    [GtkChild] private MenuButton   modifications_actions_button;
-
-    bool in_window_modifications = false;
-
-    GLib.Menu changes_pending_menu;
-    GLib.Menu quit_delayed_mode_menu;
-    private void construct_modifications_actions_button_menu ()
-    {
-        changes_pending_menu = new GLib.Menu ();
-        changes_pending_menu.append (_("Apply all"), "ui.apply-delayed-settings");
-        changes_pending_menu.append (_("Dismiss all"), "ui.dismiss-delayed-settings");
-        changes_pending_menu.freeze ();
-
-        quit_delayed_mode_menu = new GLib.Menu ();
-        quit_delayed_mode_menu.append (_("Quit mode"), "ui.dismiss-delayed-settings");
-        quit_delayed_mode_menu.freeze ();
-
-        modifications_actions_button.set_menu_model (changes_pending_menu);
-    }
-
-    private void update_modifications_button ()
-    {
-        if (disable_action_bar)
-        {
-            set_show_close_button (false);
-            if (in_window_modifications)
-            {
-                quit_button.hide ();
-                show_modifications_button.hide ();
-                ltr_right_separator.hide ();
-            }
-            else
-            {
-                if (delay_mode)
-                {
-                    quit_button.hide ();
-                    show_modifications_button.show ();
-                }
-                else
-                {
-                    show_modifications_button.hide ();
-                    quit_button.show ();
-                }
-
-                if (in_window_bookmarks || in_window_about)
-                    ltr_right_separator.hide ();
-                else
-                    ltr_right_separator.show ();
-            }
-        }
-        else
-        {
-            if (in_window_modifications)
-                hide_in_window_modifications ();
-            quit_button.hide ();
-            show_modifications_button.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)
-            modifications_actions_button.set_menu_model (changes_pending_menu);
-        else
-            modifications_actions_button.set_menu_model (quit_delayed_mode_menu);
-    }
-
-    /*\
-    * * in-window bookmarks
-    \*/
-
-    [GtkChild] private BookmarksController  bookmarks_controller;
-
-    bool in_window_bookmarks = false;
-
-    internal void show_in_window_bookmarks ()
-    {
-        if (in_window_modifications)
-            hide_in_window_modifications ();
-        else if (in_window_about)
-            hide_in_window_about ();
-
-        in_window_bookmarks = true;
-        update_modifications_button ();
-        info_button.hide ();
-        ltr_left_separator.hide ();
-        title_label.set_label (_("Bookmarks"));
-        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)
-    {
-        go_back_button.hide ();
-        ltr_left_separator.hide ();
-        in_window_bookmarks = false;
-        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 ();
-    }
-
-    internal void edit_in_window_bookmarks ()
-        requires (in_window_bookmarks == true)
-    {
-        ltr_left_separator.show ();
-        title_stack.set_visible_child (bookmarks_controller);
-    }
-
-    /*\
-    * * action entries
-    \*/
-
-    private void install_action_entries ()
-    {
-        SimpleActionGroup action_group = new SimpleActionGroup ();
-        action_group.add_action_entries (action_entries, this);
-        insert_action_group ("headerbar", action_group);
-    }
-
-    private const GLib.ActionEntry [] action_entries =
-    {
-        {   "bookmark-current",   bookmark_current },
-        { "unbookmark-current", unbookmark_current }
-    };
-
-    private void bookmark_current (/* SimpleAction action, Variant? variant */)
-    {
-        bookmark_current_path ();
-    }
-
-    private void unbookmark_current (/* SimpleAction action, Variant? variant */)
-    {
-        unbookmark_current_path ();
-    }
-
     /*\
     * * hamburger menu
     \*/
 
-    private inline void hide_hamburger_menu ()
+    protected inline void hide_hamburger_menu ()
     {
         if (info_button.active)
             info_button.active = false;
     }
 
-    internal void toggle_hamburger_menu ()
-    {
-        if (modifications_actions_button.visible)
-            modifications_actions_button.active = !modifications_actions_button.active;
-        else if (info_button.visible)
-            info_button.active = !info_button.active;
-    }
-
     protected override void update_hamburger_menu ()
     {
         GLib.Menu menu = new GLib.Menu ();
@@ -448,11 +149,7 @@ private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
         }
         else if (current_type != ViewType.SEARCH) */
 
-        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);
-
-        if (!in_window_bookmarks)
-            append_or_not_delay_mode_section (delay_mode, current_type == ViewType.FOLDER, current_path, ref 
menu);
+        populate_menu (ref menu);
 
         append_app_actions_section (ref menu);
 
@@ -460,42 +157,7 @@ private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
         info_button.set_menu_model ((MenuModel) 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)
-    {
-        GLib.Menu section = new GLib.Menu ();
-
-        if (in_window_bookmarks)
-            section.append (_("Hide bookmarks"), "ui.hide-in-window-bookmarks");    // button hidden in 
current design
-        else
-        {
-            if (is_in_bookmarks)
-                section.append (_("Unbookmark"), "headerbar.unbookmark-current");
-            else
-                section.append (_("Bookmark"), "headerbar.bookmark-current");
-
-            section.append (_("Show bookmarks"), "ui.show-in-window-bookmarks");
-        }
-        section.freeze ();
-        menu.append_section (null, section);
-    }
-
-    private static void append_or_not_delay_mode_section (bool delay_mode, bool is_folder_view, string 
current_path, ref GLib.Menu menu)
-    {
-        if (delay_mode && !is_folder_view)
-            return;
-
-        GLib.Menu section = new GLib.Menu ();
-        if (!delay_mode)
-            section.append (_("Enter delay mode"), "ui.enter-delay-mode");
-        if (is_folder_view)
-        {
-            Variant variant = new Variant.string (current_path);
-            section.append (_("Reset visible keys"), "ui.reset-visible(" + variant.print (false) + ")");
-            section.append (_("Reset view recursively"), "ui.reset-recursive(" + variant.print (false) + 
")");
-        }
-        section.freeze ();
-        menu.append_section (null, section);
-    }
+    protected virtual void populate_menu (ref GLib.Menu menu) {}
 
     private void append_app_actions_section (ref GLib.Menu menu)
     {
@@ -516,12 +178,6 @@ private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
     * * proxy callbacks
     \*/
 
-    [GtkCallback]
-    private void update_bookmarks_icons_cb (Variant bookmarks_variant)
-    {
-        update_bookmarks_icons (bookmarks_variant);
-    }
-
     [GtkCallback]
     private void search_changed_cb ()
     {
@@ -532,4 +188,49 @@ private class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
     {
         search_stopped ();
     }
+
+    /*\
+    * *
+    \*/
+
+    internal virtual void close_popovers ()
+    {
+        hide_hamburger_menu ();
+        path_widget.close_popovers ();
+    }
+
+    internal virtual bool has_popover ()
+    {
+        if (info_button.active)
+            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;
+        current_path = path;
+
+        path_widget.set_path (type, path);
+
+        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 92b6c22..1fbe01c 100644
--- a/editor/browser-window.vala
+++ b/editor/browser-window.vala
@@ -29,7 +29,7 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
     protected string    saved_selection = "";
 
     [GtkChild] protected Grid main_grid;
-               protected BrowserHeaderBar headerbar;
+               private   BrowserHeaderBar headerbar;
                protected BrowserView      browser_view;
 
     construct
@@ -299,7 +299,7 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
         if (reload)
         {
             reload_search_action.set_enabled (false);
-            browser_view.set_search_parameters (saved_view, headerbar.get_bookmarks ());
+            browser_view.set_search_parameters (saved_view, ((DConfHeaderBar) headerbar).get_bookmarks ());
             reload_search_next = false;
         }
         if (mode != PathEntry.SearchMode.UNCLEAR)
diff --git a/editor/dconf-headerbar.vala b/editor/dconf-headerbar.vala
new file mode 100644
index 0000000..d05a81c
--- /dev/null
+++ b/editor/dconf-headerbar.vala
@@ -0,0 +1,489 @@
+/*
+  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;
+
+private class DConfHeaderBar : BrowserHeaderBar
+{
+    private Bookmarks bookmarks_button;
+
+    private bool _delay_mode = false;
+    internal bool delay_mode
+    {
+        private  get { return _delay_mode; }
+        internal set
+        {
+            if (_delay_mode == value)
+                return;
+            _delay_mode = value;
+            update_modifications_button ();
+            update_hamburger_menu ();
+        }
+    }
+
+    construct
+    {
+        install_action_entries ();
+
+        add_bookmarks_revealer ();
+        add_bookmarks_controller ();
+        add_show_modifications_button ();
+        add_modifications_actions_button ();
+        construct_modifications_actions_button_menu ();
+    }
+
+    /*\
+    * * bookmarks revealer
+    \*/
+
+    internal signal void update_bookmarks_icons (Variant bookmarks_variant);
+
+    private Revealer bookmarks_revealer;
+
+    private void add_bookmarks_revealer ()
+    {
+        bookmarks_revealer = new Revealer ();
+        bookmarks_revealer.transition_type = RevealerTransitionType.SLIDE_LEFT;
+        bookmarks_revealer.reveal_child = true;
+        bookmarks_revealer.get_style_context ().add_class ("headerbar-revealer");
+
+        bookmarks_button = new Bookmarks ("/ca/desrt/dconf-editor/");
+        bookmarks_button.valign = Align.CENTER;
+        bookmarks_button.focus_on_click = false;
+        bookmarks_button.update_bookmarks_icons.connect (update_bookmarks_icons_cb);
+        bookmarks_button.get_style_context ().add_class ("image-button");   // TODO check 
https://bugzilla.gnome.org/show_bug.cgi?id=756731
+
+        bookmarks_button.visible = true;
+        bookmarks_revealer.add (bookmarks_button);
+        bookmarks_revealer.visible = true;
+        center_box.pack_end (bookmarks_revealer);
+    }
+
+    private void update_bookmarks_icons_cb (Variant bookmarks_variant)
+    {
+        update_bookmarks_icons (bookmarks_variant);
+    }
+
+    /*\
+    * * bookmarks stack
+    \*/
+
+    private BookmarksController bookmarks_controller;
+
+    private void add_bookmarks_controller ()
+    {
+        bookmarks_controller = new BookmarksController ("bmk", false);
+        bookmarks_controller.hexpand = true;
+
+        bookmarks_controller.visible = false;
+        pack_start (bookmarks_controller);
+    }
+
+    /*\
+    * * in-window bookmarks
+    \*/
+
+    bool in_window_bookmarks = false;
+
+    internal void show_in_window_bookmarks ()
+    {
+        if (in_window_modifications)
+            hide_in_window_modifications ();
+        else if (in_window_about)
+            hide_in_window_about ();
+
+        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 ();
+    }
+
+    internal void edit_in_window_bookmarks ()
+        requires (in_window_bookmarks == true)
+    {
+        ltr_left_separator.show ();
+        bookmarks_controller.show ();
+        title_stack.hide ();
+    }
+
+    /*\
+    * * show-modifications button
+    \*/
+
+    private Button show_modifications_button;
+
+    private void add_show_modifications_button ()
+    {
+        show_modifications_button = new Button.from_icon_name ("document-open-recent-symbolic");
+        show_modifications_button.valign = Align.CENTER;
+        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);
+    }
+
+    /*\
+    * *
+    \*/
+
+    private MenuButton modifications_actions_button;
+
+    private void add_modifications_actions_button ()
+    {
+        modifications_actions_button = new MenuButton ();
+        Image view_more_image = new Image.from_icon_name ("view-more-symbolic", IconSize.BUTTON);
+        modifications_actions_button.set_image (view_more_image);
+        modifications_actions_button.valign = Align.CENTER;
+        modifications_actions_button.get_style_context ().add_class ("image-button");
+
+        modifications_actions_button.visible = false;
+        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);
+        }
+    }
+
+    /*\
+    * *
+    \*/
+
+    internal string [] get_bookmarks ()     { return bookmarks_button.get_bookmarks (); }
+
+    internal void update_bookmark_icon (string bookmark, BookmarkIcon icon) { 
bookmarks_button.update_bookmark_icon (bookmark, icon); }
+
+    /*\
+    * * should move back
+    \*/
+
+    internal override void set_path (ViewType type, string path)
+    {
+        current_type = type;
+        current_path = path;
+
+        path_widget.set_path (type, path);
+        bookmarks_button.set_path (type, path);
+
+        update_hamburger_menu ();
+    }
+
+    internal override bool has_popover ()
+    {
+        if (bookmarks_button.active)
+            return true;
+        if (info_button.active)
+            return true;
+        if (path_widget.has_popover ())
+            return true;
+        return false;
+    }
+
+
+
+    internal override bool next_match ()
+    {
+        if (info_button.active)
+            return false;
+        if (bookmarks_button.active)
+            return bookmarks_button.next_match ();
+        else
+            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;
+    }
+
+    internal override void close_popovers ()
+    {
+        hide_hamburger_menu ();
+        if (bookmarks_button.active)
+            bookmarks_button.active = false;
+        path_widget.close_popovers ();
+    }
+
+    internal void click_bookmarks_button ()
+    {
+        hide_hamburger_menu ();
+        if (bookmarks_button.sensitive)
+            bookmarks_button.clicked ();
+    }
+
+    internal void bookmark_current_path ()
+    {
+        hide_hamburger_menu ();
+        bookmarks_button.bookmark_current_path ();
+        update_hamburger_menu ();
+    }
+
+    internal void unbookmark_current_path ()
+    {
+        hide_hamburger_menu ();
+        bookmarks_button.unbookmark_current_path ();
+        update_hamburger_menu ();
+    }
+
+    /*\
+    * * hamburger menu
+    \*/
+
+    internal override void toggle_hamburger_menu ()
+    {
+        if (modifications_actions_button.visible)
+            modifications_actions_button.active = !modifications_actions_button.active;
+        else if (info_button.visible)
+            info_button.active = !info_button.active;
+    }
+
+    protected override void populate_menu (ref GLib.Menu menu)
+    {
+        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);
+
+        if (!in_window_bookmarks)
+            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)
+    {
+        GLib.Menu section = new GLib.Menu ();
+
+        if (in_window_bookmarks)
+            section.append (_("Hide bookmarks"), "ui.hide-in-window-bookmarks");    // button hidden in 
current design
+        else
+        {
+            if (is_in_bookmarks)
+                section.append (_("Unbookmark"), "headerbar.unbookmark-current");
+            else
+                section.append (_("Bookmark"), "headerbar.bookmark-current");
+
+            section.append (_("Show bookmarks"), "ui.show-in-window-bookmarks");
+        }
+        section.freeze ();
+        menu.append_section (null, section);
+    }
+
+    private static void append_or_not_delay_mode_section (bool delay_mode, bool is_folder_view, string 
current_path, ref GLib.Menu menu)
+    {
+        if (delay_mode && !is_folder_view)
+            return;
+
+        GLib.Menu section = new GLib.Menu ();
+        if (!delay_mode)
+            section.append (_("Enter delay mode"), "ui.enter-delay-mode");
+        if (is_folder_view)
+        {
+            Variant variant = new Variant.string (current_path);
+            section.append (_("Reset visible keys"), "ui.reset-visible(" + variant.print (false) + ")");
+            section.append (_("Reset view recursively"), "ui.reset-recursive(" + variant.print (false) + 
")");
+        }
+        section.freeze ();
+        menu.append_section (null, section);
+    }
+    /*\
+    * * in-window modifications
+    \*/
+
+    bool in_window_modifications = false;
+
+    GLib.Menu changes_pending_menu;
+    GLib.Menu quit_delayed_mode_menu;
+    private void construct_modifications_actions_button_menu ()
+    {
+        changes_pending_menu = new GLib.Menu ();
+        changes_pending_menu.append (_("Apply all"), "ui.apply-delayed-settings");
+        changes_pending_menu.append (_("Dismiss all"), "ui.dismiss-delayed-settings");
+        changes_pending_menu.freeze ();
+
+        quit_delayed_mode_menu = new GLib.Menu ();
+        quit_delayed_mode_menu.append (_("Quit mode"), "ui.dismiss-delayed-settings");
+        quit_delayed_mode_menu.freeze ();
+
+        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 ()
+    {
+        if (disable_action_bar)
+        {
+            set_show_close_button (false);
+            if (in_window_modifications)
+            {
+                quit_button.hide ();
+                show_modifications_button.hide ();
+                ltr_right_separator.hide ();
+            }
+            else
+            {
+                if (delay_mode)
+                {
+                    quit_button.hide ();
+                    show_modifications_button.show ();
+                }
+                else
+                {
+                    show_modifications_button.hide ();
+                    quit_button.show ();
+                }
+
+                if (in_window_bookmarks || in_window_about)
+                    ltr_right_separator.hide ();
+                else
+                    ltr_right_separator.show ();
+            }
+        }
+        else
+        {
+            if (in_window_modifications)
+                hide_in_window_modifications ();
+            quit_button.hide ();
+            show_modifications_button.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)
+            modifications_actions_button.set_menu_model (changes_pending_menu);
+        else
+            modifications_actions_button.set_menu_model (quit_delayed_mode_menu);
+    }
+
+    /*\
+    * * action entries
+    \*/
+
+    private void install_action_entries ()
+    {
+        SimpleActionGroup action_group = new SimpleActionGroup ();
+        action_group.add_action_entries (action_entries, this);
+        insert_action_group ("headerbar", action_group);
+    }
+
+    private const GLib.ActionEntry [] action_entries =
+    {
+        {   "bookmark-current",   bookmark_current },
+        { "unbookmark-current", unbookmark_current }
+    };
+
+    private void bookmark_current (/* SimpleAction action, Variant? variant */)
+    {
+        bookmark_current_path ();
+    }
+
+    private void unbookmark_current (/* SimpleAction action, Variant? variant */)
+    {
+        unbookmark_current_path ();
+    }
+}
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 85ea6e0..5ea5120 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -101,6 +101,8 @@ private class DConfWindow : BrowserWindow
     private ulong delayed_changes_changed_handler = 0;
     private ulong bookmarks_selection_changed_handler = 0;
 
+    private DConfHeaderBar headerbar;
+
     private StyleContext context;
     construct
     {
@@ -119,8 +121,9 @@ 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)
     {
-        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);
+        DConfHeaderBar _headerbar = new DConfHeaderBar ();
+        Object (initial_night_time: night_time, initial_dark_theme: dark_theme, 
initial_automatic_night_mode: automatic_night_mode, adaptative_headerbar: (AdaptativeHeaderBar) _headerbar);
+        headerbar = _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);
diff --git a/editor/meson.build b/editor/meson.build
index 77de73d..e483105 100644
--- a/editor/meson.build
+++ b/editor/meson.build
@@ -78,6 +78,7 @@ sources = files(
   'browser-view.vala',
   'browser-window.vala',
   'dconf-editor.vala',
+  'dconf-headerbar.vala',
   'dconf-model.vala',
   'dconf-view.vala',
   'dconf-window.vala',



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