[gnome-characters/bilelmoussaoui/gtk4: 18/71] finish removal of the params module
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters/bilelmoussaoui/gtk4: 18/71] finish removal of the params module
- Date: Thu, 25 Nov 2021 11:03:10 +0000 (UTC)
commit a2b0737095617d8f44702d138897fe9c40dc580e
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Sat Nov 20 12:41:24 2021 +0100
finish removal of the params module
It adds a ton of over-complication to the app that's very often not needed
data/meson.build | 2 +-
po/POTFILES.in | 1 -
src/categoryList.js | 25 +++--
src/characterDialog.js | 19 ++--
src/characterList.js | 96 ++++++----------
src/main.js | 6 +-
src/menu.js | 7 +-
src/meson.build | 1 -
....Characters.BackgroundService.src.gresource.xml | 1 -
src/org.gnome.Characters.src.gresource.xml | 1 -
src/params.js | 124 ---------------------
src/util.js | 17 +--
src/window.js | 66 ++++-------
13 files changed, 89 insertions(+), 277 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 106ee00..5f7e708 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -16,7 +16,7 @@ resource_data = files(
'icons/hicolor/scalable/categories/characters-math-symbolic.svg',
'icons/hicolor/scalable/categories/characters-picture-symbolic.svg',
'icons/hicolor/scalable/categories/characters-punctuation-symbolic.svg',
- 'application.css',
+ 'style.css',
'characterlist.ui',
'character.ui',
'mainview.ui',
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 88385e7..5bb2743 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,7 +14,6 @@ src/characterDialog.js
src/characterList.js
src/main.js
src/menu.js
-src/params.js
src/searchProvider.js
src/service.js
src/util.js
diff --git a/src/categoryList.js b/src/categoryList.js
index a4baee7..8f38720 100644
--- a/src/categoryList.js
+++ b/src/categoryList.js
@@ -23,7 +23,7 @@ const Gettext = imports.gettext;
const Util = imports.util;
-const CategoryList = [
+var MainCategories = [
{
name: 'emojis',
category: Gc.Category.EMOJI,
@@ -159,6 +159,13 @@ const CategoryListRowWidget = GObject.registerClass({
});
const CategoryListWidget = GObject.registerClass({
+ Properties: {
+ 'selected-category': GObject.ParamSpec.string(
+ 'selected-category',
+ 'Current active category', 'Currently selected category',
+ GObject.ParamFlags.READWRITE,
+ ""),
+ },
}, class CategoryListWidget extends Adw.Bin {
_init(categories) {
super._init({});
@@ -167,6 +174,7 @@ const CategoryListWidget = GObject.registerClass({
this._categories = categories;
this.populateCategoryList();
this._lastSelectedRow = null;
+ this._selectedCategory = null;
for (let index in this._categories) {
let category = this._categories[index];
@@ -177,9 +185,8 @@ const CategoryListWidget = GObject.registerClass({
this.list.connect('row-selected', (row) => {
if (row != null && row.selectable) {
- let toplevel = row.get_root();
- let action = toplevel.lookup_action('category');
- action.activate(new GLib.Variant('s', row.category.name));
+ this._selectedCategory = row.category.name;
+ this.notify('selected-category');
this._lastSelectedRow = row;
}
});
@@ -392,7 +399,7 @@ var CategoryListView = GObject.registerClass({
this.append(new Gtk.Separator({orientation: Gtk.Orientation.HORIZONTAL}));
let emojis_label = new Gtk.Label ({
- label: CategoryList[0].title,
+ label: MainCategories[0].title,
halign: Gtk.Align.START,
margin_top: 12,
margin_start: 12,
@@ -412,7 +419,7 @@ var CategoryListView = GObject.registerClass({
this.append(this._emojiCategoryList);
let letters_label = new Gtk.Label ({
- label: CategoryList[1].title,
+ label: MainCategories[1].title,
halign: Gtk.Align.START,
margin_top: 12,
margin_start: 12,
@@ -431,7 +438,6 @@ var CategoryListView = GObject.registerClass({
});
this.append(this._letterCategoryList);
- this._categoryList = CategoryList.slice();
}
getCategoryByName(name) {
@@ -445,15 +451,10 @@ var CategoryListView = GObject.registerClass({
}
}
- getCategoryList() {
- return this._categoryList;
- }
-
get selectedList() {
return this._lastSelectedList
}
-
restorePreviousSelection() {
if (this._lastSelectedList) {
this._lastSelectedList.restorePreviousSelection()
diff --git a/src/characterDialog.js b/src/characterDialog.js
index b1bb2cc..d362d59 100644
--- a/src/characterDialog.js
+++ b/src/characterDialog.js
@@ -18,8 +18,6 @@
const {Gc, GLib, Gio,GObject,Gtk, Pango} = imports.gi;
-const Params = imports.params;
-
const Util = imports.util;
var CharacterDialog = GObject.registerClass({
@@ -32,13 +30,12 @@ var CharacterDialog = GObject.registerClass({
'character-label', 'missing-label', 'detail-label',
'copy-button', 'copy-revealer', 'related-listbox'],
}, class CharacterDialog extends Gtk.Dialog {
- _init(params) {
- const filtered = Params.filter(params, { character: null,
- fontDescription: null });
- params = Params.fill(params, { use_header_bar: true,
- width_request: 400,
- height_request: 400 });
- super._init(params);
+ _init(character, fontDescription) {
+ super._init({
+ use_header_bar: true,
+ width_request: 400,
+ height_request: 400
+ });
this._cancellable = new Gio.Cancellable();
@@ -57,8 +54,8 @@ var CharacterDialog = GObject.registerClass({
this._main_stack.visible_child_name = 'character';
});
- this._fontDescription = filtered.fontDescription;
- this._setCharacter(filtered.character);
+ this._fontDescription = fontDescription;
+ this._setCharacter(character);
this._copyRevealerTimeoutId = 0;
}
diff --git a/src/characterList.js b/src/characterList.js
index 86a7176..d021ee0 100644
--- a/src/characterList.js
+++ b/src/characterList.js
@@ -16,7 +16,6 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-const Params = imports.params;
const {Adw, Gc, Gdk, GLib, Gio,GObject,Gtk, Pango, PangoCairo} = imports.gi;
const Cairo = imports.cairo;
@@ -38,15 +37,12 @@ function getCellSize(fontDescription) {
const CharacterListRow = GObject.registerClass({
}, class CharacterListRow extends GObject.Object {
- _init(params) {
- const filtered = Params.filter(params, { characters: null,
- fontDescription: null,
- overlayFontDescription: null });
- params = Params.fill(params, {});
- super._init(params);
- this._characters = filtered.characters;
- this._fontDescription = filtered.fontDescription;
- this._overlayFontDescription = filtered.overlayFontDescription;
+ _init(characters, fontDescription, overlayFontDescription) {
+ super._init({});
+
+ this._characters = characters;
+ this._fontDescription = fontDescription;
+ this._overlayFontDescription = overlayFontDescription;
this._styleManager = Adw.StyleManager.get_default();
}
@@ -195,17 +191,15 @@ const CharacterListWidget = GObject.registerClass({
'character-selected': { param_types: [ GObject.TYPE_STRING ] }
},
}, class CharacterListWidget extends Gtk.DrawingArea {
- _init(params) {
- const filtered = Params.filter(params, {
- fontDescription: null,
- numRows: NUM_ROWS
+ _init(fontDescription, numRows) {
+ super._init({
+ hexpand: true,
+ vexpand: true,
});
- params = Params.fill(params, {});
- super._init(params);
this.add_css_class('character-list');
this._cellsPerRow = CELLS_PER_ROW;
- this._fontDescription = filtered.fontDescription;
- this._numRows = filtered.numRows;
+ this._fontDescription = fontDescription;
+ this._numRows = numRows;
this._characters = [];
this._rows = [];
/*this.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
@@ -322,13 +316,10 @@ const CharacterListWidget = GObject.registerClass({
_createCharacterListRow(characters) {
var context = this.get_pango_context();
- var fontDescription = context.get_font_description();
- fontDescription.set_size(fontDescription.get_size() * 0.8);
- let row = new CharacterListRow({
- characters: characters,
- fontDescription: this._fontDescription,
- overlayFontDescription: fontDescription
- });
+ var overlayFontDescription = context.get_font_description();
+ overlayFontDescription.set_size(fontDescription.get_size() * 0.8);
+
+ let row = new CharacterListRow(characters, this._fontDescription, overlayFontDescription);
return row;
}
@@ -373,6 +364,15 @@ var FontFilter = GObject.registerClass({
'filter-set': { param_types: [] }
},
}, class FontFilter extends GObject.Object {
+ _init() {
+ super._init({});
+
+ this._fontDescription = null;
+ this._filterFontDescription = null;
+
+ Main.settings.bind('font', this, 'font', Gio.SettingsBindFlags.DEFAULT);
+ }
+
get font() {
return this._font;
}
@@ -396,16 +396,6 @@ var FontFilter = GObject.registerClass({
return this._fontDescription;
}
- _init(params) {
- params = Params.fill(params, {});
- super._init(params);
-
- this._fontDescription = null;
- this._filterFontDescription = null;
-
- Main.settings.bind('font', this, 'font', Gio.SettingsBindFlags.DEFAULT);
- }
-
setFilterFont(v) {
let fontDescription;
if (v == null) {
@@ -450,22 +440,14 @@ var CharacterListView = GObject.registerClass({
'character-selected': { param_types: [ GObject.TYPE_STRING ] }
},
}, class CharacterListView extends Gtk.Stack {
- _init(params) {
- const filtered = Params.filter(params, {
- fontFilter: null,
- });
- params = Params.fill(params, {
+ _init(fontFilter) {
+ super._init({
hexpand: true, vexpand: true,
transition_type: Gtk.StackTransitionType.CROSSFADE
});
- super._init(params);
- this._fontFilter = filtered.fontFilter;
- this._characterList = new CharacterListWidget({
- hexpand: true,
- vexpand: true,
- fontDescription: this._fontFilter.fontDescription
- });
+ this._fontFilter = fontFilter;
+ this._characterList = new CharacterListWidget(this._fontFilter.fontDescription, NUM_ROWS);
this._characterList.connect('character-selected', (w, c) => this.emit('character-selected', c));
let scroll = new Gtk.ScrolledWindow({
hscrollbar_policy: Gtk.PolicyType.NEVER,
@@ -629,29 +611,19 @@ var RecentCharacterListView = GObject.registerClass({
'character-selected': { param_types: [ GObject.TYPE_STRING ] },
},
}, class RecentCharacterListView extends Adw.Bin {
- _init(params) {
- const filtered = Params.filter(params, {
- category: null,
- fontFilter: null
- });
- params = Params.fill(params, {
+ _init(category, fontFilter) {
+ super._init({
hexpand: true, vexpand: false
});
- super._init(params);
- this._fontFilter = filtered.fontFilter;
- this._characterList = new CharacterListWidget({
- hexpand: true,
- vexpand: true,
- fontDescription: this._fontFilter.fontDescription,
- numRows: 0
- });
+ this._fontFilter = fontFilter;
+ this._characterList = new CharacterListWidget(this._fontFilter.fontDescription, 0);
this._characterList.connect('character-selected', (w, c) => this.emit('character-selected', c));
this.set_child(this._characterList);
this._fontFilter.connect('filter-set', () => this._updateCharacterList());
- this._category = filtered.category;
+ this._category = category;
this._characters = [];
}
diff --git a/src/main.js b/src/main.js
index 77c13b6..72387ed 100644
--- a/src/main.js
+++ b/src/main.js
@@ -39,7 +39,7 @@ pkg.require({
const {GLib, Gio, GObject, Gtk, Adw} = imports.gi;
const Util = imports.util;
-const Window = imports.window;
+const { MainWindow } = imports.window;
var settings = null;
var application_id = pkg.name;
@@ -60,7 +60,7 @@ var MyApplication = GObject.registerClass({
}
_onSearch (action, parameter) {
- const window = new Window.MainWindow({ application: this });
+ const window = new MainWindow(this);
window.setSearchKeywords(parameter.get_strv());
window.show();
}
@@ -89,7 +89,7 @@ var MyApplication = GObject.registerClass({
vfunc_activate() {
if (!this._appwindow) {
- this._appwindow = new Window.MainWindow({ application: this });
+ this._appwindow = new MainWindow(this);
}
this._appwindow.present();
diff --git a/src/menu.js b/src/menu.js
index 52c94e4..1b7f64d 100644
--- a/src/menu.js
+++ b/src/menu.js
@@ -18,8 +18,6 @@
const {GLib, GObject, Gtk} = imports.gi;
-const Params = imports.params;
-
var MenuPopover = GObject.registerClass({
Template: 'resource:///org/gnome/Characters/menu.ui',
InternalChildren: ['search-entry', 'font-listbox'],
@@ -35,9 +33,8 @@ var MenuPopover = GObject.registerClass({
return row;
}
- _init(params) {
- params = Params.fill(params, {});
- super._init(params);
+ _init() {
+ super._init({});
let row = this._createFontListRow(_("None"), 'None');
this._font_listbox.append(row);
diff --git a/src/meson.build b/src/meson.build
index 3a2e9d5..ffa1c97 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -21,7 +21,6 @@ foreach script: scripts
endforeach
common_resource_data = files(
- 'params.js',
'util.js'
)
diff --git a/src/org.gnome.Characters.BackgroundService.src.gresource.xml
b/src/org.gnome.Characters.BackgroundService.src.gresource.xml
index c9fd00d..1541df5 100644
--- a/src/org.gnome.Characters.BackgroundService.src.gresource.xml
+++ b/src/org.gnome.Characters.BackgroundService.src.gresource.xml
@@ -3,7 +3,6 @@
<gresource prefix="/org/gnome/Characters/BackgroundService/js">
<file>service.js</file>
<file>searchProvider.js</file>
- <file>params.js</file>
<file>util.js</file>
</gresource>
</gresources>
diff --git a/src/org.gnome.Characters.src.gresource.xml b/src/org.gnome.Characters.src.gresource.xml
index 1d29d30..b89c48f 100644
--- a/src/org.gnome.Characters.src.gresource.xml
+++ b/src/org.gnome.Characters.src.gresource.xml
@@ -3,7 +3,6 @@
<gresource prefix="/org/gnome/Characters/js">
<file>main.js</file>
<file>menu.js</file>
- <file>params.js</file>
<file>util.js</file>
<file>window.js</file>
<file>categoryList.js</file>
diff --git a/src/util.js b/src/util.js
index 922b61f..e78b7c2 100644
--- a/src/util.js
+++ b/src/util.js
@@ -27,22 +27,15 @@
const {Gc, Gdk, Gio, GObject, Gtk} = imports.gi;
const Lang = imports.lang;
-const Params = imports.params;
const System = imports.system;
function initActions(actionMap, simpleActionEntries, context) {
- simpleActionEntries.forEach(function(entry) {
- let filtered = Params.filter(entry, { activate: null,
- state_changed: null,
- context: null });
- let action = new Gio.SimpleAction(entry);
-
- let context = filtered.context || actionMap;
- if (filtered.activate)
- action.connect('activate', filtered.activate.bind(context));
- if (filtered.state_changed)
- action.connect('state-changed', filtered.state_changed.bind(context));
+ simpleActionEntries.forEach(({name, parameter_type, state, activate })=> {
+ let action = new Gio.SimpleAction({name, parameter_type: parameter_type || null, state: state ||
null});
+ context = context || actionMap;
+ if (activate)
+ action.connect('activate', activate.bind(context));
actionMap.add_action(action);
});
}
diff --git a/src/window.js b/src/window.js
index 89fa040..e2a088f 100644
--- a/src/window.js
+++ b/src/window.js
@@ -26,11 +26,10 @@
const {Adw, Gio, GLib, GObject, Gtk } = imports.gi;
-const Params = imports.params;
-const CategoryList = imports.categoryList;
-const Character = imports.characterDialog;
-const CharacterList = imports.characterList;
-const Menu = imports.menu;
+const {CategoryListView, MainCategories} = imports.categoryList;
+const {CharacterDialog} = imports.characterDialog;
+const {CharacterListView, FontFilter, RecentCharacterListView} = imports.characterList;
+const {MenuPopover} = imports.menu;
const Gettext = imports.gettext;
const Main = imports.main;
@@ -50,9 +49,8 @@ var MainWindow = GObject.registerClass({
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE, false)
},
}, class MainWindow extends Adw.ApplicationWindow {
- _init(params) {
- params = Params.fill(params, { title: GLib.get_application_name() });
- super._init(params);
+ _init(application) {
+ super._init({ application, title: GLib.get_application_name() });
this._searchActive = false;
this._searchKeywords = [];
@@ -75,7 +73,8 @@ var MainWindow = GObject.registerClass({
parameter_type: new GLib.VariantType('s') },
{ name: 'filter-font',
activate: this._filterFont,
- parameter_type: new GLib.VariantType('s') },
+ parameter_type: new GLib.VariantType('s')
+ },
{
name: 'show-primary-menu',
activate: this._togglePrimaryMenu,
@@ -97,11 +96,10 @@ var MainWindow = GObject.registerClass({
this._leaflet.navigate(Adw.NavigationDirection.BACK);
});
- this._menu_popover = new Menu.MenuPopover({});
+ this._menu_popover = new MenuPopover();
this._menu_button.set_popover(this._menu_popover);
- this._categoryListView =
- new CategoryList.CategoryListView();
+ this._categoryListView = new CategoryListView();
let scroll = new Gtk.ScrolledWindow({
hscrollbar_policy: Gtk.PolicyType.NEVER,
hexpand: false,
@@ -109,9 +107,7 @@ var MainWindow = GObject.registerClass({
scroll.set_child(this._categoryListView);
this._sidebar.append(scroll);
- this._mainView = new MainView({
- categoryListView: this._categoryListView
- });
+ this._mainView = new MainView(this._categoryListView);
this._container.append(this._mainView);
@@ -293,27 +289,24 @@ const MainView = GObject.registerClass({
this._fontFilter.setFilterFont(this._filterFontFamily);
}
- _init(params) {
- const filtered = Params.filter(params, { categoryListView: null });
- params = Params.fill(params, {
+ _init(categoryView) {
+ super._init({
hexpand: true, vexpand: true,
transition_type: Gtk.StackTransitionType.CROSSFADE
});
- super._init(params);
- this._fontFilter = new CharacterList.FontFilter({});
+ this._fontFilter = new FontFilter();
this._filterFontFamily = null;
this._characterLists = {};
this._recentCharacterLists = {};
- this._categoryListView = filtered.categoryListView;
+ this._categoryListView = categoryView;
let characterList;
- let categories = this._categoryListView.getCategoryList();
let recentBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL,
hexpand: true, vexpand: false });
- for (let i in categories) {
- let category = categories[i];
+ for (let i in MainCategories) {
+ let category = MainCategories[i];
let categoryList = this._categoryListView.getCategoryByName(category.name);
let subcategories = categoryList.getCategoryList();
for (let j in subcategories) {
@@ -362,9 +355,7 @@ const MainView = GObject.registerClass({
}
_createCharacterList(name, accessible_name) {
- const characterList = new CharacterList.CharacterListView({
- fontFilter: this._fontFilter,
- });
+ const characterList = new CharacterListView(this._fontFilter);
//characterList.get_accessible().accessible_name = accessible_name;
characterList.connect('character-selected', (widget, uc) => this._handleCharacterSelected(widget,
uc));
@@ -373,10 +364,7 @@ const MainView = GObject.registerClass({
}
_createRecentCharacterList(name, accessible_name, category) {
- const characterList = new CharacterList.RecentCharacterListView({
- fontFilter: this._fontFilter,
- category: category
- });
+ const characterList = new RecentCharacterListView(category, this._fontFilter);
//characterList.get_accessible().accessible_name = accessible_name;
characterList.connect('character-selected', (widget, uc) => this._handleCharacterSelected(widget,
uc));
@@ -431,18 +419,10 @@ const MainView = GObject.registerClass({
}
_handleCharacterSelected(widget, uc) {
- const dialog = new Character.CharacterDialog({
- character: uc,
- modal: true,
- transient_for: this.get_toplevel(),
- fontDescription: this._fontFilter.fontDescription
- });
-
- dialog.show();
+ 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('response', function(self, response_id) {
- if (response_id == Gtk.ResponseType.CLOSE)
- dialog.destroy();
- });
+ dialog.show();
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]