appDisplay: Factor out item addition and removal methods
It'll be useful later. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284
This commit is contained in:
parent
2bc8175219
commit
1d86424942
@ -274,6 +274,35 @@ var BaseAppView = GObject.registerClass({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_addItem(item, page, position) {
|
||||||
|
let itemIndex = 0;
|
||||||
|
|
||||||
|
if (this._grid.nPages > 0) {
|
||||||
|
const realPage = page === -1 ? this._grid.nPages - 1 : page;
|
||||||
|
|
||||||
|
itemIndex = position === -1
|
||||||
|
? this._grid.getItemsAtPage(realPage).filter(c => c.visible).length - 1
|
||||||
|
: position;
|
||||||
|
|
||||||
|
for (let i = 0; i < realPage; i++) {
|
||||||
|
const pageItems = this._grid.getItemsAtPage(i).filter(c => c.visible);
|
||||||
|
itemIndex += pageItems.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this._orderedItems.splice(itemIndex, 0, item);
|
||||||
|
this._items.set(item.id, item);
|
||||||
|
this._grid.addItem(item, page, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
_removeItem(item) {
|
||||||
|
const iconIndex = this._orderedItems.indexOf(item);
|
||||||
|
|
||||||
|
this._orderedItems.splice(iconIndex, 1);
|
||||||
|
this._items.delete(item.id);
|
||||||
|
this._grid.removeItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
_redisplay() {
|
_redisplay() {
|
||||||
let oldApps = this._orderedItems.slice();
|
let oldApps = this._orderedItems.slice();
|
||||||
let oldAppIds = oldApps.map(icon => icon.id);
|
let oldAppIds = oldApps.map(icon => icon.id);
|
||||||
@ -286,12 +315,8 @@ var BaseAppView = GObject.registerClass({
|
|||||||
|
|
||||||
// Remove old app icons
|
// Remove old app icons
|
||||||
removedApps.forEach(icon => {
|
removedApps.forEach(icon => {
|
||||||
let iconIndex = this._orderedItems.indexOf(icon);
|
this._removeItem(icon);
|
||||||
let id = icon.id;
|
|
||||||
|
|
||||||
this._orderedItems.splice(iconIndex, 1);
|
|
||||||
icon.destroy();
|
icon.destroy();
|
||||||
this._items.delete(id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add new app icons
|
// Add new app icons
|
||||||
|
Loading…
Reference in New Issue
Block a user