265
265
getTerms: function() {
266
266
let str = Tracker.sparql_escape_string(this._string);
267
267
return str.replace(/ +/g, ' ').split(' ');
270
setDropdownState: function(state) {
271
if (this._dropdownState == state)
274
this._dropdownState = state;
275
this.emit('search-dropdown-changed', this._dropdownState);
278
getDropdownState: function() {
279
return this._dropdownState;
282
270
Signals.addSignalMethods(SearchController.prototype);
272
const Searchbar = new Lang.Class({
276
this._searchEntryTimeout = 0;
277
this._searchTypeId = 0;
278
this._searchMatchId = 0;
282
this.widget = new Gtk.Toolbar();
283
this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
285
this.actor = new GtkClutter.Actor({ contents: this.widget,
288
// subclasses will create this._searchEntry and this._searchContainer
290
this.createSearchWidgets();
292
let item = new Gtk.ToolItem();
293
item.set_expand(true);
294
item.add(this._searchContainer);
295
this.widget.insert(item, 0);
297
this._searchEntry.connect('key-press-event', Lang.bind(this,
298
function(widget, event) {
299
let keyval = event.get_keyval()[1];
301
if (keyval == Gdk.KEY_Escape) {
302
Global.application.change_action_state('search', GLib.Variant.new('b', false));
309
this._searchEntry.connect('changed', Lang.bind(this,
311
if (this._searchEntryTimeout != 0) {
312
Mainloop.source_remove(this._searchEntryTimeout);
313
this._searchEntryTimeout = 0;
316
this._searchEntryTimeout = Mainloop.timeout_add(_SEARCH_ENTRY_TIMEOUT, Lang.bind(this,
318
this._searchEntryTimeout = 0;
323
// connect to the search action state for visibility
324
let searchStateId = Global.application.connect('action-state-changed::search', Lang.bind(this,
325
function(source, actionName, state) {
326
if (state.get_boolean())
331
this.widget.connect('destroy', Lang.bind(this,
333
Global.application.disconnect(searchStateId);
334
Global.application.change_action_state('search', GLib.Variant.new('b', false));
337
this.widget.show_all();
340
createSearchWidgets: function() {
341
log('Error: Searchbar implementations must override createSearchWidgets');
344
entryChanged: function() {
345
log('Error: Searchbar implementations must override entryChanged');
348
destroy: function() {
349
this.widget.destroy();
352
handleEvent: function(event) {
356
if (!this._searchEntry.get_realized())
357
this._searchEntry.realize();
361
let preeditChanged = false;
362
let preeditChangedId =
363
this._searchEntry.connect('preedit-changed', Lang.bind(this,
365
preeditChanged = true;
368
let oldText = this._searchEntry.get_text();
369
let res = this._searchEntry.event(event);
370
let newText = this._searchEntry.get_text();
372
this._searchEntry.disconnect(preeditChangedId);
374
if (((res && (newText != oldText)) || preeditChanged)) {
378
Global.application.change_action_state('search', GLib.Variant.new('b', true));
385
let eventDevice = Gtk.get_current_event_device();
386
this._searchEntry.show();
388
Tweener.addTween(this.actor, { height: this.widget.get_preferred_height()[1],
390
transition: 'easeOutQuad',
391
onComplete: function() {
393
Gd.entry_focus_hack(this._searchEntry, eventDevice);
395
onCompleteScope: this });
399
Tweener.addTween(this.actor, { height: 0,
401
transition: 'easeOutQuad',
402
onComplete: function() {
403
this._searchEntry.hide();
406
onCompleteScope: this });
284
410
const Dropdown = new Lang.Class({
285
411
Name: 'Dropdown',
313
439
this._grid.add(this._matchView.widget);
314
440
//this._grid.add(this._categoryView.widget);
316
this.widget.show_all();
318
Global.searchController.connect('search-dropdown-changed',
319
Lang.bind(this, this._onSearchDropdown));
320
this._onSearchDropdown();
323
445
_onItemActivated: function() {
324
Global.searchController.setDropdownState(false);
327
_onSearchDropdown: function() {
328
let state = Global.searchController.getDropdownState();
335
_fadeIn: function() {
446
this.emit('item-activated');
450
this.widget.show_all();
336
451
this.actor.raise_top();
337
452
Tweener.addTween(this.actor, { opacity: 245,
339
454
transition: 'easeOutQuad' });
342
_fadeOut: function() {
343
459
Tweener.addTween(this.actor, { opacity: 0,
345
461
transition: 'easeOutQuad',
349
465
onCompleteScope: this });
353
const Searchbar = new Lang.Class({
357
this._searchEventId = 0;
358
this._searchFocusId = 0;
359
this._searchEntryTimeout = 0;
361
this._searchTypeId = 0;
362
this._searchMatchId = 0;
365
this._visible = false;
367
this.widget = new Gtk.Toolbar();
368
this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
370
this.actor = new GtkClutter.Actor({ contents: this.widget,
373
this._searchEntry = new Gd.TaggedEntry({ width_request: 260,
376
this._searchEntry.connect('tag-clicked',
377
Lang.bind(this, this._onTagClicked));
468
Signals.addSignalMethods(Dropdown.prototype);
470
const OverviewSearchbar = new Lang.Class({
471
Name: 'OverviewSearchbar',
474
_init: function(dropdown) {
475
this._dropdown = dropdown;
379
479
this._sourcesId = Global.sourceManager.connect('active-changed',
380
480
Lang.bind(this, this._onActiveSourceChanged));
388
488
this._onActiveSourceChanged();
389
489
this._onActiveTypeChanged();
390
490
this._onActiveMatchChanged();
392
let box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
393
box.add(this._searchEntry);
493
createSearchWidgets: function() {
494
this._searchContainer = new Gd.MarginContainer({ min_margin: 6,
496
this._box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
497
this._searchContainer.add(this._box);
499
// create the search entry
500
this._searchEntry = new Gd.TaggedEntry({ width_request: 260,
503
this._searchEntry.connect('tag-clicked',
504
Lang.bind(this, this._onTagClicked));
505
this._searchEntry.set_text(Global.searchController.getString());
507
// create the dropdown button
395
508
this._dropdownButton = new Gtk.ToggleButton(
396
509
{ child: new Gtk.Arrow({ arrow_type: Gtk.ArrowType.DOWN }) });
397
510
this._dropdownButton.connect('toggled', Lang.bind(this,
399
512
let active = this._dropdownButton.get_active();
400
Global.searchController.setDropdownState(active);
403
box.add(this._dropdownButton);
405
this._searchDropdownId = Global.searchController.connect('search-dropdown-changed',
406
Lang.bind(this, this._onDropdownStateChanged));
408
let container = new Gd.MarginContainer({ min_margin: 6,
412
let item = new Gtk.ToolItem();
413
item.set_expand(true);
416
this._searchEntry.connect('key-press-event', Lang.bind(this,
417
function(widget, event) {
418
let keyval = event.get_keyval()[1];
420
if (keyval == Gdk.KEY_Escape) {
428
this._searchEntry.connect('changed', Lang.bind(this, function() {
429
if (this._searchEntryTimeout != 0) {
430
Mainloop.source_remove(this._searchEntryTimeout);
431
this._searchEntryTimeout = 0;
434
this._searchEntryTimeout = Mainloop.timeout_add(_SEARCH_ENTRY_TIMEOUT, Lang.bind(this,
436
this._searchEntryTimeout = 0;
438
let currentText = this._searchEntry.get_text().toLowerCase();
439
Global.searchController.setString(currentText);
443
this.widget.insert(item, 0);
444
this._searchEntry.set_text(Global.searchController.getString());
446
this.widget.show_all();
514
this._dropdown.show();
516
this._dropdown.hide();
518
this._dropdown.connect('item-activated', Lang.bind(this,
520
this._dropdownButton.set_active(false);
523
this._box.add(this._searchEntry);
524
this._box.add(this._dropdownButton);
525
this._box.show_all();
528
entryChanged: function() {
529
let currentText = this._searchEntry.get_text().toLowerCase();
530
Global.searchController.setString(currentText);
449
533
_onActiveCollectionChanged: function() {
459
destroy: function() {
460
if (this._searchFocusId != 0) {
461
Global.searchController.disconnect(this._searchFocusId);
462
this._searchFocusId = 0;
465
if (this._searchEventId != 0) {
466
Global.searchController.disconnect(this._searchEventId);
467
this._searchEventId = 0;
470
if (this._sourcesId != 0) {
471
Global.sourceManager.disconnect(this._sourcesId);
475
if (this._searchTypeId != 0) {
476
Global.searchTypeManager.disconnect(this._searchTypeId);
477
this._searchTypeId = 0;
480
if (this._searchMatchId != 0) {
481
Global.searchMatchManager.disconnect(this._searchMatchId);
482
this._searchMatchId = 0;
485
if (this._searchDropdownId != 0) {
486
Global.searchController.disconnect(this._searchDropdownId);
487
this._searchDropdownId = 0;
490
if (this._collectionId != 0) {
491
Global.searchController.disconnect(this._collectionId);
492
this._collectionId = 0;
495
this.widget.destroy();
498
_onTagClicked: function() {
499
this._dropdownButton.set_active(true);
502
543
_onActiveChangedCommon: function(id, manager) {
503
544
let item = manager.getActiveItem();
530
571
this._onActiveChangedCommon('match', Global.searchMatchManager);
533
_onDropdownStateChanged: function() {
534
let state = Global.searchController.getDropdownState();
535
this._dropdownButton.set_active(state);
538
deliverEvent: function(event) {
542
if (!this._searchEntry.get_realized())
543
this._searchEntry.realize();
547
let preeditChanged = false;
548
let preeditChangedId =
549
this._searchEntry.connect('preedit-changed', Lang.bind(this,
551
preeditChanged = true;
554
let oldText = this._searchEntry.get_text();
555
let res = this._searchEntry.event(event);
556
let newText = this._searchEntry.get_text();
558
this._searchEntry.disconnect(preeditChangedId);
560
if (((res && (newText != oldText)) || preeditChanged)) {
578
let eventDevice = Gtk.get_current_event_device();
580
this._visible = true;
581
this._searchEntry.show();
583
Tweener.addTween(this.actor, { height: this.widget.get_preferred_height()[1],
585
transition: 'easeOutQuad',
586
onComplete: function() {
588
Gd.entry_focus_hack(this._searchEntry, eventDevice);
590
onCompleteScope: this });
574
_onTagClicked: function() {
575
this._dropdownButton.set_active(true);
578
destroy: function() {
579
if (this._sourcesId != 0) {
580
Global.sourceManager.disconnect(this._sourcesId);
584
if (this._searchTypeId != 0) {
585
Global.searchTypeManager.disconnect(this._searchTypeId);
586
this._searchTypeId = 0;
589
if (this._searchMatchId != 0) {
590
Global.searchMatchManager.disconnect(this._searchMatchId);
591
this._searchMatchId = 0;
594
if (this._collectionId != 0) {
595
Global.collectionManager.disconnect(this._collectionId);
596
this._collectionId = 0;
593
602
hide: function() {
594
603
this._dropdownButton.set_active(false);
595
this._visible = false;
597
Tweener.addTween(this.actor, { height: 0,
599
transition: 'easeOutQuad',
600
onComplete: function() {
601
this._searchEntry.hide();
604
onCompleteScope: this });