[gnome-characters/bilelmoussaoui/gtk4: 24/27] sidebar: move categories to the UI file




commit 6822a59517fbd8773b0b328fc1892c86bb0b1054
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Sun Nov 21 08:44:14 2021 +0100

    sidebar: move categories to the UI file
    
    this also cleans up the mainview a little bit
    in the upcoming commits, we will stop creating multiple view per category
    and instead have one that gets refreshed with the various items whenever
    the category changes

 data/mainview.ui                             |  17 --
 data/org.gnome.Characters.data.gresource.xml |   3 +-
 data/sidebar.ui                              | 202 ++++++++++++++++++-----
 data/{mainwindow.ui => window.ui}            |  38 +++++
 src/categoryList.js                          | 229 ++++++++++-----------------
 src/window.js                                | 171 +++++++++-----------
 6 files changed, 357 insertions(+), 303 deletions(-)
---
diff --git a/data/org.gnome.Characters.data.gresource.xml b/data/org.gnome.Characters.data.gresource.xml
index a219f7f..331ce23 100644
--- a/data/org.gnome.Characters.data.gresource.xml
+++ b/data/org.gnome.Characters.data.gresource.xml
@@ -1,13 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/Characters">
-    <file preprocess="xml-stripblanks">mainview.ui</file>
-    <file preprocess="xml-stripblanks">mainwindow.ui</file>
     <file preprocess="xml-stripblanks">character.ui</file>
     <file preprocess="xml-stripblanks">characterlist.ui</file>
     <file preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">shortcuts.ui</file>
     <file preprocess="xml-stripblanks">menu.ui</file>
     <file preprocess="xml-stripblanks">sidebar.ui</file>
+    <file preprocess="xml-stripblanks">window.ui</file>
     <file>style.css</file>
   </gresource>
   <gresource prefix="/org/gnome/Characters/icons/scalable/categories">
diff --git a/data/sidebar.ui b/data/sidebar.ui
index a3cf106..a6fd890 100644
--- a/data/sidebar.ui
+++ b/data/sidebar.ui
@@ -1,49 +1,173 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="Gjs_Sidebar" parent="GtkBox">
-    <property name="orientation">vertical</property>
+  <template class="Gjs_Sidebar" parent="AdwBin">
     <property name="vexpand">True</property>
     <property name="hexpand">True</property>
     <child>
