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



commit d593788a64b2cecb6cc1156765c5fa9620ee7278
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.

 data/theme/gnome-shell-high-contrast.css |  4 +++
 data/theme/gnome-shell-sass              |  2 +-
 data/theme/gnome-shell.css               |  4 +++
 js/ui/keyboard.js                        | 48 +++++++++++++++++++++++++++++++-
 4 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/data/theme/gnome-shell-high-contrast.css b/data/theme/gnome-shell-high-contrast.css
index bab0101a7..17f659557 100644
--- a/data/theme/gnome-shell-high-contrast.css
+++ b/data/theme/gnome-shell-high-contrast.css
@@ -1503,6 +1503,10 @@ StScrollBar {
     border-width: 0; }
 
 /* On-screen Keyboard */
+.word-suggestions {
+  font-size: 14pt;
+  spacing: 12px; }
+
 #keyboard {
   background-color: rgba(46, 52, 54, 0.7); }
 
diff --git a/data/theme/gnome-shell-sass b/data/theme/gnome-shell-sass
index 08973e0e1..683a50b92 160000
--- a/data/theme/gnome-shell-sass
+++ b/data/theme/gnome-shell-sass
@@ -1 +1 @@
-Subproject commit 08973e0e16de468bc7a1cc1085f2e17153b74609
+Subproject commit 683a50b928067732a50dcfabb57ae7d302f38849
diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css
index 9eb44a53d..edaa2aec5 100644
--- a/data/theme/gnome-shell.css
+++ b/data/theme/gnome-shell.css
@@ -1503,6 +1503,10 @@ StScrollBar {
     border-width: 0; }
 
 /* On-screen Keyboard */
+.word-suggestions {
+  font-size: 14pt;
+  spacing: 12px; }
+
 #keyboard {
   background-color: rgba(46, 52, 54, 0.7); }
 
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index eb6a0ebd1..140762fb9 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',
 
@@ -256,6 +279,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) {
@@ -427,6 +451,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
@@ -678,7 +710,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) {
@@ -833,6 +865,20 @@ var Keyboard = new Lang.Class({
         this._capturedPress = false;
     },
 
+    resetSuggestions: function(suggestions) {
+        if (!this._suggestions)
+            return;
+        this._suggestions.clear();
+        this._suggestions.actor.hide();
+    },
+
+    addSuggestion: function(text, callback) {
+        if (!this._suggestions)
+            return;
+        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]