[gnome-characters/bilelmoussaoui/gtk4: 30/76] misc: eslint fixes
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters/bilelmoussaoui/gtk4: 30/76] misc: eslint fixes
- Date: Fri, 26 Nov 2021 08:59:05 +0000 (UTC)
commit 94b9235705c781a27220b358ebe67b19d002207d
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Sun Nov 21 16:57:28 2021 +0100
misc: eslint fixes
src/categoryList.js | 107 ++++++++-------
src/characterDialog.js | 71 +++++-----
src/charactersView.js | 161 +++++++++++------------
src/main.js | 57 ++++----
src/menu.js | 44 ++++---
src/meson.build | 2 +-
src/org.gnome.Characters.BackgroundService.in | 2 +-
src/org.gnome.Characters.in | 2 +-
src/searchProvider.js | 66 +++++-----
src/service.js | 34 ++---
src/util.js | 37 +++---
src/window.js | 182 ++++++++++++--------------
12 files changed, 387 insertions(+), 378 deletions(-)
---
diff --git a/src/categoryList.js b/src/categoryList.js
index 350b783..0c5412f 100644
--- a/src/categoryList.js
+++ b/src/categoryList.js
@@ -1,3 +1,4 @@
+/* exported CategoryListRowWidget Sidebar */
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
//
// Copyright (C) 2014-2017 Daiki Ueno <dueno src gnome org>
@@ -17,10 +18,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-const {Adw, Gc, GLib, GObject, Gtk, GnomeDesktop} = imports.gi;
-
-const Gettext = imports.gettext;
-
+const { Adw, Gc, GObject, Gtk, GnomeDesktop } = imports.gi;
const Util = imports.util;
const CategoryListRowWidget = GObject.registerClass({
@@ -46,22 +44,22 @@ const CategoryListRowWidget = GObject.registerClass({
),
},
}, class CategoryListRowWidget extends Gtk.ListBoxRow {
- _init () {
+ _init() {
super._init();
- /*this.get_accessible().accessible_name =
+ /* 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);
+ 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);
+ this.bind_property('title', label, 'label', GObject.BindingFlags.DEFAULT |
GObject.BindingFlags.SYNC_CREATE);
label.add_css_class('category-label');
hbox.append(label);
@@ -97,45 +95,41 @@ var Sidebar = GObject.registerClass({
'lettersCurrencyRow', 'lettersMathRow', 'lettersLatinRow',
],
}, class Sidebar extends Adw.Bin {
- _init() {
- super._init();
- }
-
rowByName(name) {
- switch(name) {
- case 'smileys':
- return this._emojiSmileysRow;
- case 'animals':
- return this._emojiAnimalsRow;
- case 'food':
- return this._emojiFoodRow;
- case 'activities':
- return this._emojiActivitesRow;
- case 'travel':
- return this._emojiTravelRow;
- case 'objects':
- return this._emojiObjectsRow;
- case 'symbols':
- return this._emojiSymbolsRow;
- case 'flags':
- return this._emojiFlagsRow;
- case 'punctuation':
- return this._lettersPunctuationRow;
- case 'arrows':
- return this._lettersArrowsRow;
- case 'bullets':
- return this._lettersBulletsRow;
- case 'pictures':
- return this._lettersPicturesRow;
- case 'currency':
- return this._lettersCurrencyRow;
- case 'math':
- return this._lettersMathRow;
- case 'latin':
- return this._lettersLatinRow;
- default:
- return this._recentRow;
- }
+ switch (name) {
+ case 'smileys':
+ return this._emojiSmileysRow;
+ case 'animals':
+ return this._emojiAnimalsRow;
+ case 'food':
+ return this._emojiFoodRow;
+ case 'activities':
+ return this._emojiActivitesRow;
+ case 'travel':
+ return this._emojiTravelRow;
+ case 'objects':
+ return this._emojiObjectsRow;
+ case 'symbols':
+ return this._emojiSymbolsRow;
+ case 'flags':
+ return this._emojiFlagsRow;
+ case 'punctuation':
+ return this._lettersPunctuationRow;
+ case 'arrows':
+ return this._lettersArrowsRow;
+ case 'bullets':
+ return this._lettersBulletsRow;
+ case 'pictures':
+ return this._lettersPicturesRow;
+ case 'currency':
+ return this._lettersCurrencyRow;
+ case 'math':
+ return this._lettersMathRow;
+ case 'latin':
+ return this._lettersLatinRow;
+ default:
+ return this._recentRow;
+ }
}
selectRowByName(name) {
@@ -154,7 +148,7 @@ var Sidebar = GObject.registerClass({
for (let j in engines) {
let engine = engines[j];
let language = engine.get_language();
- if (language != null)
+ if (language !== null)
this._ibusLanguageList[engine.get_name()] = language;
}
}
@@ -165,7 +159,7 @@ var Sidebar = GObject.registerClass({
}
_ensureIBusLanguageList(sources) {
- if (this._ibusLanguageList != null)
+ if (this._ibusLanguageList !== null)
return;
this._ibusLanguageList = {};
@@ -182,9 +176,12 @@ var Sidebar = GObject.registerClass({
ibus.init();
let bus = new ibus.Bus();
if (bus.is_connected()) {
- bus.list_engines_async(-1, null, (sources, bus, res) => this._finishListEngines(sources, bus,
res));
- } else
+ bus.list_engines_async(-1, null, (sources_, bus_, res) => {
+ this._finishListEngines(sources_, bus_, res);
+ });
+ } else {
this._finishBuildScriptList(sources);
+ }
}
_finishBuildScriptList(sources) {
@@ -214,7 +211,7 @@ var Sidebar = GObject.registerClass({
let allScripts = [];
for (let i in languages) {
let language = GnomeDesktop.normalize_locale(languages[i]);
- if (language == null)
+ if (language === null)
continue;
let scripts = Gc.get_scripts_for_language(languages[i]);
for (let j in scripts) {
@@ -252,11 +249,11 @@ var Sidebar = GObject.registerClass({
//
let settings =
Util.getSettings('org.gnome.desktop.input-sources',
- '/org/gnome/desktop/input-sources/');
+ '/org/gnome/desktop/input-sources/');
if (settings) {
let sources = settings.get_value('sources').deep_unpack();
- let hasIBus = sources.some(function(current, index, array) {
- return current[0] == 'ibus';
+ let hasIBus = sources.some((current, _index, _array) => {
+ return current[0] === 'ibus';
});
if (hasIBus)
this._ensureIBusLanguageList(sources);
diff --git a/src/characterDialog.js b/src/characterDialog.js
index d362d59..ff46f49 100644
--- a/src/characterDialog.js
+++ b/src/characterDialog.js
@@ -1,3 +1,4 @@
+/* exported CharacterDialog */
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
//
// Copyright (C) 2014-2015 Daiki Ueno <dueno src gnome org>
@@ -16,26 +17,26 @@
// 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, GLib, Gio,GObject,Gtk, Pango} = imports.gi;
+const { Gc, GLib, Gio, GObject, Gtk, Pango } = imports.gi;
const Util = imports.util;
var CharacterDialog = GObject.registerClass({
Signals: {
- 'character-copied': { param_types: [ GObject.TYPE_STRING ] }
+ 'character-copied': { param_types: [GObject.TYPE_STRING] },
},
Template: 'resource:///org/gnome/Characters/character.ui',
InternalChildren: ['main-stack', 'character-stack',
- 'character-label', 'missing-label', 'detail-label',
- 'copy-button', 'copy-revealer', 'related-listbox'],
+ 'character-label', 'missing-label', 'detail-label',
+ 'copy-button', 'copy-revealer', 'related-listbox'],
}, class CharacterDialog extends Gtk.Dialog {
_init(character, fontDescription) {
super._init({
use_header_bar: true,
width_request: 400,
- height_request: 400
- });
+ height_request: 400,
+ });
this._cancellable = new Gio.Cancellable();
@@ -43,16 +44,16 @@ var CharacterDialog = GObject.registerClass({
this._related_listbox.connect('row-selected', (listBox, row) => this._handleRowSelected(listBox,
row));
- this._relatedButton = new Gtk.ToggleButton({ label: _("See Also") });
+ this._relatedButton = new Gtk.ToggleButton({ label: _('See Also') });
this.add_action_widget(this._relatedButton, Gtk.ResponseType.HELP);
this._relatedButton.show();
this._relatedButton.connect('toggled', () => {
- if (this._main_stack.visible_child_name == 'character')
- this._main_stack.visible_child_name = 'related';
- else
- this._main_stack.visible_child_name = 'character';
- });
+ if (this._main_stack.visible_child_name === 'character')
+ this._main_stack.visible_child_name = 'related';
+ else
+ this._main_stack.visible_child_name = 'character';
+ });
this._fontDescription = fontDescription;
this._setCharacter(character);
@@ -68,21 +69,21 @@ var CharacterDialog = GObject.registerClass({
for (let index = 0; index < result.len; index++) {
let uc = Gc.search_result_get(result, index);
let name = Gc.character_name(uc);
- if (name == null)
+ if (name === null)
continue;
let hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
let characterLabel = new Gtk.Label({ label: uc,
- valign: Gtk.Align.CENTER,
- halign: Gtk.Align.CENTER,
- width_request: 45 });
+ valign: Gtk.Align.CENTER,
+ halign: Gtk.Align.CENTER,
+ width_request: 45 });
characterLabel.add_css_class('character');
hbox.pack_start(characterLabel, false, false, 2);
let nameLabel = new Gtk.Label({ label: Util.capitalize(name),
- halign: Gtk.Align.START,
- ellipsize: Pango.EllipsizeMode.END });
+ halign: Gtk.Align.START,
+ ellipsize: Pango.EllipsizeMode.END });
hbox.pack_start(nameLabel, true, true, 0);
let row = new Gtk.ListBoxRow();
@@ -104,11 +105,11 @@ var CharacterDialog = GObject.registerClass({
let codePointHex = codePoint.toString(16).toUpperCase();
let name = Gc.character_name(this._character);
- if (name != null) {
+ if (name !== null)
name = Util.capitalize(name);
- } else {
- name = _("Unicode U+%04s").format(codePointHex);
- }
+ else
+ name = _('Unicode U+%04s').format(codePointHex);
+
let headerBar = this.get_header_bar();
headerBar.title = name;
@@ -119,28 +120,28 @@ var CharacterDialog = GObject.registerClass({
var pangoContext = this._character_label.get_pango_context();
var pangoLayout = Pango.Layout.new(pangoContext);
pangoLayout.set_text(this._character, -1);
- if (pangoLayout.get_unknown_glyphs_count() == 0) {
+ if (pangoLayout.get_unknown_glyphs_count() === 0) {
this._character_stack.visible_child_name = 'character';
} else {
var fontFamily = this._fontDescription.get_family();
this._missing_label.label =
// TRANSLATORS: the first variable is a character, the second is a font
- _("%s is not included in %s").format(name, fontFamily);
+ _('%s is not included in %s').format(name, fontFamily);
this._character_stack.visible_child_name = 'missing';
}
- this._detail_label.label = _("Unicode U+%04s").format(codePointHex);
+ this._detail_label.label = _('Unicode U+%04s').format(codePointHex);
this._cancellable.cancel();
this._cancellable.reset();
let criteria = Gc.SearchCriteria.new_related(this._character);
- let context = new Gc.SearchContext({ criteria: criteria });
+ let context = new Gc.SearchContext({ criteria });
context.search(
-1,
this._cancellable,
- (context, res) => {
+ (ctx, res) => {
try {
- let result = context.search_finish(res);
+ let result = ctx.search_finish(res);
this._finishSearch(result);
} catch (e) {
log(`Failed to search related: ${e.message}`);
@@ -162,15 +163,15 @@ var CharacterDialog = GObject.registerClass({
_clipboardOwnerChanged(clipboard) {
let text = clipboard.wait_for_text();
- if (text != this._character)
+ if (text !== this._character)
this._hideCopyRevealer();
}
_copyCharacter() {
- if (this._clipboard == null) {
+ if (this._clipboard === null) {
this._clipboard = Gc.gtk_clipboard_get();
let clipboardOwnerChanged =
- this._clipboard.connect('owner-change', (clipboard) =>
this._clipboardOwnerChanged(clipboard));
+ this._clipboard.connect('owner-change', clipboard => this._clipboardOwnerChanged(clipboard));
this.connect('destroy', () => this._clipboard.disconnect(clipboardOwnerChanged));
}
this._clipboard.set_text(this._character, -1);
@@ -184,13 +185,13 @@ var CharacterDialog = GObject.registerClass({
this._copyRevealerTimeoutId =
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 2000, () => this._hideCopyRevealer());
this.connect('destroy', () => {
- if (this._copyRevealerTimeoutId > 0)
- GLib.source_remove(this._copyRevealerTimeoutId);
- });
+ if (this._copyRevealerTimeoutId > 0)
+ GLib.source_remove(this._copyRevealerTimeoutId);
+ });
}
_handleRowSelected(listBox, row) {
- if (row != null) {
+ if (row !== null) {
this._setCharacter(row._character);
let toplevel = this.get_transient_for();
let action = toplevel.lookup_action('character');
diff --git a/src/charactersView.js b/src/charactersView.js
index 929c606..e562d5d 100644
--- a/src/charactersView.js
+++ b/src/charactersView.js
@@ -1,3 +1,4 @@
+/* exported CharactersView FontFilter RecentCharacterListView */
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
//
// Copyright (C) 2014-2015 Daiki Ueno <dueno src gnome org>
@@ -16,9 +17,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-const {Adw, Gc, Gdk, GLib, Gio,GObject,Gtk, Pango, Graphene, PangoCairo} = imports.gi;
-
-const Cairo = imports.cairo;
+const { Adw, Gc, Gdk, GLib, Gio, GObject, Gtk, Pango, Graphene, PangoCairo } = imports.gi;
const Main = imports.main;
const Util = imports.util;
@@ -30,7 +29,7 @@ const NUM_COLUMNS = 3;
const CELL_SIZE = 50;
function getCellSize(fontDescription) {
- if (fontDescription == null || fontDescription.get_size() == 0)
+ if (fontDescription === null || fontDescription.get_size() === 0)
return CELL_SIZE;
return fontDescription.get_size() * 2 / Pango.SCALE;
}
@@ -53,33 +52,33 @@ const CharacterListRow = GObject.registerClass({
this._styleContext = styleContext;
// Draw baseline.
// FIXME: Pick the baseline color from CSS.
- let accent_color = this._styleContext.lookup_color('accent_color')[1];
- Gdk.cairo_set_source_rgba(cr, accent_color);
+ let accentColor = this._styleContext.lookup_color('accent_color')[1];
+ Gdk.cairo_set_source_rgba(cr, accentColor);
cr.setLineWidth(0.5);
cr.moveTo(x, y + BASELINE_OFFSET * height);
cr.relLineTo(width, 0);
cr.stroke();
- let fg_color = this._styleContext.get_color();
- Gdk.cairo_set_source_rgba(cr, fg_color);
+ let fgColor = this._styleContext.get_color();
+ Gdk.cairo_set_source_rgba(cr, fgColor);
// Draw characters. Do centering and attach to the baseline.
let cellSize = getCellSize(this._fontDescription);
for (let i in this._characters) {
var cellRect = new Gdk.Rectangle({ x: x + cellSize * i,
- y: y,
- width: cellSize,
- height: cellSize });
+ y,
+ width: cellSize,
+ height: cellSize });
if (Gc.character_is_invisible(this._characters[i])) {
this._drawBoundingBox(cr, cellRect, this._characters[i]);
this._drawCharacterName(cr, cellRect, this._characters[i]);
} else {
layout.set_text(this._characters[i], -1);
- if (layout.get_unknown_glyphs_count () == 0) {
+ if (layout.get_unknown_glyphs_count() === 0) {
let layoutBaseline = layout.get_baseline();
- let [logicalRect, inkRect] = layout.get_extents();
+ let logicalRect = layout.get_extents()[0];
cr.moveTo(x + cellSize * i - logicalRect.x / Pango.SCALE +
(cellSize - logicalRect.width / Pango.SCALE) / 2,
- y + BASELINE_OFFSET * height -
+ y + BASELINE_OFFSET * height -
layoutBaseline / Pango.SCALE);
PangoCairo.show_layout(cr, layout);
} else {
@@ -97,17 +96,17 @@ const CharacterListRow = GObject.registerClass({
let shapeRect;
let layoutBaseline;
- if (layout.get_unknown_glyphs_count() == 0) {
- let [logicalRect, inkRect] = layout.get_extents();
+ if (layout.get_unknown_glyphs_count() === 0) {
+ let inkRect = layout.get_extents()[1];
layoutBaseline = layout.get_baseline();
shapeRect = inkRect;
} else {
// If the character cannot be rendered with the current
// font settings, show a rectangle calculated from the
// base glyphs ('AA').
- if (this._baseGlyphRect == null) {
+ if (this._baseGlyphRect === null) {
layout.set_text('AA', -1);
- let [baseLogicalRect, baseInkRect] = layout.get_extents();
+ let baseInkRect = layout.get_extents()[1];
this._baseGlyphLayoutBaseline = layout.get_baseline();
this._baseGlyphRect = baseInkRect;
}
@@ -116,9 +115,9 @@ const CharacterListRow = GObject.registerClass({
x: this._baseGlyphRect.x,
y: this._baseGlyphRect.y,
width: this._baseGlyphRect.width,
- height: this._baseGlyphRect.height
+ height: this._baseGlyphRect.height,
});
- let characterWidth = Gc.character_width (uc);
+ let characterWidth = Gc.character_width(uc);
if (characterWidth > 1)
shapeRect.width *= characterWidth;
}
@@ -127,8 +126,8 @@ const CharacterListRow = GObject.registerClass({
(cellRect.width - shapeRect.width / Pango.SCALE) / 2;
shapeRect.y = cellRect.y + BASELINE_OFFSET * cellRect.height -
layoutBaseline / Pango.SCALE;
- shapeRect.width = shapeRect.width / Pango.SCALE;
- shapeRect.height = shapeRect.height / Pango.SCALE;
+ shapeRect.width /= Pango.SCALE;
+ shapeRect.height /= Pango.SCALE;
return shapeRect;
}
@@ -144,9 +143,9 @@ const CharacterListRow = GObject.registerClass({
let borderWidth = 1;
cr.rectangle(shapeRect.x - borderWidth * 2,
- shapeRect.y - borderWidth * 2,
- shapeRect.width + borderWidth * 2,
- shapeRect.height + borderWidth * 2);
+ shapeRect.y - borderWidth * 2,
+ shapeRect.width + borderWidth * 2,
+ shapeRect.height + borderWidth * 2);
cr.setSourceRGBA(239.0 / 255.0, 239.0 / 255.0, 239.0 / 255.0, 1.0);
cr.fill();
@@ -166,20 +165,20 @@ const CharacterListRow = GObject.registerClass({
layout.set_alignment(Pango.Alignment.CENTER);
layout.set_font_description(this._overlayFontDescription);
let name = Gc.character_name(uc);
- let text = name == null ? _('Unassigned') : Util.capitalize(name);
+ let text = name === null ? _('Unassigned') : Util.capitalize(name);
layout.set_text(text, -1);
- let [logicalRect, inkRect] = layout.get_extents();
+ let logicalRect = layout.get_extents()[0];
cr.moveTo(cellRect.x - logicalRect.x / Pango.SCALE +
(cellRect.width - logicalRect.width / Pango.SCALE) / 2,
- cellRect.y - logicalRect.y / Pango.SCALE +
+ cellRect.y - logicalRect.y / Pango.SCALE +
(cellRect.height - logicalRect.height / Pango.SCALE) / 2);
- let text_color;
- if (!this._styleManager.dark) {
- text_color = this._styleContext.get_color(Gtk.StateFlags.NORMAL);
- } else {
- text_color = this._styleContext.get_background_color(Gtk.StateFlags.NORMAL);
- }
- cr.setSourceRGBA(text_color.red, text_color.green, text_color.blue, text_color.alpha);
+ let textColor;
+ if (!this._styleManager.dark)
+ textColor = this._styleContext.get_color(Gtk.StateFlags.NORMAL);
+ else
+ textColor = this._styleContext.get_background_color(Gtk.StateFlags.NORMAL);
+
+ Gdk.cairo_set_source_rgba(cr, textColor);
PangoCairo.show_layout(cr, layout);
cr.restore();
@@ -188,7 +187,7 @@ const CharacterListRow = GObject.registerClass({
const CharacterListWidget = GObject.registerClass({
Signals: {
- 'character-selected': { param_types: [ GObject.TYPE_STRING ] }
+ 'character-selected': { param_types: [GObject.TYPE_STRING] },
},
}, class CharacterListWidget extends Gtk.Widget {
_init(numRows) {
@@ -201,7 +200,7 @@ const CharacterListWidget = GObject.registerClass({
this._numRows = numRows;
this._characters = [];
this._rows = [];
- /*this.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
+ /* this.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.BUTTON_RELEASE_MASK);
this.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
null,
@@ -226,7 +225,7 @@ const CharacterListWidget = GObject.registerClass({
}
vfunc_drag_data_get(context, data, info, time) {
- if (this._character != null)
+ if (this._character !== null)
data.set_text(this._character, -1);
}
@@ -250,8 +249,8 @@ const CharacterListWidget = GObject.registerClass({
}
*/
- vfunc_measure(orientation, for_size) {
- if(orientation === Gtk.Orientation.HORIZONTAL) {
+ vfunc_measure(orientation, _forSize) {
+ if (orientation === Gtk.Orientation.HORIZONTAL) {
let cellSize = getCellSize(this._fontDescription);
let minWidth = NUM_COLUMNS * cellSize;
let natWidth = Math.max(this._cellsPerRow, NUM_COLUMNS) * cellSize;
@@ -259,7 +258,7 @@ const CharacterListWidget = GObject.registerClass({
} else {
let height = Math.max(this._rows.length, this._numRows) *
getCellSize(this._fontDescription);
- return [height, height, -1 , -1];
+ return [height, height, -1, -1];
}
}
@@ -267,8 +266,8 @@ const CharacterListWidget = GObject.registerClass({
// Clear the canvas.
let allocation = this.get_allocation();
let rect = new Graphene.Rect({
- origin: new Graphene.Point({x: 0, y:0}),
- size: new Graphene.Size({width: allocation.width, height: allocation.height})
+ origin: new Graphene.Point({ x: 0, y: 0 }),
+ size: new Graphene.Size({ width: allocation.width, height: allocation.height }),
});
let cr = snapshot.append_cairo(rect);
@@ -281,13 +280,13 @@ const CharacterListWidget = GObject.registerClass({
// https://bugzilla.gnome.org/show_bug.cgi?id=700592
// Redraw rows within the clipped region.
- let [x1, y1, x2, y2] = cr.clipExtents();
+ let [_, y1, __, y2] = cr.clipExtents();
let cellSize = getCellSize(this._fontDescription);
let start = Math.max(0, Math.floor(y1 / cellSize));
let end = Math.min(this._rows.length, Math.ceil(y2 / cellSize));
for (let index = start; index < end; index++) {
this._rows[index].draw(cr, 0, index * cellSize,
- allocation.width, cellSize, context);
+ allocation.width, cellSize, context);
}
}
@@ -300,7 +299,7 @@ const CharacterListWidget = GObject.registerClass({
let cellSize = getCellSize(this._fontDescription);
let cellsPerRow = Math.floor(width / cellSize);
- if (cellsPerRow != this._cellsPerRow) {
+ if (cellsPerRow !== this._cellsPerRow) {
// Reflow if the number of cells per row has changed.
this._cellsPerRow = cellsPerRow;
this.setCharacters(this._characters);
@@ -326,14 +325,14 @@ const CharacterListWidget = GObject.registerClass({
let start = 0, stop = 1;
for (; stop <= characters.length; stop++) {
- if (stop % this._cellsPerRow == 0) {
+ if (stop % this._cellsPerRow === 0) {
let rowCharacters = characters.slice(start, stop);
let row = this._createCharacterListRow(rowCharacters);
this._rows.push(row);
start = stop;
}
}
- if (start != stop - 1) {
+ if (start !== stop - 1) {
let rowCharacters = characters.slice(start, stop);
let row = this._createCharacterListRow(rowCharacters);
this._rows.push(row);
@@ -351,10 +350,10 @@ var FontFilter = GObject.registerClass({
'font': GObject.ParamSpec.string(
'font', '', '',
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
- 'Cantarell 50')
+ 'Cantarell 50'),
},
Signals: {
- 'filter-set': { param_types: [] }
+ 'filter-set': { param_types: [] },
},
}, class FontFilter extends GObject.Object {
_init() {
@@ -372,7 +371,7 @@ var FontFilter = GObject.registerClass({
set font(v) {
let fontDescription = Pango.FontDescription.from_string(v);
- if (fontDescription.get_size() == 0)
+ if (fontDescription.get_size() === 0)
fontDescription.set_size(CELL_SIZE * Pango.SCALE);
if (this._fontDescription &&
@@ -391,23 +390,23 @@ var FontFilter = GObject.registerClass({
setFilterFont(v) {
let fontDescription;
- if (v == null) {
+ if (v === null) {
fontDescription = null;
} else {
fontDescription = Pango.FontDescription.from_string(v);
fontDescription.set_size(this._fontDescription.get_size());
}
- if ((this._filterFontDescription != null && fontDescription == null) ||
- (this._filterFontDescription == null && fontDescription != null) ||
- (this._filterFontDescription != null && fontDescription != null &&
- !fontDescription.equal(this._filterFontDescription))) {
+ if (this._filterFontDescription !== null && fontDescription === null ||
+ this._filterFontDescription === null && fontDescription !== null ||
+ this._filterFontDescription !== null && fontDescription !== null &&
+ !fontDescription.equal(this._filterFontDescription)) {
this._filterFontDescription = fontDescription;
this.emit('filter-set');
}
}
- apply(widget, characters) {
+ filter(widget, characters) {
let fontDescription = this._fontDescription;
if (this._filterFontDescription) {
let context = widget.get_pango_context();
@@ -429,7 +428,7 @@ var FontFilter = GObject.registerClass({
var CharactersView = GObject.registerClass({
Template: 'resource:///org/gnome/Characters/characters_view.ui',
Signals: {
- 'character-selected': { param_types: [ GObject.TYPE_STRING ] }
+ 'character-selected': { param_types: [GObject.TYPE_STRING] },
},
Properties: {
'model': GObject.ParamSpec.object(
@@ -438,7 +437,7 @@ var CharactersView = GObject.registerClass({
GObject.ParamFlags.READWRITE,
Gio.ListModel.$gtype,
),
- }
+ },
}, class CharactersView extends Adw.Bin {
_init() {
super._init();
@@ -474,16 +473,16 @@ var CharactersView = GObject.registerClass({
this._stopSpinner();
this._spinnerTimeoutId =
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
- //this._loading_spinner.start();
- //this.visible_child_name = 'loading';
- });
+ // this._loading_spinner.start();
+ // this.visible_child_name = 'loading';
+ });
}
_stopSpinner() {
if (this._spinnerTimeoutId > 0) {
GLib.source_remove(this._spinnerTimeoutId);
this._spinnerTimeoutId = 0;
- //this._loading_spinner.stop();
+ // this._loading_spinner.stop();
}
}
@@ -502,7 +501,7 @@ var CharactersView = GObject.registerClass({
_updateCharacterList() {
log('Updating characters list');
- const [fontDescription, characters] = this._fontFilter.apply(this, this._characters);
+ const [fontDescription, characters] = this._fontFilter.filter(this, this._characters);
log(JSON.stringify(characters));
this._characterList.setFontDescription(fontDescription);
this._characterList.setCharacters(characters);
@@ -531,41 +530,41 @@ var CharactersView = GObject.registerClass({
_searchWithContext(context, count) {
this._startSpinner();
- context.search(count, this._cancellable, (context, res, user_data) => {
- this._stopSpinner();
- try {
- let result = context.search_finish(res);
- this._addSearchResult(result);
- } catch (e) {
- log(`Failed to search: ${e.message}`);
- }
- });
+ context.search(count, this._cancellable, (ctx, res) => {
+ this._stopSpinner();
+ try {
+ let result = ctx.search_finish(res);
+ this._addSearchResult(result);
+ } catch (e) {
+ log(`Failed to search: ${e.message}`);
+ }
+ });
}
searchByCategory(category) {
this._characters = [];
- /*if ('scripts' in category) {
+ /* if ('scripts' in category) {
this.searchByScripts(category.scripts);
return;
}*/
let criteria = Gc.SearchCriteria.new_category(category);
- this._searchContext = new Gc.SearchContext({ criteria: criteria });
+ this._searchContext = new Gc.SearchContext({ criteria });
this._searchWithContext(this._searchContext, this.initialSearchCount);
}
searchByKeywords(keywords) {
const criteria = Gc.SearchCriteria.new_keywords(keywords);
this._searchContext = new Gc.SearchContext({
- criteria: criteria,
- flags: Gc.SearchFlag.WORD
+ criteria,
+ flags: Gc.SearchFlag.WORD,
});
this._searchWithContext(this._searchContext, this.initialSearchCount);
}
searchByScripts(scripts) {
var criteria = Gc.SearchCriteria.new_scripts(scripts);
- this._searchContext = new Gc.SearchContext({ criteria: criteria });
+ this._searchContext = new Gc.SearchContext({ criteria });
this._searchWithContext(this._searchContext, this.initialSearchCount);
}
@@ -577,12 +576,12 @@ var CharactersView = GObject.registerClass({
var RecentCharacterListView = GObject.registerClass({
Signals: {
- 'character-selected': { param_types: [ GObject.TYPE_STRING ] },
+ 'character-selected': { param_types: [GObject.TYPE_STRING] },
},
}, class RecentCharacterListView extends Adw.Bin {
_init(category) {
super._init({
- hexpand: true, vexpand: false
+ hexpand: true, vexpand: false,
});
this._characterList = new CharacterListWidget(0);
@@ -606,7 +605,7 @@ var RecentCharacterListView = GObject.registerClass({
}
_updateCharacterList() {
- const [fontDescription, characters] = this._fontFilter.apply(this, this._characters);
+ const [fontDescription, characters] = this._fontFilter.filter(this, this._characters);
this._characterList.setFontDescription(fontDescription);
this._characterList.setCharacters(characters);
}
diff --git a/src/main.js b/src/main.js
index c3bd600..d429079 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,3 +1,4 @@
+/* exported main settings */
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
//
// Copyright (c) 2013 Giovanni Campagna <scampa giovanni gmail com>
@@ -26,7 +27,7 @@
pkg.initGettext();
pkg.initFormat();
-pkg.require({
+pkg.require({
'Gdk': '4.0',
'Gio': '2.0',
'GLib': '2.0',
@@ -36,73 +37,83 @@ pkg.require({
'GnomeDesktop': '4.0',
});
-const {Gc, GLib, Gio, GObject, Gtk, Adw} = imports.gi;
+const { GLib, Gio, GObject, Adw } = imports.gi;
-const Util = imports.util;
+const { CharactersView } = imports.charactersView;
+const { Sidebar } = imports.categoryList;
+const { MenuPopover } = imports.menu;
const { MainWindow } = imports.window;
+const Util = imports.util;
+
var settings = null;
-var application_id = pkg.name;
+var applicationId = pkg.name;
var MyApplication = GObject.registerClass({
-},class MyApplication extends Adw.Application {
- _init () {
+}, class MyApplication extends Adw.Application {
+ _init() {
super._init({
- application_id: application_id,
+ application_id: applicationId,
flags: Gio.ApplicationFlags.FLAGS_NONE,
resource_base_path: '/org/gnome/Characters',
});
GLib.set_application_name(_('Characters'));
}
- _onQuit () {
+ _onQuit() {
this.quit();
}
- _onSearch (action, parameter) {
+ _onSearch(action, parameter) {
const window = new MainWindow(this);
window.setSearchKeywords(parameter.get_strv());
window.show();
}
- vfunc_startup () {
+ vfunc_startup() {
super.vfunc_startup();
this.get_style_manager().set_color_scheme(Adw.ColorScheme.PREFER_LIGHT);
- Util.initActions(this,
- [{ name: 'quit',
- activate: this._onQuit },
- { name: 'search',
- activate: this._onSearch,
- parameter_type: new GLib.VariantType('as') }]);
+ Util.initActions(this, [
+ { name: 'quit', activate: this._onQuit },
+ {
+ name: 'search',
+ activate: this._onSearch,
+ parameterType: new GLib.VariantType('as'),
+ },
+ ]);
this.set_accels_for_action('app.quit', ['<Primary>q']);
this.set_accels_for_action('win.find', ['<Primary>f']);
this.set_accels_for_action('win.show-primary-menu', ['F10']);
this.set_accels_for_action('win.show-help-overlay', ['<Primary>question']);
settings = Util.getSettings('org.gnome.Characters',
- '/org/gnome/Characters/');
+ '/org/gnome/Characters/');
- log("Characters Application started");
+ log('Characters Application started');
}
vfunc_activate() {
- if (!this._appwindow) {
+ if (!this._appwindow)
this._appwindow = new MainWindow(this);
- }
+
this._appwindow.present();
- log("Characters Application activated");
+ log('Characters Application activated');
}
vfunc_shutdown() {
- log("Characters Application exiting");
+ log('Characters Application exiting');
super.vfunc_shutdown();
}
});
function main(argv) {
- return (new MyApplication()).run(argv);
+ GObject.type_ensure(CharactersView.$gtype);
+ GObject.type_ensure(Sidebar.$gtype);
+ GObject.type_ensure(MenuPopover.$gtype);
+
+ return new MyApplication().run(argv);
}
diff --git a/src/menu.js b/src/menu.js
index 1b7f64d..5843e19 100644
--- a/src/menu.js
+++ b/src/menu.js
@@ -1,3 +1,4 @@
+/* exported MenuPopover */
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
//
// Copyright (C) 2015 Daiki Ueno <dueno src gnome org>
@@ -16,7 +17,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-const {GLib, GObject, Gtk} = imports.gi;
+const { GLib, GObject, Gtk } = imports.gi;
var MenuPopover = GObject.registerClass({
Template: 'resource:///org/gnome/Characters/menu.ui',
@@ -26,8 +27,10 @@ var MenuPopover = GObject.registerClass({
const row = new Gtk.ListBoxRow();
row.add_css_class('font');
row._family = family;
- let label = new Gtk.Label({ label: title,
- halign: Gtk.Align.START });
+ let label = new Gtk.Label({
+ label: title,
+ halign: Gtk.Align.START,
+ });
label.add_css_class('font-label');
row.set_child(label);
return row;
@@ -35,28 +38,29 @@ var MenuPopover = GObject.registerClass({
_init() {
super._init({});
- let row = this._createFontListRow(_("None"), 'None');
- this._font_listbox.append(row);
+ this._font_listbox.append(this._createFontListRow(_('None'), 'None'));
let context = this.get_pango_context();
let families = context.list_families();
- families = families.sort(function(a, b) {
+ families = families.sort((a, b) => {
return a.get_name().localeCompare(b.get_name());
});
for (let index in families) {
- row = this._createFontListRow(families[index].get_name(),
- families[index].get_name());
- this._font_listbox.append(row);
+ let newRow = this._createFontListRow(families[index].get_name(),
+ families[index].get_name());
+ this._font_listbox.append(newRow);
}
this._keywords = [];
- this._search_entry.connect('search-changed', (entry) => this._handleSearchChanged(entry));
- this._font_listbox.connect('row-activated', (listBox, row) => this._handleRowActivated(listBox,
row));
- this._font_listbox.set_filter_func((row) => this._filterFunc(row));
+ this._search_entry.connect('search-changed', entry => this._handleSearchChanged(entry));
+ this._font_listbox.connect('row-activated', (_listBox, row) => {
+ this._handleRowActivated(row);
+ });
+ this._font_listbox.set_filter_func(row => this._filterFunc(row));
// This silents warning at Characters exit about this widget being
// visible but not mapped. Borrowed from Maps.
- this.connect('unmap', function(popover) {
+ this.connect('unmap', popover => {
popover._font_listbox.unselect_all();
popover.hide();
});
@@ -64,14 +68,14 @@ var MenuPopover = GObject.registerClass({
_handleSearchChanged(entry) {
let text = entry.get_text().replace(/^\s+|\s+$/g, '');
- let keywords = text == '' ? [] : text.split(/\s+/);
+ let keywords = text === '' ? [] : text.split(/\s+/);
this._keywords = keywords.map(x => x.toLowerCase());
this._font_listbox.invalidate_filter();
return true;
}
- _handleRowActivated(listBox, row) {
- if (row != null) {
+ _handleRowActivated(row) {
+ if (row !== null) {
let toplevel = this.get_root();
let action = toplevel.lookup_action('filter-font');
action.activate(new GLib.Variant('s', row._family));
@@ -79,14 +83,14 @@ var MenuPopover = GObject.registerClass({
}
_filterFunc(row) {
- if (this._keywords.length == 0)
+ if (this._keywords.length === 0)
return true;
- if (row._family == 'None')
+ if (row._family === 'None')
return true;
let nameWords = row._family.split(/\s+/).map(x => x.toLowerCase());
- return this._keywords.every(function(keyword, index, array) {
- return nameWords.some(function(nameWord, index, array) {
+ return this._keywords.every((keyword, _index, _array) => {
+ return nameWords.some((nameWord, __index, __array) => {
return nameWord.indexOf(keyword) >= 0;
});
});
diff --git a/src/meson.build b/src/meson.build
index eb44aee..f7ede14 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -13,7 +13,7 @@ scripts = [
foreach script: scripts
configure_file(
input: script + '.in',
- output: script,
+ output: '@BASENAME@',
configuration: script_conf,
install: true,
install_dir: characters_pkgdatadir
diff --git a/src/org.gnome.Characters.BackgroundService.in b/src/org.gnome.Characters.BackgroundService.in
index 0b2339b..78859da 100755
--- a/src/org.gnome.Characters.BackgroundService.in
+++ b/src/org.gnome.Characters.BackgroundService.in
@@ -3,5 +3,5 @@ imports.package.init({ name: "org.gnome.Characters",
version: "@PACKAGE_VERSION@",
prefix: "@prefix@",
libdir: "@libdir@" });
-imports.service.application_id = "@appid@";
+imports.service.applicationId = "@appid@";
imports.package.run(imports.service);
diff --git a/src/org.gnome.Characters.in b/src/org.gnome.Characters.in
index b6f14a2..ea9520b 100755
--- a/src/org.gnome.Characters.in
+++ b/src/org.gnome.Characters.in
@@ -3,5 +3,5 @@ imports.package.init({ name: "org.gnome.Characters",
version: "@PACKAGE_VERSION@",
prefix: "@prefix@",
libdir: "@libdir@" });
-imports.main.application_id = "@appid@";
+imports.main.applicationId = "@appid@";
imports.package.run(imports.main);
diff --git a/src/searchProvider.js b/src/searchProvider.js
index 5b50864..910a1d6 100644
--- a/src/searchProvider.js
+++ b/src/searchProvider.js
@@ -1,3 +1,4 @@
+/* exported SearchProvider */
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
//
// Copyright (c) 2013 Giovanni Campagna <scampa giovanni gmail com>
@@ -17,7 +18,7 @@
// with Gnome Weather; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-const {Gc, Gdk, Gio, GLib, GObject} = imports.gi;
+const { Gc, Gdk, Gio, GLib, GObject } = imports.gi;
const ByteArray = imports.byteArray;
const Service = imports.service;
@@ -51,12 +52,12 @@ var SearchProvider = GObject.registerClass({
let upper = keywords.map(x => x.toUpperCase());
let criteria = Gc.SearchCriteria.new_keywords(upper);
- let context = new Gc.SearchContext({ criteria: criteria,
- flags: Gc.SearchFlag.WORD });
+ let context = new Gc.SearchContext({ criteria,
+ flags: Gc.SearchFlag.WORD });
context.search(
MAX_SEARCH_RESULTS,
this._cancellable,
- (source_object, res, user_data) => {
+ (sourceObject, res, _userData) => {
let characters = [];
try {
let result = context.search_finish(res);
@@ -90,19 +91,18 @@ var SearchProvider = GObject.registerClass({
let codePoint = Util.toCodePoint(character);
let codePointHex = codePoint.toString(16).toUpperCase();
let name = Gc.character_name(character);
- if (name == null)
- name = _("Unknown character name");
+ if (name === null)
+ name = _('Unknown character name');
else
name = Util.capitalize(name);
- let summary = _("U+%s, %s: %s").format(codePointHex,
- character,
- name);
+ let summary = _('U+%s, %s: %s').format(codePointHex,
+ character,
+ name);
ret.push({ name: new GLib.Variant('s', name),
- id: new GLib.Variant('s', identifiers[i]),
- description: new GLib.Variant('s', summary),
- icon: (new Gio.ThemedIcon({ name: Service.application_id })).serialize(),
- clipboardText: new GLib.Variant('s', character)
- });
+ id: new GLib.Variant('s', identifiers[i]),
+ description: new GLib.Variant('s', summary),
+ icon: new Gio.ThemedIcon({ name: Service.applicationId }).serialize(),
+ clipboardText: new GLib.Variant('s', character) });
}
this._app.release();
@@ -110,7 +110,7 @@ var SearchProvider = GObject.registerClass({
return ret;
}
- ActivateResult(id, terms, timestamp) {
+ ActivateResult(id, _terms, _timestamp) {
let clipboard = Gc.gtk_clipboard_get();
clipboard.set_text(id, -1);
}
@@ -122,7 +122,7 @@ var SearchProvider = GObject.registerClass({
let app = Gio.DesktopAppInfo.new('org.gnome.Characters.desktop');
let id = context.get_startup_notify_id(app, []);
- return {'desktop-startup-id': new GLib.Variant('s', id) };
+ return { 'desktop-startup-id': new GLib.Variant('s', id) };
}
_activateAction(action, parameter, timestamp) {
@@ -133,26 +133,26 @@ var SearchProvider = GObject.registerClass({
wrappedParam = [];
Gio.DBus.session.call('org.gnome.Characters',
- '/org/gnome/Characters',
- 'org.freedesktop.Application',
- 'ActivateAction',
- new GLib.Variant('(sava{sv})', [action, wrappedParam,
- this._getPlatformData(timestamp)]),
- null,
- Gio.DBusCallFlags.NONE,
- -1, null, (connection, result) => {
- try {
- connection.call_finish(result);
- } catch(e) {
- log(`Failed to launch application: ${e.message}`);
- }
-
- this._app.release();
- });
+ '/org/gnome/Characters',
+ 'org.freedesktop.Application',
+ 'ActivateAction',
+ new GLib.Variant('(sava{sv})', [action, wrappedParam,
+ this._getPlatformData(timestamp)]),
+ null,
+ Gio.DBusCallFlags.NONE,
+ -1, null, (connection, result) => {
+ try {
+ connection.call_finish(result);
+ } catch (e) {
+ log(`Failed to launch application: ${e.message}`);
+ }
+
+ this._app.release();
+ });
}
LaunchSearch(terms, timestamp) {
this._activateAction('search', new GLib.Variant('as', terms),
- timestamp);
+ timestamp);
}
});
diff --git a/src/service.js b/src/service.js
index 94da7d4..e66eb30 100644
--- a/src/service.js
+++ b/src/service.js
@@ -1,3 +1,4 @@
+/* exported applicationId main */
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
//
// Copyright (c) 2012 Giovanni Campagna <scampa giovanni gmail com>
@@ -19,20 +20,19 @@
pkg.initGettext();
pkg.initFormat();
-pkg.require({ 'Gio': '2.0',
- 'GLib': '2.0',
- 'GObject': '2.0',
- 'Gtk': '3.0' });
+pkg.require({
+ 'Gio': '2.0',
+ 'GLib': '2.0',
+ 'GObject': '2.0',
+ 'Gtk': '3.0',
+});
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const Gtk = imports.gi.Gtk;
-const GObject = imports.gi.GObject;
+const { Gio, GLib, GObject, Gtk } = imports.gi;
const Util = imports.util;
const SearchProvider = imports.searchProvider;
-var application_id = pkg.name;
+var applicationId = pkg.name;
const BackgroundService = GObject.registerClass({
// This needs to be a Gtk.Application instead of Gio.Application,
@@ -40,9 +40,9 @@ const BackgroundService = GObject.registerClass({
}, class BackgroundService extends Gtk.Application {
_init() {
super._init({ application_id: pkg.name,
- flags: Gio.ApplicationFlags.IS_SERVICE,
- inactivity_timeout: 30000 });
- GLib.set_application_name(_("Characters"));
+ flags: Gio.ApplicationFlags.IS_SERVICE,
+ inactivity_timeout: 30000 });
+ GLib.set_application_name(_('Characters'));
this._searchProvider = new SearchProvider.SearchProvider(this);
}
@@ -58,7 +58,7 @@ const BackgroundService = GObject.registerClass({
return true;
}
-/*
+ /*
Can't do until GApplication is fixed.
vfunc_dbus_unregister(connection, path) {
@@ -71,9 +71,9 @@ const BackgroundService = GObject.registerClass({
vfunc_startup() {
super.vfunc_startup();
- Util.initActions(this,
- [{ name: 'quit',
- activate: this._onQuit }]);
+ Util.initActions(this, [
+ { name: 'quit', activate: this._onQuit },
+ ]);
}
vfunc_activate() {
@@ -82,5 +82,5 @@ const BackgroundService = GObject.registerClass({
});
function main(argv) {
- return (new BackgroundService()).run(argv);
+ return new BackgroundService().run(argv);
}
diff --git a/src/util.js b/src/util.js
index e78b7c2..e52f03c 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,3 +1,4 @@
+/* exported capitalize getSettings initActions searchResultToArray toCodePoint */
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
//
// Copyright (c) 2013 Giovanni Campagna <scampa giovanni gmail com>
@@ -24,14 +25,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-const {Gc, Gdk, Gio, GObject, Gtk} = imports.gi;
+const { Gc, Gio } = imports.gi;
-const Lang = imports.lang;
const System = imports.system;
function initActions(actionMap, simpleActionEntries, context) {
- simpleActionEntries.forEach(({name, parameter_type, state, activate })=> {
- let action = new Gio.SimpleAction({name, parameter_type: parameter_type || null, state: state ||
null});
+ simpleActionEntries.forEach(({ name, parameterType, state, activate }) => {
+ let action = new Gio.SimpleAction({
+ name,
+ parameter_type: parameterType || null,
+ state: state || null,
+ });
context = context || actionMap;
if (activate)
@@ -48,37 +52,38 @@ function getSettings(schemaId, path) {
if (!pkg.moduledir.startsWith('resource://')) {
// Running from the source tree
schemaSource = GioSSS.new_from_directory(pkg.pkgdatadir,
- GioSSS.get_default(),
- false);
+ GioSSS.get_default(),
+ false);
} else {
schemaSource = GioSSS.get_default();
}
let schemaObj = schemaSource.lookup(schemaId, true);
if (!schemaObj) {
- log('Missing GSettings schema ' + schemaId);
+ log(`Missing GSettings schema ${schemaId}`);
System.exit(1);
}
- if (path === undefined)
+ if (path === undefined) {
return new Gio.Settings({ settings_schema: schemaObj });
- else
+ } else {
return new Gio.Settings({ settings_schema: schemaObj,
- path: path });
+ path });
+ }
}
function capitalizeWord(w) {
if (w.length > 0)
- return w[0].toUpperCase() + w.slice(1).toLowerCase()
+ return w[0].toUpperCase() + w.slice(1).toLowerCase();
return w;
}
function capitalize(s) {
- return s.split(/\s+/).map(function(w) {
- let acronyms = ["CJK"];
+ return s.split(/\s+/).map(w => {
+ let acronyms = ['CJK'];
if (acronyms.indexOf(w) > -1)
return w;
- let prefixes = ["IDEOGRAPH-", "SELECTOR-"];
+ let prefixes = ['IDEOGRAPH-', 'SELECTOR-'];
for (let index in prefixes) {
let prefix = prefixes[index];
if (w.startsWith(prefix))
@@ -101,8 +106,8 @@ function toCodePoint(s) {
function searchResultToArray(result) {
let characters = [];
- for (let index = 0; index < result.len; index++) {
+ for (let index = 0; index < result.len; index++)
characters.push(Gc.search_result_get(result, index));
- }
+
return characters;
}
diff --git a/src/window.js b/src/window.js
index 98f3cb0..25faf8e 100644
--- a/src/window.js
+++ b/src/window.js
@@ -1,3 +1,4 @@
+/* exported MainWindow */
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
//
// Copyright (c) 2013 Giovanni Campagna <scampa giovanni gmail com>
@@ -24,12 +25,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-const {Adw, Gio, GLib, GObject, Gtk } = imports.gi;
+const { Adw, Gio, GLib, GObject, Gtk } = imports.gi;
-const {Sidebar, MainCategories} = imports.categoryList;
-const {CharacterDialog} = imports.characterDialog;
-const {CharactersView, FontFilter, RecentCharacterListView} = imports.charactersView;
-const {MenuPopover} = imports.menu;
+const { CharacterDialog } = imports.characterDialog;
+const { FontFilter, RecentCharacterListView } = imports.charactersView;
const Gettext = imports.gettext;
const Main = imports.main;
@@ -51,7 +50,7 @@ var MainWindow = GObject.registerClass({
'max-recent-characters': GObject.ParamSpec.uint(
'max-recent-characters', '', '',
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
- 0, GLib.MAXUINT32, 100)
+ 0, GLib.MAXUINT32, 100),
},
}, class MainWindow extends Adw.ApplicationWindow {
_init(application) {
@@ -74,10 +73,7 @@ var MainWindow = GObject.registerClass({
this._leaflet.navigate(Adw.NavigationDirection.FORWARD);
});
- let characterList;
-
-
- /*characterList = this._createCharacterList(
+ /* characterList = this._createCharacterList(
'search-result', _('Search Result Character List'));
// FIXME: Can't use GtkContainer.child_get_property.
characterList.title = _("Search Result");
@@ -88,46 +84,43 @@ var MainWindow = GObject.registerClass({
this.recentCharacters = recentCharacters.get_strv();
this._maxRecentCharacters = 100;
Main.settings.bind('max-recent-characters', this,
- 'max-recent-characters',
- Gio.SettingsBindFlags.DEFAULT);
-
-
- Util.initActions(this,
- [{ name: 'about',
- activate: this._about },
- { name: 'search-active',
- activate: this._toggleSearch,
- parameter_type: new GLib.VariantType('b'),
- state: new GLib.Variant('b', false) },
- { name: 'find',
- activate: this._find },
- { name: 'category',
- activate: this._category,
- parameter_type: new GLib.VariantType('s'),
- state: new GLib.Variant('s', 'emoji-smileys') },
- { name: 'character',
- activate: this._character,
- parameter_type: new GLib.VariantType('s') },
- { name: 'filter-font',
- activate: this._filterFont,
- parameter_type: new GLib.VariantType('s')
- },
- {
- name: 'show-primary-menu',
- activate: this._togglePrimaryMenu,
- state: new GLib.Variant('b', false),
- }]);
+ 'max-recent-characters',
+ Gio.SettingsBindFlags.DEFAULT);
+
+ Util.initActions(this, [
+ { name: 'about', activate: this._about },
+ { name: 'search-active',
+ activate: this._toggleSearch,
+ parameterType: new GLib.VariantType('b'),
+ state: new GLib.Variant('b', false) },
+ { name: 'find', activate: this._find },
+ { name: 'category',
+ activate: this._category,
+ parameterType: new GLib.VariantType('s'),
+ state: new GLib.Variant('s', 'emoji-smileys') },
+ { name: 'character',
+ activate: this._character,
+ parameterType: new GLib.VariantType('s') },
+ { name: 'filter-font',
+ activate: this._filterFont,
+ parameterType: new GLib.VariantType('s') },
+ {
+ name: 'show-primary-menu',
+ activate: this._togglePrimaryMenu,
+ state: new GLib.Variant('b', false),
+ },
+ ]);
this.bind_property('search-active', this._search_active_button, 'active',
- GObject.BindingFlags.SYNC_CREATE |
+ GObject.BindingFlags.SYNC_CREATE |
GObject.BindingFlags.BIDIRECTIONAL);
this.bind_property('search-active',
- this._search_bar,
- 'search-mode-enabled',
- GObject.BindingFlags.SYNC_CREATE |
+ this._search_bar,
+ 'search-mode-enabled',
+ GObject.BindingFlags.SYNC_CREATE |
GObject.BindingFlags.BIDIRECTIONAL);
this._search_bar.connect_entry(this._search_entry);
- this._search_entry.connect('search-changed', (entry) => this._handleSearchChanged(entry));
+ this._search_entry.connect('search-changed', entry => this._handleSearchChanged(entry));
this._back_button.connect('clicked', () => {
this._leaflet.navigate(Adw.NavigationDirection.BACK);
@@ -136,7 +129,7 @@ var MainWindow = GObject.registerClass({
// Due to limitations of gobject-introspection wrt GdkEvent
// and GdkEventKey, this needs to be a signal handler
// TODO: use EventControllerKey
- //this.connect('key-press-event', (self, event) => this._handleKeyPress(self, event));
+ // this.connect('key-press-event', (self, event) => this._handleKeyPress(self, event));
}
vfunc_map() {
@@ -151,19 +144,19 @@ var MainWindow = GObject.registerClass({
// Select the first subcategory which contains at least one character.
_selectFirstSubcategory() {
- if (this.recentCharacters.length !== 0) {
+ if (this.recentCharacters.length !== 0)
this._sidebar.selectRowByName('recent');
- } else {
+ else
this._sidebar.selectRowByName('smileys');
- }
+
}
- get search_active() {
+ get searchActive() {
return this._searchActive;
}
- set search_active(v) {
- if (this._searchActive == v)
+ set searchActive(v) {
+ if (this._searchActive === v)
return;
this._searchActive = v;
@@ -171,7 +164,7 @@ var MainWindow = GObject.registerClass({
if (this._searchActive) {
let categoryList = this._sidebar.selectedList.list;
categoryList.unselect_all();
- this._updateTitle(_("Search Result"));
+ this._updateTitle(_('Search Result'));
} else {
this._sidebar.restorePreviousSelection();
}
@@ -181,9 +174,9 @@ var MainWindow = GObject.registerClass({
_handleSearchChanged(entry) {
const text = entry.get_text().replace(/^\s+|\s+$/g, '');
- let keywords = text == '' ? [] : text.split(/\s+/);
+ let keywords = text === '' ? [] : text.split(/\s+/);
keywords = keywords.map(x => x.toUpperCase());
- if (keywords != this._searchKeywords) {
+ if (keywords !== this._searchKeywords) {
this.cancelSearch();
this._searchKeywords = keywords;
if (this._searchKeywords.length > 0)
@@ -200,23 +193,22 @@ var MainWindow = GObject.registerClass({
_about() {
const aboutDialog = new Gtk.AboutDialog(
- { artists: [ 'Allan Day <allanpday gmail com>',
- 'Jakub Steiner <jimmac gmail com>' ],
- authors: [ 'Daiki Ueno <dueno src gnome org>',
- 'Giovanni Campagna <scampa giovanni gmail com>' ],
- // TRANSLATORS: put your names here, one name per line.
- translator_credits: _("translator-credits"),
- program_name: _("GNOME Characters"),
- comments: _("Character Map"),
- copyright: 'Copyright 2014-2018 Daiki Ueno',
- license_type: Gtk.License.GPL_2_0,
- logo_icon_name: Main.application_id,
- version: pkg.version,
- website: 'https://wiki.gnome.org/Apps/Characters',
- wrap_license: true,
- modal: true,
- transient_for: this
- });
+ { artists: ['Allan Day <allanpday gmail com>',
+ 'Jakub Steiner <jimmac gmail com>'],
+ authors: ['Daiki Ueno <dueno src gnome org>',
+ 'Giovanni Campagna <scampa giovanni gmail com>'],
+ // TRANSLATORS: put your names here, one name per line.
+ translator_credits: _('translator-credits'),
+ program_name: _('GNOME Characters'),
+ comments: _('Character Map'),
+ copyright: 'Copyright 2014-2018 Daiki Ueno',
+ license_type: Gtk.License.GPL_2_0,
+ logo_icon_name: Main.applicationId,
+ version: pkg.version,
+ website: 'https://wiki.gnome.org/Apps/Characters',
+ wrap_license: true,
+ modal: true,
+ transient_for: this });
aboutDialog.show();
}
@@ -224,45 +216,46 @@ var MainWindow = GObject.registerClass({
_updateTitle(title) {
if (this.filterFontFamily) {
this._windowTitle.title =
- _("%s (%s only)").format(Gettext.gettext(title),
- this.filterFontFamily);
+ _('%s (%s only)').format(Gettext.gettext(title),
+ this.filterFontFamily);
} else {
this._windowTitle.title = Gettext.gettext(title);
}
}
_character(action, v) {
- const [uc, length] = v.get_string();
+ const uc = v.get_string()[0];
this.addToRecent(uc);
}
_filterFont(action, v) {
- let [family, length] = v.get_string();
- if (family == 'None')
+ let family = v.get_string()[0];
+ if (family === 'None')
family = null;
this.filterFontFamily = family;
- //this._updateTitle(this._stack.visible_child.title);
+ // this._updateTitle(this._stack.visible_child.title);
this._menuPopover.hide();
}
_find() {
- this.search_active = !this.search_active;
+ this.searchActive = !this.searchActive;
}
setSearchKeywords(keywords) {
- this.search_active = keywords.length > 0;
+ this.searchActive = keywords.length > 0;
this._search_entry.set_text(keywords.join(' '));
}
- get max_recent_characters() {
+ get maxRecentCharacters() {
return this._maxRecentCharacters;
}
- set max_recent_characters(v) {
+ set maxRecentCharacters(v) {
this._maxRecentCharacters = v;
- if (this.recentCharacters.length > this._maxRecentCharacters)
+ if (this.recentCharacters.length > this._maxRecentCharacters) {
this.recentCharacters = this.recentCharacters.slice(
0, this._maxRecentCharacters);
+ }
}
get filterFontFamily() {
@@ -274,9 +267,9 @@ var MainWindow = GObject.registerClass({
this._fontFilter.setFilterFont(this._filterFontFamily);
}
- _createRecentCharacterList(name, accessible_name, category) {
+ _createRecentCharacterList(name, accessibleName, category) {
const characterList = new RecentCharacterListView(category, this._fontFilter);
- //characterList.get_accessible().accessible_name = accessible_name;
+ // characterList.get_accessible().accessible_name = accessibleName;
characterList.connect('character-selected', (widget, uc) => this._handleCharacterSelected(widget,
uc));
this._characterLists[name] = characterList;
@@ -289,46 +282,45 @@ var MainWindow = GObject.registerClass({
}
cancelSearch() {
- const characterList = this.mainStack.get_child_by_name('search-result');
+ const characterList = this._mainStack.get_child_by_name('search-result');
characterList.cancelSearch();
}
setPage(pageRow) {
if (pageRow.name === 'recent') {
- if (this.recentCharacters.length === 0)
+ if (this.recentCharacters.length === 0) {
this._mainStack.visible_child_name = 'empty-recent';
- else {
+ } else {
this._charactersView.setCharacters(this.recentCharacters);
- this._mainStack.visible_child_name = 'recent';
+ this._mainStack.visible_child_name = 'character-list';
}
} else {
this._charactersView.searchByCategory(pageRow.category);
this._mainStack.visible_child_name = 'character-list';
- //this._charactersView.model = pageRow.model;
+ // this._charactersView.model = pageRow.model;
}
}
addToRecent(uc) {
if (this.recentCharacters.indexOf(uc) < 0) {
this.recentCharacters.unshift(uc);
- if (this.recentCharacters.length > this._maxRecentCharacters)
+ 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));
}
}
- _addToRecent(widget, uc) {
- this.addToRecent(uc);
- }
-
_handleCharacterSelected(widget, uc) {
const dialog = new CharacterDialog(uc, this._fontFilter.fontDescription);
dialog.set_modal(true);
dialog.set_transient_for(this.get_root());
- dialog.connect('character-copied', (widget, uc) => this._addToRecent(widget, uc));
+ dialog.connect('character-copied', (_widget, char) => {
+ this.addToRecent(char);
+ });
dialog.show();
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]