[dconf] Sort keys
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf] Sort keys
- Date: Sat, 15 Jan 2011 06:20:14 +0000 (UTC)
commit 3d3d6d3dcdb06ee29f865919e47d2ff1ef1b5f3f
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Jan 14 21:48:48 2011 -0600
Sort keys
editor/dconf-model.vala | 40 ++++++++++++++++++++++++++++------------
1 files changed, 28 insertions(+), 12 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index bd30c78..3cb3745 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -3,7 +3,6 @@ public class Key : GLib.Object
private SettingsModel model;
public Directory? parent;
- public int index;
public string name;
public string full_name;
@@ -16,6 +15,11 @@ public class Key : GLib.Object
public get { return schema != null; }
}
+ public int index
+ {
+ get { return parent.keys.index (this); }
+ }
+
public string type_string
{
private set {}
@@ -63,11 +67,10 @@ public class Key : GLib.Object
public get { update_value(); return _value == null; }
}
- public Key(SettingsModel model, Directory parent, int index, string name, string full_name)
+ public Key(SettingsModel model, Directory parent, string name, string full_name)
{
this.model = model;
this.parent = parent;
- this.index = index;
this.name = name;
this.full_name = full_name;
this.schema = model.schemas.keys.lookup(full_name);
@@ -87,7 +90,6 @@ public class Directory : GLib.Object
public string full_name;
public Directory? parent;
- public int index;
private KeyModel _key_model;
public KeyModel key_model
@@ -96,6 +98,11 @@ public class Directory : GLib.Object
private set {}
}
+ public int index
+ {
+ get { return parent.children.index (this); }
+ }
+
public GLib.HashTable<string, Directory> _child_map = new GLib.HashTable<string, Directory>(str_hash, str_equal);
public GLib.List<Directory> _children = new GLib.List<Directory>();
public GLib.List<Directory> children
@@ -114,11 +121,10 @@ public class Directory : GLib.Object
private bool have_children;
- public Directory(SettingsModel model, Directory? parent, int index, string name, string full_name)
+ public Directory(SettingsModel model, Directory? parent, string name, string full_name)
{
this.model = model;
this.parent = parent;
- this.index = index;
this.name = name;
this.full_name = full_name;
}
@@ -129,28 +135,38 @@ public class Directory : GLib.Object
if (directory == null)
{
- directory = new Directory(model, this, (int)_children.length(), name, full_name + name + "/");
- _children.append(directory);
+ directory = new Directory(model, this, name, full_name + name + "/");
+ _children.insert_sorted(directory, compare_directories);
_child_map.insert(name, directory);
}
return directory;
}
+ private static int compare_directories(Directory a, Directory b)
+ {
+ return strcmp(a.name, b.name);
+ }
+
public Key get_key(string name)
{
Key? key = _key_map.lookup(name);
if (key == null)
{
- key = new Key(model, this, (int)_keys.length(), name, full_name + name);
- _keys.append(key);
+ key = new Key(model, this, name, full_name + name);
+ _keys.insert_sorted(key, compare_keys);
_key_map.insert(name, key);
}
return key;
}
+ public static int compare_keys(Key a, Key b)
+ {
+ return strcmp(a.name, b.name);
+ }
+
public void load_schema(Schema schema, string path)
{
if (path == "")
@@ -192,7 +208,7 @@ public class Directory : GLib.Object
}
}
-public class KeyModel: GLib.Object, Gtk.TreeModel/*, Gtk.TreeSortable*/
+public class KeyModel: GLib.Object, Gtk.TreeModel
{
private Directory directory;
@@ -458,7 +474,7 @@ public class SettingsModel: GLib.Object, Gtk.TreeModel
public SettingsModel()
{
client = new DConf.Client ();
- root = new Directory(this, null, 0, "/", "/");
+ root = new Directory(this, null, "/", "/");
schemas = new SchemaList();
try
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]