[gnome-shell/gbsneto/icon-grid-dnd: 74/96] allView: Add support for custom positioning
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/gbsneto/icon-grid-dnd: 74/96] allView: Add support for custom positioning
- Date: Tue, 16 Jul 2019 23:28:21 +0000 (UTC)
commit d8a7fd558e1947ed35f6d4ed6dc9ad0a95f8a80d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Jul 2 13:38:11 2019 -0300
allView: Add support for custom positioning
Use the new 'icon-grid-layout' key to sort the applications and folders
as it is saved. Applications that are not in the key are appended, and
when compared to each other, fallback to alphabetical order.
Because the 'icon-grid-layout' key is, by default, empty, this means that
all icons and folders are sorted alphabetically the first time they are
displayed, preserving the current behavior.
This commit does not add any way to change the order without modifying
the GSettings key directly.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/603
js/ui/appDisplay.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index a231ad70a..7909531c4 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -333,6 +333,17 @@ var AllView = class AllView extends BaseAppView {
Main.queueDeferredWork(this._redisplayWorkId);
});
+ this._gridSettings = new Gio.Settings({ schema_id: 'org.gnome.shell' });
+ this._gridChangedId = this._gridSettings.connect('changed::icon-grid-layout', () => {
+ // Sort items alphabetically when the layout is reset
+ if (this._gridSettings.get_strv('icon-grid-layout').length == 0) {
+ this._allItems.sort((a, b) => a.name.localeCompare(b.name));
+ this._allItems.forEach((item, position) => this._grid.moveItem(item, position));
+ }
+ if (!this._blockGridSettings)
+ Main.queueDeferredWork(this._redisplayWorkId);
+ });
+
Main.overview.connect('item-drag-begin', this._onDragBegin.bind(this));
Main.overview.connect('item-drag-end', this._onDragEnd.bind(this));
@@ -413,12 +424,49 @@ var AllView = class AllView extends BaseAppView {
newApps.push(icon);
});
+ let gridLayout = this._gridSettings.get_strv('icon-grid-layout');
+
+ // Sort the list of apps according to the saved layout. The fallback
+ // is sorting alphabetically.
+ newApps.sort((a, b) => {
+ let indexA = gridLayout.indexOf(a.id);
+ let indexB = gridLayout.indexOf(b.id);
+
+ if (indexA == -1 && indexB == -1)
+ return a.name.localeCompare(b.name);
+ else if (indexA == -1)
+ return 1;
+ else if (indexB == -1)
+ return -1;
+ else
+ return indexA - indexB;
+ });
+
return newApps;
}
+ _saveGridLayout() {
+ let visibleApps = this._allItems.filter(icon => icon.actor.visible);
+ let gridLayout = this._gridSettings.get_strv('icon-grid-layout');
+
+ // Only save the new layout if it changed
+ let changed = false;
+ if (gridLayout.length != 0 || !Util.isSorted(visibleApps, (a, b) => a.name.localeCompare(b.name)))
+ changed = true;
+
+ if (changed) {
+ let appIds = visibleApps.map(icon => icon.id);
+
+ this._blockGridSettings = true;
+ this._gridSettings.set_strv('icon-grid-layout', appIds);
+ this._blockGridSettings = false;
+ }
+ }
+
_loadGrid() {
super._loadGrid();
this._refilterApps();
+ this._saveGridLayout();
}
// Overridden from BaseAppView
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]