-        <object class="Gjs_RecentCategoryListWidget" id="recentSection" />
-    </child>
-    <child>
-      <object class="GtkSeparator">
-        <property name="orientation">horizontal</property>
-      </object>
-    </child>
-    <child>
-      <object class="GtkLabel">
-        <property name="label" translatable="yes">Emojis</property>
-        <property name="halign">start</property>
-        <property name="margin-top">12</property>
-        <property name="margin-start">12</property>
-        <property name="margin-bottom">12</property>
-        <property name="margin-end">12</property>
-        <style>
-          <class name="heading" />
-        </style>
-      </object>
-    </child>
-    <child>
-      <object class="Gjs_EmojiCategoryListWidget" id="emojisSection" />
-    </child>
-    <child>
-      <object class="GtkLabel">
-        <property name="label" translatable="yes">Letters &amp; Symbols</property>
-        <property name="halign">start</property>
-        <property name="margin-top">12</property>
-        <property name="margin-start">12</property>
-        <property name="margin-bottom">12</property>
-        <property name="margin-end">12</property>
-        <style>
-          <class name="heading" />
-        </style>
+      <object class="GtkListBox" id="list">
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="recentRow">
+            <property name="name">recent</property>
+            <property name="icon-name">document-open-recent-symbolic</property>
+            <property name="title" translatable="yes">Recently Used</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkListBoxRow">
+            <property name="selectable">false</property>
+            <property name="activatable">false</property>
+            <child>
+              <object class="GtkSeparator">
+                <property name="orientation">horizontal</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkListBoxRow">
+            <property name="selectable">false</property>
+            <property name="activatable">false</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="label" translatable="yes">Emojis</property>
+                <property name="halign">start</property>
+                <property name="margin-top">12</property>
+                <property name="margin-start">12</property>
+                <property name="margin-bottom">12</property>
+                <property name="margin-end">12</property>
+                <style>
+                  <class name="heading" />
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="emojiSmileysRow">
+            <property name="name">emoji-smileys</property>
+            <property name="icon-name">characters-emoji-smileys</property>
+            <property name="title" translatable="yes">Smileys &amp; People</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="emojiAnimalsRow">
+            <property name="name">emoji-animals</property>
+            <property name="icon-name">characters-emoji-animals</property>
+            <property name="title" translatable="yes">Animals &amp; Nature</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="emojiFoodRow">
+            <property name="name">emoji-food</property>
+            <property name="icon-name">characters-emoji-food</property>
+            <property name="title" translatable="yes">Food &amp; Drink</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="emojiActivitiesRow">
+            <property name="name">emoji-activities</property>
+            <property name="icon-name">characters-emoji-activities</property>
+            <property name="title" translatable="yes">Activities</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="emojiTravelRow">
+            <property name="name">emoji-travel</property>
+            <property name="icon-name">characters-emoji-travel</property>
+            <property name="title" translatable="yes">Travel &amp; Places</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="emojiObjectsRow">
+            <property name="name">emoji-objects</property>
+            <property name="icon-name">characters-emoji-objects</property>
+            <property name="title" translatable="yes">Objects</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="emojiSymbolsRow">
+            <property name="name">emoji-symbols</property>
+            <property name="icon-name">characters-emoji-symbols</property>
+            <property name="title" translatable="yes">Symbols</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="emojiFlagsRow">
+            <property name="name">emoji-flags</property>
+            <property name="icon-name">characters-emoji-flags</property>
+            <property name="title" translatable="yes">Flags</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkListBoxRow">
+            <property name="selectable">false</property>
+            <property name="activatable">false</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="label" translatable="yes">Letters &amp; Symbols</property>
+                <property name="halign">start</property>
+                <property name="margin-top">12</property>
+                <property name="margin-start">12</property>
+                <property name="margin-bottom">12</property>
+                <property name="margin-end">12</property>
+                <style>
+                  <class name="heading" />
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="lettersPunctuationRow">
+            <property name="name">punctuation</property>
+            <property name="icon-name">characters-punctuation-symbolic</property>
+            <property name="title" translatable="yes">Punctuation</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="lettersArrowsRow">
+            <property name="name">arrow</property>
+            <property name="icon-name">characters-arrow-symbolic</property>
+            <property name="title" translatable="yes">Arrows</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="lettersBulletsRow">
+            <property name="name">bullet</property>
+            <property name="icon-name">characters-bullet-symbolic</property>
+            <property name="title" translatable="yes">Bullets</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="lettersPicturesRow">
+            <property name="name">picture</property>
+            <property name="icon-name">characters-picture-symbolic</property>
+            <property name="title" translatable="yes">Pictures</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="lettersCurrencyRow">
+            <property name="name">currency</property>
+            <property name="icon-name">characters-currency-symbolic</property>
+            <property name="title" translatable="yes">Currencies</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="lettersMathRow">
+            <property name="name">math</property>
+            <property name="icon-name">characters-math-symbolic</property>
+            <property name="title" translatable="yes">Math</property>
+          </object>
+        </child>
+        <child>
+          <object class="Gjs_CategoryListRowWidget" id="lettersLatinRow">
+            <property name="name">letters</property>
+            <property name="icon-name">characters-latin-symbolic</property>
+            <property name="title" translatable="yes">Letters</property>
+          </object>
+        </child>
       </object>
     </child>
-    <child>
-      <object class="Gjs_LetterCategoryListWidget" id="lettersSection" />
-    </child>
     <style>
       <class name="categories-list" />
     </style>
