[dconf-editor] Introduce BookmarksController.



commit 1b8459c423249c7232a21361ef87772526e4001a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Oct 21 05:47:03 2018 +0200

    Introduce BookmarksController.

 editor/bookmarks-controller.ui    | 120 ++++++++++++++++++++++++++
 editor/bookmarks-controller.vala  |  49 +++++++++++
 editor/bookmarks.ui               | 171 ++++++++------------------------------
 editor/bookmarks.vala             |  60 ++++++-------
 editor/dconf-editor.css           |  31 +++----
 editor/dconf-editor.gresource.xml |   1 +
 editor/meson.build                |   2 +
 7 files changed, 254 insertions(+), 180 deletions(-)
---
diff --git a/editor/bookmarks-controller.ui b/editor/bookmarks-controller.ui
new file mode 100644
index 0000000..4f073c9
--- /dev/null
+++ b/editor/bookmarks-controller.ui
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="dconf-editor">
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkImage" id="big_rows_icon">
+    <property name="visible">True</property>
+    <property name="icon-name">ca.desrt.dconf-editor.big-rows-symbolic</property>
+    <property name="icon-size">1</property>
+  </object>
+  <object class="GtkImage" id="small_rows_icon">
+    <property name="visible">True</property>
+    <property name="icon-name">ca.desrt.dconf-editor.small-rows-symbolic</property>
+    <property name="icon-size">1</property>
+  </object>
+  <template class="BookmarksController" parent="GtkGrid">
+    <property name="hexpand">True</property>
+    <property name="valign">center</property>
+    <property name="orientation">horizontal</property>
+    <property name="column-spacing">6</property>
+    <child>
+      <object class="GtkButton">
+        <property name="visible">True</property>
+        <property name="halign">start</property>
+        <property name="action-name">bookmarks.trash-bookmark</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="icon-name">user-trash-symbolic</property>
+            <property name="icon-size">1</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="halign">start</property>
+        <style>
+          <class name="linked"/>
+        </style>
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <property name="action-name">bookmarks.move-top</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">go-top-symbolic</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <property name="action-name">bookmarks.move-up</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">go-up-symbolic</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <property name="action-name">bookmarks.move-down</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">go-down-symbolic</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <property name="action-name">bookmarks.move-bottom</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">go-bottom-symbolic</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <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>
+        <style>
+          <class name="image-button"/>
+        </style>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/editor/bookmarks-controller.vala b/editor/bookmarks-controller.vala
new file mode 100644
index 0000000..eff0200
--- /dev/null
+++ b/editor/bookmarks-controller.vala
@@ -0,0 +1,49 @@
+/*
+  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/bookmarks-controller.ui")]
+private class BookmarksController : Grid
+{
+    [GtkChild] private Image big_rows_icon;
+    [GtkChild] private Image small_rows_icon;
+
+    [GtkChild] private Button rows_size_button;
+    public bool show_rows_size_button { private get; construct; default = false; }
+
+    construct
+    {
+        if (show_rows_size_button)      // TODO construct instead of hiding
+            rows_size_button.show ();
+        else
+            rows_size_button.hide ();
+    }
+
+    internal void update_rows_size_button_icon (bool small_bookmarks_rows)
+    {
+        if (small_bookmarks_rows)
+            rows_size_button.set_image (big_rows_icon);
+        else
+            rows_size_button.set_image (small_rows_icon);
+    }
+
+    internal bool get_small_rows_state ()
+    {
+        return rows_size_button.get_image () == small_rows_icon;
+    }
+}
diff --git a/editor/bookmarks.ui b/editor/bookmarks.ui
index bab9f8e..48dd100 100644
--- a/editor/bookmarks.ui
+++ b/editor/bookmarks.ui
@@ -61,137 +61,9 @@
               </packing>
             </child>
             <child>
-              <object class="GtkGrid">
+              <object class="BookmarksController" id="bookmarks_controller">
                 <property name="visible">True</property>
-                <property name="hexpand">True</property>
-                <property name="valign">center</property>
-                <property name="orientation">horizontal</property>
-                <property name="column-spacing">3</property>
-                <child>
-                  <object class="GtkButton" id="leave_edit_mode_button">
-                    <property name="visible">True</property>
-                    <property name="action-name">bookmarks.leave-edit-mode</property>
-                    <style>
-                      <class name="image-button"/>
-                      <class name="flat"/>
-                    </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="GtkSeparator">
-                    <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkButton" id="rows_size_button">
-                    <property name="visible">True</property>
-                    <property name="hexpand">True</property>
-                    <property name="halign">start</property>
-                    <property name="action-name">bookmarks.set-small-rows</property>
-                    <style>
-                      <class name="image-button"/>
-                    </style>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
-                    <property name="halign">end</property>
-                    <property name="margin-end">3</property> <!-- grid has already 3 as column spacing -->
-                    <style>
-                      <class name="linked"/>
-                    </style>
-                    <child>
-                      <object class="GtkButton">
-                        <property name="visible">True</property>
-                        <property name="action-name">bookmarks.move-top</property>
-                        <style>
-                          <class name="image-button"/>
-                        </style>
-                        <child>
-                          <object class="GtkImage">
-                            <property name="visible">True</property>
-                            <property name="icon-name">go-top-symbolic</property>
-                            <property name="icon-size">1</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkButton">
-                        <property name="visible">True</property>
-                        <property name="action-name">bookmarks.move-up</property>
-                        <style>
-                          <class name="image-button"/>
-                        </style>
-                        <child>
-                          <object class="GtkImage">
-                            <property name="visible">True</property>
-                            <property name="icon-name">go-up-symbolic</property>
-                            <property name="icon-size">1</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkButton">
-                        <property name="visible">True</property>
-                        <property name="action-name">bookmarks.move-down</property>
-                        <style>
-                          <class name="image-button"/>
-                        </style>
-                        <child>
-                          <object class="GtkImage">
-                            <property name="visible">True</property>
-                            <property name="icon-name">go-down-symbolic</property>
-                            <property name="icon-size">1</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkButton">
-                        <property name="visible">True</property>
-                        <property name="action-name">bookmarks.move-bottom</property>
-                        <style>
-                          <class name="image-button"/>
-                        </style>
-                        <child>
-                          <object class="GtkImage">
-                            <property name="visible">True</property>
-                            <property name="icon-name">go-bottom-symbolic</property>
-                            <property name="icon-size">1</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkButton">
-                    <property name="visible">True</property>
-                    <property name="halign">end</property>
-                    <property name="action-name">bookmarks.trash-bookmark</property>
-                    <style>
-                      <class name="image-button"/>
-                    </style>
-                    <child>
-                      <object class="GtkImage">
-                        <property name="visible">True</property>
-                        <property name="icon-name">user-trash-symbolic</property>
-                        <property name="icon-size">1</property>
-                      </object>
-                    </child>
-                  </object>
-                </child>
+                <property name="show-rows-size-button">True</property>
               </object>
               <packing>
                 <property name="name">edit-mode-on</property>
@@ -246,17 +118,45 @@
               </object>
             </child>
             <child type="overlay">
-              <object class="GtkButton" id="enter_edit_mode_button">
+              <object class="GtkBox" id="edit_mode_box">
                 <property name="visible">True</property>
                 <property name="halign">center</property>
                 <property name="valign">end</property>
                 <property name="width-request">200</property>
-                <property name="action-name">bookmarks.enter-edit-mode</property>
-                <property name="label" translatable="yes">Edit bookmarks list</property>
                 <style>
-                  <class name="circular"/>
-                  <class name="edit-bookmarks-list"/>
+                  <class name="linked"/>
+                  <class name="linked-circular"/>
                 </style>
+                <child>
+                  <object class="GtkModelButton">
+                    <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"/>
+                    </style>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkModelButton">
+                    <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"/>
+                    </style>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
@@ -266,6 +166,7 @@
   </object>
   <template class="Bookmarks" parent="GtkMenuButton">
     <property name="popover">bookmarks_popover</property>
+    <signal name="clicked" handler="leave_edit_mode"/>
 <!--    <style>
       <class name="image-button"/>  TODO bug https://bugzilla.gnome.org/show_bug.cgi?id=756731
     </style> -->
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index 93b8478..31d7a0d 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -41,12 +41,8 @@ private class Bookmarks : MenuButton
     [GtkChild] private Label switch_label;
 
     [GtkChild] private Stack edit_mode_stack;
-    [GtkChild] private Button rows_size_button;
-    [GtkChild] private Image big_rows_icon;
-    [GtkChild] private Image small_rows_icon;
-
-    [GtkChild] private Button enter_edit_mode_button;
-    [GtkChild] private Button leave_edit_mode_button;
+    [GtkChild] private Box edit_mode_box;
+    [GtkChild] private BookmarksController bookmarks_controller;
 
     private string   current_path = "/";
     private ViewType current_type = ViewType.FOLDER;
@@ -100,12 +96,12 @@ private class Bookmarks : MenuButton
                 }
                 else if (has_small_bookmarks_rows_class) context.remove_class ("small-bookmarks-rows");
                 has_small_bookmarks_rows_class = small_bookmarks_rows;
-                update_rows_size_button_icon (small_bookmarks_rows);
+                bookmarks_controller.update_rows_size_button_icon (small_bookmarks_rows);
             });
         has_small_bookmarks_rows_class = settings.get_boolean ("small-bookmarks-rows");
         if (has_small_bookmarks_rows_class)
             context.add_class ("small-bookmarks-rows");
-        update_rows_size_button_icon (has_small_bookmarks_rows_class);
+        bookmarks_controller.update_rows_size_button_icon (has_small_bookmarks_rows_class);
     }
 
     private void on_bookmarks_changed (GLib.Settings _settings, string key)
@@ -307,6 +303,7 @@ private class Bookmarks : MenuButton
     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)
@@ -355,13 +352,13 @@ private class Bookmarks : MenuButton
         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 [] action_entries =
     {
-        { "enter-edit-mode", enter_edit_mode },
-        { "leave-edit-mode", leave_edit_mode },
+        { "set-edit-mode", set_edit_mode, "b", "false" },
 
         { "trash-bookmark", trash_bookmark },
         { "set-small-rows", set_small_rows },
@@ -375,22 +372,37 @@ private class Bookmarks : MenuButton
         { "unbookmark",  unbookmark, "(sy)" }
     };
 
-    private void enter_edit_mode (/* SimpleAction action, Variant? variant */)
+    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 ()
     {
-        enter_edit_mode_button.hide ();
-        bookmarks_popover.get_style_context ().add_class ("edit-mode");
+        edit_mode_state_action.set_state (true);
+
         update_actions ();
 
         edit_mode_stack.set_visible_child_name ("edit-mode-on");
-        leave_edit_mode_button.grab_focus ();
+        bookmarks_list_box.grab_focus ();
 
         bookmarks_list_box.@foreach ((widget) => { ((Bookmark) widget).set_actionable (false); });
         bookmarks_list_box.set_activate_on_single_click (false);
         bookmarks_list_box.set_selection_mode (SelectionMode.MULTIPLE);
     }
 
