appDisplay: Simplify loading Folder apps a bit

Instead of plugging into _redisplay(), we can use _loadApps() for this.
It's actually exactly what _loadApps() is meant for...

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2348>
This commit is contained in:
Jonas Dreßler 2022-06-24 19:25:24 +02:00 committed by Marge Bot
parent 2566f938e6
commit 7d7b99e2d3

View File

@ -2137,7 +2137,7 @@ class FolderView extends BaseAppView {
this._scrollView.add_action(action); this._scrollView.add_action(action);
this._deletingFolder = false; this._deletingFolder = false;
this._appIds = []; this._apps = [];
this._redisplay(); this._redisplay();
} }
@ -2145,48 +2145,8 @@ class FolderView extends BaseAppView {
return new FolderGrid(); return new FolderGrid();
} }
_getFolderApps() {
const appIds = [];
const excludedApps = this._folder.get_strv('excluded-apps');
const appSys = Shell.AppSystem.get_default();
const addAppId = appId => {
if (excludedApps.includes(appId))
return;
if (this._appFavorites.isFavorite(appId))
return;
const app = appSys.lookup_app(appId);
if (!app)
return;
if (!this._parentalControlsManager.shouldShowApp(app.get_app_info()))
return;
if (appIds.indexOf(appId) !== -1)
return;
appIds.push(appId);
};
const folderApps = this._folder.get_strv('apps');
folderApps.forEach(addAppId);
const folderCategories = this._folder.get_strv('categories');
const appInfos = this._parentView.getAppInfos();
appInfos.forEach(appInfo => {
let appCategories = _getCategories(appInfo);
if (!_listsIntersect(folderCategories, appCategories))
return;
addAppId(appInfo.get_id());
});
return appIds;
}
_getItemPosition(item) { _getItemPosition(item) {
const appIndex = this._appIds.indexOf(item.id); const appIndex = this._apps.indexOf(item.app);
if (appIndex === -1) if (appIndex === -1)
return [-1, -1]; return [-1, -1];
@ -2196,8 +2156,8 @@ class FolderView extends BaseAppView {
} }
_compareItems(a, b) { _compareItems(a, b) {
const aPosition = this._appIds.indexOf(a.id); const aPosition = this._apps.indexOf(a.app);
const bPosition = this._appIds.indexOf(b.id); const bPosition = this._apps.indexOf(b.app);
if (aPosition === -1 && bPosition === -1) if (aPosition === -1 && bPosition === -1)
return a.name.localeCompare(b.name); return a.name.localeCompare(b.name);
@ -2243,27 +2203,52 @@ class FolderView extends BaseAppView {
} }
_loadApps() { _loadApps() {
let apps = []; this._apps = [];
let appSys = Shell.AppSystem.get_default(); const excludedApps = this._folder.get_strv('excluded-apps');
const appSys = Shell.AppSystem.get_default();
const addAppId = appId => {
if (excludedApps.includes(appId))
return;
if (this._appFavorites.isFavorite(appId))
return;
this._appIds.forEach(appId => {
const app = appSys.lookup_app(appId); const app = appSys.lookup_app(appId);
if (!app)
return;
let icon = this._items.get(appId); if (!this._parentalControlsManager.shouldShowApp(app.get_app_info()))
return;
if (this._apps.indexOf(app) !== -1)
return;
this._apps.push(app);
};
const folderApps = this._folder.get_strv('apps');
folderApps.forEach(addAppId);
const folderCategories = this._folder.get_strv('categories');
const appInfos = this._parentView.getAppInfos();
appInfos.forEach(appInfo => {
let appCategories = _getCategories(appInfo);
if (!_listsIntersect(folderCategories, appCategories))
return;
addAppId(appInfo.get_id());
});
let items = [];
this._apps.forEach(app => {
let icon = this._items.get(app.get_id());
if (!icon) if (!icon)
icon = new AppIcon(app); icon = new AppIcon(app);
apps.push(icon); items.push(icon);
}); });
return apps; return items;
}
_redisplay() {
// Keep the app ids list cached
this._appIds = this._getFolderApps();
super._redisplay();
} }
acceptDrop(source) { acceptDrop(source) {