[sushi: 1/3] Emit SelectionEvent D-Bus signal when required



commit 5ac853bea2734cce9d3973eb605a9d9d68c84736
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Jul 6 22:56:31 2019 -0700

    Emit SelectionEvent D-Bus signal when required
    
    When the arrow keys are used in the preview window, emit a signal over
    D-Bus which can be caught by Nautilus to update our preview file.
    
    https://gitlab.gnome.org/GNOME/sushi/issues/5

 src/org.gnome.NautilusPreviewer2.xml |  3 +++
 src/ui/application.js                | 11 ++++++++++-
 src/ui/mainWindow.js                 | 15 +++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/src/org.gnome.NautilusPreviewer2.xml b/src/org.gnome.NautilusPreviewer2.xml
index 41d79de..c9f0baa 100644
--- a/src/org.gnome.NautilusPreviewer2.xml
+++ b/src/org.gnome.NautilusPreviewer2.xml
@@ -7,5 +7,8 @@
     </method>
     <method name="Close">
     </method>
+    <signal name="SelectionEvent">
+      <arg type="q" name="direction" />
+    </signal>
   </interface>
 </node>
diff --git a/src/ui/application.js b/src/ui/application.js
index 90ce116..ba96031 100644
--- a/src/ui/application.js
+++ b/src/ui/application.js
@@ -23,7 +23,7 @@
  *
  */
 
-const {Gdk, Gio, GObject, Gtk} = imports.gi;
+const {Gio, GLib, GObject, Gtk} = imports.gi;
 
 const ByteArray = imports.byteArray;
 
@@ -38,6 +38,10 @@ var NautilusPreviewerSkeleton = class {
             ByteArray.toString(bytes.toArray()), this);
     }
 
+    get impl() {
+        return this._skeleton;
+    }
+
     export(connection, path) {
         try {
             this._skeleton.export(connection, path);
@@ -124,6 +128,11 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
             this._mainWindow.destroy();
     }
 
+    emitSelectionEvent(direction) {
+        this._skeleton2.impl.emit_signal(
+            'SelectionEvent', new GLib.Variant('(u)', [direction]));
+    }
+
     showFile(uri, windowHandle, closeIfAlreadyShown) {
         this._ensureMainWindow();
 
diff --git a/src/ui/mainWindow.js b/src/ui/mainWindow.js
index 530bb5e..b4906e7 100644
--- a/src/ui/mainWindow.js
+++ b/src/ui/mainWindow.js
@@ -176,6 +176,21 @@ var MainWindow = GObject.registerClass(class MainWindow extends Gtk.ApplicationW
         });
         this.application.set_accels_for_action('win.fullscreen', ['f', 'F11']);
         this.add_action(fullscreen);
+
+        var _addSelectAction = ((name, accel, direction) => {
+            let action = new Gio.SimpleAction({ name: name });
+            action.connect('activate', () => {
+                this.application.emitSelectionEvent(direction);
+            });
+
+            this.application.set_accels_for_action(`win.${name}`, [accel]);
+            this.add_action(action);
+        });
+
+        _addSelectAction('select-left', 'Left', Gtk.DirectionType.LEFT);
+        _addSelectAction('select-right', 'Right', Gtk.DirectionType.RIGHT);
+        _addSelectAction('select-up', 'Up', Gtk.DirectionType.UP);
+        _addSelectAction('select-down', 'Down', Gtk.DirectionType.DOWN);
     }
 
     _onButtonPressEvent(window, event) {


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