diff --git a/data/mainwindow.ui b/data/window.ui
similarity index 74%
rename from data/mainwindow.ui
rename to data/window.ui
index b5eb669..42c0614 100644
--- a/data/mainwindow.ui
+++ b/data/window.ui
@@ -120,6 +120,44 @@
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkStack" id="mainStack">
+                <property name="hexpand">true</property>
+                <property name="vexpand">true</property>
+                <property name="transition-type">crossfade</property>
+                <child>
+                  <object class="GtkStackPage">
+                    <property name="name">empty-recent</property>
+                    <property name="child">
+                      <object class="AdwStatusPage">
+                        <property name="icon_name">characters-punctuation-symbolic</property>
+                        <property name="title" translatable="yes">No Recent Characters</property>
+                        <property name="description" translatable="yes">Characters will appear here if you 
use them.</property>
+                      </object>
+                    </property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkStackPage">
+                    <property name="name">recent</property>
+                    <property name="child">
+                      <object class="GtkScrolledWindow">
+                        <property name="hscrollbar-policy">never</property>
+                        <property name="hexpand">false</property>
+                        <child>
+                          <object class="GtkBox" id="recentBox">
+                            <property name="orientation">vertical</property>
+                            <property name="hexpand">true</property>
+                            <property name="vexpand">false</property>
+
+                          </object>
+                        </child>
+                      </object>
+                    </property>
+                  </object>
+                </child>
+              </object>
+            </child>
           </object>
         </child>
       </object>
