[shotwell/wip/phako/configure-sidebar: 250/254] WIP



commit b473498b6ea250d514e26a464525f2224698b327
Author: Jens Georg <mail jensge org>
Date:   Sun Jul 15 21:06:24 2018 +0200

    WIP

 data/ui/preferences_dialog.ui          | 21 ++++++++++---------
 data/ui/preferences_dialog_list_row.ui | 10 ++++-----
 src/dialogs/Preferences.vala           | 38 +++++++++++++++++++++++++++++++++-
 3 files changed, 52 insertions(+), 17 deletions(-)
---
diff --git a/data/ui/preferences_dialog.ui b/data/ui/preferences_dialog.ui
index 41256eac..049a9cf1 100644
--- a/data/ui/preferences_dialog.ui
+++ b/data/ui/preferences_dialog.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.0 -->
+<!-- Generated with glade 3.22.1 -->
 <interface domain="shotwell">
   <requires lib="gtk+" version="3.18"/>
   <template class="PreferencesDialog" parent="GtkDialog">
@@ -7,6 +7,15 @@
     <property name="destroy_with_parent">True</property>
     <property name="type_hint">dialog</property>
     <property name="skip_taskbar_hint">True</property>
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="headerbar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="title">Shotwell Preferences</property>
+        <property name="has_subtitle">False</property>
+        <property name="show_close_button">True</property>
+      </object>
+    </child>
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog-vbox3">
         <property name="visible">True</property>
@@ -450,6 +459,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="halign">start</property>
+                    <property name="valign">center</property>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -642,15 +652,6 @@
         </child>
       </object>
     </child>
-    <child type="titlebar">
-      <object class="GtkHeaderBar" id="headerbar">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="title">Shotwell Preferences</property>
-        <property name="has_subtitle">False</property>
-        <property name="show_close_button">True</property>
-      </object>
-    </child>
   </template>
   <object class="GtkSizeGroup">
     <property name="mode">vertical</property>
diff --git a/data/ui/preferences_dialog_list_row.ui b/data/ui/preferences_dialog_list_row.ui
index 82769298..fb366cbb 100644
--- a/data/ui/preferences_dialog_list_row.ui
+++ b/data/ui/preferences_dialog_list_row.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.0 -->
+<!-- Generated with glade 3.22.1 -->
 <interface>
   <requires lib="gtk+" version="3.18"/>
   <template class="SidebarPreferencesListRow" parent="GtkListBoxRow">
@@ -46,13 +46,11 @@
           </packing>
         </child>
         <child>
-          <object class="GtkCheckButton" id="visibility">
-            <property name="label" translatable="yes">Visible</property>
+          <object class="GtkSwitch" id="visibility">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="halign">end</property>
-            <property name="draw_indicator">True</property>
+            <property name="valign">center</property>
+            <property name="active">True</property>
           </object>
           <packing>
             <property name="expand">False</property>
diff --git a/src/dialogs/Preferences.vala b/src/dialogs/Preferences.vala
index 954e431f..a504faa4 100644
--- a/src/dialogs/Preferences.vala
+++ b/src/dialogs/Preferences.vala
@@ -14,7 +14,7 @@ public class SidebarPreferencesListRow : Gtk.ListBoxRow {
     private Gtk.Label label;
 
     [GtkChild]
-    private Gtk.CheckButton visibility;
+    private Gtk.Switch visibility;
 
     public bool tree_visibility {
         set {
@@ -41,6 +41,7 @@ public class SidebarPreferencesListRow : Gtk.ListBoxRow {
         handle.drag_begin.connect(this.on_drag_begin);
         label.set_text (Resources.map_subtree_name(name));
         drag_data_received.connect(this.on_drag_data_received);
+        visibility.bind_property ("active", this, "tree-visibility");
     }
 
     private void on_drag_data_received(Gtk.Widget target, Gdk.DragContext ctx, int x, int y, 
Gtk.SelectionData data, uint info, uint time) {
@@ -142,6 +143,7 @@ public class PreferencesDialog : Gtk.Dialog {
     private Gtk.RadioButton transparent_none_radio;
     [GtkChild]
     private Gtk.ListBox sidebar_content;
+    private ulong sidebar_content_updated_handler;
 
     private PreferencesDialog() {
         Object (use_header_bar: Resources.use_header_bar());
@@ -223,19 +225,27 @@ public class PreferencesDialog : Gtk.Dialog {
         default_raw_developer_combo.changed.connect(on_default_raw_developer_changed);
         switch_dark.active = Gtk.Settings.get_default().gtk_application_prefer_dark_theme;
         switch_dark.notify["active"].connect(on_theme_variant_changed);
+
+        this.sidebar_content_updated_handler = sidebar_content.add.connect(this.on_update_sidebar_order);
     }
 
     public void populate_preference_options() {
         var visibility = Config.Facade.get_instance().get_sidebar_content();
         var content = Config.Facade.get_instance().get_sidebar_content_order();
+        if (this.sidebar_content_updated_handler != 0)
+            SignalHandler.block (sidebar_content, this.sidebar_content_updated_handler);
+
         foreach (var child in sidebar_content.get_children())
             child.destroy();
 
         foreach (var tree in content) {
             var row = new SidebarPreferencesListRow(tree);
             row.tree_visibility = tree in visibility;
+            row.notify["tree-visibility"].connect (this.on_update_sidebar_visibility);
             sidebar_content.add(row);
         }
+        if (this.sidebar_content_updated_handler != 0)
+            SignalHandler.unblock (sidebar_content, this.sidebar_content_updated_handler);
 
         populate_app_combo_box(photo_editor_combo, PhotoFileFormat.get_editable_mime_types(),
             Config.Facade.get_instance().get_external_photo_app(), out external_photo_apps);
@@ -248,6 +258,32 @@ public class PreferencesDialog : Gtk.Dialog {
         lowercase.set_active(Config.Facade.get_instance().get_use_lowercase_filenames());
     }
 
+    private void on_update_sidebar_visibility (GLib.Object o, GLib.ParamSpec ps) {
+        var config = Config.Facade.get_instance();
+        string[] rows = new string[0];
+        sidebar_content.foreach ((child) => {
+            var row = (child as SidebarPreferencesListRow);
+
+            if (row.tree_visibility) {
+                rows += row.row_name;
+            }
+        });
+
+        config.set_sidebar_content(rows);
+    }
+
+    private void on_update_sidebar_order () {
+        critical ("=> Updating sidebar");
+        var config = Config.Facade.get_instance();
+        string[] rows = new string[0];
+        sidebar_content.foreach ((child) => {
+            var row = (child as SidebarPreferencesListRow);
+            rows += row.row_name;
+        });
+
+        config.set_sidebar_content_order(rows);
+    }
+
     private void on_theme_variant_changed(GLib.Object o, GLib.ParamSpec ps) {
         var config = Config.Facade.get_instance();
         config.set_gtk_theme_variant(switch_dark.active);


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