2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-11-12 17:45:29 +00:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2012-10-08 16:16:55 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
2011-02-23 19:21:47 +00:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2010-11-12 17:45:29 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
2012-07-28 20:06:46 +00:00
|
|
|
const AppDisplay = imports.ui.appDisplay;
|
2010-11-12 17:45:29 +00:00
|
|
|
const Main = imports.ui.main;
|
2013-01-24 06:35:19 +00:00
|
|
|
const OverviewControls = imports.ui.overviewControls;
|
2012-12-13 22:20:46 +00:00
|
|
|
const Params = imports.misc.params;
|
2012-07-28 20:06:46 +00:00
|
|
|
const RemoteSearch = imports.ui.remoteSearch;
|
2010-11-12 17:45:29 +00:00
|
|
|
const Search = imports.ui.search;
|
|
|
|
const SearchDisplay = imports.ui.searchDisplay;
|
2011-10-11 22:38:24 +00:00
|
|
|
const ShellEntry = imports.ui.shellEntry;
|
2010-11-12 17:45:29 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
2012-07-28 20:06:46 +00:00
|
|
|
const Wanda = imports.ui.wanda;
|
|
|
|
const WorkspacesView = imports.ui.workspacesView;
|
2010-11-12 17:45:29 +00:00
|
|
|
|
2012-10-08 16:16:55 +00:00
|
|
|
const SHELL_KEYBINDINGS_SCHEMA = 'org.gnome.shell.keybindings';
|
2010-11-12 17:45:29 +00:00
|
|
|
|
2013-02-13 21:13:14 +00:00
|
|
|
const ViewPage = {
|
|
|
|
WINDOWS: 1,
|
|
|
|
APPS: 2,
|
|
|
|
SEARCH: 3
|
|
|
|
};
|
|
|
|
|
2012-03-10 00:33:31 +00:00
|
|
|
const FocusTrap = new Lang.Class({
|
|
|
|
Name: 'FocusTrap',
|
|
|
|
Extends: St.Widget,
|
|
|
|
|
|
|
|
vfunc_navigate_focus: function(from, direction) {
|
|
|
|
if (direction == Gtk.DirectionType.TAB_FORWARD ||
|
|
|
|
direction == Gtk.DirectionType.TAB_BACKWARD)
|
|
|
|
return this.parent(from, direction);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-09 02:05:15 +00:00
|
|
|
function getTermsForSearchString(searchString) {
|
|
|
|
searchString = searchString.replace(/^\s+/g, '').replace(/\s+$/g, '');
|
|
|
|
if (searchString == '')
|
|
|
|
return [];
|
|
|
|
|
|
|
|
let terms = searchString.split(/\s+/);
|
|
|
|
return terms;
|
|
|
|
}
|
2012-03-10 00:33:31 +00:00
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
const ViewSelector = new Lang.Class({
|
|
|
|
Name: 'ViewSelector',
|
|
|
|
|
|
|
|
_init : function(searchEntry, showAppsButton) {
|
2012-12-13 22:21:53 +00:00
|
|
|
this.actor = new Shell.Stack({ name: 'viewSelector' });
|
2012-06-21 22:52:56 +00:00
|
|
|
|
2013-02-16 17:55:59 +00:00
|
|
|
this._showAppsBlocked = false;
|
2012-06-21 22:52:56 +00:00
|
|
|
this._showAppsButton = showAppsButton;
|
2012-06-21 22:52:56 +00:00
|
|
|
this._showAppsButton.connect('notify::checked', Lang.bind(this, this._onShowAppsButtonToggled));
|
2012-06-21 22:52:56 +00:00
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
this._activePage = null;
|
2010-11-18 12:51:47 +00:00
|
|
|
|
2012-08-24 16:24:49 +00:00
|
|
|
this._searchActive = false;
|
2010-11-18 12:51:47 +00:00
|
|
|
this._searchTimeoutId = 0;
|
|
|
|
|
|
|
|
this._searchSystem = new Search.SearchSystem();
|
|
|
|
|
2012-07-28 20:47:55 +00:00
|
|
|
this._entry = searchEntry;
|
2011-10-11 22:38:24 +00:00
|
|
|
ShellEntry.addContextMenu(this._entry);
|
2012-06-21 22:52:56 +00:00
|
|
|
|
2011-02-16 18:20:03 +00:00
|
|
|
this._text = this._entry.clutter_text;
|
2012-06-21 22:52:56 +00:00
|
|
|
this._text.connect('text-changed', Lang.bind(this, this._onTextChanged));
|
2011-02-16 18:27:05 +00:00
|
|
|
this._text.connect('key-press-event', Lang.bind(this, this._onKeyPress));
|
2012-06-21 22:52:56 +00:00
|
|
|
this._text.connect('key-focus-in', Lang.bind(this, function() {
|
|
|
|
this._searchResults.highlightDefault(true);
|
|
|
|
}));
|
|
|
|
this._text.connect('key-focus-out', Lang.bind(this, function() {
|
|
|
|
this._searchResults.highlightDefault(false);
|
|
|
|
}));
|
|
|
|
this._entry.connect('notify::mapped', Lang.bind(this, this._onMapped));
|
|
|
|
global.stage.connect('notify::key-focus', Lang.bind(this, this._onStageKeyFocusChanged));
|
2011-02-16 18:20:03 +00:00
|
|
|
|
2013-03-03 18:56:12 +00:00
|
|
|
this._entry.set_primary_icon(new St.Icon({ style_class: 'search-entry-icon',
|
|
|
|
icon_name: 'edit-find-symbolic' }));
|
2013-08-26 22:24:26 +00:00
|
|
|
if (this._entry.get_text_direction() == Clutter.TextDirection.RTL)
|
|
|
|
this._clearIcon = new St.Icon({ style_class: 'search-entry-icon',
|
|
|
|
icon_name: 'edit-clear-rtl-symbolic' });
|
|
|
|
else
|
|
|
|
this._clearIcon = new St.Icon({ style_class: 'search-entry-icon',
|
|
|
|
icon_name: 'edit-clear-symbolic' });
|
2011-02-16 18:20:03 +00:00
|
|
|
|
|
|
|
this._iconClickedId = 0;
|
2012-06-21 22:52:56 +00:00
|
|
|
this._capturedEventId = 0;
|
2011-02-16 18:20:03 +00:00
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
this._workspacesDisplay = new WorkspacesView.WorkspacesDisplay();
|
2012-12-13 22:20:46 +00:00
|
|
|
this._workspacesPage = this._addPage(this._workspacesDisplay.actor,
|
2012-11-20 10:51:56 +00:00
|
|
|
_("Windows"), 'emblem-documents-symbolic');
|
2011-02-16 18:20:03 +00:00
|
|
|
|
2011-07-09 13:30:42 +00:00
|
|
|
this.appDisplay = new AppDisplay.AppDisplay();
|
|
|
|
this._appsPage = this._addPage(this.appDisplay.actor,
|
2012-11-20 10:51:56 +00:00
|
|
|
_("Applications"), 'view-grid-symbolic');
|
2011-02-16 18:20:03 +00:00
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
this._searchResults = new SearchDisplay.SearchResults(this._searchSystem);
|
2012-12-13 22:20:46 +00:00
|
|
|
this._searchPage = this._addPage(this._searchResults.actor,
|
|
|
|
_("Search"), 'edit-find-symbolic',
|
|
|
|
{ a11yFocus: this._entry });
|
2011-02-16 18:20:03 +00:00
|
|
|
|
2012-11-01 14:33:40 +00:00
|
|
|
this._searchSettings = new Gio.Settings({ schema: Search.SEARCH_PROVIDERS_SCHEMA });
|
|
|
|
this._searchSettings.connect('changed::disabled', Lang.bind(this, this._reloadRemoteProviders));
|
2012-11-01 20:18:12 +00:00
|
|
|
this._searchSettings.connect('changed::disable-external', Lang.bind(this, this._reloadRemoteProviders));
|
2012-11-01 19:57:18 +00:00
|
|
|
this._searchSettings.connect('changed::sort-order', Lang.bind(this, this._reloadRemoteProviders));
|
2012-11-01 14:33:40 +00:00
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
// Default search providers
|
|
|
|
// Wanda comes obviously first
|
|
|
|
this.addSearchProvider(new Wanda.WandaSearchProvider());
|
|
|
|
this.addSearchProvider(new AppDisplay.AppSearchProvider());
|
2011-11-12 04:40:56 +00:00
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
// Load remote search providers provided by applications
|
|
|
|
RemoteSearch.loadRemoteSearchProviders(Lang.bind(this, this.addSearchProvider));
|
2011-11-14 03:13:26 +00:00
|
|
|
|
2011-11-12 04:40:56 +00:00
|
|
|
// Since the entry isn't inside the results container we install this
|
|
|
|
// dummy widget as the last results container child so that we can
|
2012-03-10 00:33:31 +00:00
|
|
|
// include the entry in the keynav tab path
|
|
|
|
this._focusTrap = new FocusTrap({ can_focus: true });
|
2011-11-12 04:40:56 +00:00
|
|
|
this._focusTrap.connect('key-focus-in', Lang.bind(this, function() {
|
|
|
|
this._entry.grab_key_focus();
|
|
|
|
}));
|
|
|
|
this._searchResults.actor.add_actor(this._focusTrap);
|
|
|
|
|
|
|
|
global.focus_manager.add_group(this._searchResults.actor);
|
2012-06-21 22:52:56 +00:00
|
|
|
|
|
|
|
this._stageKeyPressId = 0;
|
|
|
|
Main.overview.connect('showing', Lang.bind(this,
|
|
|
|
function () {
|
|
|
|
this._resetShowAppsButton();
|
|
|
|
this._stageKeyPressId = global.stage.connect('key-press-event',
|
|
|
|
Lang.bind(this, this._onStageKeyPress));
|
|
|
|
}));
|
|
|
|
Main.overview.connect('hiding', Lang.bind(this,
|
|
|
|
function () {
|
|
|
|
this._resetShowAppsButton();
|
|
|
|
if (this._stageKeyPressId != 0) {
|
|
|
|
global.stage.disconnect(this._stageKeyPressId);
|
|
|
|
this._stageKeyPressId = 0;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2012-08-16 12:46:23 +00:00
|
|
|
Main.wm.addKeybinding('toggle-application-view',
|
|
|
|
new Gio.Settings({ schema: SHELL_KEYBINDINGS_SCHEMA }),
|
|
|
|
Meta.KeyBindingFlags.NONE,
|
2012-12-12 13:14:13 +00:00
|
|
|
Shell.KeyBindingMode.NORMAL |
|
|
|
|
Shell.KeyBindingMode.OVERVIEW,
|
2012-08-16 12:46:23 +00:00
|
|
|
Lang.bind(this, this._toggleAppsPage));
|
2013-04-17 23:26:06 +00:00
|
|
|
|
|
|
|
Main.wm.addKeybinding('toggle-overview',
|
|
|
|
new Gio.Settings({ schema: SHELL_KEYBINDINGS_SCHEMA }),
|
|
|
|
Meta.KeyBindingFlags.NONE,
|
|
|
|
Shell.KeyBindingMode.NORMAL |
|
|
|
|
Shell.KeyBindingMode.OVERVIEW,
|
|
|
|
Lang.bind(Main.overview, Main.overview.toggle));
|
|
|
|
|
2012-10-08 16:16:55 +00:00
|
|
|
},
|
|
|
|
|
2012-08-16 12:46:23 +00:00
|
|
|
_toggleAppsPage: function() {
|
2012-10-08 16:16:55 +00:00
|
|
|
Main.overview.show();
|
2012-08-16 12:46:23 +00:00
|
|
|
this._showAppsButton.checked = !this._showAppsButton.checked;
|
2012-06-21 22:52:56 +00:00
|
|
|
},
|
|
|
|
|
2013-04-24 17:32:41 +00:00
|
|
|
showApps: function() {
|
|
|
|
Main.overview.show();
|
|
|
|
this._showAppsButton.checked = true;
|
|
|
|
},
|
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
show: function() {
|
2012-06-21 22:52:56 +00:00
|
|
|
this._activePage = this._workspacesPage;
|
|
|
|
|
2013-02-16 17:54:19 +00:00
|
|
|
this.reset();
|
2012-06-21 22:52:56 +00:00
|
|
|
this._appsPage.hide();
|
|
|
|
this._searchPage.hide();
|
2012-06-21 22:52:56 +00:00
|
|
|
this._workspacesDisplay.show();
|
|
|
|
|
|
|
|
if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows())
|
|
|
|
Main.overview.fadeOutDesktop();
|
2012-06-21 22:52:56 +00:00
|
|
|
|
2013-02-16 17:59:54 +00:00
|
|
|
this._showPage(this._workspacesPage, true);
|
2012-06-21 22:52:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
zoomFromOverview: function() {
|
|
|
|
this._workspacesDisplay.zoomFromOverview();
|
|
|
|
|
|
|
|
if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows())
|
|
|
|
Main.overview.fadeInDesktop();
|
2010-11-18 12:51:47 +00:00
|
|
|
},
|
|
|
|
|
2013-02-25 23:25:27 +00:00
|
|
|
setWorkspacesFullGeometry: function(geom) {
|
|
|
|
this._workspacesDisplay.setWorkspacesFullGeometry(geom);
|
2013-02-25 23:11:59 +00:00
|
|
|
},
|
|
|
|
|
2010-11-18 12:51:47 +00:00
|
|
|
hide: function() {
|
2012-06-21 22:52:56 +00:00
|
|
|
this._workspacesDisplay.hide();
|
|
|
|
},
|
|
|
|
|
2012-12-13 22:20:46 +00:00
|
|
|
_addPage: function(actor, name, a11yIcon, params) {
|
|
|
|
params = Params.parse(params, { a11yFocus: null });
|
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
let page = new St.Bin({ child: actor,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START,
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
2012-12-13 22:20:46 +00:00
|
|
|
if (params.a11yFocus)
|
|
|
|
Main.ctrlAltTabManager.addGroup(params.a11yFocus, name, a11yIcon);
|
2012-06-21 22:52:56 +00:00
|
|
|
else
|
|
|
|
Main.ctrlAltTabManager.addGroup(actor, name, a11yIcon,
|
|
|
|
{ proxy: this.actor,
|
|
|
|
focusCallback: Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._a11yFocusPage(page);
|
|
|
|
})
|
|
|
|
});;
|
2012-12-13 22:21:53 +00:00
|
|
|
this.actor.add_actor(page);
|
2012-11-01 13:45:04 +00:00
|
|
|
return page;
|
2012-06-21 22:52:56 +00:00
|
|
|
},
|
|
|
|
|
2013-02-16 17:59:54 +00:00
|
|
|
_fadePageIn: function(oldPage) {
|
|
|
|
if (oldPage)
|
|
|
|
oldPage.hide();
|
|
|
|
|
2013-02-16 01:43:45 +00:00
|
|
|
this.emit('page-empty');
|
|
|
|
|
2013-01-24 06:35:19 +00:00
|
|
|
this._activePage.show();
|
|
|
|
Tweener.addTween(this._activePage,
|
|
|
|
{ opacity: 255,
|
2013-02-18 05:17:56 +00:00
|
|
|
time: OverviewControls.SIDE_CONTROLS_ANIMATION_TIME,
|
2013-01-24 06:35:19 +00:00
|
|
|
transition: 'easeOutQuad'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-02-16 17:59:54 +00:00
|
|
|
_showPage: function(page, noFade) {
|
2013-01-24 21:35:11 +00:00
|
|
|
if (page == this._activePage)
|
2012-06-21 22:52:56 +00:00
|
|
|
return;
|
2012-06-21 22:52:56 +00:00
|
|
|
|
2013-01-24 21:35:11 +00:00
|
|
|
let oldPage = this._activePage;
|
2013-01-24 06:35:19 +00:00
|
|
|
this._activePage = page;
|
|
|
|
this.emit('page-changed');
|
|
|
|
|
2013-02-16 17:59:54 +00:00
|
|
|
if (oldPage && !noFade)
|
2013-01-24 21:35:11 +00:00
|
|
|
Tweener.addTween(oldPage,
|
2012-06-21 22:52:56 +00:00
|
|
|
{ opacity: 0,
|
2013-02-18 05:17:56 +00:00
|
|
|
time: OverviewControls.SIDE_CONTROLS_ANIMATION_TIME,
|
2012-06-21 22:52:56 +00:00
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: Lang.bind(this,
|
|
|
|
function() {
|
2013-02-16 17:59:54 +00:00
|
|
|
this._fadePageIn(oldPage);
|
2012-06-21 22:52:56 +00:00
|
|
|
})
|
|
|
|
});
|
2013-01-24 06:35:19 +00:00
|
|
|
else
|
2013-02-16 17:59:54 +00:00
|
|
|
this._fadePageIn(oldPage);
|
2012-06-21 22:52:56 +00:00
|
|
|
},
|
2012-06-21 22:52:56 +00:00
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
_a11yFocusPage: function(page) {
|
|
|
|
this._showAppsButton.checked = page == this._appsPage;
|
|
|
|
page.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
|
2012-06-21 22:52:56 +00:00
|
|
|
},
|
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
_onShowAppsButtonToggled: function() {
|
2013-02-16 17:55:59 +00:00
|
|
|
if (this._showAppsBlocked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._showPage(this._showAppsButton.checked ?
|
|
|
|
this._appsPage : this._workspacesPage);
|
2012-06-21 22:52:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_resetShowAppsButton: function() {
|
2013-02-16 17:55:59 +00:00
|
|
|
this._showAppsBlocked = true;
|
2012-06-21 22:52:56 +00:00
|
|
|
this._showAppsButton.checked = false;
|
2013-02-16 17:55:59 +00:00
|
|
|
this._showAppsBlocked = false;
|
|
|
|
|
|
|
|
this._showPage(this._workspacesPage, true);
|
2012-06-21 22:52:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onStageKeyPress: function(actor, event) {
|
2012-11-12 17:41:14 +00:00
|
|
|
// Ignore events while anything but the overview has
|
|
|
|
// pushed a modal (system modals, looking glass, ...)
|
|
|
|
if (Main.modalCount > 1)
|
|
|
|
return false;
|
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
let modifiers = event.get_state();
|
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
|
|
|
|
if (symbol == Clutter.Escape) {
|
2012-08-24 16:24:49 +00:00
|
|
|
if (this._searchActive)
|
2012-06-21 22:52:56 +00:00
|
|
|
this.reset();
|
2012-08-15 10:20:24 +00:00
|
|
|
else if (this._showAppsButton.checked)
|
2013-02-16 17:50:25 +00:00
|
|
|
this._showAppsButton.checked = false;
|
2012-06-21 22:52:56 +00:00
|
|
|
else
|
|
|
|
Main.overview.hide();
|
|
|
|
return true;
|
2013-02-22 19:56:24 +00:00
|
|
|
} else if (this._shouldTriggerSearch(symbol)) {
|
2012-06-21 22:52:56 +00:00
|
|
|
this.startSearch(event);
|
2012-08-24 16:24:49 +00:00
|
|
|
} else if (!this._searchActive) {
|
2012-08-15 10:03:09 +00:00
|
|
|
if (symbol == Clutter.Tab || symbol == Clutter.Down) {
|
2012-06-21 22:52:56 +00:00
|
|
|
this._activePage.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
|
2012-06-21 22:52:56 +00:00
|
|
|
return true;
|
|
|
|
} else if (symbol == Clutter.ISO_Left_Tab) {
|
2012-06-21 22:52:56 +00:00
|
|
|
this._activePage.navigate_focus(null, Gtk.DirectionType.TAB_BACKWARD, false);
|
2012-06-21 22:52:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_searchCancelled: function() {
|
2012-06-21 22:52:56 +00:00
|
|
|
this._showPage(this._showAppsButton.checked ? this._appsPage
|
|
|
|
: this._workspacesPage);
|
2010-11-18 12:51:47 +00:00
|
|
|
|
2011-04-07 23:10:24 +00:00
|
|
|
// Leave the entry focused when it doesn't have any text;
|
|
|
|
// when replacing a selected search term, Clutter emits
|
|
|
|
// two 'text-changed' signals, one for deleting the previous
|
|
|
|
// 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 != '')
|
2012-02-27 14:17:33 +00:00
|
|
|
this.reset();
|
2011-02-16 18:20:03 +00:00
|
|
|
},
|
|
|
|
|
2012-02-27 14:17:33 +00:00
|
|
|
reset: function () {
|
2011-02-16 18:27:05 +00:00
|
|
|
global.stage.set_key_focus(null);
|
2011-02-16 18:20:03 +00:00
|
|
|
|
2012-02-27 14:17:33 +00:00
|
|
|
this._entry.text = '';
|
|
|
|
|
2011-02-16 18:20:03 +00:00
|
|
|
this._text.set_cursor_visible(true);
|
|
|
|
this._text.set_selection(0, 0);
|
|
|
|
},
|
|
|
|
|
2012-02-27 17:43:59 +00:00
|
|
|
_onStageKeyFocusChanged: function() {
|
2011-02-16 18:20:03 +00:00
|
|
|
let focus = global.stage.get_key_focus();
|
2012-03-10 04:50:17 +00:00
|
|
|
let appearFocused = (this._entry.contains(focus) ||
|
|
|
|
this._searchResults.actor.contains(focus));
|
2012-02-27 17:43:59 +00:00
|
|
|
|
2012-03-10 04:50:17 +00:00
|
|
|
this._text.set_cursor_visible(appearFocused);
|
|
|
|
|
|
|
|
if (appearFocused)
|
|
|
|
this._entry.add_style_pseudo_class('focus');
|
|
|
|
else
|
|
|
|
this._entry.remove_style_pseudo_class('focus');
|
2011-02-16 18:20:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onMapped: function() {
|
|
|
|
if (this._entry.mapped) {
|
|
|
|
// Enable 'find-as-you-type'
|
|
|
|
this._capturedEventId = global.stage.connect('captured-event',
|
|
|
|
Lang.bind(this, this._onCapturedEvent));
|
|
|
|
this._text.set_cursor_visible(true);
|
|
|
|
this._text.set_selection(0, 0);
|
|
|
|
} else {
|
|
|
|
// Disable 'find-as-you-type'
|
|
|
|
if (this._capturedEventId > 0)
|
|
|
|
global.stage.disconnect(this._capturedEventId);
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
}
|
2010-11-18 12:51:47 +00:00
|
|
|
},
|
|
|
|
|
2013-02-22 19:56:24 +00:00
|
|
|
_shouldTriggerSearch: function(symbol) {
|
|
|
|
let unicode = Clutter.keysym_to_unicode(symbol);
|
|
|
|
if (unicode == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (getTermsForSearchString(String.fromCharCode(unicode)).length > 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return symbol == Clutter.BackSpace && this._searchActive;
|
|
|
|
},
|
|
|
|
|
2011-02-16 18:27:05 +00:00
|
|
|
startSearch: function(event) {
|
|
|
|
global.stage.set_key_focus(this._text);
|
2012-09-14 18:04:18 +00:00
|
|
|
this._text.event(event, true);
|
2011-02-16 18:27:05 +00:00
|
|
|
},
|
|
|
|
|
2011-02-16 18:20:03 +00:00
|
|
|
// the entry does not show the hint
|
|
|
|
_isActivated: function() {
|
|
|
|
return this._text.text == this._entry.get_text();
|
|
|
|
},
|
|
|
|
|
2010-11-18 12:51:47 +00:00
|
|
|
_onTextChanged: function (se, prop) {
|
2013-02-09 02:05:15 +00:00
|
|
|
let terms = getTermsForSearchString(this._entry.get_text());
|
|
|
|
|
2012-08-24 16:24:49 +00:00
|
|
|
let searchPreviouslyActive = this._searchActive;
|
2013-02-09 02:05:15 +00:00
|
|
|
this._searchActive = (terms.length > 0);
|
2012-08-24 16:24:49 +00:00
|
|
|
|
|
|
|
let startSearch = this._searchActive && !searchPreviouslyActive;
|
|
|
|
if (startSearch)
|
2010-11-18 12:51:47 +00:00
|
|
|
this._searchResults.startingSearch();
|
2012-08-24 16:24:49 +00:00
|
|
|
|
|
|
|
if (this._searchActive) {
|
2013-03-03 18:56:12 +00:00
|
|
|
this._entry.set_secondary_icon(this._clearIcon);
|
2011-02-16 18:20:03 +00:00
|
|
|
|
2012-08-24 16:24:49 +00:00
|
|
|
if (this._iconClickedId == 0)
|
2011-02-16 18:20:03 +00:00
|
|
|
this._iconClickedId = this._entry.connect('secondary-icon-clicked',
|
2012-08-24 16:24:49 +00:00
|
|
|
Lang.bind(this, this.reset));
|
|
|
|
|
|
|
|
if (this._searchTimeoutId == 0)
|
|
|
|
this._searchTimeoutId = Mainloop.timeout_add(150,
|
|
|
|
Lang.bind(this, this._doSearch));
|
2010-11-18 12:51:47 +00:00
|
|
|
} else {
|
2012-08-24 16:24:49 +00:00
|
|
|
if (this._iconClickedId > 0) {
|
2011-02-16 18:20:03 +00:00
|
|
|
this._entry.disconnect(this._iconClickedId);
|
2012-08-24 16:24:49 +00:00
|
|
|
this._iconClickedId = 0;
|
|
|
|
}
|
2011-02-16 18:20:03 +00:00
|
|
|
|
2010-11-18 12:51:47 +00:00
|
|
|
if (this._searchTimeoutId > 0) {
|
|
|
|
Mainloop.source_remove(this._searchTimeoutId);
|
|
|
|
this._searchTimeoutId = 0;
|
|
|
|
}
|
2012-08-24 16:24:49 +00:00
|
|
|
|
2013-03-03 18:56:12 +00:00
|
|
|
this._entry.set_secondary_icon(null);
|
2012-08-24 16:24:49 +00:00
|
|
|
this._searchCancelled();
|
2010-11-18 12:51:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-11-03 17:30:08 +00:00
|
|
|
_onKeyPress: function(entry, event) {
|
2010-11-18 12:51:47 +00:00
|
|
|
let symbol = event.get_key_symbol();
|
2011-11-14 03:13:26 +00:00
|
|
|
if (symbol == Clutter.Escape) {
|
2011-02-16 18:27:05 +00:00
|
|
|
if (this._isActivated()) {
|
2012-02-27 14:17:33 +00:00
|
|
|
this.reset();
|
2011-02-16 18:27:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-08-24 16:24:49 +00:00
|
|
|
} else if (this._searchActive) {
|
2012-03-10 02:40:46 +00:00
|
|
|
let arrowNext, nextDirection;
|
|
|
|
if (entry.get_text_direction() == Clutter.TextDirection.RTL) {
|
|
|
|
arrowNext = Clutter.Left;
|
|
|
|
nextDirection = Gtk.DirectionType.LEFT;
|
|
|
|
} else {
|
|
|
|
arrowNext = Clutter.Right;
|
|
|
|
nextDirection = Gtk.DirectionType.RIGHT;
|
|
|
|
}
|
|
|
|
|
2011-11-12 04:40:56 +00:00
|
|
|
if (symbol == Clutter.Tab) {
|
2011-11-14 03:13:26 +00:00
|
|
|
this._searchResults.navigateFocus(Gtk.DirectionType.TAB_FORWARD);
|
2011-11-12 04:40:56 +00:00
|
|
|
return true;
|
|
|
|
} else if (symbol == Clutter.ISO_Left_Tab) {
|
|
|
|
this._focusTrap.can_focus = false;
|
2011-11-14 03:13:26 +00:00
|
|
|
this._searchResults.navigateFocus(Gtk.DirectionType.TAB_BACKWARD);
|
2011-11-12 04:40:56 +00:00
|
|
|
this._focusTrap.can_focus = true;
|
|
|
|
return true;
|
2012-03-10 02:40:46 +00:00
|
|
|
} else if (symbol == Clutter.Down) {
|
|
|
|
this._searchResults.navigateFocus(Gtk.DirectionType.DOWN);
|
|
|
|
return true;
|
|
|
|
} else if (symbol == arrowNext && this._text.position == -1) {
|
|
|
|
this._searchResults.navigateFocus(nextDirection);
|
|
|
|
return true;
|
2013-01-27 19:00:59 +00:00
|
|
|
} else if (symbol == Clutter.Return || symbol == Clutter.KP_Enter) {
|
|
|
|
// We can't connect to 'activate' here because search providers
|
|
|
|
// might want to do something with the modifiers in activateDefault.
|
|
|
|
if (this._searchTimeoutId > 0) {
|
|
|
|
Mainloop.source_remove(this._searchTimeoutId);
|
|
|
|
this._doSearch();
|
|
|
|
}
|
|
|
|
this._searchResults.activateDefault();
|
|
|
|
return true;
|
2011-11-12 04:40:56 +00:00
|
|
|
}
|
2010-11-18 12:51:47 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-02-16 18:20:03 +00:00
|
|
|
_onCapturedEvent: function(actor, event) {
|
2011-02-16 18:27:05 +00:00
|
|
|
if (event.type() == Clutter.EventType.BUTTON_PRESS) {
|
|
|
|
let source = event.get_source();
|
2011-10-09 20:24:59 +00:00
|
|
|
if (source != this._text && this._text.text == '' &&
|
|
|
|
!Main.layoutManager.keyboardBox.contains(source)) {
|
2011-02-16 18:20:03 +00:00
|
|
|
// the user clicked outside after activating the entry, but
|
2011-10-09 20:24:59 +00:00
|
|
|
// with no search term entered and no keyboard button pressed
|
|
|
|
// - cancel the search
|
2012-02-27 14:17:33 +00:00
|
|
|
this.reset();
|
2011-02-16 18:27:05 +00:00
|
|
|
}
|
2011-02-16 18:20:03 +00:00
|
|
|
}
|
2011-02-16 18:44:03 +00:00
|
|
|
|
|
|
|
return false;
|
2011-02-16 18:20:03 +00:00
|
|
|
},
|
|
|
|
|
2010-11-18 12:51:47 +00:00
|
|
|
_doSearch: function () {
|
|
|
|
this._searchTimeoutId = 0;
|
|
|
|
|
2013-02-09 02:05:15 +00:00
|
|
|
let terms = getTermsForSearchString(this._entry.get_text());
|
|
|
|
|
|
|
|
this._searchSystem.updateSearchResults(terms);
|
2012-06-21 22:52:56 +00:00
|
|
|
this._showPage(this._searchPage);
|
2010-11-12 17:45:29 +00:00
|
|
|
},
|
|
|
|
|
2012-11-01 14:33:40 +00:00
|
|
|
_shouldUseSearchProvider: function(provider) {
|
2012-11-01 20:18:12 +00:00
|
|
|
// the disable-external GSetting only affects remote providers
|
2012-11-01 14:33:40 +00:00
|
|
|
if (!provider.isRemoteProvider)
|
|
|
|
return true;
|
|
|
|
|
2012-11-01 20:18:12 +00:00
|
|
|
if (this._searchSettings.get_boolean('disable-external'))
|
|
|
|
return false;
|
|
|
|
|
2012-11-01 14:33:40 +00:00
|
|
|
let appId = provider.appInfo.get_id();
|
|
|
|
let disable = this._searchSettings.get_strv('disabled');
|
|
|
|
return disable.indexOf(appId) == -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
_reloadRemoteProviders: function() {
|
|
|
|
// removeSearchProvider() modifies the provider list we iterate on,
|
|
|
|
// so make a copy first
|
|
|
|
let remoteProviders = this._searchSystem.getRemoteProviders().slice(0);
|
|
|
|
|
|
|
|
remoteProviders.forEach(Lang.bind(this, this.removeSearchProvider));
|
|
|
|
RemoteSearch.loadRemoteSearchProviders(Lang.bind(this, this.addSearchProvider));
|
|
|
|
},
|
|
|
|
|
2010-11-12 17:45:29 +00:00
|
|
|
addSearchProvider: function(provider) {
|
2012-11-01 14:33:40 +00:00
|
|
|
if (!this._shouldUseSearchProvider(provider))
|
|
|
|
return;
|
|
|
|
|
2012-06-21 22:52:56 +00:00
|
|
|
this._searchSystem.registerProvider(provider);
|
2013-02-08 23:23:53 +00:00
|
|
|
this._searchResults.createProviderDisplay(provider);
|
2011-08-28 11:20:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
removeSearchProvider: function(provider) {
|
2012-06-21 22:52:56 +00:00
|
|
|
this._searchSystem.unregisterProvider(provider);
|
2013-02-08 23:23:53 +00:00
|
|
|
this._searchResults.destroyProviderDisplay(provider);
|
2013-02-13 21:13:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getActivePage: function() {
|
|
|
|
if (this._activePage == this._workspacesPage)
|
|
|
|
return ViewPage.WINDOWS;
|
|
|
|
else if (this._activePage == this._appsPage)
|
|
|
|
return ViewPage.APPS;
|
|
|
|
else
|
|
|
|
return ViewPage.SEARCH;
|
2013-02-18 04:45:24 +00:00
|
|
|
},
|
|
|
|
|
2011-07-09 13:30:42 +00:00
|
|
|
setActivePage: function(page) {
|
|
|
|
if (page == ViewPage.WINDOWS)
|
|
|
|
this._showPage(this._workspacesPage);
|
|
|
|
else
|
|
|
|
this._showPage(this._appsPage);
|
|
|
|
},
|
|
|
|
|
2013-02-18 04:45:24 +00:00
|
|
|
fadeIn: function() {
|
|
|
|
let actor = this._activePage;
|
|
|
|
Tweener.addTween(actor, { opacity: 255,
|
|
|
|
time: OverviewControls.SIDE_CONTROLS_ANIMATION_TIME / 2,
|
|
|
|
transition: 'easeInQuad'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
fadeHalf: function() {
|
|
|
|
let actor = this._activePage;
|
|
|
|
Tweener.addTween(actor, { opacity: 128,
|
|
|
|
time: OverviewControls.SIDE_CONTROLS_ANIMATION_TIME / 2,
|
|
|
|
transition: 'easeOutQuad'
|
|
|
|
});
|
2010-11-12 17:45:29 +00:00
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2010-11-12 17:45:29 +00:00
|
|
|
Signals.addSignalMethods(ViewSelector.prototype);
|