[gnome-characters/bilelmoussaoui/gtk4: 26/27] characters: create a new common view widget




commit bf8f59281aef264787f8471793c89611db750c65
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Sun Nov 21 15:27:30 2021 +0100

    characters: create a new common view widget
    
    This will be used for all the various categories instead of creating
    various a view per category
    It also cleans up a ton of  code by moving it to UI files instead of source code

 data/characterlist.ui                        |  45 --------
 data/characters_view.ui                      |  10 ++
 data/meson.build                             |   7 +-
 data/org.gnome.Characters.data.gresource.xml |   2 +-
 data/sidebar.ui                              |  15 +++
 data/window.ui                               |  56 +++++++++
 lib/gc.h                                     |   5 +-
 lib/meson.build                              |   4 +-
 src/categoryList.js                          | 126 +++------------------
 src/{characterList.js => charactersView.js}  | 163 +++++++++++----------------
 src/main.js                                  |   2 +-
 src/meson.build                              |   2 +-
 src/org.gnome.Characters.src.gresource.xml   |   2 +-
 src/window.js                                |  95 ++++------------
 14 files changed, 194 insertions(+), 340 deletions(-)
---
diff --git a/data/characters_view.ui b/data/characters_view.ui
new file mode 100644
index 0000000..fff893d
--- /dev/null
+++ b/data/characters_view.ui
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="Gjs_CharactersView" parent="AdwBin">
+    <child>
+      <object class="GtkFlowBox" id="flow">
+
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/data/meson.build b/data/meson.build
index 5f7e708..d83d9a0 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -17,11 +17,10 @@ resource_data = files(
   'icons/hicolor/scalable/categories/characters-picture-symbolic.svg',
   'icons/hicolor/scalable/categories/characters-punctuation-symbolic.svg',
   'style.css',
-  'characterlist.ui',
   'character.ui',
-  'mainview.ui',
-  'mainwindow.ui',
-  'menu.ui'
+  'characters_view.ui',
+  'menu.ui',
+  'window.ui',
 )
 
 resources = [
diff --git a/data/org.gnome.Characters.data.gresource.xml b/data/org.gnome.Characters.data.gresource.xml
index 331ce23..d1c6e4d 100644
--- a/data/org.gnome.Characters.data.gresource.xml
+++ b/data/org.gnome.Characters.data.gresource.xml
@@ -2,7 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/Characters">
     <file preprocess="xml-stripblanks">character.ui</file>
-    <file preprocess="xml-stripblanks">characterlist.ui</file>
+    <file preprocess="xml-stripblanks">characters_view.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>
diff --git a/data/sidebar.ui b/data/sidebar.ui
index a6fd890..4056ccf 100644
--- a/data/sidebar.ui
+++ b/data/sidebar.ui
@@ -44,6 +44,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="emojiSmileysRow">
+            <property name="category">GC_CATEGORY_EMOJI_SMILEYS</property>
             <property name="name">emoji-smileys</property>
             <property name="icon-name">characters-emoji-smileys</property>
             <property name="title" translatable="yes">Smileys &amp; People</property>
@@ -51,6 +52,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="emojiAnimalsRow">
+            <property name="category">GC_CATEGORY_EMOJI_ANIMALS</property>
             <property name="name">emoji-animals</property>
             <property name="icon-name">characters-emoji-animals</property>
             <property name="title" translatable="yes">Animals &amp; Nature</property>
@@ -58,6 +60,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="emojiFoodRow">
+            <property name="category">GC_CATEGORY_EMOJI_FOOD</property>
             <property name="name">emoji-food</property>
             <property name="icon-name">characters-emoji-food</property>
             <property name="title" translatable="yes">Food &amp; Drink</property>
@@ -65,6 +68,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="emojiActivitiesRow">
+            <property name="category">GC_CATEGORY_EMOJI_ACTIVITIES</property>
             <property name="name">emoji-activities</property>
             <property name="icon-name">characters-emoji-activities</property>
             <property name="title" translatable="yes">Activities</property>
@@ -72,6 +76,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="emojiTravelRow">
+            <property name="category">GC_CATEGORY_EMOJI_TRAVEL</property>
             <property name="name">emoji-travel</property>
             <property name="icon-name">characters-emoji-travel</property>
             <property name="title" translatable="yes">Travel &amp; Places</property>
@@ -79,6 +84,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="emojiObjectsRow">
+            <property name="category">GC_CATEGORY_EMOJI_OBJECTS</property>
             <property name="name">emoji-objects</property>
             <property name="icon-name">characters-emoji-objects</property>
             <property name="title" translatable="yes">Objects</property>
@@ -86,6 +92,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="emojiSymbolsRow">
+            <property name="category">GC_CATEGORY_EMOJI_SYMBOLS</property>
             <property name="name">emoji-symbols</property>
             <property name="icon-name">characters-emoji-symbols</property>
             <property name="title" translatable="yes">Symbols</property>
@@ -93,6 +100,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="emojiFlagsRow">
+            <property name="category">GC_CATEGORY_EMOJI_FLAGS</property>
             <property name="name">emoji-flags</property>
             <property name="icon-name">characters-emoji-flags</property>
             <property name="title" translatable="yes">Flags</property>
@@ -119,6 +127,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="lettersPunctuationRow">
+            <property name="category">GC_CATEGORY_LETTER_PUNCTUATION</property>
             <property name="name">punctuation</property>
             <property name="icon-name">characters-punctuation-symbolic</property>
             <property name="title" translatable="yes">Punctuation</property>
@@ -126,6 +135,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="lettersArrowsRow">
+            <property name="category">GC_CATEGORY_LETTER_ARROW</property>
             <property name="name">arrow</property>
             <property name="icon-name">characters-arrow-symbolic</property>
             <property name="title" translatable="yes">Arrows</property>
@@ -133,6 +143,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="lettersBulletsRow">
+            <property name="category">GC_CATEGORY_LETTER_BULLET</property>
             <property name="name">bullet</property>
             <property name="icon-name">characters-bullet-symbolic</property>
             <property name="title" translatable="yes">Bullets</property>
@@ -140,6 +151,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="lettersPicturesRow">
+            <property name="category">GC_CATEGORY_LETTER_PICTURE</property>
             <property name="name">picture</property>
             <property name="icon-name">characters-picture-symbolic</property>
             <property name="title" translatable="yes">Pictures</property>
@@ -147,6 +159,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="lettersCurrencyRow">
+            <property name="category">GC_CATEGORY_LETTER_CURRENCY</property>
             <property name="name">currency</property>
             <property name="icon-name">characters-currency-symbolic</property>
             <property name="title" translatable="yes">Currencies</property>
@@ -154,6 +167,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="lettersMathRow">
+            <property name="category">GC_CATEGORY_LETTER_MATH</property>
             <property name="name">math</property>
             <property name="icon-name">characters-math-symbolic</property>
             <property name="title" translatable="yes">Math</property>
@@ -161,6 +175,7 @@
         </child>
         <child>
           <object class="Gjs_CategoryListRowWidget" id="lettersLatinRow">
+            <property name="category">GC_CATEGORY_LETTER_LATIN</property>
             <property name="name">letters</property>
             <property name="icon-name">characters-latin-symbolic</property>
             <property name="title" translatable="yes">Letters</property>
diff --git a/data/window.ui b/data/window.ui
index d47ce8e..64b6415 100644
--- a/data/window.ui
+++ b/data/window.ui
@@ -159,6 +159,62 @@
                     </property>
                   </object>
                 </child>
+                <child>
+                  <object class="GtkStackPage">
+                    <property name="name">character-list</property>
+                    <property name="child">
+                      <object class="GtkScrolledWindow">
+                        <property name="hscrollbar-policy">never</property>
+                        <child>
+                          <object class="Gjs_CharactersView" id="charactersView" />
+                        </child>
+                        <style>
+                          <class name="character-list-scroll" />
+                        </style>
+                      </object>
+                    </property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkStackPage">
+                    <property name="name">unavailable</property>
+                    <property name="child">
+                      <object class="AdwStatusPage">
+                        <property name="icon-name">system-search-symbolic</property>
+                        <property name="title" translatable="yes">No Results</property>
+                        <property name="description" translatable="yes">Try a different search.</property>
+                      </object>
+                    </property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkStackPage">
+                    <property name="name">loading</property>
+                    <property name="child">
+                      <object class="GtkGrid" id="loading-grid">
+                        <property name="halign">center</property>
+                        <property name="valign">center</property>
+                        <style>
+                          <class name="banner"/>
+                        </style>
+                        <child>
+                          <object class="GtkSpinner" id="loading-spinner">
+                            <property name="width-request">128</property>
+                            <property name="height-request">128</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="loading-label">
+                            <property name="label" translatable="yes">Loading…</property>
+                            <style>
+                              <class name="banner-label"/>
+                            </style>
+                          </object>
+                        </child>
+                      </object>
+                    </property>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
diff --git a/lib/gc.h b/lib/gc.h
index 3bd8c0e..18238f5 100644
--- a/lib/gc.h
+++ b/lib/gc.h
@@ -5,7 +5,6 @@
 #define __GC_H__
 
 #include <gio/gio.h>
-#include <gtk/gtk.h>
 #include <pango/pango.h>
 #include "gc-enumtypes.h"
 
@@ -14,7 +13,9 @@ G_BEGIN_DECLS
 /* libunistring support.  In libunistring, the Unicode general
    categories are defined as global constant, which is not accessible
    through GI.  */
-
+/**
+ * GcCategory:
+ */
 typedef enum
 {
   GC_CATEGORY_NONE,
diff --git a/lib/meson.build b/lib/meson.build
index 62de48e..10ceb38 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -32,13 +32,13 @@ libgc = shared_library(
 
 gnome.generate_gir(
   libgc,
-  sources: sources + [gc_enums[0], gc_h],
+  sources: sources + [gc_enums[0], gc_enums[1], gc_h],
   nsversion: characters_gir_version,
   namespace: characters_ns,
   identifier_prefix: characters_ns,
   symbol_prefix: characters_ns.to_lower(),
   header: gc_h,
-  includes: ['Gio-2.0'],
+  includes: ['Gio-2.0', 'Pango-1.0'],
   install: true,
   install_dir_gir: join_paths(characters_pkgdatadir, 'gir-' + characters_gir_version),
   install_dir_typelib: join_paths(characters_pkglibdir, 'girepository-' + characters_gir_version)
diff --git a/src/categoryList.js b/src/categoryList.js
index b11efbd..350b783 100644
--- a/src/categoryList.js
+++ b/src/categoryList.js
@@ -23,117 +23,6 @@ const Gettext = imports.gettext;
 
 const Util = imports.util;
 
-var MainCategories = [
-    {
-        name: 'emojis',
-        category: Gc.Category.EMOJI,
-        title: N_('Emojis'),
-        icon_name: 'characters-emoji-smileys',
-    },
-    {
-        name: 'letters',
-        category: Gc.Category.LETTER,
-        title: N_('Letters & Symbols'),
-        icon_name: 'characters-latin-symbolic',
-    }
-];
-
-const LetterCategoryList = [
-    {
-        name: 'punctuation',
-        category: Gc.Category.LETTER_PUNCTUATION,
-        title: N_('Punctuation'),
-        icon_name: 'characters-punctuation-symbolic',
-    },
-    {
-        name: 'arrow',
-        category: Gc.Category.LETTER_ARROW,
-        title: N_('Arrows'),
-        icon_name: 'characters-arrow-symbolic',
-    },
-    {
-        name: 'bullet',
-        category: Gc.Category.LETTER_BULLET,
-        title: N_('Bullets'),
-        icon_name: 'characters-bullet-symbolic',
-    },
-    {
-        name: 'picture',
-        category: Gc.Category.LETTER_PICTURE,
-        title: N_('Pictures'),
-        icon_name: 'characters-picture-symbolic',
-    },
-    {
-        name: 'currency',
-        category: Gc.Category.LETTER_CURRENCY,
-        title: N_('Currencies'),
-        icon_name: 'characters-currency-symbolic',
-    },
-    {
-        name: 'math',
-        category: Gc.Category.LETTER_MATH,
-        title: N_('Math'),
-        icon_name: 'characters-math-symbolic',
-    },
-    {
-        name: 'letters',
-        category: Gc.Category.LETTER_LATIN,
-        title: N_('Letters'),
-        icon_name: 'characters-latin-symbolic',
-    }
-];
-
-const EmojiCategoryList = [
-    {
-        name: 'emoji-smileys',
-        category: Gc.Category.EMOJI_SMILEYS,
-        title: N_('Smileys & People'),
-        icon_name: 'characters-emoji-smileys',
-    },
-    {
-        name: 'emoji-animals',
-        category: Gc.Category.EMOJI_ANIMALS,
-        title: N_('Animals & Nature'),
-        icon_name: 'characters-emoji-animals',
-    },
-    {
-        name: 'emoji-food',
-        category: Gc.Category.EMOJI_FOOD,
-        title: N_('Food & Drink'),
-        icon_name: 'characters-emoji-food',
-    },
-    {
-        name: 'emoji-activities',
-        category: Gc.Category.EMOJI_ACTIVITIES,
-        title: N_('Activities'),
-        icon_name: 'characters-emoji-activities',
-    },
-    {
-        name: 'emoji-travel',
-        category: Gc.Category.EMOJI_TRAVEL,
-        title: N_('Travel & Places'),
-        icon_name: 'characters-emoji-travel',
-    },
-    {
-        name: 'emoji-objects',
-        category: Gc.Category.EMOJI_OBJECTS,
-        title: N_('Objects'),
-        icon_name: 'characters-emoji-objects',
-    },
-    {
-        name: 'emoji-symbols',
-        category: Gc.Category.EMOJI_SYMBOLS,
-        title: N_('Symbols'),
-        icon_name: 'characters-emoji-symbols',
-    },
-    {
-        name: 'emoji-flags',
-        category: Gc.Category.EMOJI_FLAGS,
-        title: N_('Flags'),
-        icon_name: 'characters-emoji-flags',
-    }
-];
-
 const CategoryListRowWidget = GObject.registerClass({
     Properties: {
         'title': GObject.ParamSpec.string(
@@ -142,6 +31,13 @@ const CategoryListRowWidget = GObject.registerClass({
             GObject.ParamFlags.READWRITE,
             '',
         ),
+        'category': GObject.ParamSpec.enum(
+            'category',
+            'Category', 'Category',
+            GObject.ParamFlags.READWRITE,
+            Gc.Category.$gtype,
+            Gc.Category.NONE,
+        ),
         'icon-name': GObject.ParamSpec.string(
             'icon-name',
             'Category Icon Name', 'Category Icon Name',
@@ -179,6 +75,14 @@ const CategoryListRowWidget = GObject.registerClass({
     set title(title) {
         this._title = title;
     }
+
+    get category() {
+        return this._category || Gc.Category.NONE;
+    }
+
+    set category(value) {
+        this._category = value;
+    }
 });
 
 var Sidebar = GObject.registerClass({
diff --git a/src/characterList.js b/src/charactersView.js
similarity index 84%
rename from src/characterList.js
rename to src/charactersView.js
index d021ee0..65e4ee8 100644
--- a/src/characterList.js
+++ b/src/charactersView.js
@@ -16,7 +16,7 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-const {Adw, Gc, Gdk, GLib, Gio,GObject,Gtk, Pango, PangoCairo} = imports.gi;
+const {Adw, Gc, Gdk, GLib, Gio,GObject,Gtk, Pango, Graphene, PangoCairo} = imports.gi;
 
 const Cairo = imports.cairo;
 
@@ -51,10 +51,9 @@ const CharacterListRow = GObject.registerClass({
         layout.set_font_description(this._fontDescription);
 
         this._styleContext = styleContext;
-
         // Draw baseline.
         // FIXME: Pick the baseline color from CSS.
-        let fg_color = this._styleContext.get_color(Gtk.StateFlags.NORMAL);
+        let fg_color = this._styleContext.lookup_color('accent_color');
         cr.setSourceRGBA(114.0 / 255.0, 159.0 / 255.0, 207.0 / 255.0, 1.0);
         cr.setLineWidth(0.5);
         cr.moveTo(x, y + BASELINE_OFFSET * height);
@@ -190,15 +189,14 @@ const CharacterListWidget = GObject.registerClass({
     Signals: {
         'character-selected': { param_types: [ GObject.TYPE_STRING ] }
     },
-}, class CharacterListWidget extends Gtk.DrawingArea {
-    _init(fontDescription, numRows) {
+}, class CharacterListWidget extends Gtk.Widget {
+    _init(numRows) {
         super._init({
             hexpand: true,
             vexpand: true,
         });
         this.add_css_class('character-list');
         this._cellsPerRow = CELLS_PER_ROW;
-        this._fontDescription = fontDescription;
         this._numRows = numRows;
         this._characters = [];
         this._rows = [];
@@ -249,42 +247,37 @@ const CharacterListWidget = GObject.registerClass({
             this.emit('character-selected', this._character);
         return false;
     }
-    vfunc_get_preferred_height() {
-        let [minWidth, natWidth] = this.vfunc_get_preferred_width();
-        return this.vfunc_get_preferred_height_for_width(minWidth);
-    }
-
-
-    vfunc_get_preferred_height_for_width(width) {
-        let height = Math.max(this._rows.length, this._numRows) *
-            getCellSize(this._fontDescription);
-        return [height, height];
-    }
+    */
 
-    vfunc_get_preferred_width() {
-        return this.vfunc_get_preferred_width_for_height(0);
+    vfunc_measure(orientation, for_size) {
+        if(orientation === Gtk.Orientation.HORIZONTAL) {
+            let cellSize = getCellSize(this._fontDescription);
+            let minWidth = NUM_COLUMNS * cellSize;
+            let natWidth = Math.max(this._cellsPerRow, NUM_COLUMNS) * cellSize;
+            return [minWidth, natWidth, -1, -1];
+        } else {
+            let height = Math.max(this._rows.length, this._numRows) *
+                getCellSize(this._fontDescription);
+            return [height, height, -1 , -1];
+        }
     }
 
-    vfunc_get_preferred_width_for_height(height) {
-        let cellSize = getCellSize(this._fontDescription);
-        let minWidth = NUM_COLUMNS * cellSize;
-        let natWidth = Math.max(this._cellsPerRow, NUM_COLUMNS) * cellSize;
-        return [minWidth, natWidth];
-    }
-    vfunc_draw(cr) {
+    vfunc_snapshot(snapshot) {
         // Clear the canvas.
-        let context = this.get_style_context();
-        let fg = context.get_color(Gtk.StateFlags.NORMAL);
-        let bg = context.get_background_color(Gtk.StateFlags.NORMAL);
+        let allocation = this.get_allocation();
+        let rect = new Graphene.Rect({
+            origin: new Graphene.Point({x: 0, y:0}),
+            size: new Graphene.Size({width: allocation.width, height: allocation.height})
+        });
+        let cr = snapshot.append_cairo(rect);
 
-        cr.setSourceRGBA(bg.red, bg.green, bg.blue, bg.alpha);
-        cr.paint();
-        cr.setSourceRGBA(fg.red, fg.green, fg.blue, fg.alpha);
+        let context = this.get_style_context();
+        let fg = context.get_color();
+        Gdk.cairo_set_source_rgba(cr, fg);
 
         // Use device coordinates directly, since PangoCairo doesn't
         // work well with scaled matrix:
         // https://bugzilla.gnome.org/show_bug.cgi?id=700592
-        let allocation = this.get_allocation();
 
         // Redraw rows within the clipped region.
         let [x1, y1, x2, y2] = cr.clipExtents();
@@ -296,17 +289,16 @@ const CharacterListWidget = GObject.registerClass({
                                    allocation.width, cellSize, context);
         }
     }
-    */
 
     vfunc_get_request_mode() {
         return Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH;
     }
 
-    vfunc_size_allocate(allocation) {
-        super.vfunc_size_allocate(allocation);
+    vfunc_size_allocate(width, height, baseline) {
+        super.vfunc_size_allocate(width, height, baseline);
 
         let cellSize = getCellSize(this._fontDescription);
-        let cellsPerRow = Math.floor(allocation.width / cellSize);
+        let cellsPerRow = Math.floor(width / cellSize);
         if (cellsPerRow != this._cellsPerRow) {
             // Reflow if the number of cells per row has changed.
             this._cellsPerRow = cellsPerRow;
@@ -317,7 +309,7 @@ const CharacterListWidget = GObject.registerClass({
     _createCharacterListRow(characters) {
         var context = this.get_pango_context();
         var overlayFontDescription = context.get_font_description();
-        overlayFontDescription.set_size(fontDescription.get_size() * 0.8);
+        overlayFontDescription.set_size(overlayFontDescription.get_size() * 0.8);
 
         let row = new CharacterListRow(characters, this._fontDescription, overlayFontDescription);
         return row;
@@ -433,35 +425,27 @@ var FontFilter = GObject.registerClass({
     }
 });
 
-var CharacterListView = GObject.registerClass({
-    Template: 'resource:///org/gnome/Characters/characterlist.ui',
-    InternalChildren: ['loading-spinner'],
+var CharactersView = GObject.registerClass({
+    Template: 'resource:///org/gnome/Characters/characters_view.ui',
     Signals: {
         'character-selected': { param_types: [ GObject.TYPE_STRING ] }
     },
-}, class CharacterListView extends Gtk.Stack {
-    _init(fontFilter) {
-        super._init({
-            hexpand: true, vexpand: true,
-            transition_type: Gtk.StackTransitionType.CROSSFADE
-        });
+    Properties: {
+        'model': GObject.ParamSpec.object(
+            'model',
+            'Characters List Model', 'Characters List Model',
+            GObject.ParamFlags.READWRITE,
+            Gio.ListModel.$gtype,
+        ),
+    }
+}, class CharactersView extends Adw.Bin {
+    _init() {
+        super._init();
 
-        this._fontFilter = fontFilter;
-        this._characterList = new CharacterListWidget(this._fontFilter.fontDescription, NUM_ROWS);
+        this._characterList = new CharacterListWidget(NUM_ROWS);
         this._characterList.connect('character-selected', (w, c) => this.emit('character-selected', c));
-        let scroll = new Gtk.ScrolledWindow({
-            hscrollbar_policy: Gtk.PolicyType.NEVER,
-        });
-
-        scroll.set_child(this._characterList);
-
-        let context = scroll.get_style_context();
-        context.add_class('character-list-scroll');
-        context.save();
-        this.add_named(scroll, 'character-list');
-        this.visible_child_name = 'character-list';
 
-        this._fontFilter.connect('filter-set', () => this._updateCharacterList());
+        this.set_child(this._characterList);
 
         this._characters = [];
         this._spinnerTimeoutId = 0;
@@ -479,13 +463,18 @@ var CharacterListView = GObject.registerClass({
         */
     }
 
+    setFontFilter(fontFilter) {
+        this._characterList.setFontDescription(fontFilter.fontDescription);
+        fontFilter.connect('filter-set', () => this._updateCharacterList());
+        this._fontFilter = fontFilter;
+    }
+
     _startSpinner() {
         this._stopSpinner();
         this._spinnerTimeoutId =
             GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
-                                 this._loading_spinner.start();
-                                 this.visible_child_name = 'loading';
-                                 this.show_all();
+                                 //this._loading_spinner.start();
+                                 //this.visible_child_name = 'loading';
                              });
     }
 
@@ -493,7 +482,7 @@ var CharacterListView = GObject.registerClass({
         if (this._spinnerTimeoutId > 0) {
             GLib.source_remove(this._spinnerTimeoutId);
             this._spinnerTimeoutId = 0;
-            this._loading_spinner.stop();
+            //this._loading_spinner.stop();
         }
     }
 
@@ -511,26 +500,11 @@ var CharacterListView = GObject.registerClass({
     }
 
     _updateCharacterList() {
+        log('Updating characters list');
         const [fontDescription, characters] = this._fontFilter.apply(this, this._characters);
+        log(JSON.stringify(characters));
         this._characterList.setFontDescription(fontDescription);
         this._characterList.setCharacters(characters);
-        if (characters.length == 0) {
-            this.visible_child_name = 'unavailable';
-        } else {
-            this.visible_child_name = 'character-list';
-        }
-    }
-
-    _maybeLoadMore() {
-        if (this._searchContext != null && !this._searchContext.is_finished()) {
-            this._searchWithContext(this._searchContext, MAX_SEARCH_RESULTS);
-        }
-    }
-
-    _onEdgeReached(scrolled, pos) {
-        if (pos == Gtk.PositionType.BOTTOM) {
-            this._maybeLoadMore();
-        }
     }
 
     get initialSearchCount() {
@@ -549,12 +523,6 @@ var CharacterListView = GObject.registerClass({
         return Math.max(MAX_SEARCH_RESULTS, heightInRows * cellsPerRow);
     }
 
-    _onSizeAllocate(scrolled, allocation) {
-        if (this._characters.length < this.initialSearchCount) {
-            this._maybeLoadMore();
-        }
-    }
-
     _addSearchResult(result) {
         const characters = Util.searchResultToArray(result);
         this.setCharacters(this._characters.concat(characters));
@@ -575,12 +543,12 @@ var CharacterListView = GObject.registerClass({
 
     searchByCategory(category) {
         this._characters = [];
-        if ('scripts' in category) {
+        /*if ('scripts' in category) {
             this.searchByScripts(category.scripts);
             return;
-        }
+        }*/
 
-        let criteria = Gc.SearchCriteria.new_category(category.category);
+        let criteria = Gc.SearchCriteria.new_category(category);
         this._searchContext = new Gc.SearchContext({ criteria: criteria });
         this._searchWithContext(this._searchContext, this.initialSearchCount);
     }
@@ -611,22 +579,25 @@ var RecentCharacterListView = GObject.registerClass({
         'character-selected': { param_types: [ GObject.TYPE_STRING ] },
     },
 }, class RecentCharacterListView extends Adw.Bin {
-    _init(category, fontFilter) {
+    _init(category) {
         super._init({
             hexpand: true, vexpand: false
         });
 
-        this._fontFilter = fontFilter;
-        this._characterList = new CharacterListWidget(this._fontFilter.fontDescription, 0);
+        this._characterList = new CharacterListWidget(0);
         this._characterList.connect('character-selected', (w, c) => this.emit('character-selected', c));
         this.set_child(this._characterList);
 
-        this._fontFilter.connect('filter-set', () => this._updateCharacterList());
-
         this._category = category;
         this._characters = [];
     }
 
+    setFontFilter(fontFilter) {
+        this._characterList.setFontDescription(fontFilter.fontDescription);
+        fontFilter.connect('filter-set', () => this._updateCharacterList());
+        this._fontFilter = fontFilter;
+    }
+
     setCharacters(characters) {
         const result = Gc.filter_characters(this._category, characters);
         this._characters = Util.searchResultToArray(result);
diff --git a/src/main.js b/src/main.js
index 72387ed..c3bd600 100644
--- a/src/main.js
+++ b/src/main.js
@@ -36,7 +36,7 @@ pkg.require({
     'GnomeDesktop': '4.0',
 });
 
-const {GLib, Gio, GObject, Gtk, Adw} = imports.gi;
+const {Gc, GLib, Gio, GObject, Gtk, Adw} = imports.gi;
 
 const Util = imports.util;
 const { MainWindow } = imports.window;
diff --git a/src/meson.build b/src/meson.build
index ffa1c97..eb44aee 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -27,7 +27,7 @@ common_resource_data = files(
 resource_data = common_resource_data + files(
   'categoryList.js',
   'characterDialog.js',
-  'characterList.js',
+  'charactersView.js',
   'main.js',
   'menu.js',
   'window.js'
diff --git a/src/org.gnome.Characters.src.gresource.xml b/src/org.gnome.Characters.src.gresource.xml
index b89c48f..3abe275 100644
--- a/src/org.gnome.Characters.src.gresource.xml
+++ b/src/org.gnome.Characters.src.gresource.xml
@@ -7,6 +7,6 @@
     <file>window.js</file>
     <file>categoryList.js</file>
     <file>characterDialog.js</file>
-    <file>characterList.js</file>
+    <file>charactersView.js</file>
   </gresource>
 </gresources>
diff --git a/src/window.js b/src/window.js
index 8ed3aac..98f3cb0 100644
--- a/src/window.js
+++ b/src/window.js
@@ -28,7 +28,7 @@ const {Adw, Gio, GLib, GObject, Gtk } = imports.gi;
 
 const {Sidebar, MainCategories} = imports.categoryList;
 const {CharacterDialog} = imports.characterDialog;
-const {CharacterListView, FontFilter, RecentCharacterListView} = imports.characterList;
+const {CharactersView, FontFilter, RecentCharacterListView} = imports.charactersView;
 const {MenuPopover} = imports.menu;
 const Gettext = imports.gettext;
 
@@ -42,6 +42,7 @@ var MainWindow = GObject.registerClass({
         'search-bar', 'search-entry', 'back-button',
         'menuPopover', 'container', 'sidebar',
         'leaflet', 'mainStack', 'recentBox', 'windowTitle',
+        'charactersView',
     ],
     Properties: {
         'search-active': GObject.ParamSpec.boolean(
@@ -63,40 +64,17 @@ var MainWindow = GObject.registerClass({
         this._filterFontFamily = null;
         this._characterLists = {};
         this._recentCharacterLists = {};
+        this._charactersView.setFontFilter(this._fontFilter);
+        this._charactersView.connect('character-selected', (widget, uc) => 
this._handleCharacterSelected(widget, uc));
+
 
         this._sidebar.list.connect('row-selected', (sidebar, row) => {
-            this._windowTitle.title = row.title;
+            this.setPage(row);
+            this._updateTitle(row.title);
+            this._leaflet.navigate(Adw.NavigationDirection.FORWARD);
         });
 
         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(
@@ -245,32 +223,11 @@ var MainWindow = GObject.registerClass({
 
     _updateTitle(title) {
         if (this.filterFontFamily) {
-            this._main_headerbar.title =
+            this._windowTitle.title =
                 _("%s (%s only)").format(Gettext.gettext(title),
                                          this.filterFontFamily);
         } else {
-            this._main_headerbar.title = Gettext.gettext(title);
-        }
-    }
-
-    _category(action, v) {
-        this.search_active = false;
-
-        let [name, length] = v.get_string();
-        let categoryName;
-        if(name.startsWith("emoji")) {
-            categoryName = "emojis";
-        } else if(name === "recent") {
-            categoryName = "recent";
-        } else {
-            categoryName = "letters";
-        } 
-        let categoryList = this._sidebar.getCategoryByName(categoryName);
-        let category = categoryList.getCategory(name);
-        if (category) {
-            this.setPage(category);
-            this._updateTitle(category.title);
-            this._leaflet.navigate(Adw.NavigationDirection.FORWARD);
+            this._windowTitle.title = Gettext.gettext(title);
         }
     }
 
@@ -317,15 +274,6 @@ var MainWindow = GObject.registerClass({
         this._fontFilter.setFilterFont(this._filterFontFamily);
     }
 
-    _createCharacterList(name, accessible_name) {
-        const characterList = new CharacterListView(this._fontFilter);
-        //characterList.get_accessible().accessible_name = accessible_name;
-        characterList.connect('character-selected', (widget, uc) => this._handleCharacterSelected(widget, 
uc));
-
-        this._characterLists[name] = characterList;
-        return characterList;
-    }
-
     _createRecentCharacterList(name, accessible_name, category) {
         const characterList = new RecentCharacterListView(category, this._fontFilter);
         //characterList.get_accessible().accessible_name = accessible_name;
@@ -336,7 +284,7 @@ var MainWindow = GObject.registerClass({
     }
 
     searchByKeywords(keywords) {
-        this.visible_child_name = 'search-result';
+        this._mainStack.visible_child_name = 'search-result';
         this.visible_child.searchByKeywords(keywords);
     }
 
@@ -345,23 +293,18 @@ var MainWindow = GObject.registerClass({
         characterList.cancelSearch();
     }
 
-    setPage(category) {
-        if (category.name === 'recent') {
+    setPage(pageRow) {
+        if (pageRow.name === 'recent') {
             if (this.recentCharacters.length === 0)
-                this.visible_child_name = 'empty-recent';
+                this._mainStack.visible_child_name = 'empty-recent';
             else {
-                let categories = this._sidebar.getCategoryList();
-                for (let i in categories) {
-                    let category = categories[i];
-                    let characterList = this._recentCharacterLists[category.name];
-                    characterList.setCharacters(this.recentCharacters);
-                }
-                this.visible_child_name = 'recent';
+                this._charactersView.setCharacters(this.recentCharacters);
+                this._mainStack.visible_child_name = 'recent';
             }
         } else {
-            let characterList = this.get_child_by_name(category.name);
-            characterList.searchByCategory(category);
-            this.visible_child = characterList;
+            this._charactersView.searchByCategory(pageRow.category);
+            this._mainStack.visible_child_name = 'character-list';
+            //this._charactersView.model = pageRow.model;
         }
     }
 


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