[dconf-editor] Move path_requested in DConfWindow.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Move path_requested in DConfWindow.
- Date: Tue, 28 Nov 2017 06:28:44 +0000 (UTC)
commit 8adcb00a16061896d2a11a89d776ed9accbd2878
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Nov 4 06:53:01 2017 +0100
Move path_requested in DConfWindow.
editor/dconf-window.vala | 113 +++++++++++++++++++++++++++++++++-
editor/registry-view.vala | 147 +++++---------------------------------------
2 files changed, 126 insertions(+), 134 deletions(-)
---
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index f980ab2..1ddf775 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -39,6 +39,8 @@ class DConfWindow : ApplicationWindow
public string current_path { private get; set; default = "/"; } // not synced bidi, needed for saving on
destroy, even after child destruction
+ private SettingsModel model = new SettingsModel ();
+
private int window_width = 0;
private int window_height = 0;
private bool window_is_maximized = false;
@@ -131,9 +133,11 @@ class DConfWindow : ApplicationWindow
registry_view.init (settings.get_string ("saved-view"), settings.get_boolean ("restore-view"));
// TODO better?
else
registry_view.init ((!) path, true);
+
+ path_requested (current_path, null, true);
}
- public static string stripped_path (string path)
+ private static string stripped_path (string path)
{
if (path.length <= 1)
return "/";
@@ -233,7 +237,7 @@ class DConfWindow : ApplicationWindow
}
/*\
- * * Path changing
+ * * Directories tree
\*/
[GtkCallback]
@@ -241,8 +245,109 @@ class DConfWindow : ApplicationWindow
{
// registry_view.set_search_mode (false); // TODO not useful when called from bookmark
highcontrast = ("HighContrast" in Gtk.Settings.get_default ().gtk_theme_name);
- registry_view.path_requested (full_name, pathbar.get_selected_child (full_name));
+ path_requested (full_name, pathbar.get_selected_child (full_name));
}
+ private void path_requested (string _full_name, string? selected, bool tolerant = false)
+ {
+ string full_name = _full_name.dup ();
+ string folder_name;
+ if (full_name.has_suffix ("/"))
+ folder_name = full_name;
+ else
+ folder_name = stripped_path (full_name);
+
+ Directory? dir = get_folder (model, folder_name);
+ if (dir == null)
+ {
+ show_notification (_("Cannot find folder “%s”.").printf (folder_name));
+ current_path = "/";
+ registry_view.set_directory (model.get_root_directory (), null);
+ return;
+ }
+
+ if (full_name == folder_name)
+ {
+ registry_view.set_directory ((!) dir, selected);
+ return;
+ }
+
+ string [] names = full_name.split ("/");
+ string object_name = names [names.length - 1];
+ SettingObject? object = get_object_from_name (((!) dir).key_model, object_name, false);
+ if ((object == null) || (((!) object) is Directory))
+ {
+ if ((object != null) && tolerant)
+ {
+ dir = get_folder (model, full_name + "/");
+ if (dir == null)
+ assert_not_reached ();
+
+ registry_view.set_directory ((!) dir, null);
+ return;
+ }
+ else
+ {
+ registry_view.set_directory ((!) dir, null);
+ show_notification (_("Cannot find key “%s” here.").printf (object_name));
+ return;
+ }
+ }
+ if (((!) object) is DConfKey && ((DConfKey) ((!) object)).is_ghost)
+ {
+ registry_view.set_directory ((!) dir, folder_name + object_name);
+ show_notification (_("Key “%s” has been removed.").printf (object_name));
+ return;
+ }
+
+ registry_view.show_properties_view ((Key) ((!) object), full_name, ((!)
dir).warning_multiple_schemas);
+ }
+ private static Directory? get_folder (SettingsModel model, string full_name)
+ {
+ if (full_name == "/")
+ return model.get_root_directory ();
+
+ SettingObject? dir = model.get_root_directory ();
+
+ string [] names = full_name.split ("/");
+ uint index = 1;
+ while (index < names.length - 1)
+ {
+ dir = get_object_from_name (((Directory) (!) dir).key_model, names [index], true);
+ if (dir == null)
+ return null;
+ index++;
+ }
+
+ return (Directory) (!) dir;
+ }
+ private static SettingObject? get_object_from_name (GLib.ListStore key_model, string object_name, bool
searching_a_directory)
+ {
+ SettingObject? existing_directory = null;
+
+ uint position = 0;
+ while (position < key_model.get_n_items ())
+ {
+ SettingObject object = (SettingObject) key_model.get_object (position);
+ if (object.name == object_name)
+ {
+ if (!searching_a_directory)
+ {
+ if (object is Directory)
+ existing_directory = object;
+ else
+ return object;
+ }
+ else if (object is Directory)
+ return object;
+ }
+ position++;
+ }
+ return existing_directory;
+ }
+
+ /*\
+ * * Path changing
+ \*/
public void update_path_elements ()
{
@@ -481,7 +586,7 @@ class DConfWindow : ApplicationWindow
* * Non-existant path notifications
\*/
- public void show_notification (string notification)
+ private void show_notification (string notification)
{
notification_label.set_text (notification);
notification_revealer.set_reveal_child (true);
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index b069ddf..e99c849 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -28,7 +28,6 @@ class RegistryView : Grid, PathElement
[GtkChild] private Revealer multiple_schemas_warning_revealer;
private bool multiple_schemas_warning_needed;
- private SettingsModel model = new SettingsModel ();
private Directory current_directory;
[GtkChild] private Stack stack;
@@ -86,7 +85,6 @@ class RegistryView : Grid, PathElement
public void init (string path, bool restore_view) // TODO check path format
{
current_path = (restore_view && path != "" && path [0] == '/') ? path : "/";
- path_requested (current_path, null, true);
sorting_options.notify.connect (() => {
if (!is_not_browsing_view () && current_directory.need_sorting (sorting_options))
@@ -98,6 +96,20 @@ class RegistryView : Grid, PathElement
* * Stack switching
\*/
+ public void set_directory (Directory directory, string? selected)
+ {
+ current_directory = directory;
+
+ current_directory.sort_key_model (sorting_options);
+ key_model = current_directory.key_model;
+
+ multiple_schemas_warning_needed = current_directory.warning_multiple_schemas;
+
+ key_list_box.bind_model (key_model, new_list_box_row);
+
+ show_browse_view (directory.full_name, selected);
+ }
+
private void show_browse_view (string path, string? selected, bool grab_focus = true)
{
stack.set_transition_type (current_path.has_prefix (path) ? StackTransitionType.CROSSFADE :
StackTransitionType.NONE);
@@ -147,9 +159,10 @@ class RegistryView : Grid, PathElement
key_list_box.get_adjustment ().set_value (row_allocation.y + (int) ((row_allocation.height -
list_allocation.height) / 2.0));
}
-
- private void show_properties_view (string path)
+ public void show_properties_view (Key key, string path, bool warning_multiple_schemas)
{
+ properties_view.populate_properties_list_box (key, warning_multiple_schemas);
+
need_reload_warning_revealer.set_reveal_child (false);
multiple_schemas_warning_revealer.set_reveal_child (false);
@@ -167,132 +180,6 @@ class RegistryView : Grid, PathElement
}
/*\
- * * Directories tree
- \*/
-
- private void dir_selected_cb ()
- {
- current_directory.sort_key_model (sorting_options);
- key_model = current_directory.key_model;
-
- multiple_schemas_warning_needed = current_directory.warning_multiple_schemas;
-
- key_list_box.bind_model (key_model, new_list_box_row);
- }
-
- public void path_requested (string _full_name, string? selected, bool tolerant = false)
- {
- string full_name = _full_name.dup ();
- string folder_name;
- if (full_name.has_suffix ("/"))
- folder_name = full_name;
- else
- folder_name = DConfWindow.stripped_path (full_name);
-
- if (!select_folder (folder_name))
- {
- window.show_notification (_("Cannot find folder “%s”.").printf (folder_name));
- current_path = "/";
- current_directory = model.get_root_directory ();
- dir_selected_cb ();
- show_browse_view ("/", null);
- return;
- }
-
- if (full_name == folder_name)
- {
- show_browse_view (full_name, selected);
- return;
- }
-
- string [] names = full_name.split ("/");
- string object_name = names [names.length - 1];
- SettingObject? object = get_object_from_name (object_name);
- if ((object == null) || (((!) object) is Directory))
- {
- if ((object != null) && tolerant)
- {
- if (!select_folder (full_name + "/"))
- assert_not_reached ();
- show_browse_view (full_name + "/", null);
- }
- else
- {
- show_browse_view (folder_name, null);
- window.show_notification (_("Cannot find key “%s” here.").printf (object_name));
- }
- return;
- }
- if (((!) object) is DConfKey && ((DConfKey) ((!) object)).is_ghost)
- {
- show_browse_view (folder_name, folder_name + object_name);
- window.show_notification (_("Key “%s” has been removed.").printf (object_name));
- return;
- }
-
- properties_view.populate_properties_list_box ((Key) ((!) object),
current_directory.warning_multiple_schemas);
- show_properties_view (full_name);
- }
- private bool select_folder (string full_name)
- {
- if (full_name == "/")
- {
- current_directory = model.get_root_directory ();
- dir_selected_cb ();
- return true;
- }
-
- Directory? dir = model.get_root_directory ();
-
- string [] names = full_name.split ("/");
- uint index = 1;
- while (index < names.length - 1)
- {
- ((!) dir).sort_key_model (sorting_options);
- dir = get_directory (((!) dir).key_model, names [index]);
- if (dir == null)
- return false;
- index++;
- }
-
- current_directory = (!) dir;
- dir_selected_cb ();
- return true;
- }
- private Directory? get_directory (GLib.ListStore dir_key_model, string object_name)
- {
- uint position = 0;
- while (position < dir_key_model.get_n_items ())
- {
- SettingObject object = (SettingObject) dir_key_model.get_object (position);
- if ((object is Directory) && (object.name == object_name))
- return (Directory) object;
- position++;
- }
- return null;
- }
- private SettingObject? get_object_from_name (string object_name)
- requires (key_model != null)
- {
- SettingObject? directory_exists = null;
-
- uint position = 0;
- while (position < ((!) key_model).get_n_items ())
- {
- SettingObject object = (SettingObject) ((!) key_model).get_object (position);
- if (object.name == object_name)
- {
- if (object is Directory)
- directory_exists = object;
- else
- return object;
- }
- position++;
- }
- return directory_exists;
- }
-
- /*\
* * Key ListBox
\*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]