[gnome-shell/gbsneto/40-stuff: 65/68] Rename ViewSelector to SearchController




commit 66ae3b71f17386688728ec70a36120c661414cb1
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jan 15 09:59:58 2021 -0300

    Rename ViewSelector to SearchController
    
    Rename ViewSelector to SearchController, since ViewSelector now effectively
    only handles search. Rename the file correspondingly as well. I took the
    liberty to sneak in some trivial style fixes.

 js/js-resources.gresource.xml                  |  2 +-
 js/ui/overviewControls.js                      | 31 ++++++------
 js/ui/{viewSelector.js => searchController.js} | 67 ++++++++++++++------------
 po/POTFILES.in                                 |  2 +-
 4 files changed, 54 insertions(+), 48 deletions(-)
---
diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml
index 707df4604b..41f8649ced 100644
--- a/js/js-resources.gresource.xml
+++ b/js/js-resources.gresource.xml
@@ -95,6 +95,7 @@
     <file>ui/screenshot.js</file>
     <file>ui/scripting.js</file>
     <file>ui/search.js</file>
+    <file>ui/searchController.js</file>
     <file>ui/sessionMode.js</file>
     <file>ui/shellDBus.js</file>
     <file>ui/shellEntry.js</file>
@@ -105,7 +106,6 @@
     <file>ui/switchMonitor.js</file>
     <file>ui/unlockDialog.js</file>
     <file>ui/userWidget.js</file>
-    <file>ui/viewSelector.js</file>
     <file>ui/windowAttentionHandler.js</file>
     <file>ui/windowMenu.js</file>
     <file>ui/windowManager.js</file>
diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js
index ba5aa387e1..49f13fc283 100644
--- a/js/ui/overviewControls.js
+++ b/js/ui/overviewControls.js
@@ -6,8 +6,8 @@ const { Clutter, Gio, GObject, Meta, Shell, St } = imports.gi;
 const AppDisplay = imports.ui.appDisplay;
 const Dash = imports.ui.dash;
 const Main = imports.ui.main;
-const ViewSelector = imports.ui.viewSelector;
 const Overview = imports.ui.overview;
+const SearchController = imports.ui.searchController;
 const WindowManager = imports.ui.windowManager;
 const WorkspacesView = imports.ui.workspacesView;
 