-    private void leave_edit_mode (/* used both as action and method */)
+    [GtkCallback]
+    private void leave_edit_mode (/* used both as action and callback */)
     {
+        edit_mode_state_action.set_state (false);
+
         ListBoxRow? row = (ListBoxRow?) bookmarks_list_box.get_focus_child ();  // broken, the child needs 
to have the global focus...
         bool give_focus_to_switch = row == null;
         if (give_focus_to_switch)
@@ -405,9 +417,6 @@ private class Bookmarks : MenuButton
 
         edit_mode_stack.set_visible_child_name ("edit-mode-off");
 
-        bookmarks_popover.get_style_context ().remove_class ("edit-mode");
-        enter_edit_mode_button.show ();
-
         if (row != null)
             select_row_for_real ((!) row);
         if (give_focus_to_switch)
@@ -455,14 +464,7 @@ private class Bookmarks : MenuButton
 
     private void set_small_rows (/* SimpleAction action, Variant? variant */)
     {
-        settings.set_boolean ("small-bookmarks-rows", rows_size_button.get_image () == small_rows_icon);
-    }
-    private void update_rows_size_button_icon (bool small_bookmarks_rows)
-    {
-        if (small_bookmarks_rows)
-            rows_size_button.set_image (big_rows_icon);
-        else
-            rows_size_button.set_image (small_rows_icon);
+        settings.set_boolean ("small-bookmarks-rows", bookmarks_controller.get_small_rows_state ());
     }
 
     private void move_top       (/* SimpleAction action, Variant? variant */)
@@ -687,7 +689,7 @@ private class Bookmarks : MenuButton
                 has_empty_list_class = true;
             }
 
