switcherPopup: Handle removal of items from SwitcherPopup
This will be mainly useful for closing apps from the applications switcher, but can be implemented generically enough to select the nearest existing item after removal if there's any, or destroying the popup's actor otherwise. Specifically for the apps switcher, doing this also removes the need of having to manually either update the current app in AppSwitcher and highlight it, if there are still any items after the removal, or simply destroy the AppSwitcher otherwise. Besides, calling _select() in the handler for item-removed makes sure that the list of thumbnails in the switcher is always closed, if open, when quitting the app. https://bugzilla.gnome.org/show_bug.cgi?id=620106
This commit is contained in:
parent
a3918d8c38
commit
06f790d86c
@ -812,13 +812,6 @@ var AppSwitcher = new Lang.Class({
|
|||||||
|
|
||||||
this.icons.splice(index, 1);
|
this.icons.splice(index, 1);
|
||||||
this.removeItem(index);
|
this.removeItem(index);
|
||||||
|
|
||||||
if (this._curApp == index)
|
|
||||||
this._curApp = SwitcherPopup.mod(index, this.icons.length);
|
|
||||||
if (this.icons.length > 0)
|
|
||||||
this.highlight(this._curApp);
|
|
||||||
else
|
|
||||||
this.actor.destroy();
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -133,6 +133,7 @@ var SwitcherPopup = new Lang.Class({
|
|||||||
this.actor.add_actor(this._switcherList.actor);
|
this.actor.add_actor(this._switcherList.actor);
|
||||||
this._switcherList.connect('item-activated', Lang.bind(this, this._itemActivated));
|
this._switcherList.connect('item-activated', Lang.bind(this, this._itemActivated));
|
||||||
this._switcherList.connect('item-entered', Lang.bind(this, this._itemEntered));
|
this._switcherList.connect('item-entered', Lang.bind(this, this._itemEntered));
|
||||||
|
this._switcherList.connect('item-removed', Lang.bind(this, this._itemRemoved));
|
||||||
|
|
||||||
// Need to force an allocation so we can figure out whether we
|
// Need to force an allocation so we can figure out whether we
|
||||||
// need to scroll when selecting
|
// need to scroll when selecting
|
||||||
@ -247,6 +248,19 @@ var SwitcherPopup = new Lang.Class({
|
|||||||
this._itemEnteredHandler(n);
|
this._itemEnteredHandler(n);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_itemRemovedHandler: function(n) {
|
||||||
|
if (this._items.length > 0) {
|
||||||
|
let newIndex = Math.min(n, this._items.length - 1);
|
||||||
|
this._select(newIndex);
|
||||||
|
} else {
|
||||||
|
this.actor.destroy();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_itemRemoved: function(switcher, n) {
|
||||||
|
this._itemRemovedHandler(n);
|
||||||
|
},
|
||||||
|
|
||||||
_disableHover: function() {
|
_disableHover: function() {
|
||||||
this.mouseActive = false;
|
this.mouseActive = false;
|
||||||
|
|
||||||
@ -421,6 +435,7 @@ var SwitcherList = new Lang.Class({
|
|||||||
removeItem: function(index) {
|
removeItem: function(index) {
|
||||||
let item = this._items.splice(index, 1);
|
let item = this._items.splice(index, 1);
|
||||||
item[0].destroy();
|
item[0].destroy();
|
||||||
|
this.emit('item-removed', index);
|
||||||
},
|
},
|
||||||
|
|
||||||
_onItemClicked: function (index) {
|
_onItemClicked: function (index) {
|
||||||
@ -442,15 +457,15 @@ var SwitcherList = new Lang.Class({
|
|||||||
this._items[this._highlighted].remove_style_pseudo_class('selected');
|
this._items[this._highlighted].remove_style_pseudo_class('selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
this._highlighted = index;
|
if (this._items[index]) {
|
||||||
|
|
||||||
if (this._highlighted != -1) {
|
|
||||||
if (justOutline)
|
if (justOutline)
|
||||||
this._items[this._highlighted].add_style_pseudo_class('outlined');
|
this._items[index].add_style_pseudo_class('outlined');
|
||||||
else
|
else
|
||||||
this._items[this._highlighted].add_style_pseudo_class('selected');
|
this._items[index].add_style_pseudo_class('selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._highlighted = index;
|
||||||
|
|
||||||
let adjustment = this._scrollView.hscroll.adjustment;
|
let adjustment = this._scrollView.hscroll.adjustment;
|
||||||
let [value, lower, upper, stepIncrement, pageIncrement, pageSize] = adjustment.get_values();
|
let [value, lower, upper, stepIncrement, pageIncrement, pageSize] = adjustment.get_values();
|
||||||
let [absItemX, absItemY] = this._items[index].get_transformed_position();
|
let [absItemX, absItemY] = this._items[index].get_transformed_position();
|
||||||
|
Loading…
Reference in New Issue
Block a user