@@ -57,14 +57,14 @@ class DashFader extends St.Bin {
 
 var ControlsManagerLayout = GObject.registerClass(
 class ControlsManagerLayout extends Clutter.BinLayout {
-    _init(searchEntry, appDisplay, workspacesDisplay, viewSelector, dash, adjustment) {
+    _init(searchEntry, appDisplay, workspacesDisplay, searchController, dash, adjustment) {
         super._init();
 
         this._appDisplay = appDisplay;
         this._workspacesDisplay = workspacesDisplay;
         this._adjustment = adjustment;
         this._searchEntry = searchEntry;
-        this._viewSelector = viewSelector;
+        this._searchController = searchController;
         this._dash = dash;
 
         adjustment.connect('notify::value', () => this.layout_changed());
@@ -185,10 +185,10 @@ class ControlsManagerLayout extends Clutter.BinLayout {
             this._appDisplay.allocate(initialBox.interpolate(finalBox, progress));
         }
 
-        // ViewSelector
+        // Search
         childBox.set_origin(0, searchHeight + spacing);
         childBox.set_size(width, availableHeight);
-        this._viewSelector.allocate(childBox);
+        this._searchController.allocate(childBox);
     }
 });
 
@@ -282,9 +282,10 @@ class ControlsManager extends St.Widget {
             workspaceManager.connect('notify::n-workspaces',
                 this._updateAdjustment.bind(this));
 
-        this.viewSelector = new ViewSelector.ViewSelector(this._searchEntry,
+        this._searchController = new SearchController.SearchController(
+            this._searchEntry,
             this.dash.showAppsButton);
-        this.viewSelector.connect('notify::searching', this._onSearchChanged.bind(this));
+        this._searchController.connect('notify::searching', this._onSearchChanged.bind(this));
 
         this._workspacesDisplay = new WorkspacesView.WorkspacesDisplay(
             this._workspaceAdjustment,
@@ -294,13 +295,13 @@ class ControlsManager extends St.Widget {
         this.add_child(searchEntryBin);
         this.add_child(this._appDisplay);
         this.add_child(this._dashFader);
-        this.add_child(this.viewSelector);
+        this.add_child(this._searchController);
         this.add_child(this._workspacesDisplay);
 
         this.layout_manager = new ControlsManagerLayout(searchEntryBin,
             this._appDisplay,
             this._workspacesDisplay,
-            this.viewSelector,
+            this._searchController,
             this._dashFader,
             this._adjustment);
 
@@ -344,14 +345,14 @@ class ControlsManager extends St.Widget {
     }
 
     _onSearchChanged() {
-        const { searching } = this.viewSelector;
+        const { searching } = this._searchController;
 
         if (!searching) {
             this._appDisplay.show();
             this._workspacesDisplay.reactive = true;
             this._workspacesDisplay.setPrimaryWorkspaceVisible(true);
         } else {
-            this.viewSelector.show();
+            this._searchController.show();
         }
 
         this._appDisplay.ease({
@@ -369,11 +370,11 @@ class ControlsManager extends St.Widget {
                 this._workspacesDisplay.setPrimaryWorkspaceVisible(!searching);
             },
         });
-        this.viewSelector.ease({
+        this._searchController.ease({
             opacity: searching ? 255 : 0,
             duration: SIDE_CONTROLS_ANIMATION_TIME,
             mode: Clutter.AnimationMode.EASE_OUT_QUAD,
-            onComplete: () => (this.viewSelector.visible = searching),
+            onComplete: () => (this._searchController.visible = searching),
         });
     }
 
@@ -426,7 +427,7 @@ class ControlsManager extends St.Widget {
     animateToOverview(state, onComplete) {
         this._animating = true;
 
-        this.viewSelector.prepareToEnterOverview();
+        this._searchController.prepareToEnterOverview();
         this._workspacesDisplay.prepareToEnterOverview();
         if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows())
             Main.overview.fadeOutDesktop();
@@ -481,7 +482,7 @@ class ControlsManager extends St.Widget {
             : Math.round(progress);
 
         tracker.confirmSwipe(baseDistance, points, progress, cancelProgress);
-        this.viewSelector.prepareToEnterOverview();
+        this._searchController.prepareToEnterOverview();
         this._workspacesDisplay.prepareToEnterOverview();
         if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows())
             Main.overview.fadeInDesktop();
diff --git a/js/ui/viewSelector.js b/js/ui/searchController.js
similarity index 85%
rename from js/ui/viewSelector.js
rename to js/ui/searchController.js
index e54c7dab87..a5be926226 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/searchController.js
@@ -1,7 +1,7 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-/* exported ViewSelector */
+/* exported SearchController */
 
-const { Clutter, GObject, Shell, St } = imports.gi;
+const { Clutter, GObject, St } = imports.gi;
 
 const Main = imports.ui.main;
 const Search = imports.ui.search;
@@ -10,8 +10,8 @@ const ShellEntry = imports.ui.shellEntry;
 var FocusTrap = GObject.registerClass(
 class FocusTrap extends St.Widget {
     vfunc_navigate_focus(from, direction) {
-        if (direction == St.DirectionType.TAB_FORWARD ||
-            direction == St.DirectionType.TAB_BACKWARD)
+        if (direction === St.DirectionType.TAB_FORWARD ||
+            direction === St.DirectionType.TAB_BACKWARD)
             return super.vfunc_navigate_focus(from, direction);
         return false;
     }
@@ -19,25 +19,26 @@ class FocusTrap extends St.Widget {
 
 function getTermsForSearchString(searchString) {
     searchString = searchString.replace(/^\s+/g, '').replace(/\s+$/g, '');
-    if (searchString == '')
+    if (searchString === '')
         return [];
-
-    let terms = searchString.split(/\s+/);
-    return terms;
+    return searchString.split(/\s+/);
 }
 
-var ViewSelector = GObject.registerClass({
+var SearchController = GObject.registerClass({
     Properties: {
         'searching': GObject.ParamSpec.boolean(
             'searching', 'searching', 'searching',
             GObject.ParamFlags.READABLE,
             false),
     },
-}, class ViewSelector extends Shell.Stack {
+}, class SearchController extends St.Widget {
     _init(searchEntry, showAppsButton) {
         super._init({
-            name: 'viewSelector',
+            name: 'searchController',
+            layout_manager: new Clutter.BinLayout(),
+            visible: false,
             x_expand: true,
+            y_expand: true,
         });
 
         this._showAppsButton = showAppsButton;
@@ -69,10 +70,14 @@ var ViewSelector = GObject.registerClass({
         this._entry.connect('notify::mapped', this._onMapped.bind(this));
         global.stage.connect('notify::key-focus', this._onStageKeyFocusChanged.bind(this));
 
-        this._entry.set_primary_icon(new St.Icon({ style_class: 'search-entry-icon',
-                                                   icon_name: 'edit-find-symbolic' }));
-        this._clearIcon = new St.Icon({ style_class: 'search-entry-icon',
-                                        icon_name: 'edit-clear-symbolic' });
+        this._entry.set_primary_icon(new St.Icon({
+            style_class: 'search-entry-icon',
+            icon_name: 'edit-find-symbolic',
+        }));
+        this._clearIcon = new St.Icon({
+            style_class: 'search-entry-icon',
+            icon_name: 'edit-clear-symbolic',
+        });
 
         this._iconClickedId = 0;
         this._capturedEventId = 0;
@@ -94,11 +99,11 @@ var ViewSelector = GObject.registerClass({
 
         this._stageKeyPressId = 0;
         Main.overview.connect('showing', () => {
-            this._stageKeyPressId = global.stage.connect('key-press-event',
-                                                         this._onStageKeyPress.bind(this));
+            this._stageKeyPressId =
+                global.stage.connect('key-press-event', this._onStageKeyPress.bind(this));
         });
         Main.overview.connect('hiding', () => {
-            if (this._stageKeyPressId != 0) {
+            if (this._stageKeyPressId !== 0) {
                 global.stage.disconnect(this._stageKeyPressId);
                 this._stageKeyPressId = 0;
             }
@@ -172,7 +177,7 @@ var ViewSelector = GObject.registerClass({
         // text and one for the new one - the second one is handled
         // incorrectly when we remove focus
         // (https://bugzilla.gnome.org/show_bug.cgi?id=636341) */
-        if (this._text.text != '')
+        if (this._text.text !== '')
             this.reset();
     }
 
@@ -205,8 +210,8 @@ var ViewSelector = GObject.registerClass({
     _onMapped() {
         if (this._entry.mapped) {
             // Enable 'find-as-you-type'
-            this._capturedEventId = global.stage.connect('captured-event',
-                                                         this._onCapturedEvent.bind(this));
+            this._capturedEventId =
+                global.stage.connect('captured-event', this._onCapturedEvent.bind(this));
             this._text.set_cursor_visible(true);
             this._text.set_selection(0, 0);
         } else {
@@ -225,7 +230,7 @@ var ViewSelector = GObject.registerClass({
             return true;
 
         let unicode = Clutter.keysym_to_unicode(symbol);
-        if (unicode == 0)
+        if (unicode === 0)
             return false;
 
         if (getTermsForSearchString(String.fromCharCode(unicode)).length > 0)
@@ -244,7 +249,7 @@ var ViewSelector = GObject.registerClass({
 
     // the entry does not show the hint
     _isActivated() {
-        return this._text.text == this._entry.get_text();
+        return this._text.text === this._entry.get_text();
     }
 
     _onTextChanged() {
@@ -258,9 +263,9 @@ var ViewSelector = GObject.registerClass({
 
             this._entry.set_secondary_icon(this._clearIcon);
 
-            if (this._iconClickedId == 0) {
-                this._iconClickedId = this._entry.connect('secondary-icon-clicked',
-                                                          this.reset.bind(this));
+            if (this._iconClickedId === 0) {
+                this._iconClickedId =
+                    this._entry.connect('secondary-icon-clicked', this.reset.bind(this));
             }
         } else {
             if (this._iconClickedId > 0) {
@@ -282,7 +287,7 @@ var ViewSelector = GObject.registerClass({
             }
         } else if (this._searchActive) {
             let arrowNext, nextDirection;
-            if (entry.get_text_direction() == Clutter.TextDirection.RTL) {
+            if (entry.get_text_direction() === Clutter.TextDirection.RTL) {
                 arrowNext = Clutter.KEY_Left;
                 nextDirection = St.DirectionType.LEFT;
             } else {
@@ -301,7 +306,7 @@ var ViewSelector = GObject.registerClass({
             } else if (symbol === Clutter.KEY_Down) {
                 this._searchResults.navigateFocus(St.DirectionType.DOWN);
                 return Clutter.EVENT_STOP;
-            } else if (symbol == arrowNext && this._text.position == -1) {
+            } else if (symbol === arrowNext && this._text.position === -1) {
                 this._searchResults.navigateFocus(nextDirection);
                 return Clutter.EVENT_STOP;
             } else if (symbol === Clutter.KEY_Return || symbol === Clutter.KEY_KP_Enter) {
@@ -313,11 +318,11 @@ var ViewSelector = GObject.registerClass({
     }
 
     _onCapturedEvent(actor, event) {
-        if (event.type() == Clutter.EventType.BUTTON_PRESS) {
+        if (event.type() === Clutter.EventType.BUTTON_PRESS) {
             let source = event.get_source();
-            if (source != this._text &&
+            if (source !== this._text &&
                 this._text.has_key_focus() &&
-                this._text.text == '' &&
+                this._text.text === '' &&
                 !this._text.has_preedit() &&
                 !Main.layoutManager.keyboardBox.contains(source)) {
                 // the user clicked outside after activating the entry, but
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 745ea58f19..90b5bf09ac 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -48,6 +48,7 @@ js/ui/popupMenu.js
 js/ui/runDialog.js
 js/ui/screenShield.js
 js/ui/search.js
+js/ui/searchController.js
 js/ui/shellEntry.js
 js/ui/shellMountOperation.js
 js/ui/status/accessibility.js
@@ -66,7 +67,6 @@ js/ui/status/thunderbolt.js
 js/ui/status/volume.js
 js/ui/switchMonitor.js
 js/ui/unlockDialog.js
-js/ui/viewSelector.js
 js/ui/windowAttentionHandler.js
 js/ui/windowManager.js
 js/ui/windowMenu.js


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