[gnome-shell/wip/carlosg/osk-cldr: 33/35] keyboard: Add Suggestions object/actor



commit 9b9795240317e1b582b9330480dc571816ce65c1
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Dec 6 13:46:02 2017 +0100

    keyboard: Add Suggestions object/actor
    
    This will display completion suggestions, that when clicked will get the
    text inserted into the current IM focus.

 js/ui/keyboard.js |   44 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index b8f99d9..c497803 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -49,6 +49,29 @@ const defaultKeysPost = [
       [{ label: '🌐', width: 1.5 }, { label: '⌨', width: 1.5, action: 'hide' }] ],
 ];
 
+var Suggestions = new Lang.Class({
+    Name: 'Suggestions',
+
+    _init: function() {
+        this.actor = new St.BoxLayout({ style_class: 'word-suggestions',
+                                        vertical: false });
+        this.actor.hide();
+    },
+
+    add: function(word, callback) {
+        let button = new St.Button({ label: word });
+        button.connect('clicked', callback);
+        this.actor.add(button);
+        this.actor.show();
+    },
+
+    clear: function() {
+        this.actor.remove_all_children();
+        this.actor.hide();
+    },
+});
+Signals.addSignalMethods(Suggestions.prototype);
+
 var Key = new Lang.Class({
     Name: 'Key',
 
@@ -253,6 +276,7 @@ var Keyboard = new Lang.Class({
         this._a11yApplicationsSettings = new Gio.Settings({ schema_id: A11Y_APPLICATIONS_SCHEMA });
         this._a11yApplicationsSettings.connect('changed', Lang.bind(this, this._syncEnabled));
         this._lastDeviceId = null;
+        this._suggestions = null;
 
         Meta.get_backend().connect('last-device-changed', Lang.bind(this,
             function (backend, deviceId) {
@@ -425,6 +449,14 @@ var Keyboard = new Lang.Class({
         this._groups = {};
         this._current_page = null;
 
+        this._suggestions = new Suggestions();
+        this._suggestions.connect('suggestion-clicked', Lang.bind(this, function(suggestions, str) {
+            this._keyboardController.commitString(str);
+        }));
+        this.actor.add(this._suggestions.actor,
+                       { x_align: St.Align.MIDDLE,
+                         x_fill: false });
+
         this._addKeys();
 
         // Keyboard models are defined in LTR, we must override
@@ -670,7 +702,7 @@ var Keyboard = new Lang.Class({
         let keyHeight = Math.floor((maxHeight - allVerticalSpacing - 2 * padding) / numOfVertSlots);
 
         let keySize = Math.min(keyWidth, keyHeight);
-        this.actor.height = keySize * numOfVertSlots + allVerticalSpacing + 2 * padding;
+        layout.height = keySize * numOfVertSlots + allVerticalSpacing + 2 * padding;
 
         let rows = this._current_page.get_children();
         for (let i = 0; i < rows.length; ++i) {
@@ -825,6 +857,16 @@ var Keyboard = new Lang.Class({
         this._capturedPress = false;
     },
 
+    resetSuggestions: function(suggestions) {
+        this._suggestions.clear();
+        this._suggestions.actor.hide();
+    },
+
+    addSuggestion: function(text, callback) {
+        this._suggestions.add(text, callback);
+        this._suggestions.actor.show();
+    },
+
     _moveTemporarily: function () {
         let currentWindow = global.screen.get_display().focus_window;
         let rect = currentWindow.get_frame_rect();


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