[meld] dirdiff: Migrate column ordering and visibility to GSettings



commit 13f4836a197e73d2743db22dfc34ae66dc1e351a
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Nov 26 06:45:05 2013 +1000

    dirdiff: Migrate column ordering and visibility to GSettings

 meld/dirdiff.py     |   32 ++++++++++++--------------------
 meld/preferences.py |   24 ++++++++----------------
 2 files changed, 20 insertions(+), 36 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 13b4efc..f239ceb 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -45,7 +45,6 @@ from collections import namedtuple
 from decimal import Decimal
 from gettext import gettext as _
 from gettext import ngettext
-from .meldapp import app
 
 from meld.settings import meldsettings, settings
 
@@ -253,11 +252,6 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
 
     __gtype_name__ = "DirDiff"
 
-    columns = GObject.property(
-        type=GObject.TYPE_PYOBJECT,
-        nick="Columns to display",
-        blurb="List of columns to display in folder comparison",
-    )
     ignore_symlinks = GObject.property(
         type=bool,
         nick="Ignore symbolic links",
@@ -403,7 +397,6 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
             column.set_attributes(rentext, markup=col_index(COL_PERMS, i))
             self.treeview[i].append_column(column)
             self.columns_dict[i]["permissions"] = column
-        self.update_treeview_columns(self.prefs.dirdiff_columns)
 
         for i in range(3):
             selection = self.treeview[i].get_selection()
@@ -415,8 +408,10 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
                 "value-changed", self._sync_hscroll)
         self.linediffs = [[], []]
 
-        settings.bind('folder-columns', self, 'columns',
-                      Gio.SettingsBindFlags.DEFAULT)
+        self.update_treeview_columns(settings, 'folder-columns')
+        settings.connect('changed::folder-columns',
+                         self.update_treeview_columns)
+
         settings.bind('folder-ignore-symlinks', self, 'ignore-symlinks',
                       Gio.SettingsBindFlags.DEFAULT)
         settings.bind('folder-shallow-comparison', self, 'shallow-comparison',
@@ -467,9 +462,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
             diffmap.queue_draw()
 
     def on_preference_changed(self, key, value):
-        if key == "dirdiff_columns":
-            self.update_treeview_columns(value)
-        elif key == "ignore_blank_lines":
+        if key == "ignore_blank_lines":
             self.update_comparator()
 
     def update_comparator(self, *args):
@@ -482,20 +475,19 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
             _files_same, comparison_args=comparison_args)
         self.refresh()
 
-    def update_treeview_columns(self, columns):
+    def update_treeview_columns(self, settings, key):
         """Update the visibility and order of columns"""
-        for i in range(3):
+        columns = settings.get_value(key)
+        for i, treeview in enumerate(self.treeview):
             extra_cols = False
-            last_column = self.treeview[i].get_column(0)
-            for line in columns:
-                column_name, visible = line.rsplit(" ", 1)
-                visible = bool(int(visible))
+            last_column = treeview.get_column(0)
+            for column_name, visible in columns:
                 extra_cols = extra_cols or visible
                 current_column = self.columns_dict[i][column_name]
                 current_column.set_visible(visible)
-                self.treeview[i].move_column_after(current_column, last_column)
+                treeview.move_column_after(current_column, last_column)
                 last_column = current_column
-            self.treeview[i].set_headers_visible(extra_cols)
+            treeview.set_headers_visible(extra_cols)
 
     def on_custom_filter_menu_toggled(self, item):
         if item.get_active():
diff --git a/meld/preferences.py b/meld/preferences.py
index 2463bcd..82007bb 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -94,19 +94,14 @@ class ColumnList(listwidget.ListWidget):
         "permissions",
     ))
 
-    def __init__(self, prefs, key):
+    def __init__(self, key):
         listwidget.ListWidget.__init__(self, "EditableList.ui",
-                               "columns_ta", ["ColumnsListStore"],
-                               "columns_treeview")
-        self.prefs = prefs
+                                       "columns_ta", ["ColumnsListStore"],
+                                       "columns_treeview")
         self.key = key
 
-        prefs_columns = []
-        for column in getattr(self.prefs, self.key):
-            column_name, visibility = column.rsplit(" ", 1)
-            visibility = bool(int(visibility))
-            prefs_columns.append((column_name, visibility))
-
+        # Unwrap the variant
+        prefs_columns = [(k, v) for k, v in settings.get_value(self.key)]
         missing = self.available_columns - set([c[0] for c in prefs_columns])
         prefs_columns.extend([(m, False) for m in missing])
         for column_name, visibility in prefs_columns:
@@ -122,8 +117,8 @@ class ColumnList(listwidget.ListWidget):
         self.model[path][0] = not ren.get_active()
 
     def _update_columns(self, *args):
-        columns = ["%s %d" % (c[1].lower(), int(c[0])) for c in self.model]
-        setattr(self.prefs, self.key, columns)
+        value = [(c[1].lower(), c[0]) for c in self.model]
+        settings.set_value(self.key, GLib.Variant('a(sb)', value))
 
 
 class GSettingsComboBox(Gtk.ComboBox):
@@ -228,7 +223,7 @@ class PreferencesDialog(gnomeglade.Component):
         # encoding
         self.entry_text_codecs.set_text( self.prefs.text_codecs )
 
-        columnlist = ColumnList(self.prefs, "dirdiff_columns")
+        columnlist = ColumnList("folder-columns")
         self.column_list_vbox.pack_start(columnlist.widget, True, True, 0)
 
         model = Gtk.ListStore(str, int)
@@ -300,9 +295,6 @@ class MeldPreferences(prefs.Preferences):
         # Currently, we're using a quite simple format to store the columns:
         # each line contains a column name followed by a 1 or a 0
         # depending on whether the column is visible or not.
-        "dirdiff_columns": prefs.Value(prefs.LIST,
-                                         ["size 1", "modification time 1",
-                                          "permissions 0"]),
         "vc_left_is_local": prefs.Value(prefs.BOOL, False),
     }
 


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