[dconf-editor] Use an array.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Use an array.
- Date: Sun, 1 Jul 2018 16:24:20 +0000 (UTC)
commit 6c45b281af911d9221f68a882ea78d664a039e6d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sun Jul 1 18:23:25 2018 +0200
Use an array.
editor/browser-stack.vala | 2 +-
editor/browser-view.vala | 15 +++++++++------
editor/dconf-model.vala | 25 ++++++++++++++++++++++---
editor/dconf-window.vala | 16 ++++++----------
editor/modifications-revealer.vala | 21 ++++++++-------------
editor/registry-search.vala | 14 +++++++-------
editor/registry-view.vala | 23 ++++++++++++++---------
7 files changed, 67 insertions(+), 49 deletions(-)
---
diff --git a/editor/browser-stack.vala b/editor/browser-stack.vala
index 585e837..b288715 100644
--- a/editor/browser-stack.vala
+++ b/editor/browser-stack.vala
@@ -157,7 +157,7 @@ class BrowserStack : Grid
search_view.set_search_parameters (current_path, bookmarks, sorting_options);
}
- public bool check_reload_folder (GLib.ListStore fresh_key_model)
+ public bool check_reload_folder (SettingObject [] fresh_key_model)
{
return folder_view.check_reload (fresh_key_model);
}
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 428b428..f555bd2 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -151,11 +151,14 @@ class BrowserView : Grid
* * Views
\*/
- public void prepare_folder_view (GLib.ListStore key_model, bool is_ancestor)
+ public void prepare_folder_view (SettingObject [] key_array, bool is_ancestor)
{
- this.key_model = key_model;
- sorting_options.sort_key_model (key_model);
- current_child.prepare_folder_view (key_model, is_ancestor);
+ key_model = new GLib.ListStore (typeof (SettingObject));
+ for (uint i = 0; i < key_array.length; i++)
+ ((!) key_model).append (key_array [i]);
+
+ sorting_options.sort_key_model ((!) key_model);
+ current_child.prepare_folder_view ((!) key_model, is_ancestor);
hide_reload_warning ();
}
@@ -205,8 +208,8 @@ class BrowserView : Grid
if (type == ViewType.FOLDER)
{
- GLib.ListStore? fresh_key_model = model.get_children (path);
- if (fresh_key_model != null && !current_child.check_reload_folder ((!) fresh_key_model))
+ SettingObject [] fresh_key_model = model.get_children (path);
+ if (!current_child.check_reload_folder (fresh_key_model))
return false;
if (show_infobar)
{
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index f9c6845..ff3b005 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -103,7 +103,7 @@ public class SettingsModel : Object
return null;
}
- public GLib.ListStore? get_children (string folder_path)
+ private GLib.ListStore? get_children_as_liststore (string folder_path)
{
Directory? dir = get_directory (folder_path);
if (dir == null)
@@ -121,6 +121,25 @@ public class SettingsModel : Object
return null;
}
+ public SettingObject [] get_children (string folder_path)
+ {
+ GLib.ListStore? list_store = get_children_as_liststore (folder_path);
+ if (list_store == null)
+ return {};
+
+ SettingObject [] keys_array = {};
+ uint position = 0;
+ Object? object = ((!) list_store).get_item (0);
+ do
+ {
+ keys_array += (SettingObject) (!) object;
+ position++;
+ object = ((!) list_store).get_item (position);
+ }
+ while (object != null);
+ return keys_array;
+ }
+
public SettingObject? get_object (string path)
{
if (is_key_path (path))
@@ -131,7 +150,7 @@ public class SettingsModel : Object
public Key? get_key (string path, string context = "")
{
- GLib.ListStore? key_model = get_children (get_parent_path (path));
+ GLib.ListStore? key_model = get_children_as_liststore (get_parent_path (path));
return get_key_from_path_and_name (key_model, get_name (path), context);
}
@@ -139,7 +158,7 @@ public class SettingsModel : Object
{
if (is_key_path (path))
{
- GLib.ListStore? key_model = get_children (get_parent_path (path));
+ GLib.ListStore? key_model = get_children_as_liststore (get_parent_path (path));
return get_key_from_path_and_name (key_model, get_name (path)) != null;
}
else
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index dd66cc9..4ddf280 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -550,17 +550,13 @@ class DConfWindow : ApplicationWindow
if (notify_missing && (fallback_path != full_name))
cannot_find_folder (full_name); // do not place after, full_name is in some cases changed by
set_directory()...
- GLib.ListStore? key_model = model.get_children (fallback_path);
- if (key_model != null)
- {
- browser_view.prepare_folder_view ((!) key_model, current_path.has_prefix (fallback_path));
- update_current_path (ViewType.FOLDER, fallback_path);
+ browser_view.prepare_folder_view (model.get_children (fallback_path), current_path.has_prefix
(fallback_path));
+ update_current_path (ViewType.FOLDER, fallback_path);
- if (selected_or_empty == "")
- browser_view.select_row (pathbar.get_selected_child (fallback_path));
- else
- browser_view.select_row (selected_or_empty);
- }
+ if (selected_or_empty == "")
+ browser_view.select_row (pathbar.get_selected_child (fallback_path));
+ else
+ browser_view.select_row (selected_or_empty);
search_bar.search_mode_enabled = false; // do last to avoid flickering RegistryView before
PropertiesView when selecting a search result
}
diff --git a/editor/modifications-revealer.vala b/editor/modifications-revealer.vala
index 421fe00..a185b6f 100644
--- a/editor/modifications-revealer.vala
+++ b/editor/modifications-revealer.vala
@@ -70,32 +70,27 @@ class ModificationsRevealer : Revealer
* * Reseting objects
\*/
- public void reset_objects (GLib.ListStore? objects, bool recursively)
+ public void reset_objects (SettingObject [] objects, bool recursively)
{
_reset_objects (objects, recursively);
warn_if_no_planned_changes ();
}
- private void _reset_objects (GLib.ListStore? objects, bool recursively)
+ private void _reset_objects (SettingObject [] objects, bool recursively)
{
- SettingsModel model = modifications_handler.model;
- if (objects == null)
+ if (objects.length == 0)
return;
+ SettingsModel model = modifications_handler.model;
- for (uint position = 0;; position++)
+ for (uint position = 0; position < objects.length; position++)
{
- Object? object = ((!) objects).get_object (position);
- if (object == null)
- return;
-
- SettingObject setting_object = (SettingObject) ((!) object);
+ SettingObject setting_object = (SettingObject) objects [position];
if (!SettingsModel.is_key_path (setting_object.full_name))
{
if (recursively)
{
- GLib.ListStore? children = model.get_children (setting_object.full_name);
- if (children != null)
- _reset_objects ((!) children, true);
+ SettingObject [] children = model.get_children (setting_object.full_name);
+ _reset_objects (children, true);
}
continue;
}
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index a914205..2923ea1 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -336,10 +336,10 @@ class RegistrySearch : RegistryList
if (!SettingsModel.is_key_path (current_path))
{
- GLib.ListStore? key_model = model.get_children (current_path);
- for (uint i = 0; i < ((!) key_model).get_n_items (); i++)
+ SettingObject [] key_model = model.get_children (current_path);
+ for (uint i = 0; i < key_model.length; i++)
{
- SettingObject item = (SettingObject) ((!) key_model).get_item (i);
+ SettingObject item = key_model [i];
if (term in item.name)
list_model.insert_sorted (item, compare);
}
@@ -420,13 +420,13 @@ class RegistrySearch : RegistryList
string next = (!) search_nodes.pop_head ();
bool local_again = next == current_path;
- GLib.ListStore? next_key_model = model.get_children (next);
- if (next_key_model == null)
+ SettingObject [] next_key_model = model.get_children (next);
+ if (next_key_model.length == 0)
return true;
- for (uint i = 0; i < ((!) next_key_model).get_n_items (); i++)
+ for (uint i = 0; i < next_key_model.length; i++)
{
- SettingObject item = (SettingObject) ((!) next_key_model).get_item (i);
+ SettingObject item = next_key_model [i];
if (!SettingsModel.is_key_path (item.full_name))
{
if (!local_again && term in item.name)
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index fee6b01..c70d016 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -220,30 +220,35 @@ class RegistryView : RegistryList
key_list_box.bind_model (list_model, new_list_box_row);
}
- public bool check_reload (GLib.ListStore fresh_key_model)
+ public bool check_reload (SettingObject [] fresh_key_model)
{
- if (list_model.get_n_items () != fresh_key_model.get_n_items ())
+ if (list_model.get_n_items () != fresh_key_model.length)
return true;
+ bool [] skip = new bool [fresh_key_model.length];
for (uint i = 0; i < list_model.get_n_items (); i++)
{
- SettingObject setting_object = (SettingObject) list_model.get_item (i);
+ SettingObject? setting_object = (SettingObject) list_model.get_item (i);
+ if (setting_object == null)
+ assert_not_reached ();
bool found = false;
- for (uint j = 0; j < fresh_key_model.get_n_items (); j++)
+ for (uint j = 0; j < fresh_key_model.length; j++)
{
- SettingObject fresh_setting_object = (SettingObject) fresh_key_model.get_item (j);
- if (setting_object.get_type () != fresh_setting_object.get_type ())
+ if (skip [j])
continue;
- if (setting_object.name != fresh_setting_object.name)
+ SettingObject fresh_setting_object = fresh_key_model [j];
+ if (((!) setting_object).get_type () != fresh_setting_object.get_type ())
+ continue;
+ if (((!) setting_object).name != fresh_setting_object.name)
continue;
// TODO compare other visible info (i.e. key summary and value)
found = true;
- fresh_key_model.remove (j);
+ skip [j] = true;
break;
}
if (!found)
return true;
}
- if (fresh_key_model.get_n_items () > 0)
+ if (fresh_key_model.length > 0)
return true;
return false;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]