diff options
author | Eitan Isaacson <eitan@monotonous.org> | 2011-06-02 10:45:14 -0700 |
---|---|---|
committer | Eitan Isaacson <eitan@monotonous.org> | 2011-06-02 11:03:12 -0700 |
commit | 33f0c869983b390ae4ba53c60f6cb17389c6739d (patch) | |
tree | 658e6fa3b086ef88c5a932fab393b2f5d3a11c40 /libcaribou | |
parent | 8bd157c10cb64f3cdc9ac225998e3d3eee5b1ee2 (diff) | |
download | caribou-33f0c869983b390ae4ba53c60f6cb17389c6739d.tar.gz |
libcaribou: Use GLib.List instead of arrays
Diffstat (limited to 'libcaribou')
-rw-r--r-- | libcaribou/column-model.vala | 4 | ||||
-rw-r--r-- | libcaribou/group-model.vala | 10 | ||||
-rw-r--r-- | libcaribou/ikeyboard-object.vala | 30 | ||||
-rw-r--r-- | libcaribou/key-model.vala | 20 | ||||
-rw-r--r-- | libcaribou/keyboard-model.vala | 12 | ||||
-rw-r--r-- | libcaribou/level-model.vala | 9 | ||||
-rw-r--r-- | libcaribou/row-model.vala | 8 |
7 files changed, 55 insertions, 38 deletions
diff --git a/libcaribou/column-model.vala b/libcaribou/column-model.vala index b1db3cb..b1d2b57 100644 --- a/libcaribou/column-model.vala +++ b/libcaribou/column-model.vala @@ -26,8 +26,8 @@ namespace Caribou { return (IScannableItem[]) keys.to_array (); } - public IKeyboardObject[] get_children () { - return (IKeyboardObject[]) keys.to_array (); + public List<IKeyboardObject> get_children () { + return (List<IKeyboardObject>) collection_to_object_list (keys); } } } diff --git a/libcaribou/group-model.vala b/libcaribou/group-model.vala index 6b578d4..5c20fd4 100644 --- a/libcaribou/group-model.vala +++ b/libcaribou/group-model.vala @@ -33,8 +33,8 @@ namespace Caribou { } } - public string[] get_levels () { - return (string[]) levels.keys.to_array (); + public List<string> get_levels () { + return (List<string>) collection_to_string_list (levels.keys); } public LevelModel get_level (string level_name) { @@ -48,9 +48,9 @@ namespace Caribou { active_level = new_level; } - public IKeyboardObject[] get_children () { - return (IKeyboardObject[]) levels.values.to_array (); + public List<IKeyboardObject> get_children () { + return (List<IKeyboardObject>) + collection_to_object_list (levels.values); } - } }
\ No newline at end of file diff --git a/libcaribou/ikeyboard-object.vala b/libcaribou/ikeyboard-object.vala index f227492..a76b604 100644 --- a/libcaribou/ikeyboard-object.vala +++ b/libcaribou/ikeyboard-object.vala @@ -1,18 +1,32 @@ namespace Caribou { public interface IKeyboardObject : Object { - public abstract IKeyboardObject[] get_children (); + public abstract List<IKeyboardObject> get_children (); public signal void key_activated (KeyModel key); - public virtual KeyModel[] get_keys () { - Gee.ArrayList<KeyModel> keys = new Gee.ArrayList<KeyModel> (); + public virtual List<KeyModel> get_keys () { + var keys = new List<KeyModel> (); foreach (IKeyboardObject obj in get_children ()) { - KeyModel[] obj_keys = obj.get_keys(); - foreach (KeyModel key in obj_keys) { - keys.add(key); - } + List<weak KeyModel> child_keys = obj.get_keys(); + keys.concat (child_keys.copy()); } - return (KeyModel[]) keys.to_array (); + return keys; + } + + internal static List<Object> collection_to_object_list (Gee.Collection<Object> c) { + var l = new List<Object> (); + foreach (Object item in c) { + l.append (item); + } + return l; + } + + internal static List<string> collection_to_string_list (Gee.Collection<string> c) { + List<string> l = new List<string> (); + foreach (string item in c) { + l.append (item); + } + return l; } } }
\ No newline at end of file diff --git a/libcaribou/key-model.vala b/libcaribou/key-model.vala index 32ed771..bae89bc 100644 --- a/libcaribou/key-model.vala +++ b/libcaribou/key-model.vala @@ -79,19 +79,21 @@ namespace Caribou { return false; } - public KeyModel[] get_extended_keys () { - return (KeyModel[]) extended_keys.to_array (); + public List<KeyModel> get_extended_keys () { + return (List<KeyModel>) collection_to_object_list(extended_keys); } - public KeyModel[] get_keys () { - Gee.ArrayList<KeyModel> all_keys = new Gee.ArrayList<KeyModel> (); - all_keys.add (this); - all_keys.add_all (extended_keys); - return (KeyModel[]) all_keys.to_array (); + public List<KeyModel> get_keys () { + List<KeyModel> all_keys = new List<KeyModel> (); + all_keys.append (this); + var ekeys = (List<weak KeyModel>) get_extended_keys (); + all_keys.concat (ekeys.copy()); + return all_keys; } - public IKeyboardObject[] get_children () { - return (IKeyboardObject[]) extended_keys.to_array (); + public List<IKeyboardObject> get_children () { + return (List<IKeyboardObject>) + collection_to_object_list (extended_keys); } public void activate () { diff --git a/libcaribou/keyboard-model.vala b/libcaribou/keyboard-model.vala index e34a3a3..2d1ac7c 100644 --- a/libcaribou/keyboard-model.vala +++ b/libcaribou/keyboard-model.vala @@ -49,8 +49,8 @@ namespace Caribou { key_activated (key); } - public string[] get_groups () { - return (string[]) groups.keys.to_array (); + public List<string> get_groups () { + return (List<string>) collection_to_string_list (groups.keys); } public GroupModel get_group (string group_name) { @@ -62,12 +62,14 @@ namespace Caribou { if (groups.get (group_name) != null) { active_group = group_name; } else { - active_group = get_groups ()[0]; + string[] keys = (string[]) groups.keys.to_array(); + active_group = keys[0]; } } - public IKeyboardObject[] get_children () { - return (IKeyboardObject[]) groups.values.to_array (); + public List<IKeyboardObject> get_children () { + return (List<IKeyboardObject>) + collection_to_object_list (groups.values); } } }
\ No newline at end of file diff --git a/libcaribou/level-model.vala b/libcaribou/level-model.vala index 0d209d3..6c041d8 100644 --- a/libcaribou/level-model.vala +++ b/libcaribou/level-model.vala @@ -30,8 +30,8 @@ namespace Caribou { row.add_key (colnum, key); } - public RowModel[] get_rows () { - return (RowModel[]) rows.to_array (); + public List<RowModel> get_rows () { + return (List<RowModel>) get_children (); } private void on_key_activated (KeyModel key) { @@ -49,9 +49,8 @@ namespace Caribou { return (IScannableItem[]) rows.to_array (); } - public IKeyboardObject[] get_children () { - return (IKeyboardObject[]) get_rows (); + public List<IKeyboardObject> get_children () { + return (List<IKeyboardObject>) collection_to_object_list (rows); } - } } diff --git a/libcaribou/row-model.vala b/libcaribou/row-model.vala index 7aac08e..4020fe3 100644 --- a/libcaribou/row-model.vala +++ b/libcaribou/row-model.vala @@ -27,8 +27,8 @@ namespace Caribou { column.add_key (key); } - public ColumnModel[] get_columns () { - return (ColumnModel[]) columns.to_array (); + public List<ColumnModel> get_columns () { + return (List<ColumnModel>) get_children (); } public override IScannableItem[] get_scan_children () { @@ -38,8 +38,8 @@ namespace Caribou { return (IScannableItem[]) columns.to_array (); } - public IKeyboardObject[] get_children () { - return (IKeyboardObject[]) get_columns (); + public List<IKeyboardObject> get_children () { + return (List<IKeyboardObject>) collection_to_object_list (columns); } } } |