[dconf-editor] Rework ListBoxRowHeader.



commit 2bdca1aab436f7f4432d11df596860e48e60511b
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Nov 30 17:06:44 2017 +0100

    Rework ListBoxRowHeader.

 editor/key-list-box-row.vala |   28 ++++++++++++++++++++++++++++
 editor/registry-search.vala  |   26 +-------------------------
 editor/registry-view.vala    |   14 ++------------
 3 files changed, 31 insertions(+), 37 deletions(-)
---
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 003adcd..eef8e80 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -35,6 +35,34 @@ private class ListBoxRowHeader : Grid
         base.get_preferred_width (out minimum_width, out natural_width);
         natural_width = MAX_ROW_WIDTH;
     }
+
+    public ListBoxRowHeader (bool is_first_row, string? header_text = null)
+    {
+        if (header_text == null)
+        {
+            if (is_first_row)
+                return;
+        }
+        else
+        {
+            Label label = new Label ((!) header_text);
+            label.visible = true;
+            label.halign = Align.START;
+            label.margin_top = 10; // TODO CSS
+            label.margin_left = 10; // TODO CSS
+            label.get_style_context ().add_class ("dim-label");
+            label.get_style_context ().add_class ("bold-label");
+            add (label);
+        }
+
+        orientation = Orientation.VERTICAL;
+        halign = Align.CENTER;
+
+        Separator separator = new Separator (Orientation.HORIZONTAL);
+        separator.visible = true;
+        separator.hexpand = true;
+        add (separator);
+    }
 }
 
 private abstract class ClickableListBoxRow : EventBox
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index e4f6da4..e3cd05e 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -567,11 +567,6 @@ class RegistrySearch : Grid, PathElement, BrowsableView
 
     private void update_search_results_header (ListBoxRow row, ListBoxRow? before)
     {
-        ListBoxRowHeader header = new ListBoxRowHeader ();
-        header.visible = true;
-        header.orientation = Orientation.VERTICAL;
-        header.halign = Align.CENTER;
-
         string? label_text = null;
         if (before == null && post_local > 0)
             label_text = _("Current folder");
@@ -582,26 +577,7 @@ class RegistrySearch : Grid, PathElement, BrowsableView
         else if (row.get_index () == post_folders)
             label_text = _("Keys");
 
-        if (label_text != null)
-        {
-            Label label = new Label ((!) label_text);
-            label.visible = true;
-            label.halign = Align.START;
-            label.margin_top = 10; // TODO CSS
-            label.margin_left = 10; // TODO CSS
-            label.get_style_context ().add_class ("dim-label");
-            label.get_style_context ().add_class ("bold-label");
-            header.add (label);
-        }
-
-        if (before != null || label_text != null)
-        {
-            Separator separator = new Separator (Orientation.HORIZONTAL);
-            separator.visible = true;
-            separator.hexpand = true;
-            header.add (separator);
-        }
-
+        ListBoxRowHeader header = new ListBoxRowHeader (before == null, label_text);
         row.set_header (header);
     }
 }
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 2fdca7c..e091ab8 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -121,18 +121,8 @@ class RegistryView : Grid, PathElement, BrowsableView
 
     private void update_row_header (ListBoxRow row, ListBoxRow? before)
     {
-        if (before != null)
-        {
-            ListBoxRowHeader header = new ListBoxRowHeader ();
-            header.set_halign (Align.CENTER);
-            header.show ();
-
-            Separator separator = new Separator (Orientation.HORIZONTAL);
-            separator.show ();
-            separator.set_hexpand (true);
-            header.add (separator);
-            row.set_header (header);
-        }
+        ListBoxRowHeader header = new ListBoxRowHeader (before == null);
+        row.set_header (header);
     }
 
     private Widget new_list_box_row (Object item)


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