[dconf-editor] Allow opening path from command-line.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Allow opening path from command-line.
- Date: Thu, 5 Oct 2017 15:32:08 +0000 (UTC)
commit febde42643fd914a012571701757e8036318817d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Oct 5 17:31:19 2017 +0200
Allow opening path from command-line.
https://bugzilla.gnome.org/show_bug.cgi?id=788460
editor/dconf-editor.vala | 66 ++++++++++++++++++++++++++++++++++++++++++--
editor/dconf-window.vala | 8 ++++-
editor/registry-view.vala | 42 ++++++++++++++++++----------
3 files changed, 96 insertions(+), 20 deletions(-)
---
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index aa2f598..d84f108 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -50,7 +50,7 @@ class ConfigurationEditor : Gtk.Application
public ConfigurationEditor ()
{
- Object (application_id: "ca.desrt.dconf-editor", flags: ApplicationFlags.FLAGS_NONE);
+ Object (application_id: "ca.desrt.dconf-editor", flags: ApplicationFlags.HANDLES_COMMAND_LINE);
add_main_option_entries (option_entries);
}
@@ -80,12 +80,72 @@ class ConfigurationEditor : Gtk.Application
Gdk.Screen? screen = Gdk.Screen.get_default ();
return_if_fail (screen != null);
Gtk.StyleContext.add_provider_for_screen ((!) screen, css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
-
- add_window (new DConfWindow ());
}
+ /*\
+ * * Window activation
+ \*/
+
+ private bool first_window = true;
+
protected override void activate ()
{
+ simple_activation ();
+ }
+
+ protected override int command_line (ApplicationCommandLine commands)
+ {
+ string [] args = commands.get_arguments ();
+
+ switch (args.length)
+ {
+ case 0 :
+ assert_not_reached ();
+
+ case 1 : // ['dconf-editor']
+ simple_activation ();
+ return Posix.EXIT_SUCCESS;
+
+ case 2 :
+ int ret = Posix.EXIT_SUCCESS;
+ if (first_window)
+ {
+ string arg = args [1];
+ string? path = arg;
+
+ if (!arg.has_prefix ("/"))
+ {
+ commands.print (_("Path should start with a '/'.\n"));
+ path = null;
+ ret = Posix.EXIT_FAILURE;
+ }
+ // TODO more tests
+
+ add_window (new DConfWindow (path));
+ first_window = false;
+ }
+ else
+ {
+ commands.print (_("Only one window can be opened for now.\n"));
+ ret = Posix.EXIT_FAILURE;
+ }
+ get_active_window ().present ();
+ return ret;
+
+ default:
+ commands.print (_("Only one argument is accepted for now.\n"));
+ simple_activation ();
+ return Posix.EXIT_FAILURE;
+ }
+ }
+
+ private void simple_activation ()
+ {
+ if (first_window)
+ {
+ add_window (new DConfWindow (null));
+ first_window = false;
+ }
get_active_window ().present ();
}
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index cfd6af5..5ad8e2f 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -59,7 +59,7 @@ class DConfWindow : ApplicationWindow
private ulong small_keys_list_rows_handler = 0;
private ulong small_bookmarks_rows_handler = 0;
- public DConfWindow ()
+ public DConfWindow (string? path)
{
add_action_entries (action_entries, this);
@@ -101,7 +101,11 @@ class DConfWindow : ApplicationWindow
registry_view.bind_property ("current-path", this, "current-path"); // TODO in UI file?
settings.bind ("behaviour", registry_view, "behaviour",
SettingsBindFlags.GET|SettingsBindFlags.NO_SENSITIVITY);
- registry_view.init (settings.get_string ("saved-view"), settings.get_boolean ("restore-view")); //
TODO better?
+
+ if (path == null)
+ registry_view.init (settings.get_string ("saved-view"), settings.get_boolean ("restore-view"));
// TODO better?
+ else
+ registry_view.init ((!) path, true);
}
public static string stripped_path (string path)
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 5f82a36..7c1db5f 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -69,7 +69,7 @@ class RegistryView : Grid, PathElement
dir_tree_view.expand_all ();
current_path = (restore_view && path != "" && path [0] == '/') ? path : "/";
- path_requested (current_path, null);
+ path_requested (current_path, null, true);
application_settings.changed ["sort-case-sensitive"].connect (() => {
if (get_selected_directory ().need_sorting (application_settings.get_boolean
("sort-case-sensitive")))
@@ -168,7 +168,7 @@ class RegistryView : Grid, PathElement
return model.get_root_directory ();
}
- public void path_requested (string _full_name, string? selected)
+ public void path_requested (string _full_name, string? selected, bool tolerant = false)
{
string full_name = _full_name.dup ();
string folder_name;
@@ -192,22 +192,27 @@ class RegistryView : Grid, PathElement
}
string [] names = full_name.split ("/");
- string key_name = names [names.length - 1];
- Key? key = get_key_from_name (key_name);
- if (key == null)
+ string object_name = names [names.length - 1];
+ SettingObject? object = get_object_from_name (object_name);
+ if ((object == null) || (((!) object) is Directory))
{
- show_browse_view (folder_name, null);
- get_dconf_window ().show_notification (_("Cannot find key “%s” here.").printf (key_name));
+ if ((object != null) && tolerant)
+ show_browse_view (folder_name + object_name + "/", null);
+ else
+ {
+ show_browse_view (folder_name, null);
+ get_dconf_window ().show_notification (_("Cannot find key “%s” here.").printf (object_name));
+ }
return;
}
- if (((!) key) is DConfKey && ((DConfKey) ((!) key)).is_ghost)
+ if (((!) object) is DConfKey && ((DConfKey) ((!) object)).is_ghost)
{
- show_browse_view (folder_name, folder_name + key_name);
- get_dconf_window ().show_notification (_("Key “%s” has been removed.").printf (key_name));
+ show_browse_view (folder_name, folder_name + object_name);
+ get_dconf_window ().show_notification (_("Key “%s” has been removed.").printf (object_name));
return;
}
- properties_view.populate_properties_list_box ((!) key);
+ properties_view.populate_properties_list_box ((Key) ((!) object));
show_properties_view (full_name);
}
private bool select_folder (string full_name)
@@ -246,18 +251,25 @@ class RegistryView : Grid, PathElement
assert_not_reached ();
return false;
}
- private Key? get_key_from_name (string key_name)
+ 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 is Key && object.name == key_name)
- return (Key) object;
+ if (object.name == object_name)
+ {
+ if (object is Directory)
+ directory_exists = object;
+ else
+ return object;
+ }
position++;
}
- return null;
+ return directory_exists;
}
private DConfWindow get_dconf_window ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]