[gnome-shell/gbsneto/custom-icon-positions: 12/27] appDisplay: Use custom function to retrieve item page and position
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/gbsneto/custom-icon-positions: 12/27] appDisplay: Use custom function to retrieve item page and position
- Date: Thu, 25 Jun 2020 19:58:01 +0000 (UTC)
commit 17d200e75f2db05997a655f2b6d4ce84a2d02b8d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue May 26 01:41:43 2020 -0300
appDisplay: Use custom function to retrieve item page and position
It is important that '_loadApps()' return a sorted list -- adding the
same icons at the same positions but in different orders results in
a wrong icon grid.
Add support for using a custom positioning function, and implement it
in AppDisplay. Because FolderView doesn't implement a custom sorting
function, the items are still sorted alphabetically.
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284
js/ui/appDisplay.js | 42 ++++++++++++++++++++++++++++++++++--------
1 file changed, 34 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index b426512822..88c28ceaf9 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -309,7 +309,7 @@ var BaseAppView = GObject.registerClass({
let oldApps = this._orderedItems.slice();
let oldAppIds = oldApps.map(icon => icon.id);
- let newApps = this._loadApps().sort(this._compareItems);
+ let newApps = this._loadApps().sort(this._compareItems.bind(this));
let newAppIds = newApps.map(icon => icon.id);
let addedApps = newApps.filter(icon => !oldAppIds.includes(icon.id));
@@ -323,15 +323,20 @@ var BaseAppView = GObject.registerClass({
// Add new app icons
const { itemsPerPage } = this._grid;
- addedApps.forEach(icon => {
- let iconIndex = newApps.indexOf(icon);
-
- this._orderedItems.splice(iconIndex, 0, icon);
- this._items.set(icon.id, icon);
+ const getItemPosition = item => {
+ if (this._getItemPosition)
+ return this._getItemPosition(item);
+ const iconIndex = newApps.indexOf(item);
const page = Math.floor(iconIndex / itemsPerPage);
const position = iconIndex % itemsPerPage;
- this._grid.addItem(icon, page, position);
+
+ return [page, position];
+ };
+
+ addedApps.forEach(icon => {
+ const [page, position] = getItemPosition(icon);
+ this._addItem(icon, page, position);
});
this._viewIsReady = true;
@@ -721,7 +726,7 @@ class AppDisplay extends BaseAppView {
// supposed to be and reinsert it where it's sorted.
let oldIdx = this._orderedItems.indexOf(item);
this._orderedItems.splice(oldIdx, 1);
- let newIdx = Util.insertSorted(this._orderedItems, item, this._compareItems);
+ let newIdx = Util.insertSorted(this._orderedItems, item, this._compareItems.bind(this));
this._grid.removeItem(item);
@@ -737,6 +742,27 @@ class AppDisplay extends BaseAppView {
return this._appInfoList;
}
+ _getItemPosition(item) {
+ return this._pageManager.getAppPosition(item.id);
+ }
+
+ _compareItems(a, b) {
+ const [aPage, aPosition] = this._pageManager.getAppPosition(a.id);
+ const [bPage, bPosition] = this._pageManager.getAppPosition(b.id);
+
+ if (aPage === -1 && bPage === -1)
+ return a.name.localeCompare(b.name);
+ else if (aPage === -1)
+ return 1;
+ else if (bPage === -1)
+ return -1;
+
+ if (aPage !== bPage)
+ return aPage - bPage;
+
+ return aPosition - bPosition;
+ }
+
_loadApps() {
let appIcons = [];
this._appInfoList = Shell.AppSystem.get_default().get_installed().filter(appInfo => {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]