[dconf-editor] Add and use some helper functions
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Add and use some helper functions
- Date: Mon, 11 Dec 2017 22:59:28 +0000 (UTC)
commit da6cb7a064947c63756287a5585652ccdfe4207f
Author: Davi da Silva Böger <dsboger gmail com>
Date: Fri Dec 8 21:53:51 2017 -0200
Add and use some helper functions
editor/browser-view.vala | 2 +-
editor/dconf-model.vala | 26 ++++++++++++++++++++------
editor/dconf-window.vala | 6 ++----
editor/registry-search.vala | 4 ++--
4 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index e4c9474..aa772b7 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -159,7 +159,7 @@ class BrowserView : Grid, PathElement
need_reload_warning_revealer.set_reveal_child (false);
browse_view.show_multiple_schemas_warning (false);
- stack.set_transition_type (path.has_prefix (current_path) && current_path.length ==
path.last_index_of_char ('/') + 1 && pre_search_view == null ? StackTransitionType.CROSSFADE :
StackTransitionType.NONE);
+ stack.set_transition_type (current_path == SettingsModel.get_parent_path (path) && pre_search_view
== null ? StackTransitionType.CROSSFADE : StackTransitionType.NONE);
pre_search_view = null;
update_current_path (path);
stack.set_visible_child (properties_view);
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index ba36a77..b7c28a1 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -772,7 +772,7 @@ public class SettingsModel : Object
public static string get_base_path (string path)
{
- if (path.has_suffix ("/"))
+ if (!is_key_path (path))
return path;
else
return stripped_path (path);
@@ -893,7 +893,7 @@ public class SettingsModel : Object
foreach (string item in items)
{
string full_name = path + item;
- if ((full_name.has_suffix ("/") && new_key.full_name.has_prefix (full_name)) ||
full_name == new_key.full_name) // TODO better
+ if ((!is_key_path (full_name) && new_key.full_name.has_prefix (full_name)) || full_name
== new_key.full_name) // TODO better
{
new_key.is_ghost = client.read (new_key.full_name) == null;
new_key.value_changed ();
@@ -905,20 +905,34 @@ public class SettingsModel : Object
public SettingObject? get_object (string path)
{
- if (path.has_suffix ("/"))
+ if (!is_key_path (path))
return get_directory (path);
Directory? parent = get_directory (get_base_path (path));
if (parent == null)
return null;
- string name = path [path.last_index_of_char ('/') + 1:path.length];
- return get_key_from_path_and_name (get_children ((!) parent), name);
+ return get_key_from_path_and_name (get_children ((!) parent), get_name (path));
+ }
+
+ public static bool is_key_path (string path)
+ {
+ return !path.has_suffix ("/");
+ }
+
+ public static string get_name (string path)
+ {
+ if (path == "/")
+ return "/";
+ if (is_key_path (path))
+ return path [path.last_index_of_char ('/') + 1:path.length];
+ string tmp = path[0:-1];
+ return tmp [tmp.last_index_of_char ('/') + 1:tmp.length];
}
public static string get_parent_path (string path)
{
if (path == "/")
return path;
- return get_base_path (path.has_suffix ("/") ? path [0:-1] : path);
+ return get_base_path (!is_key_path (path) ? path [0:-1] : path);
}
private static string stripped_path (string path)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 39bf15f..efc2cda 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -367,7 +367,7 @@ class DConfWindow : ApplicationWindow
GLib.Menu menu = new GLib.Menu ();
menu.append (_("Copy current path"), "app.copy(\"" + current_path.escape (null).escape (null) +
"\")");
- if (current_path.has_suffix ("/"))
+ if (!SettingsModel.is_key_path (current_path))
{
section = new GLib.Menu ();
section.append (_("Reset visible keys"), "win.reset-visible");
@@ -629,10 +629,8 @@ class DConfWindow : ApplicationWindow
return;
if (shift)
request_path ("/");
- else if (current_path.has_suffix ("/"))
- request_path (current_path.slice (0, current_path.slice (0, current_path.length -
1).last_index_of_char ('/') + 1));
else
- request_path (current_path.slice (0, current_path.last_index_of_char ('/') + 1));
+ request_path (SettingsModel.get_parent_path (current_path));
}
// TODO do something when open_child fails (returns false)?
private void go_forward (bool shift)
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index 107916d..81cbe5b 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -137,7 +137,7 @@ class RegistrySearch : Grid, PathElement, BrowsableView
SettingObject setting_object = (SettingObject) item;
string full_name = setting_object.full_name;
string parent_path;
- if (full_name.has_suffix ("/"))
+ if (!SettingsModel.is_key_path (full_name))
parent_path = SettingsModel.get_base_path (full_name [0:full_name.length - 1]);
else
parent_path = SettingsModel.get_base_path (full_name);
@@ -482,7 +482,7 @@ class RegistrySearch : Grid, PathElement, BrowsableView
SettingComparator comparator = browser_view.sorting_options.get_comparator ();
GLib.CompareDataFunc compare = (a, b) => comparator.compare((SettingObject) a, (SettingObject) b);
- if (current_path.has_suffix ("/"))
+ if (!SettingsModel.is_key_path (current_path))
{
Directory? local = model.get_directory (current_path);
if (local != null)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]