[gnome-characters/bilelmoussaoui/gtk4: 26/76] window: update title when a sidebar item is selected




commit e36ec49ccea21ff299249943be6ed05b74848645
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Sun Nov 21 09:12:22 2021 +0100

    window: update title when a sidebar item is selected

 data/window.ui      |  3 +++
 src/categoryList.js | 22 +++++++++++-----------
 src/window.js       |  7 +++----
 3 files changed, 17 insertions(+), 15 deletions(-)
---
diff --git a/data/window.ui b/data/window.ui
index 42c0614..d47ce8e 100644
--- a/data/window.ui
+++ b/data/window.ui
@@ -99,6 +99,9 @@
             <child>
               <object class="GtkHeaderBar" id="main-headerbar">
                 <property name="show-title-buttons">True</property>
+                <property name="title-widget">
+                  <object class="AdwWindowTitle" id="windowTitle" />
+                </property>
                 <child>
                   <object class="GtkRevealer">
                     <property name="transition-type">crossfade</property>
diff --git a/src/categoryList.js b/src/categoryList.js
index 82b8a2c..b11efbd 100644
--- a/src/categoryList.js
+++ b/src/categoryList.js
@@ -151,7 +151,7 @@ const CategoryListRowWidget = GObject.registerClass({
     },
 }, class CategoryListRowWidget extends Gtk.ListBoxRow {
     _init () {
-        super._init({});
+        super._init();
         /*this.get_accessible().accessible_name =
             _('%s Category List Row').format(category.title);*/
 
@@ -171,17 +171,17 @@ const CategoryListRowWidget = GObject.registerClass({
 
         this.add_css_class('category');
     }
+
+    get title() {
+        return this._title || '';
+    }
+
+    set title(title) {
+        this._title = title;
+    }
 });
 
 var Sidebar = GObject.registerClass({
-    Properties: {
-        'selected-item': GObject.ParamSpec.object(
-            'selected-item',
-            'Current active category', 'Currently selected category',
-            GObject.ParamFlags.READWRITE,
-            Gtk.ListBoxRow.$gtype,
-        ),
-    },
     Template: 'resource:///org/gnome/Characters/sidebar.ui',
     InternalChildren: [
         'list',
@@ -239,8 +239,8 @@ var Sidebar = GObject.registerClass({
         this._list.select_row(row);
     }
 
-    get selectedItem() {
-        return this._selected_item;
+    get list() {
+        return this._list;
     }
 
     _finishListEngines(sources, bus, res) {
diff --git a/src/window.js b/src/window.js
index d6c2cc4..8ed3aac 100644
--- a/src/window.js
+++ b/src/window.js
@@ -41,7 +41,7 @@ var MainWindow = GObject.registerClass({
         'main-headerbar', 'search-active-button',
         'search-bar', 'search-entry', 'back-button',
         'menuPopover', 'container', 'sidebar',
-        'leaflet', 'mainStack', 'recentBox',
+        'leaflet', 'mainStack', 'recentBox', 'windowTitle',
     ],
     Properties: {
         'search-active': GObject.ParamSpec.boolean(
@@ -64,9 +64,8 @@ var MainWindow = GObject.registerClass({
         this._characterLists = {};
         this._recentCharacterLists = {};
 
-        this._sidebar.connect('notify::selected-item', (sidebar) => {
-            let selectedCategory = sidebar.selectedItem.category;
-            this._main_headerbar.title = selectedCategory.title;
+        this._sidebar.list.connect('row-selected', (sidebar, row) => {
+            this._windowTitle.title = row.title;
         });
 
         let characterList;


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