-            enter_edit_mode_button.hide ();
+            edit_mode_box.hide ();
         }
         else
         {
@@ -697,9 +699,7 @@ private class Bookmarks : MenuButton
                 has_empty_list_class = false;
             }
 
-            string? visible_child_name = edit_mode_stack.get_visible_child_name (); // do it like that
-            if (visible_child_name != null && (!) visible_child_name == "edit-mode-off")
-                enter_edit_mode_button.show ();
+            edit_mode_box.show ();
         }
     }
     private static void create_bookmark_rows (Variant bookmarks_variant, ref ListBox bookmarks_list_box, ref 
HashTable<string, Bookmark> bookmarks_hashtable, ref Bookmark? last_row, ref uint n_bookmarks)
diff --git a/editor/dconf-editor.css b/editor/dconf-editor.css
index 9b68c82..e808c90 100644
--- a/editor/dconf-editor.css
+++ b/editor/dconf-editor.css
@@ -60,30 +60,31 @@
   margin-bottom:0;
 }
 
-.bookmarks                 .padding-bottom {
+.bookmarks .padding-bottom {
   padding-bottom:0;
   transition:padding-bottom 0.3s,
              font-size      0.3s;
 }
-.bookmarks:not(.edit-mode) .padding-bottom:not(.empty-list) {
-  padding-bottom:2.4rem;
+.bookmarks .padding-bottom:not(.empty-list) {
+  padding-bottom:2.8rem;
 }
 
-.edit-bookmarks-list {
-  padding-left:0.1rem;
-  padding-right:0.1rem;
-  padding-bottom:0.1rem;
-  border-radius:1.8rem 1.8rem 0 0;
-  border-bottom:none;
+.linked-circular {
+  margin-bottom:0.3rem;
+}
 
-  transition:all           0    ease,
-             margin-bottom 0.3s ease,
-             padding       0.3s ease;
-  margin-bottom:0;
+.linked-circular:dir(rtl) .right-on-ltr,
+.linked-circular:dir(ltr) .left-on-ltr {
+  border-radius:2rem 0 0 2rem;
+  -gtk-outline-top-left-radius:2rem;
+  -gtk-outline-bottom-left-radius:2rem;
 }
 
-.edit-bookmarks-list label {
-  transition:all 0 ease;
+.linked-circular:dir(ltr) .right-on-ltr,
+.linked-circular:dir(rtl) .left-on-ltr {
+  border-radius:0 2rem 2rem 0;
+  -gtk-outline-top-right-radius:2rem;
+  -gtk-outline-bottom-right-radius:2rem;
 }
 
 /* hack: fix the double space when the child of the revealer is hidden; 6px is the spacing of the 
centerwidget box */
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 66fb826..8696a68 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -4,6 +4,7 @@
     <file preprocess="xml-stripblanks">adaptative-pathbar.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>
diff --git a/editor/meson.build b/editor/meson.build
index d6d81d6..feadf38 100644
--- a/editor/meson.build
+++ b/editor/meson.build
@@ -68,6 +68,7 @@ install_data(
 sources = files(
   'adaptative-pathbar.vala',
   'bookmarks.vala',
+  'bookmarks-controller.vala',
   'browser-headerbar.vala',
   'browser-infobar.vala',
   'browser-stack.vala',
@@ -99,6 +100,7 @@ sources = files(
 resource_data = files(
   'adaptative-pathbar.ui',
   'bookmarks.ui',
+  'bookmarks-controller.ui',
   'bookmark.ui',
   'browser-headerbar.ui',
   'browser-infobar.ui',


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