[dconf-editor] Rework command-line.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Rework command-line.
- Date: Mon, 4 Dec 2017 00:49:18 +0000 (UTC)
commit 012a17d5b61a44a5afc716e3fd5b8eef03498247
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Dec 4 01:48:49 2017 +0100
Rework command-line.
editor/dconf-editor.vala | 134 ++++++++++++++++++++++++++++++++++------------
editor/dconf-model.vala | 45 +++++++++++++++
editor/dconf-window.vala | 53 ++++++++++++++++--
3 files changed, 192 insertions(+), 40 deletions(-)
---
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index f4356e4..20d577c 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -120,53 +120,117 @@ class ConfigurationEditor : Gtk.Application
{
string [] args = commands.get_arguments ();
- switch (args.length)
+ if (args.length == 0)
{
- case 0 :
- assert_not_reached ();
+ assert_not_reached ();
+ simple_activation ();
+ return Posix.EXIT_FAILURE;
+ }
+ if (args.length == 1) // ['dconf-editor']
+ {
+ simple_activation ();
+ return Posix.EXIT_SUCCESS;
+ }
+ if (args.length > 1 && !first_window)
+ {
+ commands.print (_("Only one window can be opened for now.\n"));
+ get_active_window ().present ();
+ return Posix.EXIT_FAILURE;
+ }
+
+ args = args [1:args.length];
+
+ string arg0 = args [0];
+ if (" " in arg0)
+ {
+ if (args.length == 1)
+ {
+ args = arg0.split (" ");
+ arg0 = args [0];
+ }
+ else
+ return failure_space (commands);
+ }
+
+ if (args.length > 2)
+ {
+ commands.print (_("Cannot understand: too much arguments.\n"));
+ simple_activation ();
+ return Posix.EXIT_FAILURE;
+ }
+
+ int ret = Posix.EXIT_SUCCESS;
+
+ if (arg0.has_prefix ("/"))
+ {
+ if (args.length == 2)
+ {
+ commands.print (_("Cannot understand second argument in this context.\n"));
+ ret = Posix.EXIT_FAILURE;
+ }
+ DConfWindow window = new DConfWindow (disable_warning, null, arg0, null);
+ add_window (window);
+ first_window = false;
+ window.present ();
+ return ret;
+ }
+
+ string? key_name = null;
- case 1 : // ['dconf-editor']
+ if (args.length == 2)
+ {
+ key_name = args [1];
+ if (" " in (!) key_name)
+ return failure_space (commands);
+ if ("/" in (!) key_name)
+ {
+ commands.print (_("Cannot understand: slash character in second argument.\n"));
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 (disable_warning, 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"));
+ return Posix.EXIT_FAILURE;
+ }
+ }
+
+ string [] test_format = arg0.split (":");
+
+ if (test_format.length > 2)
+ {
+ commands.print (_("Cannot understand: too many colons.\n"));
+ simple_activation ();
+ return Posix.EXIT_FAILURE;
+ }
+
+ string? path = null;
+
+ if (test_format.length == 2)
+ {
+ path = test_format [1];
+ if (!((!) path).has_prefix ("/") || !((!) path).has_suffix ("/"))
+ {
+ commands.print (_("Schema path should start and end with a “/”.\n"));
simple_activation ();
return Posix.EXIT_FAILURE;
+ }
}
+
+ DConfWindow window = new DConfWindow (disable_warning, test_format [0], path, key_name);
+ add_window (window);
+ first_window = false;
+ window.present ();
+ return ret;
+ }
+
+ private int failure_space (ApplicationCommandLine commands)
+ {
+ commands.print (_("Cannot understand: space character in argument.\n"));
+ simple_activation ();
+ return Posix.EXIT_FAILURE;
}
private void simple_activation ()
{
if (first_window)
{
- add_window (new DConfWindow (disable_warning, null));
+ add_window (new DConfWindow (disable_warning, null, null, null));
first_window = false;
}
get_active_window ().present ();
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 6c41a03..2e6293e 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -776,6 +776,51 @@ public class SettingsModel : Object
}
/*\
+ * * Schemas manipulation
+ \*/
+
+ public bool is_relocatable_schema (string id)
+ {
+ string [] non_relocatable_schemas;
+ string [] relocatable_schemas;
+
+ SettingsSchemaSource? settings_schema_source = SettingsSchemaSource.get_default ();
+ if (settings_schema_source == null)
+ return false; // TODO better
+
+ ((!) settings_schema_source).list_schemas (true, out non_relocatable_schemas, out
relocatable_schemas);
+
+ return (id in relocatable_schemas);
+ }
+
+ public bool is_non_relocatable_schema (string id)
+ {
+ string [] non_relocatable_schemas;
+ string [] relocatable_schemas;
+
+ SettingsSchemaSource? settings_schema_source = SettingsSchemaSource.get_default ();
+ if (settings_schema_source == null)
+ return false; // TODO better
+
+ ((!) settings_schema_source).list_schemas (true, out non_relocatable_schemas, out
relocatable_schemas);
+
+ return (id in non_relocatable_schemas);
+ }
+
+ public string? get_schema_path (string id)
+ {
+ SettingsSchemaSource? settings_schema_source = SettingsSchemaSource.get_default ();
+ if (settings_schema_source == null)
+ return null; // TODO better
+
+ SettingsSchema? schema = ((!) settings_schema_source).lookup (id, true);
+ if (schema == null)
+ return null;
+
+ return ((!) schema).get_path ();
+ }
+
+ /*\
* * Path requests
\*/
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 19cd4c8..92e3842 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -72,7 +72,7 @@ class DConfWindow : ApplicationWindow
private ulong small_keys_list_rows_handler = 0;
private ulong small_bookmarks_rows_handler = 0;
- public DConfWindow (bool disable_warning, string? path)
+ public DConfWindow (bool disable_warning, string? schema, string? path, string? key_name)
{
model = new SettingsModel (settings);
@@ -129,10 +129,53 @@ class DConfWindow : ApplicationWindow
settings.bind ("mouse-forward-button", this, "mouse-forward-button",
SettingsBindFlags.GET|SettingsBindFlags.NO_SENSITIVITY);
/* init current_path */
- if (path == null)
- browser_view.init (settings.get_string ("saved-view"), settings.get_boolean ("restore-view"));
// TODO better?
+ bool strict = false;
+ if (schema == null)
+ {
+ if (key_name != null)
+ assert_not_reached ();
+
+ if (path == null)
+ browser_view.init (settings.get_string ("saved-view"), settings.get_boolean
("restore-view")); // TODO better?
+ else
+ browser_view.init ((!) path, true);
+ }
+ else if (model.is_relocatable_schema ((!) schema))
+ {
+ if (path == null)
+ {
+ warning (_("Schema is relocatable, a path is needed."));
+ browser_view.init (settings.get_string ("saved-view"), settings.get_boolean
("restore-view")); // TODO better?
+ }
+ // TODO automatically map schema to path
+ else if (key_name == null)
+ browser_view.init ((!) path, true);
+ else
+ browser_view.init ((!) path + (!) key_name, true);
+ }
+ else if (model.is_non_relocatable_schema ((!) schema))
+ {
+ string? schema_path = model.get_schema_path ((!) schema);
+ if (schema_path == null) // something wrong is happening
+ browser_view.init (settings.get_string ("saved-view"), settings.get_boolean
("restore-view")); // TODO better?
+ else if (path != null && path != schema_path)
+ {
+ warning (_("Schema is not installed on given path."));
+ browser_view.init (settings.get_string ("saved-view"), settings.get_boolean
("restore-view")); // TODO better?
+ }
+ else if (key_name == null)
+ browser_view.init ((!) schema_path, true);
+ else
+ {
+ strict = true;
+ browser_view.init ((!) schema_path + (!) key_name, true);
+ }
+ }
else
- browser_view.init ((!) path, true);
+ {
+ warning ("Unknown schema %s.".printf ((!) schema));
+ browser_view.init (settings.get_string ("saved-view"), settings.get_boolean ("restore-view"));
// TODO better?
+ }
/* go to directory */
string folder_name = SettingsModel.get_base_path (current_path);
@@ -164,7 +207,7 @@ class DConfWindow : ApplicationWindow
}
else
{
- if (existing_dir != null)
+ if (!strict && existing_dir != null)
browser_view.set_directory ((!) existing_dir, null);
else
cannot_find_key (object_name, (!) dir);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]