[gnome-documents] application: Allow to open previews from the command line



commit e5f507d922d22f7ccd55e25d8ebca9009e465806
Author: Florian MÃllner <fmuellner gnome org>
Date:   Thu Dec 1 14:58:16 2011 +0100

    application: Allow to open previews from the command line
    
    Allow to pass in a URN on the command line and handle it in the
    primary instance. This will be used by the gnome-shell search
    provider to open search results.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=665300

 src/application.js     |   28 +++++++++++++++++++++++++++-
 src/gnome-documents.in |    2 +-
 src/main.js            |    2 +-
 3 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 37ad66f..1385adf 100644
--- a/src/application.js
+++ b/src/application.js
@@ -59,9 +59,11 @@ Application.prototype = {
         // TODO: subclass Gtk.Application once we support GObject inheritance,
         //       see https://bugzilla.gnome.org/show_bug.cgi?id=663492
         this.application = new Gtk.Application({
-            application_id: 'org.gnome.Documents'
+            application_id: 'org.gnome.Documents',
+            flags: Gio.ApplicationFlags.HANDLES_COMMAND_LINE
         });
         this.application.connect('startup', Lang.bind(this, this._onStartup));
+        this.application.connect('command-line', Lang.bind(this, this._commandLine));
         this.application.connect('activate', Lang.bind(this,
             function() {
                 this._mainWindow.window.present();
@@ -114,5 +116,29 @@ Application.prototype = {
 
         this._mainWindow = new MainWindow.MainWindow();
         this.application.add_window(this._mainWindow.window);
+    },
+
+    _commandLine: function(app, commandLine) {
+        app.activate();
+
+        let args = commandLine.get_arguments();
+        if (args.length) {
+            let urn = args[0]; // gjs eats argv[0]
+            let doc = Global.documentManager.getItemById(args[0]);
+            if (doc) {
+                Global.documentManager.setActiveItem(doc);
+            } else {
+                let job = new Documents.SingleItemJob(urn);
+                job.run(Query.QueryFlags.UNFILTERED, Lang.bind(this,
+                    function(cursor) {
+                        if (!cursor)
+                            return;
+                        let doc = Global.documentManager.createDocumentFromCursor(cursor);
+                        Global.documentManager.addItem(doc);
+                        Global.documentManager.setActiveItem(doc);
+                    }));
+            }
+        }
+        return 0;
     }
 };
diff --git a/src/gnome-documents.in b/src/gnome-documents.in
index 728d2f7..48a3d7b 100644
--- a/src/gnome-documents.in
+++ b/src/gnome-documents.in
@@ -12,4 +12,4 @@ else
     export GI_TYPELIB_PATH= libdir@/girepository-1.0:$GI_TYPELIB_PATH
 fi
 
- GJS_CONSOLE@ -I @pkgdatadir@/js -c "const Main = imports.main; Main.start();"
+ GJS_CONSOLE@ -I @pkgdatadir@/js -c "const Main = imports.main; Main.start();" "$@"
diff --git a/src/main.js b/src/main.js
index de17463..3ae7cf3 100644
--- a/src/main.js
+++ b/src/main.js
@@ -23,5 +23,5 @@ const Application = imports.application;
 
 function start() {
     let application = new Application.Application();
-    application.application.run(null);
+    return application.application.run(ARGV);
 }



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