[gnome-characters] window: Remember recently used characters
- From: Daiki Ueno <dueno src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters] window: Remember recently used characters
- Date: Fri, 13 Feb 2015 00:06:25 +0000 (UTC)
commit ec18af5108b8c1135de16ee527c51ca538422d1d
Author: Daiki Ueno <dueno src gnome org>
Date: Fri Feb 13 03:17:46 2015 +0900
window: Remember recently used characters
data/org.gnome.Characters.gschema.xml | 7 +++++++
src/window.js | 33 ++++++++++++++++++++++++++++++++-
2 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/data/org.gnome.Characters.gschema.xml b/data/org.gnome.Characters.gschema.xml
index ec1808a..30fb382 100644
--- a/data/org.gnome.Characters.gschema.xml
+++ b/data/org.gnome.Characters.gschema.xml
@@ -7,5 +7,12 @@
Use the font to render characters on the character list.
</description>
</key>
+ <key name="recent-characters" type="as">
+ <default>[]</default>
+ </key>
+ <key name="max-recent-characters" type="u">
+ <default>100</default>
+ <summary>Maximum recent characters</summary>
+ </key>
</schema>
</schemalist>
diff --git a/src/window.js b/src/window.js
index d682489..8e5e365 100644
--- a/src/window.js
+++ b/src/window.js
@@ -37,6 +37,7 @@ const Pango = imports.gi.Pango;
const Gc = imports.gi.Gc;
const Gettext = imports.gettext;
+const Main = imports.main;
const Util = imports.util;
const MAX_SEARCH_RESULTS = 100;
@@ -182,6 +183,23 @@ const MainView = new Lang.Class({
Extends: Gtk.Stack,
Template: 'resource:///org/gnome/Characters/mainview.ui',
InternalChildren: ['loading-banner-spinner'],
+ Properties: {
+ 'max-recent-characters': GObject.ParamSpec.uint(
+ 'max-recent-characters', '', '',
+ GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
+ 0, GLib.MAXUINT32, 100)
+ },
+
+ get max_recent_characters() {
+ return this._maxRecentCharacters;
+ },
+
+ set max_recent_characters(v) {
+ this._maxRecentCharacters = v;
+ if (this._recentCharacters.length > this._maxRecentCharacters)
+ this._recentCharacters = this._recentCharacters.slice(
+ 0, this._maxRecentCharacters);
+ },
_init: function(params) {
params = Params.fill(params, { hexpand: true, vexpand: true });
@@ -210,7 +228,14 @@ const MainView = new Lang.Class({
this._spinnerTimeoutId = 0;
- this._recentCharacters = [];
+ // FIXME: Can't use GSettings.bind with 'as' from Gjs
+ let recentCharacters = Main.settings.get_value('recent-characters');
+ this._recentCharacters = recentCharacters.get_strv();
+ this._maxRecentCharacters = 100;
+ Main.settings.bind('max-recent-characters', this,
+ 'max-recent-characters',
+ Gio.SettingsBindFlags.DEFAULT);
+
this._cancellable = new Gio.Cancellable();
},
@@ -339,6 +364,12 @@ const MainView = new Lang.Class({
selectCharacter: function(uc) {
if (this._recentCharacters.indexOf(uc) < 0) {
this._recentCharacters.push(uc);
+ if (this._recentCharacters.length > this._maxRecentCharacters)
+ this._recentCharacters = this._recentCharacters.slice(
+ 0, this._maxRecentCharacters);
+ Main.settings.set_value(
+ 'recent-characters',
+ GLib.Variant.new_strv(this._recentCharacters));
if (this.visible_child_name == 'recent')
this.setPage('recent');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]