[polari] userList: Use automatic accessors
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] userList: Use automatic accessors
- Date: Sat, 19 Mar 2022 00:31:49 +0000 (UTC)
commit 90671ea1c6038f19aed38f8dfc6e8d63cf44b111
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Mar 19 01:02:32 2022 +0100
userList: Use automatic accessors
Commit 56efe1afcf77c1e fixed the issue of accidentally overriding
the construct-time value, but now the setters try to access template
children that are only initialized after the GObject constructor.
So solve this differently by replacing the "special" bits from the
setters with a property binding and notify handler. Besides fixing
the warning, this also allows us to rely on gjs' auto accessors.
Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/249>
src/userList.js | 51 ++++++++++++++-------------------------------------
1 file changed, 14 insertions(+), 37 deletions(-)
---
diff --git a/src/userList.js b/src/userList.js
index aa34c6c3..2b12077c 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -125,11 +125,11 @@ class UserDetails extends Gtk.Box {
static [GObject.properties] = {
'expanded': GObject.ParamSpec.boolean(
'expanded', 'expanded', 'expanded',
- GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
+ GObject.ParamFlags.READWRITE,
false),
'notifications-enabled': GObject.ParamSpec.boolean(
'notifications-enabled', 'notifications-enabled', 'notifications-enabled',
- GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
+ GObject.ParamFlags.READWRITE,
false),
};
@@ -149,24 +149,19 @@ class UserDetails extends Gtk.Box {
this._updateButtonVisibility();
this._detailsGrid.hide();
- this._notificationLabel.opacity = this.notifications_enabled ? 1. : 0.;
- }
-
- // eslint-disable-next-line camelcase
- get notifications_enabled() {
- return this._notificationsEnabled;
- }
-
- // eslint-disable-next-line camelcase
- set notifications_enabled(value) {
- if (this._notificationsEnabled === value)
- return;
- this._notificationsEnabled = value;
-
- this.notify('notifications-enabled');
-
- this._notificationLabel.opacity = value ? 1. : 0.;
+ this.bind_property_full('notifications-enabled',
+ this._notificationLabel, 'opacity',
+ GObject.BindingFlags.SYNC_CREATE,
+ (p, source) => [true, source ? 1. : 0.],
+ null);
+
+ this.connect('notify::expanded', () => {
+ if (this.expanded)
+ this._expand();
+ else
+ this._unexpand();
+ });
}
set user(user) {
@@ -203,24 +198,6 @@ class UserDetails extends Gtk.Box {
this._updateButtonVisibility();
}
- get expanded() {
- return this._expanded;
- }
-
- set expanded(v) {
- if (v === this._expanded)
- return;
-
- this._expanded = v;
-
- if (this._expanded)
- this._expand();
- else
- this._unexpand();
-
- this.notify('expanded');
- }
-
_expand() {
this._detailsGrid.visible = this._initialDetailsLoaded;
this._spinnerBox.visible = !this._initialDetailsLoaded;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]