[gnome-characters/bilelmoussaoui/gtk4: 4/6] split sidebar into sidebar/sidebar row




commit 6ac7ce07e96af744d0d4ca215dc06de5df4bf841
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Mon Nov 22 08:27:38 2021 +0100

    split sidebar into sidebar/sidebar row

 data/sidebar.ui                            | 32 ++++++------
 src/main.js                                |  2 +-
 src/meson.build                            |  3 +-
 src/org.gnome.Characters.src.gresource.xml |  3 +-
 src/{categoryList.js => sidebar.js}        | 72 +++-----------------------
 src/sidebarRow.js                          | 83 ++++++++++++++++++++++++++++++
 src/window.js                              |  6 +--
 7 files changed, 113 insertions(+), 88 deletions(-)
---
diff --git a/data/sidebar.ui b/data/sidebar.ui
index 4056ccf..de1d104 100644
--- a/data/sidebar.ui
+++ b/data/sidebar.ui
@@ -6,7 +6,7 @@
     <child>
       <object class="GtkListBox" id="list">
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="recentRow">
+          <object class="Gjs_SidebarRow" id="recentRow">
             <property name="name">recent</property>
             <property name="icon-name">document-open-recent-symbolic</property>
             <property name="title" translatable="yes">Recently Used</property>
@@ -43,7 +43,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="emojiSmileysRow">
+          <object class="Gjs_SidebarRow" id="emojiSmileysRow">
             <property name="category">GC_CATEGORY_EMOJI_SMILEYS</property>
             <property name="name">emoji-smileys</property>
             <property name="icon-name">characters-emoji-smileys</property>
@@ -51,7 +51,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="emojiAnimalsRow">
+          <object class="Gjs_SidebarRow" id="emojiAnimalsRow">
             <property name="category">GC_CATEGORY_EMOJI_ANIMALS</property>
             <property name="name">emoji-animals</property>
             <property name="icon-name">characters-emoji-animals</property>
@@ -59,7 +59,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="emojiFoodRow">
+          <object class="Gjs_SidebarRow" id="emojiFoodRow">
             <property name="category">GC_CATEGORY_EMOJI_FOOD</property>
             <property name="name">emoji-food</property>
             <property name="icon-name">characters-emoji-food</property>
@@ -67,7 +67,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="emojiActivitiesRow">
+          <object class="Gjs_SidebarRow" id="emojiActivitiesRow">
             <property name="category">GC_CATEGORY_EMOJI_ACTIVITIES</property>
             <property name="name">emoji-activities</property>
             <property name="icon-name">characters-emoji-activities</property>
@@ -75,7 +75,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="emojiTravelRow">
+          <object class="Gjs_SidebarRow" id="emojiTravelRow">
             <property name="category">GC_CATEGORY_EMOJI_TRAVEL</property>
             <property name="name">emoji-travel</property>
             <property name="icon-name">characters-emoji-travel</property>
@@ -83,7 +83,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="emojiObjectsRow">
+          <object class="Gjs_SidebarRow" id="emojiObjectsRow">
             <property name="category">GC_CATEGORY_EMOJI_OBJECTS</property>
             <property name="name">emoji-objects</property>
             <property name="icon-name">characters-emoji-objects</property>
@@ -91,7 +91,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="emojiSymbolsRow">
+          <object class="Gjs_SidebarRow" id="emojiSymbolsRow">
             <property name="category">GC_CATEGORY_EMOJI_SYMBOLS</property>
             <property name="name">emoji-symbols</property>
             <property name="icon-name">characters-emoji-symbols</property>
@@ -99,7 +99,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="emojiFlagsRow">
+          <object class="Gjs_SidebarRow" id="emojiFlagsRow">
             <property name="category">GC_CATEGORY_EMOJI_FLAGS</property>
             <property name="name">emoji-flags</property>
             <property name="icon-name">characters-emoji-flags</property>
@@ -126,7 +126,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="lettersPunctuationRow">
+          <object class="Gjs_SidebarRow" id="lettersPunctuationRow">
             <property name="category">GC_CATEGORY_LETTER_PUNCTUATION</property>
             <property name="name">punctuation</property>
             <property name="icon-name">characters-punctuation-symbolic</property>
@@ -134,7 +134,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="lettersArrowsRow">
+          <object class="Gjs_SidebarRow" id="lettersArrowsRow">
             <property name="category">GC_CATEGORY_LETTER_ARROW</property>
             <property name="name">arrow</property>
             <property name="icon-name">characters-arrow-symbolic</property>
@@ -142,7 +142,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="lettersBulletsRow">
+          <object class="Gjs_SidebarRow" id="lettersBulletsRow">
             <property name="category">GC_CATEGORY_LETTER_BULLET</property>
             <property name="name">bullet</property>
             <property name="icon-name">characters-bullet-symbolic</property>
@@ -150,7 +150,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="lettersPicturesRow">
+          <object class="Gjs_SidebarRow" id="lettersPicturesRow">
             <property name="category">GC_CATEGORY_LETTER_PICTURE</property>
             <property name="name">picture</property>
             <property name="icon-name">characters-picture-symbolic</property>
@@ -158,7 +158,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="lettersCurrencyRow">
+          <object class="Gjs_SidebarRow" id="lettersCurrencyRow">
             <property name="category">GC_CATEGORY_LETTER_CURRENCY</property>
             <property name="name">currency</property>
             <property name="icon-name">characters-currency-symbolic</property>
@@ -166,7 +166,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="lettersMathRow">
+          <object class="Gjs_SidebarRow" id="lettersMathRow">
             <property name="category">GC_CATEGORY_LETTER_MATH</property>
             <property name="name">math</property>
             <property name="icon-name">characters-math-symbolic</property>
@@ -174,7 +174,7 @@
           </object>
         </child>
         <child>
