[gnome-characters/bilelmoussaoui/gtk4: 30/71] Fix search
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters/bilelmoussaoui/gtk4: 30/71] Fix search
- Date: Thu, 25 Nov 2021 11:03:11 +0000 (UTC)
commit 6323666879807a6f39b9af333dc465eeb8d28060
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Sun Nov 21 17:49:55 2021 +0100
Fix search
data/window.ui | 21 +--------------------
src/categoryList.js | 12 ++++++++++++
src/charactersView.js | 9 +++------
src/window.js | 31 +++++++++++++++++++------------
4 files changed, 35 insertions(+), 38 deletions(-)
---
diff --git a/data/window.ui b/data/window.ui
index 64b6415..994ef02 100644
--- a/data/window.ui
+++ b/data/window.ui
@@ -140,25 +140,6 @@
</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>
<child>
<object class="GtkStackPage">
<property name="name">character-list</property>
@@ -177,7 +158,7 @@
</child>
<child>
<object class="GtkStackPage">
- <property name="name">unavailable</property>
+ <property name="name">no-results</property>
<property name="child">
<object class="AdwStatusPage">
<property name="icon-name">system-search-symbolic</property>
diff --git a/src/categoryList.js b/src/categoryList.js
index 0c5412f..d518fcd 100644
--- a/src/categoryList.js
+++ b/src/categoryList.js
@@ -95,6 +95,18 @@ var Sidebar = GObject.registerClass({
'lettersCurrencyRow', 'lettersMathRow', 'lettersLatinRow',
],
}, class Sidebar extends Adw.Bin {
+ _init() {
+ super._init({});
+
+ this.lastSelectedRow = null;
+ }
+
+ restorePreviousSelection() {
+ if (this.lastSelectedRow) {
+ this._list.select_row(this.lastSelectedRow);
+ }
+ }
+
rowByName(name) {
switch (name) {
case 'smileys':
diff --git a/src/charactersView.js b/src/charactersView.js
index e562d5d..54b859b 100644
--- a/src/charactersView.js
+++ b/src/charactersView.js
@@ -39,6 +39,7 @@ const CharacterListRow = GObject.registerClass({
_init(characters, fontDescription, overlayFontDescription) {
super._init({});
+ this._baseGlyphRect = null;
this._characters = characters;
this._fontDescription = fontDescription;
this._overlayFontDescription = overlayFontDescription;
@@ -172,12 +173,8 @@ const CharacterListRow = GObject.registerClass({
(cellRect.width - logicalRect.width / Pango.SCALE) / 2,
cellRect.y - logicalRect.y / Pango.SCALE +
(cellRect.height - logicalRect.height / Pango.SCALE) / 2);
- let textColor;
- if (!this._styleManager.dark)
- textColor = this._styleContext.get_color(Gtk.StateFlags.NORMAL);
- else
- textColor = this._styleContext.get_background_color(Gtk.StateFlags.NORMAL);
+ let textColor = this._styleContext.lookup_color('foreground_color')[1];
Gdk.cairo_set_source_rgba(cr, textColor);
PangoCairo.show_layout(cr, layout);
@@ -502,7 +499,6 @@ var CharactersView = GObject.registerClass({
_updateCharacterList() {
log('Updating characters list');
const [fontDescription, characters] = this._fontFilter.filter(this, this._characters);
- log(JSON.stringify(characters));
this._characterList.setFontDescription(fontDescription);
this._characterList.setCharacters(characters);
}
@@ -560,6 +556,7 @@ var CharactersView = GObject.registerClass({
flags: Gc.SearchFlag.WORD,
});
this._searchWithContext(this._searchContext, this.initialSearchCount);
+ return this._characters.length;
}
searchByScripts(scripts) {
diff --git a/src/window.js b/src/window.js
index 25faf8e..2918172 100644
--- a/src/window.js
+++ b/src/window.js
@@ -37,10 +37,10 @@ const Util = imports.util;
var MainWindow = GObject.registerClass({
Template: 'resource:///org/gnome/Characters/window.ui',
InternalChildren: [
- 'main-headerbar', 'search-active-button',
+ 'search-active-button',
'search-bar', 'search-entry', 'back-button',
'menuPopover', 'container', 'sidebar',
- 'leaflet', 'mainStack', 'recentBox', 'windowTitle',
+ 'leaflet', 'mainStack', 'windowTitle',
'charactersView',
],
Properties: {
@@ -64,13 +64,18 @@ var MainWindow = GObject.registerClass({
this._characterLists = {};
this._recentCharacterLists = {};
this._charactersView.setFontFilter(this._fontFilter);
- this._charactersView.connect('character-selected', (widget, uc) =>
this._handleCharacterSelected(widget, uc));
+ this._charactersView.connect('character-selected', (widget, uc) => {
+ this._handleCharacterSelected(widget, uc);
+ });
this._sidebar.list.connect('row-selected', (sidebar, row) => {
- this.setPage(row);
- this._updateTitle(row.title);
- this._leaflet.navigate(Adw.NavigationDirection.FORWARD);
+ if (row) {
+ this._sidebar.lastSelectedRow = row;
+ this.setPage(row);
+ this._updateTitle(row.title);
+ this._leaflet.navigate(Adw.NavigationDirection.FORWARD);
+ }
});
/* characterList = this._createCharacterList(
@@ -162,8 +167,7 @@ var MainWindow = GObject.registerClass({
this._searchActive = v;
if (this._searchActive) {
- let categoryList = this._sidebar.selectedList.list;
- categoryList.unselect_all();
+ this._sidebar.list.unselect_all();
this._updateTitle(_('Search Result'));
} else {
this._sidebar.restorePreviousSelection();
@@ -277,13 +281,16 @@ var MainWindow = GObject.registerClass({
}
searchByKeywords(keywords) {
- this._mainStack.visible_child_name = 'search-result';
- this.visible_child.searchByKeywords(keywords);
+ let totalResults = this._charactersView.searchByKeywords(keywords);
+ if(totalResults === 0) {
+ this._mainStack.visible_child_name = 'no-results';
+ } else {
+ this._mainStack.visible_child_name = 'character-list';
+ }
}
cancelSearch() {
- const characterList = this._mainStack.get_child_by_name('search-result');
- characterList.cancelSearch();
+ this._charactersView.cancelSearch();
}
setPage(pageRow) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]