[gnome-characters] menu: Preserve filter font until reset



commit 4ffc1ead7b48e088be371fc2739298b5bf4ab366
Author: Daiki Ueno <dueno src gnome org>
Date:   Sun Feb 15 17:24:37 2015 +0900

    menu: Preserve filter font until reset
    
    Remember the last selected filter font.  In order to provide a disable
    option, add a special 'None' entry to the filter font list.

 data/menu.ui         |    2 +-
 src/characterList.js |    2 +-
 src/menu.js          |   47 ++++++++++++++++++++++++-----------------------
 src/window.js        |   22 +++++++++++++---------
 4 files changed, 39 insertions(+), 34 deletions(-)
---
diff --git a/data/menu.ui b/data/menu.ui
index 39811c2..969dd5b 100644
--- a/data/menu.ui
+++ b/data/menu.ui
@@ -43,7 +43,7 @@
                    <property name="can_focus">False</property>
                    <property name="visible">True</property>
                    <property name="vexpand">True</property>
-                   <property name="selection_mode">none</property>
+                   <property name="selection_mode">single</property>
                    <child>
                      <placeholder/>
                    </child>
diff --git a/src/characterList.js b/src/characterList.js
index 58694a9..4af1651 100644
--- a/src/characterList.js
+++ b/src/characterList.js
@@ -369,5 +369,5 @@ const CharacterListView = new Lang.Class({
             this._filterFontDescription = fontDescription;
             this.updateCharacterList();
         }
-    },
+    }
 });
diff --git a/src/menu.js b/src/menu.js
index 526798d..bb5c21e 100644
--- a/src/menu.js
+++ b/src/menu.js
@@ -34,16 +34,23 @@ const MenuPopover = new Lang.Class({
         params = Params.fill(params, {});
         this.parent(params);
 
+        let row = new Gtk.ListBoxRow({ visible: true });
+        row._family = 'None';
+        row.add(new Gtk.Label({ label: _("None"),
+                                               visible: true,
+                                halign: Gtk.Align.START }));
+        this._font_listbox.add(row);
+
         let context = this.get_pango_context();
         let families = context.list_families();
         families = families.sort(function(a, b) {
             return a.get_name().localeCompare(b.get_name());
         });
         for (let index in families) {
-            let row = new Gtk.ListBoxRow({ visible: true });
-            row._family = families[index];
-            row.add(new Gtk.Label({ label: row._family.get_name(),
-                                   visible: true,
+            row = new Gtk.ListBoxRow({ visible: true });
+            row._family = families[index].get_name();
+            row.add(new Gtk.Label({ label: row._family,
+                                                   visible: true,
                                     halign: Gtk.Align.START }));
             this._font_listbox.add(row);
         }
@@ -51,20 +58,13 @@ const MenuPopover = new Lang.Class({
         this._keywords = [];
         this._search_entry.connect('search-changed',
                                    Lang.bind(this, this._handleSearchChanged));
-        this._font_listbox.connect('row-activated',
-                                   Lang.bind(this, this._handleRowActivated));
+        this._font_listbox.connect('row-selected',
+                                   Lang.bind(this, this._handleRowSelected));
         this._font_listbox.set_filter_func(Lang.bind(this, this._filterFunc));
 
         // This silents warning at Characters exit about this widget being
         // visible but not mapped.  Borrowed from Maps.
         this.connect('unmap', function(popover) { popover.hide(); });
-
-        // Reset filter font when this popover is closed.
-        this.connect('hide', function(popover) {
-            let toplevel = popover.get_toplevel();
-            let action = toplevel.lookup_action('filter-font');
-            action.activate(new GLib.Variant('s', ''));
-        });
     },
 
     _handleSearchChanged: function(entry) {
@@ -75,25 +75,26 @@ const MenuPopover = new Lang.Class({
         return true;
     },
 
-    _handleRowActivated: function(listBox, row) {
+    _handleRowSelected: function(listBox, row) {
         if (row != null) {
             let toplevel = this.get_toplevel();
             let action = toplevel.lookup_action('filter-font');
-            action.activate(new GLib.Variant('s', row._family.get_name()));
+            action.activate(new GLib.Variant('s', row._family));
         }
     },
 
     _filterFunc: function(row) {
         if (this._keywords.length == 0)
-           return true;
-       else {
-            let name = row._family.get_name();
-            let nameWords = name.split(/\s+/).map(String.toLowerCase);
+               return true;
+        if (row._family == 'None')
+            return true;
+
+        let name = row._family.get_name();
+        let nameWords = name.split(/\s+/).map(String.toLowerCase);
            return this._keywords.some(function(keyword, index, array) {
-               return nameWords.some(function(nameWord, index, array) {
-                   return nameWord.indexOf(keyword) >= 0;
-               });
+                   return nameWords.some(function(nameWord, index, array) {
+                       return nameWord.indexOf(keyword) >= 0;
+                   });
            });
-       }
     }
 });
diff --git a/src/window.js b/src/window.js
index 623cc9e..730c2a9 100644
--- a/src/window.js
+++ b/src/window.js
@@ -61,6 +61,7 @@ const MainWindow = new Lang.Class({
 
         this._searchActive = false;
         this._searchKeywords = [];
+        this._filterFontFamily = null;
 
         Util.initActions(this,
                          [{ name: 'about',
@@ -120,6 +121,7 @@ const MainWindow = new Lang.Class({
         if (this._searchActive == v)
             return;
 
+        this._categoryList.unselect_all();
         this._searchActive = v;
         this.notify('search-active');
     },
@@ -166,10 +168,11 @@ const MainWindow = new Lang.Class({
         });
     },
 
-    _updateTitle: function(title, filterFont) {
-        if (filterFont) {
+    _updateTitle: function(title) {
+        if (this._filterFontFamily) {
             this._main_headerbar.title =
-                _("%s (%s only)").format(Gettext.gettext(title), filterFont);
+                _("%s (%s only)").format(Gettext.gettext(title),
+                                         this._filterFontFamily);
         } else {
             this._main_headerbar.title = Gettext.gettext(title);
         }
@@ -188,8 +191,8 @@ const MainWindow = new Lang.Class({
         }
 
         Util.assertNotEqual(category, null);
-        this._mainView.setPage(category.name);
-        this._updateTitle(category.title, null);
+        this._mainView.setPage(category.name, this._filterFontFamily);
+        this._updateTitle(category.title);
     },
 
     _character: function(action, v) {
@@ -199,10 +202,11 @@ const MainWindow = new Lang.Class({
 
     _filterFont: function(action, v) {
         let [family, length] = v.get_string()
-        if (family == '')
+        if (family == 'None')
             family = null;
         this._mainView.setFilterFont(family);
-        this._updateTitle(this._mainView.visible_child.title, family);
+        this._filterFontFamily = family;
+        this._updateTitle(this._mainView.visible_child.title);
     },
 });
 
@@ -280,12 +284,12 @@ const MainView = new Lang.Class({
         this.visible_child.cancelSearch();
     },
 
-    setPage: function(name) {
+    setPage: function(name, filterFontFamily) {
         if (!(name in this._characterLists))
             return;
 
         this.visible_child_name = name;
-        this.visible_child.setFilterFont(null);
+        this.visible_child.setFilterFont(filterFontFamily);
 
         if (name == 'recent') {
             if (this._recentCharacters.length == 0)


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