-          <object class="Gjs_CategoryListRowWidget" id="lettersLatinRow">
+          <object class="Gjs_SidebarRow" id="lettersLatinRow">
             <property name="category">GC_CATEGORY_LETTER_LATIN</property>
             <property name="name">letters</property>
             <property name="icon-name">characters-latin-symbolic</property>
diff --git a/src/main.js b/src/main.js
index d429079..67b3e94 100644
--- a/src/main.js
+++ b/src/main.js
@@ -40,7 +40,7 @@ pkg.require({
 const { GLib, Gio, GObject, Adw } = imports.gi;
 
 const { CharactersView } = imports.charactersView;
-const { Sidebar } = imports.categoryList;
+const { Sidebar } = imports.sidebar;
 const { MenuPopover } = imports.menu;
 const { MainWindow } = imports.window;
 
diff --git a/src/meson.build b/src/meson.build
index f7ede14..8e43f81 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -25,11 +25,12 @@ common_resource_data = files(
 )
 
 resource_data = common_resource_data + files(
-  'categoryList.js',
   'characterDialog.js',
   'charactersView.js',
   'main.js',
   'menu.js',
+  'sidebar.js',
+  'sidebarRow.js',
   'window.js'
 )
 resources = [[characters_name, resource_data]]
diff --git a/src/org.gnome.Characters.src.gresource.xml b/src/org.gnome.Characters.src.gresource.xml
index 3abe275..8b6eeef 100644
--- a/src/org.gnome.Characters.src.gresource.xml
+++ b/src/org.gnome.Characters.src.gresource.xml
@@ -3,9 +3,10 @@
   <gresource prefix="/org/gnome/Characters/js">
     <file>main.js</file>
     <file>menu.js</file>
+    <file>sidebar.js</file>
+    <file>sidebarRow.js</file>
     <file>util.js</file>
     <file>window.js</file>
-    <file>categoryList.js</file>
     <file>characterDialog.js</file>
     <file>charactersView.js</file>
   </gresource>
diff --git a/src/categoryList.js b/src/sidebar.js
similarity index 77%
rename from src/categoryList.js
rename to src/sidebar.js
index d518fcd..8823f82 100644
--- a/src/categoryList.js
+++ b/src/sidebar.js
@@ -1,4 +1,4 @@
-/* exported CategoryListRowWidget Sidebar */
+/* exported Sidebar */
 // -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
 //
 // Copyright (C) 2014-2017  Daiki Ueno <dueno src gnome org>
@@ -18,71 +18,10 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 
-const { Adw, Gc, GObject, Gtk, GnomeDesktop } = imports.gi;
+const { Adw, Gc, GObject, GnomeDesktop } = imports.gi;
+const { SidebarRow } = imports.sidebarRow;
 const Util = imports.util;
 
-const CategoryListRowWidget = GObject.registerClass({
-    Properties: {
-        'title': GObject.ParamSpec.string(
-            'title',
-            'Category title', 'Category title',
-            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',
-            GObject.ParamFlags.READWRITE,
-            '',
-        ),
-    },
-}, class CategoryListRowWidget extends Gtk.ListBoxRow {
-    _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();
-        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({ 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');
-    }
-
-    get title() {
-        return this._title || '';
-    }
-
-    set title(title) {
-        this._title = title;
-    }
-
-    get category() {
-        return this._category || Gc.Category.NONE;
-    }
-
-    set category(value) {
-        this._category = value;
-    }
-});
-
 var Sidebar = GObject.registerClass({
     Template: 'resource:///org/gnome/Characters/sidebar.ui',
     InternalChildren: [
@@ -96,15 +35,16 @@ var Sidebar = GObject.registerClass({
     ],
 }, class Sidebar extends Adw.Bin {
     _init() {
+        GObject.type_ensure(SidebarRow.$gtype);
         super._init({});
 
         this.lastSelectedRow = null;
     }
 
     restorePreviousSelection() {
-        if (this.lastSelectedRow) {
+        if (this.lastSelectedRow)
             this._list.select_row(this.lastSelectedRow);
-        }
+
     }
 
     rowByName(name) {
diff --git a/src/sidebarRow.js b/src/sidebarRow.js
new file mode 100644
index 0000000..9c37008
--- /dev/null
+++ b/src/sidebarRow.js
@@ -0,0 +1,83 @@
+/* exported SidebarRow */
+// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
+//
+// Copyright (C) 2014-2017  Daiki Ueno <dueno src gnome org>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+const { Gc, GObject, Gtk } = imports.gi;
+
+var SidebarRow = GObject.registerClass({
+    Properties: {
+        'title': GObject.ParamSpec.string(
+            'title',
+            'Category title', 'Category title',
+            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',
+            GObject.ParamFlags.READWRITE,
+            '',
+        ),
+    },
+}, class SidebarRow extends Gtk.ListBoxRow {
+    _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();
+        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({ 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');
+    }
+
+    get title() {
+        return this._title || '';
+    }
+
+    set title(title) {
+        this._title = title;
+    }
+
+    get category() {
+        return this._category || Gc.Category.NONE;
+    }
+
+    set category(value) {
+        this._category = value;
+    }
+});
+
diff --git a/src/window.js b/src/window.js
index 2918172..a777390 100644
--- a/src/window.js
+++ b/src/window.js
@@ -282,11 +282,11 @@ var MainWindow = GObject.registerClass({
 
     searchByKeywords(keywords) {
         let totalResults = this._charactersView.searchByKeywords(keywords);
-        if(totalResults === 0) {
+        if (totalResults === 0)
             this._mainStack.visible_child_name = 'no-results';
-        } else {
+        else
             this._mainStack.visible_child_name = 'character-list';
-        }
+
     }
 
     cancelSearch() {


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