2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-11-12 12:45:29 -05:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2011-02-23 14:21:47 -05:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2010-11-12 12:45:29 -05: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 16:06:46 -04:00
|
|
|
const AppDisplay = imports.ui.appDisplay;
|
2010-11-12 12:45:29 -05:00
|
|
|
const Main = imports.ui.main;
|
2012-07-28 16:06:46 -04:00
|
|
|
const PlaceDisplay = imports.ui.placeDisplay;
|
|
|
|
const RemoteSearch = imports.ui.remoteSearch;
|
2010-11-12 12:45:29 -05:00
|
|
|
const Search = imports.ui.search;
|
|
|
|
const SearchDisplay = imports.ui.searchDisplay;
|
2011-10-11 18:38:24 -04:00
|
|
|
const ShellEntry = imports.ui.shellEntry;
|
2010-11-12 12:45:29 -05:00
|
|
|
const Tweener = imports.ui.tweener;
|
2012-07-28 16:06:46 -04:00
|
|
|
const Wanda = imports.ui.wanda;
|
|
|
|
const WorkspacesView = imports.ui.workspacesView;
|
2010-11-12 12:45:29 -05:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const BaseTab = new Lang.Class({
|
|
|
|
Name: 'BaseTab',
|
2010-11-12 12:45:29 -05:00
|
|
|
|
2011-02-23 14:21:47 -05:00
|
|
|
_init: function(titleActor, pageActor, name, a11yIcon) {
|
2010-11-12 12:45:29 -05:00
|
|
|
this.title = titleActor;
|
|
|
|
this.page = new St.Bin({ child: pageActor,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START,
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true,
|
|
|
|
style_class: 'view-tab-page' });
|
|
|
|
|
2011-02-23 14:21:47 -05:00
|
|
|
if (this.title.can_focus) {
|
|
|
|
Main.ctrlAltTabManager.addGroup(this.title, name, a11yIcon);
|
|
|
|
} else {
|
|
|
|
Main.ctrlAltTabManager.addGroup(this.page, name, a11yIcon,
|
|
|
|
{ proxy: this.title,
|
|
|
|
focusCallback: Lang.bind(this, this._a11yFocus) });
|
|
|
|
}
|
|
|
|
|
2010-11-12 12:45:29 -05:00
|
|
|
this.visible = false;
|
|
|
|
},
|
|
|
|
|
2011-03-10 07:14:48 -05:00
|
|
|
show: function(animate) {
|
2010-11-12 12:45:29 -05:00
|
|
|
this.visible = true;
|
|
|
|
this.page.show();
|
|
|
|
|
2011-03-10 07:14:48 -05:00
|
|
|
if (!animate)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.page.opacity = 0;
|
2010-11-12 12:45:29 -05:00
|
|
|
Tweener.addTween(this.page,
|
|
|
|
{ opacity: 255,
|
|
|
|
time: 0.1,
|
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this.visible = false;
|
|
|
|
Tweener.addTween(this.page,
|
|
|
|
{ opacity: 0,
|
|
|
|
time: 0.1,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this.page.hide();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-02-23 14:21:47 -05:00
|
|
|
_a11yFocus: function() {
|
|
|
|
this._activate();
|
|
|
|
this.page.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
|
|
|
|
},
|
|
|
|
|
2010-11-12 12:45:29 -05:00
|
|
|
_activate: function() {
|
|
|
|
this.emit('activated');
|
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2010-11-12 12:45:29 -05:00
|
|
|
Signals.addSignalMethods(BaseTab.prototype);
|
|
|
|
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const ViewTab = new Lang.Class({
|
|
|
|
Name: 'ViewTab',
|
|
|
|
Extends: BaseTab,
|
2010-11-12 12:45:29 -05:00
|
|
|
|
2011-03-08 19:26:28 -05:00
|
|
|
_init: function(id, label, pageActor, a11yIcon) {
|
|
|
|
this.id = id;
|
|
|
|
|
2010-11-12 12:45:29 -05:00
|
|
|
let titleActor = new St.Button({ label: label,
|
|
|
|
style_class: 'view-tab-title' });
|
|
|
|
titleActor.connect('clicked', Lang.bind(this, this._activate));
|
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(titleActor, pageActor, label, a11yIcon);
|
2010-11-12 12:45:29 -05:00
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2010-11-12 12:45:29 -05:00
|
|
|
|
|
|
|
|
2012-06-21 18:52:56 -04:00
|
|
|
const ViewSelector = new Lang.Class({
|
|
|
|
Name: 'ViewSelector',
|
|
|
|
|
|
|
|
_init : function(searchEntry, showAppsButton) {
|
|
|
|
this.actor = new St.BoxLayout({ name: 'viewSelector',
|
|
|
|
vertical: true });
|
|
|
|
|
|
|
|
this._showAppsButton = showAppsButton;
|
|
|
|
this._showAppsButton.connect('notify::checked', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
if (this._showAppsButton.checked)
|
|
|
|
this._switchTab(this._appsTab);
|
|
|
|
else
|
|
|
|
this._switchTab(this._windowsTab);
|
|
|
|
}));
|
|
|
|
|
|
|
|
// The page area holds the tab pages. Every page is given the
|
|
|
|
// area's full allocation, so that the pages would appear on top
|
|
|
|
// of each other if the inactive ones weren't hidden.
|
|
|
|
this._pageArea = new Shell.Stack();
|
|
|
|
this.actor.add(this._pageArea, { x_fill: true,
|
|
|
|
y_fill: true,
|
|
|
|
expand: true });
|
|
|
|
|
|
|
|
this._tabs = [];
|
|
|
|
this._activeTab = null;
|
2010-11-18 07:51:47 -05:00
|
|
|
|
2011-02-16 13:27:05 -05:00
|
|
|
this.active = false;
|
2010-11-18 07:51:47 -05:00
|
|
|
this._searchPending = false;
|
|
|
|
this._searchTimeoutId = 0;
|
|
|
|
|
|
|
|
this._searchSystem = new Search.SearchSystem();
|
|
|
|
|
2012-07-28 16:47:55 -04:00
|
|
|
this._entry = searchEntry;
|
2011-10-11 18:38:24 -04:00
|
|
|
ShellEntry.addContextMenu(this._entry);
|
2012-06-21 18:52:56 -04:00
|
|
|
|
2011-02-16 13:20:03 -05:00
|
|
|
this._text = this._entry.clutter_text;
|
2012-06-21 18:52:56 -04:00
|
|
|
this._text.connect('text-changed', Lang.bind(this, this._onTextChanged));
|
2011-02-16 13:27:05 -05:00
|
|
|
this._text.connect('key-press-event', Lang.bind(this, this._onKeyPress));
|
2012-06-21 18:52:56 -04: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 13:20:03 -05:00
|
|
|
|
|
|
|
this._inactiveIcon = new St.Icon({ style_class: 'search-entry-icon',
|
|
|
|
icon_name: 'edit-find',
|
|
|
|
icon_type: St.IconType.SYMBOLIC });
|
|
|
|
this._activeIcon = new St.Icon({ style_class: 'search-entry-icon',
|
|
|
|
icon_name: 'edit-clear',
|
|
|
|
icon_type: St.IconType.SYMBOLIC });
|
|
|
|
this._entry.set_secondary_icon(this._inactiveIcon);
|
|
|
|
|
|
|
|
this._iconClickedId = 0;
|
2012-06-21 18:52:56 -04:00
|
|
|
this._capturedEventId = 0;
|
2011-02-16 13:20:03 -05:00
|
|
|
|
2012-06-21 18:52:56 -04:00
|
|
|
this._workspacesDisplay = new WorkspacesView.WorkspacesDisplay();
|
|
|
|
this._windowsTab = new ViewTab('windows', _("Windows"), this._workspacesDisplay.actor, 'text-x-generic');
|
|
|
|
this._addViewTab(this._windowsTab);
|
2011-02-16 13:20:03 -05:00
|
|
|
|
2012-06-21 18:52:56 -04:00
|
|
|
let appView = new AppDisplay.AllAppDisplay();
|
|
|
|
this._appsTab = new ViewTab('applications', _("Applications"), appView.actor, 'system-run');
|
|
|
|
this._addViewTab(this._appsTab);
|
2011-02-16 13:20:03 -05:00
|
|
|
|
2012-06-21 18:52:56 -04:00
|
|
|
this._searchResults = new SearchDisplay.SearchResults(this._searchSystem);
|
|
|
|
this._searchTab = new BaseTab(new St.Bin(), this._searchResults.actor, _("Search"), 'edit-find');
|
|
|
|
this._addTab(this._searchTab);
|
2011-02-16 13:20:03 -05:00
|
|
|
|
2012-06-21 18:52:56 -04:00
|
|
|
// Default search providers
|
|
|
|
// Wanda comes obviously first
|
|
|
|
this.addSearchProvider(new Wanda.WandaSearchProvider());
|
|
|
|
this.addSearchProvider(new AppDisplay.AppSearchProvider());
|
|
|
|
this.addSearchProvider(new AppDisplay.SettingsSearchProvider());
|
|
|
|
this.addSearchProvider(new PlaceDisplay.PlaceSearchProvider());
|
2011-11-11 23:40:56 -05:00
|
|
|
|
2012-06-21 18:52:56 -04:00
|
|
|
// Load remote search providers provided by applications
|
|
|
|
RemoteSearch.loadRemoteSearchProviders(Lang.bind(this, this.addSearchProvider));
|
2011-11-13 22:13:26 -05:00
|
|
|
|
2011-11-11 23:40:56 -05: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
|
|
|
|
// include the entry in the keynav tab path...
|
|
|
|
this._focusTrap = new St.Bin({ can_focus: true });
|
|
|
|
this._focusTrap.connect('key-focus-in', Lang.bind(this, function() {
|
|
|
|
this._entry.grab_key_focus();
|
|
|
|
}));
|
|
|
|
// ... but make it unfocusable using arrow keys keynav by making its
|
|
|
|
// bounding box always contain the possible focus source's bounding
|
|
|
|
// box since StWidget's keynav logic won't ever select it as a target
|
|
|
|
// in that case.
|
|
|
|
this._focusTrap.add_constraint(new Clutter.BindConstraint({ source: this._searchResults.actor,
|
|
|
|
coordinate: Clutter.BindCoordinate.ALL }));
|
|
|
|
this._searchResults.actor.add_actor(this._focusTrap);
|
|
|
|
|
|
|
|
global.focus_manager.add_group(this._searchResults.actor);
|
2012-06-21 18:52:56 -04:00
|
|
|
|
|
|
|
Main.overview.connect('item-drag-begin',
|
|
|
|
Lang.bind(this, this._resetShowAppsButton));
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Public constraints which may be used to tie actors' height or
|
|
|
|
// vertical position to the current tab's content; as the content's
|
|
|
|
// height and position depend on the view selector's style properties
|
|
|
|
// (e.g. font size, padding, spacing, ...) it would be extremely hard
|
|
|
|
// and ugly to get these from the outside. While it would be possible
|
|
|
|
// to use position and height properties directly, outside code would
|
|
|
|
// need to ensure that the content is properly allocated before
|
|
|
|
// accessing the properties.
|
|
|
|
this.constrainHeight = new Clutter.BindConstraint({ source: this._pageArea,
|
|
|
|
coordinate: Clutter.BindCoordinate.HEIGHT });
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function() {
|
|
|
|
this._workspacesDisplay.show();
|
|
|
|
|
|
|
|
if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows())
|
|
|
|
Main.overview.fadeOutDesktop();
|
|
|
|
},
|
|
|
|
|
|
|
|
zoomFromOverview: function() {
|
|
|
|
this._workspacesDisplay.zoomFromOverview();
|
|
|
|
|
|
|
|
if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows())
|
|
|
|
Main.overview.fadeInDesktop();
|
2010-11-18 07:51:47 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
2012-06-21 18:52:56 -04:00
|
|
|
this._workspacesDisplay.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
_addTab: function(tab) {
|
|
|
|
tab.page.hide();
|
|
|
|
this._pageArea.add_actor(tab.page);
|
|
|
|
tab.connect('activated', Lang.bind(this, function(tab) {
|
|
|
|
this._switchTab(tab);
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
_addViewTab: function(viewTab) {
|
|
|
|
this._tabs.push(viewTab);
|
|
|
|
this._addTab(viewTab);
|
|
|
|
},
|
|
|
|
|
|
|
|
_switchTab: function(tab) {
|
|
|
|
let firstSwitch = this._activeTab == null;
|
|
|
|
|
|
|
|
if (this._activeTab && this._activeTab.visible) {
|
|
|
|
if (this._activeTab == tab)
|
|
|
|
return;
|
|
|
|
this._activeTab.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tab != this._searchTab) {
|
|
|
|
this._activeTab = tab;
|
|
|
|
if (this._searchTab.visible) {
|
|
|
|
this._searchTab.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only fade when switching between tabs,
|
|
|
|
// not when setting the initially selected one.
|
|
|
|
if (!tab.visible)
|
|
|
|
tab.show(!firstSwitch);
|
|
|
|
},
|
|
|
|
|
|
|
|
switchTab: function(id) {
|
|
|
|
for (let i = 0; i < this._tabs.length; i++)
|
|
|
|
if (this._tabs[i].id == id) {
|
|
|
|
this._switchTab(this._tabs[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_resetShowAppsButton: function() {
|
|
|
|
this._showAppsButton.checked = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onStageKeyPress: function(actor, event) {
|
|
|
|
let modifiers = event.get_state();
|
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
|
|
|
|
if (symbol == Clutter.Escape) {
|
|
|
|
if (this.active)
|
|
|
|
this.reset();
|
|
|
|
else
|
|
|
|
Main.overview.hide();
|
|
|
|
return true;
|
|
|
|
} else if (Clutter.keysym_to_unicode(symbol) ||
|
|
|
|
(symbol == Clutter.BackSpace && this.active)) {
|
|
|
|
this.startSearch(event);
|
|
|
|
} else if (!this.active) {
|
|
|
|
if (symbol == Clutter.Tab) {
|
|
|
|
this._activeTab.page.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
|
|
|
|
return true;
|
|
|
|
} else if (symbol == Clutter.ISO_Left_Tab) {
|
|
|
|
this._activeTab.page.navigate_focus(null, Gtk.DirectionType.TAB_BACKWARD, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_searchCancelled: function() {
|
|
|
|
this._switchTab(this._activeTab);
|
2010-11-18 07:51:47 -05:00
|
|
|
|
2011-04-07 19:10:24 -04: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 09:17:33 -05:00
|
|
|
this.reset();
|
2011-02-16 13:20:03 -05:00
|
|
|
},
|
|
|
|
|
2012-02-27 09:17:33 -05:00
|
|
|
reset: function () {
|
2011-02-16 13:27:05 -05:00
|
|
|
global.stage.set_key_focus(null);
|
2011-02-16 13:20:03 -05:00
|
|
|
|
2012-02-27 09:17:33 -05:00
|
|
|
this._entry.text = '';
|
|
|
|
|
2011-02-16 13:20:03 -05:00
|
|
|
this._text.set_cursor_visible(true);
|
|
|
|
this._text.set_selection(0, 0);
|
|
|
|
},
|
|
|
|
|
2012-02-27 12:43:59 -05:00
|
|
|
_onStageKeyFocusChanged: function() {
|
2011-02-16 13:20:03 -05:00
|
|
|
let focus = global.stage.get_key_focus();
|
2012-03-09 23:50:17 -05:00
|
|
|
let appearFocused = (this._entry.contains(focus) ||
|
|
|
|
this._searchResults.actor.contains(focus));
|
2012-02-27 12:43:59 -05:00
|
|
|
|
2012-03-09 23:50:17 -05: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 13:20:03 -05: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 07:51:47 -05:00
|
|
|
},
|
|
|
|
|
2011-02-16 13:27:05 -05:00
|
|
|
startSearch: function(event) {
|
|
|
|
global.stage.set_key_focus(this._text);
|
|
|
|
this._text.event(event, false);
|
|
|
|
},
|
|
|
|
|
2011-02-16 13:20:03 -05:00
|
|
|
// the entry does not show the hint
|
|
|
|
_isActivated: function() {
|
|
|
|
return this._text.text == this._entry.get_text();
|
|
|
|
},
|
|
|
|
|
2010-11-18 07:51:47 -05:00
|
|
|
_onTextChanged: function (se, prop) {
|
2011-02-16 13:27:05 -05:00
|
|
|
let searchPreviouslyActive = this.active;
|
|
|
|
this.active = this._entry.get_text() != '';
|
|
|
|
this._searchPending = this.active && !searchPreviouslyActive;
|
2010-11-18 07:51:47 -05:00
|
|
|
if (this._searchPending) {
|
|
|
|
this._searchResults.startingSearch();
|
|
|
|
}
|
2011-02-16 13:27:05 -05:00
|
|
|
if (this.active) {
|
2011-02-16 13:20:03 -05:00
|
|
|
this._entry.set_secondary_icon(this._activeIcon);
|
|
|
|
|
|
|
|
if (this._iconClickedId == 0) {
|
|
|
|
this._iconClickedId = this._entry.connect('secondary-icon-clicked',
|
|
|
|
Lang.bind(this, function() {
|
2012-02-27 09:17:33 -05:00
|
|
|
this.reset();
|
2011-02-16 13:20:03 -05:00
|
|
|
}));
|
|
|
|
}
|
2012-06-21 18:52:56 -04:00
|
|
|
this._switchTab(this._searchTab);
|
2010-11-18 07:51:47 -05:00
|
|
|
} else {
|
2011-02-16 13:20:03 -05:00
|
|
|
if (this._iconClickedId > 0)
|
|
|
|
this._entry.disconnect(this._iconClickedId);
|
|
|
|
this._iconClickedId = 0;
|
|
|
|
|
|
|
|
this._entry.set_secondary_icon(this._inactiveIcon);
|
2012-06-21 18:52:56 -04:00
|
|
|
this._searchCancelled();
|
2010-11-18 07:51:47 -05:00
|
|
|
}
|
2011-02-16 13:27:05 -05:00
|
|
|
if (!this.active) {
|
2010-11-18 07:51:47 -05:00
|
|
|
if (this._searchTimeoutId > 0) {
|
|
|
|
Mainloop.source_remove(this._searchTimeoutId);
|
|
|
|
this._searchTimeoutId = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this._searchTimeoutId > 0)
|
|
|
|
return;
|
|
|
|
this._searchTimeoutId = Mainloop.timeout_add(150, Lang.bind(this, this._doSearch));
|
|
|
|
},
|
|
|
|
|
2010-11-03 13:30:08 -04:00
|
|
|
_onKeyPress: function(entry, event) {
|
2010-11-18 07:51:47 -05:00
|
|
|
let symbol = event.get_key_symbol();
|
2011-11-13 22:13:26 -05:00
|
|
|
if (symbol == Clutter.Escape) {
|
2011-02-16 13:27:05 -05:00
|
|
|
if (this._isActivated()) {
|
2012-02-27 09:17:33 -05:00
|
|
|
this.reset();
|
2011-02-16 13:27:05 -05:00
|
|
|
return true;
|
|
|
|
}
|
2012-06-21 18:52:56 -04: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-11 23:40:56 -05:00
|
|
|
} else if (this.active) {
|
2012-03-09 21:40:46 -05: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-11 23:40:56 -05:00
|
|
|
if (symbol == Clutter.Tab) {
|
2011-11-13 22:13:26 -05:00
|
|
|
this._searchResults.navigateFocus(Gtk.DirectionType.TAB_FORWARD);
|
2011-11-11 23:40:56 -05:00
|
|
|
return true;
|
|
|
|
} else if (symbol == Clutter.ISO_Left_Tab) {
|
|
|
|
this._focusTrap.can_focus = false;
|
2011-11-13 22:13:26 -05:00
|
|
|
this._searchResults.navigateFocus(Gtk.DirectionType.TAB_BACKWARD);
|
2011-11-11 23:40:56 -05:00
|
|
|
this._focusTrap.can_focus = true;
|
|
|
|
return true;
|
2012-03-09 21:40:46 -05: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;
|
2011-11-11 23:40:56 -05:00
|
|
|
}
|
2010-11-18 07:51:47 -05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-02-16 13:20:03 -05:00
|
|
|
_onCapturedEvent: function(actor, event) {
|
2011-02-16 13:27:05 -05:00
|
|
|
if (event.type() == Clutter.EventType.BUTTON_PRESS) {
|
|
|
|
let source = event.get_source();
|
2011-10-09 16:24:59 -04:00
|
|
|
if (source != this._text && this._text.text == '' &&
|
|
|
|
!Main.layoutManager.keyboardBox.contains(source)) {
|
2011-02-16 13:20:03 -05:00
|
|
|
// the user clicked outside after activating the entry, but
|
2011-10-09 16:24:59 -04:00
|
|
|
// with no search term entered and no keyboard button pressed
|
|
|
|
// - cancel the search
|
2012-02-27 09:17:33 -05:00
|
|
|
this.reset();
|
2011-02-16 13:27:05 -05:00
|
|
|
}
|
2011-02-16 13:20:03 -05:00
|
|
|
}
|
2011-02-16 13:44:03 -05:00
|
|
|
|
|
|
|
return false;
|
2011-02-16 13:20:03 -05:00
|
|
|
},
|
|
|
|
|
2010-11-18 07:51:47 -05:00
|
|
|
_doSearch: function () {
|
|
|
|
this._searchTimeoutId = 0;
|
2011-02-16 13:20:03 -05:00
|
|
|
let text = this._text.get_text().replace(/^\s+/g, '').replace(/\s+$/g, '');
|
2011-07-24 06:29:36 -04:00
|
|
|
this._searchResults.doSearch(text);
|
2010-11-18 07:51:47 -05:00
|
|
|
|
2010-11-12 12:45:29 -05:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
addSearchProvider: function(provider) {
|
2012-06-21 18:52:56 -04:00
|
|
|
this._searchSystem.registerProvider(provider);
|
|
|
|
this._searchResults.createProviderMeta(provider);
|
2011-08-28 07:20:37 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
removeSearchProvider: function(provider) {
|
2012-06-21 18:52:56 -04:00
|
|
|
this._searchSystem.unregisterProvider(provider);
|
|
|
|
this._searchResults.destroyProviderMeta(provider);
|
2010-11-12 12:45:29 -05:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2010-11-12 12:45:29 -05:00
|
|
|
Signals.addSignalMethods(ViewSelector.prototype);
|