[gnome-shell] search: Define SearchResultInterface and implement valid results with it



commit 91a51331163b7e1ef6c13cbd787d45c396eb6cea
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date:   Wed Oct 16 12:38:48 2019 +0200

    search: Define SearchResultInterface and implement valid results with it
    
    Since all the search result classes are now GObject classes, we can enforce
    the methods we want to have in there (just activate() for now) using an
    interface, to make sure they are implementing what we require and to easily
    group all the classes that can be used as search results, even though they
    are not extending SearchResult.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559

 js/ui/appDisplay.js |  1 +
 js/ui/search.js     | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 6edf03c406..6ffe58b6c4 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -2035,6 +2035,7 @@ var AppFolderPopup = GObject.registerClass({
 
 var AppIcon = GObject.registerClass({
     GTypeName: 'AppDisplay_AppIcon',
+    Implements: [Search.SearchResultInterface],
     Signals: {
         'menu-state-changed': { param_types: [GObject.TYPE_BOOLEAN] },
         'sync-tooltip': {},
diff --git a/js/ui/search.js b/js/ui/search.js
index 7e7645a3db..169ceab8a3 100644
--- a/js/ui/search.js
+++ b/js/ui/search.js
@@ -1,5 +1,5 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-/* exported SearchResultsView */
+/* exported SearchResultsView, SearchResultInterface */
 
 const { Clutter, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
 
@@ -32,8 +32,17 @@ class MaxWidthBox extends St.BoxLayout {
     }
 });
 
-var SearchResult = GObject.registerClass(
-class SearchResult extends St.Button {
+var SearchResultInterface = GObject.registerClass({
+    Requires: [Clutter.Actor],
+}, class SearchResultInterface extends GObject.Interface {
+    activate() {
+        throw new GObject.NotImplementedError('activate in %s'.format(this.constructor.name));
+    }
+});
+
+var SearchResult = GObject.registerClass({
+    Implements: [SearchResultInterface]
+}, class SearchResult extends St.Button {
     _init(provider, metaInfo, resultsView) {
         this.provider = provider;
         this.metaInfo = metaInfo;
@@ -242,6 +251,8 @@ var SearchResultsBase = GObject.registerClass({
                 metasNeeded.forEach((resultId, i) => {
                     let meta = metas[i];
                     let display = this._createResultDisplay(meta);
+                    if (!(display instanceof SearchResultInterface))
+                        throw new Error(`${display} is not a valid search result`);
                     display.connect('key-focus-in', this._keyFocusIn.bind(this));
                     this._resultDisplays[resultId] = display;
                 });


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