[dconf-editor] Allow bookmarks control on small screens.



commit 1cd14e2367624e6808468a94eb2b29702f1ec9e8
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Nov 12 08:36:48 2018 +0100

    Allow bookmarks control on small screens.

 editor/bookmarks-controller.ui   |  17 ++---
 editor/bookmarks-controller.vala |  18 +++++
 editor/bookmarks-list.ui         |   8 +--
 editor/bookmarks-list.vala       |  27 ++++++--
 editor/bookmarks.ui              |   9 +--
 editor/browser-headerbar.ui      |   8 +++
 editor/browser-headerbar.vala    |  14 +++-
 editor/browser-view.ui           |   4 +-
 editor/browser-view.vala         |  52 +++++++++++++++
 editor/dconf-editor.ui           |   1 +
 editor/dconf-window.vala         | 139 +++++++++++++++++++++++++++++++++++++++
 11 files changed, 266 insertions(+), 31 deletions(-)
---
diff --git a/editor/bookmarks-controller.ui b/editor/bookmarks-controller.ui
index 4f073c9..7bb9501 100644
--- a/editor/bookmarks-controller.ui
+++ b/editor/bookmarks-controller.ui
@@ -17,10 +17,9 @@
     <property name="orientation">horizontal</property>
     <property name="column-spacing">6</property>
     <child>
-      <object class="GtkButton">
+      <object class="GtkButton" id="trash_bookmark_button">
         <property name="visible">True</property>
         <property name="halign">start</property>
-        <property name="action-name">bookmarks.trash-bookmark</property>
         <style>
           <class name="image-button"/>
         </style>
@@ -41,9 +40,8 @@
           <class name="linked"/>
         </style>
         <child>
-          <object class="GtkButton">
+          <object class="GtkButton" id="move_top_button">
             <property name="visible">True</property>
-            <property name="action-name">bookmarks.move-top</property>
             <style>
               <class name="image-button"/>
             </style>
@@ -57,9 +55,8 @@
           </object>
         </child>
         <child>
-          <object class="GtkButton">
+          <object class="GtkButton" id="move_up_button">
             <property name="visible">True</property>
-            <property name="action-name">bookmarks.move-up</property>
             <style>
               <class name="image-button"/>
             </style>
@@ -73,9 +70,8 @@
           </object>
         </child>
         <child>
-          <object class="GtkButton">
+          <object class="GtkButton" id="move_down_button">
             <property name="visible">True</property>
-            <property name="action-name">bookmarks.move-down</property>
             <style>
               <class name="image-button"/>
             </style>
@@ -89,9 +85,8 @@
           </object>
         </child>
         <child>
-          <object class="GtkButton">
+          <object class="GtkButton" id="move_bottom_button">
             <property name="visible">True</property>
-            <property name="action-name">bookmarks.move-bottom</property>
             <style>
               <class name="image-button"/>
             </style>
@@ -110,7 +105,7 @@
       <object class="GtkButton" id="rows_size_button">
         <property name="hexpand">True</property>
         <property name="halign">end</property>
-        <property name="action-name">bookmarks.set-small-rows</property>
+        <property name="action-name">bookmarks.set-small-rows</property> <!-- only used from popover, so 
keep this action -->
         <style>
           <class name="image-button"/>
         </style>
diff --git a/editor/bookmarks-controller.vala b/editor/bookmarks-controller.vala
index eff0200..eeed446 100644
--- a/editor/bookmarks-controller.vala
+++ b/editor/bookmarks-controller.vala
@@ -26,6 +26,24 @@ private class BookmarksController : Grid
     [GtkChild] private Button rows_size_button;
     public bool show_rows_size_button { private get; construct; default = false; }
 
