[gnome-shell/gbsneto/custom-icon-positions: 12/30] appDisplay: Introduce PageManager



commit 457441e82a33fae0921c7d7da671272e66b26a8c
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Dec 5 12:31:52 2019 -0300

    appDisplay: Introduce PageManager
    
    The PageManager does the heavy lifting between reading the
    'app-picker-layout' GSettings key, and saving the new pages.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284

 js/ui/appDisplay.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 27a1d6d161..0e9e9d9ce5 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -538,6 +538,61 @@ var BaseAppView = GObject.registerClass({
     }
 });
 
+var PageManager = GObject.registerClass({
+    Signals: { 'layout-changed': {} },
+}, class PageManager extends GObject.Object {
+    _init() {
+        super._init();
+
+        global.settings.connect('changed::app-picker-layout',
+            this._loadPages.bind(this));
+
+        this._loadPages();
+    }
+
+    _loadPages() {
+        const layout = global.settings.get_value('app-picker-layout');
+        this._pages = layout.recursiveUnpack();
+        this.emit('layout-changed');
+    }
+
+    getAppPosition(appId) {
+        let position = -1;
+        let page = -1;
+
+        for (let pageIndex = 0; pageIndex < this._pages.length; pageIndex++) {
+            const pageData = this._pages[pageIndex];
+
+            if (!(appId in pageData))
+                continue;
+
+            page = pageIndex;
+            position = pageData[appId].position;
+        }
+
+        return [page, position];
+    }
+
+    set pages(p) {
+        const packedPages = [];
+
+        // Pack the icon properties as a GVariant
+        for (const page of p) {
+            const pageData = {};
+            for (const [appId, properties] of Object.entries(page))
+                pageData[appId] = new GLib.Variant('a{sv}', properties);
+            packedPages.push(pageData);
+        }
+
+        const variant = new GLib.Variant('aa{sv}', packedPages);
+        global.settings.set_value('app-picker-layout', variant);
+    }
+
+    get pages() {
+        return this._pages;
+    }
+});
+
 var AppDisplay = GObject.registerClass(
 class AppDisplay extends BaseAppView {
     _init() {
@@ -548,6 +603,7 @@ class AppDisplay extends BaseAppView {
         });
 
         this._grid._delegate = this;
+        this._pageManager = new PageManager();
 
         this._scrollView.add_style_class_name('all-apps');
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]