diff --git a/src/categoryList.js b/src/categoryList.js
index 9ce4ecc..82b8a2c 100644
--- a/src/categoryList.js
+++ b/src/categoryList.js
@@ -135,94 +135,112 @@ const EmojiCategoryList = [
 ];
 
 const CategoryListRowWidget = GObject.registerClass({
+    Properties: {
+        'title': GObject.ParamSpec.string(
+            'title',
+            'Category title', 'Category title',
+            GObject.ParamFlags.READWRITE,
+            '',
+        ),
+        'icon-name': GObject.ParamSpec.string(
+            'icon-name',
+            'Category Icon Name', 'Category Icon Name',
+            GObject.ParamFlags.READWRITE,
+            '',
+        ),
+    },
 }, class CategoryListRowWidget extends Gtk.ListBoxRow {
-
-    _init (category) {
-        super._init();
-        this.category = category;
+    _init () {
+        super._init({});
         /*this.get_accessible().accessible_name =
             _('%s Category List Row').format(category.title);*/
 
         let hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
         this.set_child(hbox);
-        let image = Gtk.Image.new_from_icon_name(category.icon_name);
+        let image = Gtk.Image.new();
+        this.bind_property("icon-name", image, "icon-name",
+        GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE);
         image.set_icon_size(Gtk.IconSize.LARGE_TOOLBAR);
         image.add_css_class('category-icon');
         hbox.append(image);
 
-        let label = new Gtk.Label({ label: Gettext.gettext(category.title),
-                                    halign: Gtk.Align.START });
+        let label = new Gtk.Label({ halign: Gtk.Align.START });
+        this.bind_property("title", label, "label",GObject.BindingFlags.DEFAULT | 
GObject.BindingFlags.SYNC_CREATE);
         label.add_css_class('category-label');
         hbox.append(label);
 
+        this.add_css_class('category');
     }
 });
 
-const CategoryListWidget = GObject.registerClass({
+var Sidebar = GObject.registerClass({
     Properties: {
-        'selected-category': GObject.ParamSpec.string(
-            'selected-category',
+        'selected-item': GObject.ParamSpec.object(
+            'selected-item',
             'Current active category', 'Currently selected category',
             GObject.ParamFlags.READWRITE,
-        ""),
+            Gtk.ListBoxRow.$gtype,
+        ),
     },
-}, class CategoryListWidget extends Adw.Bin {
-    _init(categories) {
-        super._init({});
-
-        this.list = Gtk.ListBox.new();
-        this._categories = categories;
-        this._lastSelectedRow = null;
-        this._selectedCategory = null;
-
-        for (let index in this._categories) {
-            let category = this._categories[index];
-            let rowWidget = new CategoryListRowWidget(category);
-            rowWidget.add_css_class('category');
-            this.list.append(rowWidget);
-        }
-
-        this.list.connect('row-selected', (row) => {
-            if (row != null && row.selectable) {
-                this._selectedCategory = row.category.name;
-                this.notify('selected-category');
-                this._lastSelectedRow = row;
-            }
-        });
-        this.set_child(this.list);
-    }
-
-    getCategoryList() {
-        return this._categories;
-    }
-
-    getCategory(name) {
-        for (let index in this._categories) {
-            let category = this._categories[index];
-            if (category.name == name)
-                return category;
-        }
-        return null;
+    Template: 'resource:///org/gnome/Characters/sidebar.ui',
+    InternalChildren: [
+        'list',
+        'recentRow', 'emojiSmileysRow', 'emojiAnimalsRow',
+        'emojiFoodRow', 'emojiActivitiesRow', 'emojiTravelRow',
+        'emojiObjectsRow', 'emojiSymbolsRow', 'emojiFlagsRow',
+        'lettersPunctuationRow', 'lettersArrowsRow',
+        'lettersBulletsRow', 'lettersPicturesRow',
+        'lettersCurrencyRow', 'lettersMathRow', 'lettersLatinRow',
+    ],
+}, class Sidebar extends Adw.Bin {
+    _init() {
+        super._init();
     }
 
-    restorePreviousSelection() {
-        if (this._lastSelectedRow) {
-            this.list.select_row(this._lastSelectedRow)
-        }
+    rowByName(name) {
+        switch(name) {
+            case 'smileys':
+                return this._emojiSmileysRow;
+            case 'animals':
+                return this._emojiAnimalsRow;
+            case 'food':
+                return this._emojiFoodRow;
+            case 'activities':
+                return this._emojiActivitesRow;
+            case 'travel':
+                return this._emojiTravelRow;
+            case 'objects':
+                return this._emojiObjectsRow;
+            case 'symbols':
+                return this._emojiSymbolsRow;
+            case 'flags':
+                return this._emojiFlagsRow;
+            case 'punctuation':
+                return this._lettersPunctuationRow;
+            case 'arrows':
+                return this._lettersArrowsRow;
+            case 'bullets':
+                return this._lettersBulletsRow;
+            case 'pictures':
+                return this._lettersPicturesRow;
+            case 'currency':
+                return this._lettersCurrencyRow;
+            case 'math':
+                return this._lettersMathRow;
+            case 'latin':
+                return this._lettersLatinRow;
+            default:
+                return this._recentRow;
+       }
     }
 
-    unselect() {
-        let selected = this.list.get_selected_row()
-        if (selected)
-            this.list.unselect_row(selected)
+    selectRowByName(name) {
+        let row = this.rowByName(name);
+        this._list.select_row(row);
     }
-});
 
-const LetterCategoryListWidget = GObject.registerClass({
-}, class LetterCategoryListWidget extends CategoryListWidget {
-    _init() {
-        super._init(LetterCategoryList);
-        this.populateCategoryList();
+    get selectedItem() {
+        return this._selected_item;
     }
 
     _finishListEngines(sources, bus, res) {
@@ -343,90 +361,3 @@ const LetterCategoryListWidget = GObject.registerClass({
         }
     }
 });
-
-const EmojiCategoryListWidget = GObject.registerClass({
-
-}, class EmojiCategoryListWidget extends CategoryListWidget {
-    _init() {
-        super._init(EmojiCategoryList);
-    }
-
-    getCategory(name) {
-        return super.getCategory(name);
-    }
-});
-
-const RecentCategoryListWidget = GObject.registerClass({
-
-}, class RecentCategoryListWidget extends CategoryListWidget {
-    _init() {
-        this.recentCategory = {
-            name: 'recent',
-            category: Gc.Category.NONE,
-            title: N_('Recently Used'),
-            icon_name: 'document-open-recent-symbolic',
-        };
-        super._init([this.recentCategory]);
-        this.recentRow = new CategoryListRowWidget(this.recentCategory);
-        this.recentRow.add_css_class('category');
-        this.recentRow.add_css_class('recent-category');
-        this.set_child(this.recentRow)
-    }
-
-    getCategory(name) {
-        return this.recentCategory;
-    }
-});
-
-var Sidebar = GObject.registerClass({
-    Template: 'resource:///org/gnome/Characters/sidebar.ui',
-    InternalChildren: [
-        'recentSection', 'emojisSection', 'lettersSection'
-    ],
-}, class Sidebar extends Gtk.Box {
-    _init() {
-        super._init();
-        this._lastSelectedList = null;
-
-        this._recentSection.list.connect('row-selected', (list, row) => {
-            this._lettersSection.unselect();
-            this._emojisSection.unselect();
-            this._lastSelectedList = this._recentSection;
-            list.select_row(row);
-        });
-        this._emojisSection.list.connect('row-selected', (list, row) => {
-            this._recentSection.unselect();
-            this._lettersSection.unselect();
-            this._lastSelectedList = this._emojisSection;
-            list.select_row(row);
-        });
-
-        this._lettersSection.list.connect('row-selected', (list, row) => {
-            this._emojisSection.unselect();
-            this._recentSection.unselect();
-            this._lastSelectedList = this._lettersSection;
-            list.select_row(row);
-        });
-    }
-
-    getCategoryByName(name) {
-        switch (name) {
-            case 'emojis':
-                return this._emojisSection
-            case 'recent':
-                return this._recentSection
-            default:
-                return this._lettersSection
-        }
-    }
-
-    get selectedList() {
-        return this._lastSelectedList
-    }
-    
-    restorePreviousSelection() {
-        if (this._lastSelectedList) {
-            this._lastSelectedList.restorePreviousSelection()
-        }
-    }
-});
diff --git a/src/window.js b/src/window.js
index b60b987..d6c2cc4 100644
--- a/src/window.js
+++ b/src/window.js
@@ -36,17 +36,21 @@ const Main = imports.main;
 const Util = imports.util;
 
 var MainWindow = GObject.registerClass({
-    Template: 'resource:///org/gnome/Characters/mainwindow.ui',
+    Template: 'resource:///org/gnome/Characters/window.ui',
     InternalChildren: [
         'main-headerbar', 'search-active-button',
         'search-bar', 'search-entry', 'back-button',
         'menuPopover', 'container', 'sidebar',
-        'leaflet'
+        'leaflet', 'mainStack', 'recentBox',
     ],
     Properties: {
         'search-active': GObject.ParamSpec.boolean(
             'search-active', '', '',
-            GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE, false)
+            GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE, false),
+        'max-recent-characters': GObject.ParamSpec.uint(
+            'max-recent-characters', '', '',
+            GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
+            0, GLib.MAXUINT32, 100)
     },
 }, class MainWindow extends Adw.ApplicationWindow {
     _init(application) {
@@ -55,6 +59,62 @@ var MainWindow = GObject.registerClass({
         this._searchActive = false;
         this._searchKeywords = [];
 
+        this._fontFilter = new FontFilter();
+        this._filterFontFamily = null;
+        this._characterLists = {};
+        this._recentCharacterLists = {};
+
+        this._sidebar.connect('notify::selected-item', (sidebar) => {
+            let selectedCategory = sidebar.selectedItem.category;
+            this._main_headerbar.title = selectedCategory.title;
+        });
+
+        let characterList;
+        /*
+        for (let i in MainCategories) {
+            let category = MainCategories[i];
+            let categoryList = this._sidebar.getCategoryByName(category.name);
+            let subcategories = categoryList.getCategoryList();
+            for (let j in subcategories) {
+                let subcategory = subcategories[j];
+                characterList = this._createCharacterList(
+                    subcategory.name,
+                    _('%s Character List').format(subcategory.title));
+                // FIXME: Can't use GtkContainer.child_get_property.
+                characterList.title = subcategory.title;
+                this._mainStack.add_titled(characterList, subcategory.name, subcategory.title);
+            }
+            characterList = this._createRecentCharacterList(
+                category.name,
+                // TRANSLATORS: %s will be either 'emojis' or 'letters'
+                _('Recently Used %s Character List').format(category.title),
+                category.category);
+            this._recentCharacterLists[category.name] = characterList;
+            if (i > 0) {
+                let separator = new Gtk.Separator({});
+                this._recentBox.append(separator);
+            }
+            this._recentBox.append(characterList);
+        }*/
+
+        // scroll.title = _('Recently Used');
+
+
+        /*characterList = this._createCharacterList(
+            'search-result', _('Search Result Character List'));
+        // FIXME: Can't use GtkContainer.child_get_property.
+        characterList.title = _("Search Result");
+        this._mainStack.add_named(characterList, 'search-result');
+        */
+        // FIXME: Can't use GSettings.bind with 'as' from Gjs
+        let recentCharacters = Main.settings.get_value('recent-characters');
+        this.recentCharacters = recentCharacters.get_strv();
+        this._maxRecentCharacters = 100;
+        Main.settings.bind('max-recent-characters', this,
+                           'max-recent-characters',
+                           Gio.SettingsBindFlags.DEFAULT);
+
+
         Util.initActions(this,
                          [{ name: 'about',
                             activate: this._about },
@@ -96,10 +156,6 @@ var MainWindow = GObject.registerClass({
             this._leaflet.navigate(Adw.NavigationDirection.BACK);
         });
 
-        this._mainView = new MainView(this._sidebar);
-
-        this._container.append(this._mainView);
-
         // Due to limitations of gobject-introspection wrt GdkEvent
         // and GdkEventKey, this needs to be a signal handler
         // TODO: use EventControllerKey
@@ -118,13 +174,11 @@ var MainWindow = GObject.registerClass({
 
     // Select the first subcategory which contains at least one character.
     _selectFirstSubcategory() {
-        let categoryList;
-        if (this._mainView.recentCharacters.length !== 0) {
-            categoryList = this._sidebar.getCategoryByName('recent').list;
+        if (this.recentCharacters.length !== 0) {
+            this._sidebar.selectRowByName('recent');
         } else {
-            categoryList = this._sidebar.getCategoryByName('emojis').list;
+            this._sidebar.selectRowByName('smileys');
         }
-        categoryList.select_row(categoryList.get_row_at_index(0));
     }
 
     get search_active() {
@@ -153,10 +207,10 @@ var MainWindow = GObject.registerClass({
         let keywords = text == '' ? [] : text.split(/\s+/);
         keywords = keywords.map(x => x.toUpperCase());
         if (keywords != this._searchKeywords) {
-            this._mainView.cancelSearch();
+            this.cancelSearch();
             this._searchKeywords = keywords;
             if (this._searchKeywords.length > 0)
-                this._mainView.searchByKeywords(this._searchKeywords);
+                this.searchByKeywords(this._searchKeywords);
         }
         return true;
     }
@@ -191,10 +245,10 @@ var MainWindow = GObject.registerClass({
     }
 
     _updateTitle(title) {
-        if (this._mainView.filterFontFamily) {
+        if (this.filterFontFamily) {
             this._main_headerbar.title =
                 _("%s (%s only)").format(Gettext.gettext(title),
-                                         this._mainView.filterFontFamily);
+                                         this.filterFontFamily);
         } else {
             this._main_headerbar.title = Gettext.gettext(title);
         }
@@ -215,7 +269,7 @@ var MainWindow = GObject.registerClass({
         let categoryList = this._sidebar.getCategoryByName(categoryName);
         let category = categoryList.getCategory(name);
         if (category) {
-            this._mainView.setPage(category);
+            this.setPage(category);
             this._updateTitle(category.title);
             this._leaflet.navigate(Adw.NavigationDirection.FORWARD);
         }
@@ -223,15 +277,15 @@ var MainWindow = GObject.registerClass({
 
     _character(action, v) {
         const [uc, length] = v.get_string();
-        this._mainView.addToRecent(uc);
+        this.addToRecent(uc);
     }
 
     _filterFont(action, v) {
         let [family, length] = v.get_string();
         if (family == 'None')
             family = null;
-        this._mainView.filterFontFamily = family;
-        this._updateTitle(this._mainView.visible_child.title);
+        this.filterFontFamily = family;
+        //this._updateTitle(this._stack.visible_child.title);
         this._menuPopover.hide();
     }
 
@@ -243,17 +297,7 @@ var MainWindow = GObject.registerClass({
         this.search_active = keywords.length > 0;
         this._search_entry.set_text(keywords.join(' '));
     }
-});
 
-const MainView = GObject.registerClass({
-    Template: 'resource:///org/gnome/Characters/mainview.ui',
-    Properties: {
-        'max-recent-characters': GObject.ParamSpec.uint(
-            'max-recent-characters', '', '',
-            GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
-            0, GLib.MAXUINT32, 100)
-    },
-}, class MainView extends Gtk.Stack {
     get max_recent_characters() {
         return this._maxRecentCharacters;
     }
@@ -274,71 +318,6 @@ const MainView = GObject.registerClass({
         this._fontFilter.setFilterFont(this._filterFontFamily);
     }
 
-    _init(sidebar) {
-        super._init({
-            hexpand: true, vexpand: true,
-            transition_type: Gtk.StackTransitionType.CROSSFADE
-        });
-
-        this._fontFilter = new FontFilter();
-        this._filterFontFamily = null;
-        this._characterLists = {};
-        this._recentCharacterLists = {};
-        this._sidebar = sidebar;
-
-        let characterList;
-        let recentBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL,
-                                      hexpand: true, vexpand: false });
-
-        for (let i in MainCategories) {
-            let category = MainCategories[i];
-            let categoryList = this._sidebar.getCategoryByName(category.name);
-            let subcategories = categoryList.getCategoryList();
-            for (let j in subcategories) {
-                let subcategory = subcategories[j];
-                characterList = this._createCharacterList(
-                    subcategory.name,
-                    _('%s Character List').format(subcategory.title));
-                // FIXME: Can't use GtkContainer.child_get_property.
-                characterList.title = subcategory.title;
-                this.add_titled(characterList, subcategory.name, subcategory.title);
-            }
-            characterList = this._createRecentCharacterList(
-                category.name,
-                // TRANSLATORS: %s will be either 'emojis' or 'letters'
-                _('Recently Used %s Character List').format(category.title),
-                category.category);
-            this._recentCharacterLists[category.name] = characterList;
-            if (i > 0) {
-                let separator = new Gtk.Separator({});
-                recentBox.append(separator);
-            }
-            recentBox.append(characterList);
-        }
-        let scroll = new Gtk.ScrolledWindow({
-            hscrollbar_policy: Gtk.PolicyType.NEVER,
-            hexpand: false,
-        });
-        scroll.set_child(recentBox);
-        // FIXME: Can't use GtkContainer.child_get_property.
-        scroll.title = _('Recently Used');
-        this.add_titled(scroll, 'recent', scroll.title);
-
-        characterList = this._createCharacterList(
-            'search-result', _('Search Result Character List'));
-        // FIXME: Can't use GtkContainer.child_get_property.
-        characterList.title = _("Search Result");
-        this.add_named(characterList, 'search-result');
-
-        // FIXME: Can't use GSettings.bind with 'as' from Gjs
-        let recentCharacters = Main.settings.get_value('recent-characters');
-        this.recentCharacters = recentCharacters.get_strv();
-        this._maxRecentCharacters = 100;
-        Main.settings.bind('max-recent-characters', this,
-                           'max-recent-characters',
-                           Gio.SettingsBindFlags.DEFAULT);
-    }
-
     _createCharacterList(name, accessible_name) {
         const characterList = new CharacterListView(this._fontFilter);
         //characterList.get_accessible().accessible_name = accessible_name;
@@ -363,7 +342,7 @@ const MainView = GObject.registerClass({
     }
 
     cancelSearch() {
-        const characterList = this.get_child_by_name('search-result');
+        const characterList = this.mainStack.get_child_by_name('search-result');
         characterList.cancelSearch();
     }
 


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