+    [GtkChild] private Button trash_bookmark_button;
+    [GtkChild] private Button move_top_button;
+    [GtkChild] private Button move_up_button;
+    [GtkChild] private Button move_down_button;
+    [GtkChild] private Button move_bottom_button;
+    public string controller_action_prefix
+    {
+        construct
+        {
+            // TODO sanitize "value"
+            trash_bookmark_button.set_detailed_action_name (value + ".trash-bookmark");
+            move_top_button.set_detailed_action_name (value + ".move-top");
+            move_up_button.set_detailed_action_name (value + ".move-up");
+            move_down_button.set_detailed_action_name (value + ".move-down");
+            move_bottom_button.set_detailed_action_name (value + ".move-bottom");
+        }
+    }
+
     construct
     {
         if (show_rows_size_button)      // TODO construct instead of hiding
diff --git a/editor/bookmarks-list.ui b/editor/bookmarks-list.ui
index 62c2318..a901981 100644
--- a/editor/bookmarks-list.ui
+++ b/editor/bookmarks-list.ui
@@ -44,14 +44,12 @@
           <class name="linked-circular"/>
         </style>
         <child>
-          <object class="GtkModelButton">
+          <object class="GtkModelButton" id="leave_edit_mode_button">
             <property name="visible">True</property>
             <property name="hexpand">True</property>
             <property name="centered">True</property>
             <property name="iconic">True</property>
             <property name="focus-on-click">False</property>
-            <property name="action-name">bookmarks.set-edit-mode</property>
-            <property name="action-target">false</property>
             <property name="text" translatable="yes">Use</property>
             <style>
               <class name="left-on-ltr"/>
@@ -59,14 +57,12 @@
           </object>
         </child>
         <child>
-          <object class="GtkModelButton">
+          <object class="GtkModelButton" id="enter_edit_mode_button">
             <property name="visible">True</property>
             <property name="hexpand">True</property>
             <property name="centered">True</property>
             <property name="iconic">True</property>
             <property name="focus-on-click">False</property>
-            <property name="action-name">bookmarks.set-edit-mode</property>
-            <property name="action-target">true</property>
             <property name="text" translatable="yes">Edit</property>
             <style>
               <class name="right-on-ltr"/>
diff --git a/editor/bookmarks-list.vala b/editor/bookmarks-list.vala
index aa5044e..5cfca6c 100644
--- a/editor/bookmarks-list.vala
+++ b/editor/bookmarks-list.vala
@@ -24,7 +24,17 @@ private class BookmarksList : Overlay
     [GtkChild] private ListBox          bookmarks_list_box;
     [GtkChild] private Box              edit_mode_box;
 
-    public bool allow_edit      { private get; internal construct; }
+    [GtkChild] private ModelButton enter_edit_mode_button;
+    [GtkChild] private ModelButton leave_edit_mode_button;
+    public string edit_mode_action_prefix
+    {
+        construct
+        {
+            // TODO sanitize "value"
+            enter_edit_mode_button.set_detailed_action_name (value + ".set-edit-mode(true)");
+            leave_edit_mode_button.set_detailed_action_name (value + ".set-edit-mode(false)");
+        }
+    }
 
     [GtkChild] private RegistryPlaceholder placeholder;
     public bool big_placeholder { internal construct { placeholder.big = value; }}
@@ -44,10 +54,14 @@ private class BookmarksList : Overlay
             settings = new GLib.Settings.with_path (schema_id, value);
 
             bookmarks_changed_handler = settings.changed ["bookmarks"].connect (on_bookmarks_changed);
-            create_bookmark_rows (settings.get_value ("bookmarks"));
-
             ulong bookmarks_writable_handler = settings.writable_changed ["bookmarks"].connect 
(on_writability_changed);
 
+            Variant bookmarks_variant = settings.get_value ("bookmarks");
+            bool is_writable = settings.is_writable ("bookmarks");
+
+            create_bookmark_rows (bookmarks_variant);
+            edit_mode_box.set_visible (is_writable && !has_empty_list_class);
+
             bookmarks_changed (settings.get_value ("bookmarks"), settings.is_writable ("bookmarks"));
 
             destroy.connect (() => {
@@ -68,7 +82,9 @@ private class BookmarksList : Overlay
     internal signal void writability_changed (bool writable);
     private void on_writability_changed (GLib.Settings _settings, string key)
     {
-        writability_changed (_settings.is_writable (key));
+        bool is_writable = _settings.is_writable (key);
+        writability_changed (is_writable);
+        edit_mode_box.set_visible (is_writable);
     }
 
     internal signal void selection_changed ();
@@ -485,9 +501,6 @@ private class BookmarksList : Overlay
     [GtkCallback]
     private void on_content_changed ()
     {
-        if (!allow_edit)
-            return;
-
         List<weak Widget> widgets = bookmarks_list_box.get_children ();
         if (widgets.length () == 0)
             edit_mode_box.hide ();
diff --git a/editor/bookmarks.ui b/editor/bookmarks.ui
index 020e6bd..661b6f9 100644
--- a/editor/bookmarks.ui
+++ b/editor/bookmarks.ui
@@ -64,6 +64,7 @@
               <object class="BookmarksController" id="bookmarks_controller">
                 <property name="visible">True</property>
                 <property name="show-rows-size-button">True</property>
+                <property name="controller-action-prefix">bookmarks</property>
               </object>
               <packing>
                 <property name="name">edit-mode-on</property>
@@ -87,11 +88,11 @@
         <child>
           <object class="BookmarksList" id="bookmarks_list">
             <property name="visible">True</property>
-            <property name="allow-edit">True</property>
             <property name="big-placeholder">False</property>
-            <signal name="writability-changed" handler="on_writability_changed"/>
-            <signal name="bookmarks-changed"   handler="on_bookmarks_changed"/>
-            <signal name="selection-changed"   handler="on_selection_changed"/>
+            <property name="edit-mode-action-prefix">bookmarks</property>
+            <signal name="writability-changed"    handler="on_writability_changed"/>
+            <signal name="bookmarks-changed"      handler="on_bookmarks_changed"/>
+            <signal name="selection-changed"      handler="on_selection_changed"/>
             <signal name="update_bookmarks_icons" handler="on_update_bookmarks_icons"/>
           </object>
         </child>
diff --git a/editor/browser-headerbar.ui b/editor/browser-headerbar.ui
index e68752c..2119f74 100644
--- a/editor/browser-headerbar.ui
+++ b/editor/browser-headerbar.ui
@@ -29,6 +29,14 @@
                 <property name="label" translatable="yes">Bookmarks</property>
               </object>
             </child>
+            <child>
+              <object class="BookmarksController" id="bookmarks_controller">
+                <property name="visible">True</property>
+                <property name="hexpand">False</property>
+                <property name="show-rows-size-button">False</property>
+                <property name="controller-action-prefix">bmk</property>
+              </object>
+            </child>
           </object>
         </child>
         <child>
diff --git a/editor/browser-headerbar.vala b/editor/browser-headerbar.vala
index 0d62871..3ae9f5c 100644
--- a/editor/browser-headerbar.vala
+++ b/editor/browser-headerbar.vala
@@ -155,14 +155,16 @@ private class BrowserHeaderBar : HeaderBar, AdaptativeWidget
     * * in-window bookmarks
     \*/
 
-    [GtkChild] private Stack bookmarks_stack;
-    [GtkChild] private Label bookmarks_label;
+    [GtkChild] private Stack                bookmarks_stack;
+    [GtkChild] private Label                bookmarks_label;
+    [GtkChild] private BookmarksController  bookmarks_controller;
 
     bool in_window_bookmarks = false;
 
     internal void show_in_window_bookmarks ()
     {
         in_window_bookmarks = true;
+        bookmarks_stack.hexpand = false;    // hack 1/3
         bookmarks_stack.set_visible_child (bookmarks_label);
         update_hamburger_menu ();
     }
@@ -170,10 +172,18 @@ private class BrowserHeaderBar : HeaderBar, AdaptativeWidget
     internal void hide_in_window_bookmarks ()
     {
         in_window_bookmarks = false;
+        bookmarks_stack.hexpand = false;    // hack 2/3
         bookmarks_stack.set_visible_child (path_widget);
         update_hamburger_menu ();
     }
 
+    internal void edit_in_window_bookmarks ()
+        requires (in_window_bookmarks == true)
+    {
+        bookmarks_stack.hexpand = true;     // hack 3/3
+        bookmarks_stack.set_visible_child (bookmarks_controller);
+    }
+
     /*\
     * * action entries
     \*/
diff --git a/editor/browser-view.ui b/editor/browser-view.ui
index e1ee41e..200d4d5 100644
--- a/editor/browser-view.ui
+++ b/editor/browser-view.ui
@@ -23,8 +23,10 @@
     <child>
       <object class="BookmarksList" id="bookmarks_list">
         <property name="visible">True</property>
-        <property name="allow-edit">False</property>
         <property name="big-placeholder">True</property>
+        <property name="edit-mode-action-prefix">bmk</property>
+        <property name="schema-path">/ca/desrt/dconf-editor/</property>
+        <signal name="selection-changed" handler="on_selection_changed"/>
       </object>
     </child>
   </template>
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 10088c4..6faf679 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -233,6 +233,58 @@ private class BrowserView : Stack, AdaptativeWidget
         set_visible_child (current_child_grid);
     }
 
+    internal void enter_bookmarks_edit_mode ()
+        requires (in_window_bookmarks == true)
+    {
+        bookmarks_list.enter_edit_mode ();
+    }
+
+    internal bool leave_bookmarks_edit_mode ()
+        requires (in_window_bookmarks == true)
+    {
+        return bookmarks_list.leave_edit_mode ();
+    }
+
+    internal BookmarksList.SelectionState get_bookmarks_selection_state ()
+    {
+        return bookmarks_list.get_selection_state ();
+    }
+
+    internal void trash_bookmark ()
+    {
+        bookmarks_list.trash_bookmark ();
+    }
+
+    internal void move_top ()
+    {
+        bookmarks_list.move_top ();
+    }
+
+    internal void move_up ()
+    {
+        bookmarks_list.move_up ();
+    }
+
+    internal void move_down ()
+    {
+        bookmarks_list.move_down ();
+    }
+
+    internal void move_bottom ()
+    {
+        bookmarks_list.move_bottom ();
+    }
+
+    [GtkCallback]
+    private void on_selection_changed ()
+    {
+        if (!in_window_bookmarks)
+            return;
+        bookmarks_selection_changed ();
+    }
+
+    internal signal void bookmarks_selection_changed ();
+
     /*\
     * * Views
     \*/
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index 7821b4f..576f1f0 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -33,6 +33,7 @@
               <object class="BrowserView" id="browser_view">
                 <property name="visible">True</property>
                 <property name="vexpand">True</property>
+                <signal name="bookmarks-selection-changed" handler="on_bookmarks_selection_changed"/>
               </object>
             </child>
             <child>
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index dafcfe3..35a0bf4 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -136,6 +136,7 @@ private class DConfWindow : ApplicationWindow
 
         install_ui_action_entries ();
         install_kbd_action_entries ();
+        install_bmk_action_entries ();
 
         headerbar.update_bookmarks_icons.connect (update_bookmarks_icons_from_variant);
 
@@ -871,6 +872,144 @@ private class DConfWindow : ApplicationWindow
         notification_revealer.set_reveal_child (false);
     }
 
+    /*\
+    * * bookmarks action entries
+    \*/
+
+    bool actions_init_done = false;
+    private SimpleAction move_top_action;
+    private SimpleAction move_up_action;
+    private SimpleAction move_down_action;
+    private SimpleAction move_bottom_action;
+    private SimpleAction trash_bookmark_action;
+    private SimpleAction edit_mode_state_action;
+
+    private void update_actions ()
+        requires (actions_init_done)
+    {
+        BookmarksList.SelectionState selection_state = browser_view.get_bookmarks_selection_state ();
+
+        bool has_selected_items = selection_state != BookmarksList.SelectionState.EMPTY;
+        bool has_one_selected_item = has_selected_items && (selection_state != 
BookmarksList.SelectionState.MULTIPLE);
+
+        bool enable_move_top_action     = has_one_selected_item;    // TODO has_selected_items;
+        bool enable_move_up_action      = has_one_selected_item;
+        bool enable_move_down_action    = has_one_selected_item;
+        bool enable_move_bottom_action  = has_one_selected_item;    // TODO has_selected_items;
+
+        if (has_one_selected_item)
+        {
+            if (selection_state == BookmarksList.SelectionState.UNIQUE || selection_state == 
BookmarksList.SelectionState.FIRST)
+            {
+                enable_move_top_action = false;
+                enable_move_up_action = false;
+            }
+            if (selection_state == BookmarksList.SelectionState.UNIQUE || selection_state == 
BookmarksList.SelectionState.LAST)
+            {
+                enable_move_down_action = false;
+                enable_move_bottom_action = false;
+            }
+        }
+
+               move_up_action.set_enabled (enable_move_up_action);
+              move_top_action.set_enabled (enable_move_top_action);
+             move_down_action.set_enabled (enable_move_down_action);
+           move_bottom_action.set_enabled (enable_move_bottom_action);
+        trash_bookmark_action.set_enabled (has_selected_items);
+    }
+
+    private void install_bmk_action_entries ()
+    {
+        SimpleActionGroup action_group = new SimpleActionGroup ();
+        action_group.add_action_entries (bmk_action_entries, this);
+        insert_action_group ("bmk", action_group);
+
+        move_top_action         = (SimpleAction) action_group.lookup_action ("move-top");
+        move_up_action          = (SimpleAction) action_group.lookup_action ("move-up");
+        move_down_action        = (SimpleAction) action_group.lookup_action ("move-down");
+        move_bottom_action      = (SimpleAction) action_group.lookup_action ("move-bottom");
+        trash_bookmark_action   = (SimpleAction) action_group.lookup_action ("trash-bookmark");
+        edit_mode_state_action  = (SimpleAction) action_group.lookup_action ("set-edit-mode");
+        actions_init_done = true;
+    }
+
+    private const GLib.ActionEntry [] bmk_action_entries =
+    {
+        { "set-edit-mode", set_edit_mode, "b", "false" },
+
+        { "trash-bookmark", trash_bookmark },
+
+        { "move-top",    move_top    },
+        { "move-up",     move_up     },
+        { "move-down",   move_down   },
+        { "move-bottom", move_bottom }
+    };
+
+    private void set_edit_mode (SimpleAction action, Variant? variant)
+        requires (variant != null)
+    {
+        bool new_state = ((!) variant).get_boolean ();
+        action.set_state (new_state);
+
+        if (new_state)
+            enter_edit_mode ();
+        else
+            leave_edit_mode ();
+    }
+
+    private void enter_edit_mode ()
+    {
+        edit_mode_state_action.set_state (true);
+
+        update_actions ();
+
+        headerbar.edit_in_window_bookmarks ();
+        browser_view.enter_bookmarks_edit_mode ();
+    }
+
+    private void leave_edit_mode ()
+    {
+        edit_mode_state_action.set_state (false);
+
+        bool give_focus_to_info_button = browser_view.leave_bookmarks_edit_mode ();
+        headerbar.show_in_window_bookmarks ();
+
+/*        if (give_focus_to_info_button)
+            info_button.grab_focus (); */
+    }
+
+    private void trash_bookmark (/* SimpleAction action, Variant? variant */)
+    {
+        browser_view.trash_bookmark ();
+//        update_bookmarks_icons_from_array (new_bookmarks);
+    }
+
+    private void move_top       (/* SimpleAction action, Variant? variant */)
+    {
+        browser_view.move_top ();
+    }
+
+    private void move_up        (/* SimpleAction action, Variant? variant */)
+    {
+        browser_view.move_up ();
+    }
+
+    private void move_down      (/* SimpleAction action, Variant? variant */)
+    {
+        browser_view.move_down ();
+    }
+
+    private void move_bottom    (/* SimpleAction action, Variant? variant */)
+    {
+        browser_view.move_bottom ();
+    }
+
+    [GtkCallback]
+    private void on_bookmarks_selection_changed ()
+    {
+        update_actions ();
+    }
+
     /*\
     * * Keyboad action entries
     \*/


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