[dconf-editor] Fun with command-line.



commit 1651195bdbc61334386ac4076578911b716eeb34
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Dec 9 12:34:06 2017 +0100

    Fun with command-line.

 editor/dconf-editor.vala |   21 +++++++++++----------
 editor/dconf-window.vala |    8 +++++---
 2 files changed, 16 insertions(+), 13 deletions(-)
---
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index d9bcf04..f6211fd 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -17,6 +17,9 @@
 
 class ConfigurationEditor : Gtk.Application
 {
+    [CCode (cname = "G_OPTION_REMAINING")]
+    extern const string OPTION_REMAINING;
+
     public static string [,] known_mappings = {
             {"com.gexperts.Tilix.Profile",
                 "/com/gexperts/Tilix/profiles//"},
@@ -116,6 +119,7 @@ class ConfigurationEditor : Gtk.Application
         };
 
     private static bool disable_warning = false;
+    private static string [] remaining = new string [3];
 
     private const OptionEntry [] option_entries =
     {
@@ -123,6 +127,8 @@ class ConfigurationEditor : Gtk.Application
         { "list-relocatable-schemas", 0, 0, OptionArg.NONE, null, N_("Print relocatable schemas and exit"), 
null },
 
         { "I-understand-that-changing-options-can-break-applications", 0, 0, OptionArg.NONE, ref 
disable_warning, N_("Do not show initial warning"), null },
+
+        { OPTION_REMAINING, 0, 0, OptionArg.STRING_ARRAY, ref remaining, "args", N_("[PATH|FIXED_SCHEMA 
[KEY]|RELOCATABLE_SCHEMA:PATH [KEY]]") },
         {}
     };
 
@@ -279,29 +285,24 @@ class ConfigurationEditor : Gtk.Application
 
     protected override int command_line (ApplicationCommandLine commands)
     {
-        string [] args = commands.get_arguments ();
+        string [] args = {};
+        foreach (string? i in remaining)
+            if (i != null)
+                args += (!) i;
 
         if (args.length == 0)
         {
-            assert_not_reached ();
-            simple_activation ();
-            return Posix.EXIT_FAILURE;
-        }
-        if (args.length == 1)   // ['dconf-editor']
-        {
             simple_activation ();
             return Posix.EXIT_SUCCESS;
         }
         Gtk.Window? test_window = get_active_window ();
-        if (args.length > 1 && test_window != null)
+        if (test_window != null)
         {
             commands.print (_("Only one window can be opened for now.\n"));
             ((!) test_window).present ();
             return Posix.EXIT_FAILURE;
         }
 
-        args = args [1:args.length];
-
         string arg0 = args [0];
         if (" " in arg0)
         {
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 095a889..20a8afa 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -150,9 +150,11 @@ class DConfWindow : ApplicationWindow
                 warning (_("Schema is relocatable, a path is needed."));
                 browser_view.init (settings.get_string ("saved-view"), settings.get_boolean 
("restore-view"));  // TODO better?
             }
-            model.add_mapping ((!) schema, (!) path);
-
-            browser_view.init (key_name == null ? (!) path : (!) path + (!) key_name, true);
+            else
+            {
+                model.add_mapping ((!) schema, (!) path);
+                browser_view.init (key_name == null ? (!) path : (!) path + (!) key_name, true);
+            }
         }
         else if (model.is_non_relocatable_schema ((!) schema))
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]