mirror of
https://gitlab.gnome.org/julianschacher/top-bar-organizer.git
synced 2025-10-27 15:19:09 +00:00
Refactor: Use private fields instead of pref. with _, where suitable
This commit is contained in:
parent
cedb54ed64
commit
58a078c15c
@ -27,13 +27,17 @@ var BoxOrderManager = GObject.registerClass({
|
|||||||
"appIndicatorReady": {}
|
"appIndicatorReady": {}
|
||||||
}
|
}
|
||||||
}, class BoxOrderManager extends GObject.Object {
|
}, class BoxOrderManager extends GObject.Object {
|
||||||
|
#appIndicatorReadyHandlerIdMap;
|
||||||
|
#appIndicatorItemApplicationRoleMap;
|
||||||
|
#settings;
|
||||||
|
|
||||||
constructor(params = {}) {
|
constructor(params = {}) {
|
||||||
super(params);
|
super(params);
|
||||||
|
|
||||||
this._appIndicatorReadyHandlerIdMap = new Map();
|
this.#appIndicatorReadyHandlerIdMap = new Map();
|
||||||
this._appIndicatorItemApplicationRoleMap = new Map();
|
this.#appIndicatorItemApplicationRoleMap = new Map();
|
||||||
|
|
||||||
this._settings = ExtensionUtils.getSettings();
|
this.#settings = ExtensionUtils.getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,13 +58,13 @@ var BoxOrderManager = GObject.registerClass({
|
|||||||
const appIndicator = indicatorContainer.get_child()._indicator;
|
const appIndicator = indicatorContainer.get_child()._indicator;
|
||||||
let application = appIndicator.id;
|
let application = appIndicator.id;
|
||||||
|
|
||||||
if (!application && this._appIndicatorReadyHandlerIdMap) {
|
if (!application && this.#appIndicatorReadyHandlerIdMap) {
|
||||||
const handlerId = appIndicator.connect("ready", () => {
|
const handlerId = appIndicator.connect("ready", () => {
|
||||||
this.emit("appIndicatorReady");
|
this.emit("appIndicatorReady");
|
||||||
appIndicator.disconnect(handlerId);
|
appIndicator.disconnect(handlerId);
|
||||||
this._appIndicatorReadyHandlerIdMap.delete(handlerId);
|
this.#appIndicatorReadyHandlerIdMap.delete(handlerId);
|
||||||
});
|
});
|
||||||
this._appIndicatorReadyHandlerIdMap.set(handlerId, appIndicator);
|
this.#appIndicatorReadyHandlerIdMap.set(handlerId, appIndicator);
|
||||||
throw new Error("Application can't be determined.");
|
throw new Error("Application can't be determined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +75,7 @@ var BoxOrderManager = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Associate the role with the application.
|
// Associate the role with the application.
|
||||||
let roles = this._appIndicatorItemApplicationRoleMap.get(application);
|
let roles = this.#appIndicatorItemApplicationRoleMap.get(application);
|
||||||
if (roles) {
|
if (roles) {
|
||||||
// If the application already has an array of associated roles, just
|
// If the application already has an array of associated roles, just
|
||||||
// add the role to it, if needed.
|
// add the role to it, if needed.
|
||||||
@ -80,7 +84,7 @@ var BoxOrderManager = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise create a new array.
|
// Otherwise create a new array.
|
||||||
this._appIndicatorItemApplicationRoleMap.set(application, [role]);
|
this.#appIndicatorItemApplicationRoleMap.set(application, [role]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the placeholder.
|
// Return the placeholder.
|
||||||
@ -111,7 +115,7 @@ var BoxOrderManager = GObject.registerClass({
|
|||||||
const application = role.replace("appindicator-kstatusnotifieritem-", "");
|
const application = role.replace("appindicator-kstatusnotifieritem-", "");
|
||||||
|
|
||||||
// Then get the actual roles associated with this application.
|
// Then get the actual roles associated with this application.
|
||||||
let actualRoles = this._appIndicatorItemApplicationRoleMap.get(application);
|
let actualRoles = this.#appIndicatorItemApplicationRoleMap.get(application);
|
||||||
|
|
||||||
// If there are no actual roles, continue.
|
// If there are no actual roles, continue.
|
||||||
if (!actualRoles) {
|
if (!actualRoles) {
|
||||||
@ -131,12 +135,12 @@ var BoxOrderManager = GObject.registerClass({
|
|||||||
* sure all signals are disconnected.
|
* sure all signals are disconnected.
|
||||||
*/
|
*/
|
||||||
disconnectSignals() {
|
disconnectSignals() {
|
||||||
for (const [handlerId, appIndicator] of this._appIndicatorReadyHandlerIdMap) {
|
for (const [handlerId, appIndicator] of this.#appIndicatorReadyHandlerIdMap) {
|
||||||
if (handlerId && appIndicator) {
|
if (handlerId && appIndicator) {
|
||||||
appIndicator.disconnect(handlerId);
|
appIndicator.disconnect(handlerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._appIndicatorReadyHandlerIdMap = null;
|
this.#appIndicatorReadyHandlerIdMap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,7 +157,7 @@ var BoxOrderManager = GObject.registerClass({
|
|||||||
*/
|
*/
|
||||||
createValidBoxOrder(box) {
|
createValidBoxOrder(box) {
|
||||||
// Get a resolved box order.
|
// Get a resolved box order.
|
||||||
let boxOrder = this.#resolveAppIndicatorPlaceholders(this._settings.get_strv(`${box}-box-order`));
|
let boxOrder = this.#resolveAppIndicatorPlaceholders(this.#settings.get_strv(`${box}-box-order`));
|
||||||
|
|
||||||
// ToDo: simplify.
|
// ToDo: simplify.
|
||||||
// Get the indicator containers (of the items) currently present in the
|
// Get the indicator containers (of the items) currently present in the
|
||||||
@ -191,9 +195,9 @@ var BoxOrderManager = GObject.registerClass({
|
|||||||
saveNewTopBarItems() {
|
saveNewTopBarItems() {
|
||||||
// Load the configured box orders from settings.
|
// Load the configured box orders from settings.
|
||||||
const boxOrders = {
|
const boxOrders = {
|
||||||
left: this._settings.get_strv("left-box-order"),
|
left: this.#settings.get_strv("left-box-order"),
|
||||||
center: this._settings.get_strv("center-box-order"),
|
center: this.#settings.get_strv("center-box-order"),
|
||||||
right: this._settings.get_strv("right-box-order"),
|
right: this.#settings.get_strv("right-box-order"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get roles (of items) currently present in the Gnome Shell top bar and
|
// Get roles (of items) currently present in the Gnome Shell top bar and
|
||||||
@ -257,11 +261,11 @@ var BoxOrderManager = GObject.registerClass({
|
|||||||
|
|
||||||
// This function saves the given box order to settings.
|
// This function saves the given box order to settings.
|
||||||
const saveBoxOrderToSettings = (boxOrder, box) => {
|
const saveBoxOrderToSettings = (boxOrder, box) => {
|
||||||
const currentBoxOrder = this._settings.get_strv(`${box}-box-order`);
|
const currentBoxOrder = this.#settings.get_strv(`${box}-box-order`);
|
||||||
// Only save the updated box order to settings, if it is different,
|
// Only save the updated box order to settings, if it is different,
|
||||||
// to avoid loops, when listening on settings changes.
|
// to avoid loops, when listening on settings changes.
|
||||||
if (JSON.stringify(currentBoxOrder) !== JSON.stringify(boxOrder)) {
|
if (JSON.stringify(currentBoxOrder) !== JSON.stringify(boxOrder)) {
|
||||||
this._settings.set_strv(`${box}-box-order`, boxOrder);
|
this.#settings.set_strv(`${box}-box-order`, boxOrder);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,9 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
|
|||||||
"item-name-display-label"
|
"item-name-display-label"
|
||||||
]
|
]
|
||||||
}, class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
}, class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
||||||
|
#drag_starting_point_x;
|
||||||
|
#drag_starting_point_y;
|
||||||
|
|
||||||
constructor(params = {}, item) {
|
constructor(params = {}, item) {
|
||||||
super(params);
|
super(params);
|
||||||
|
|
||||||
@ -65,8 +68,8 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
|
|||||||
value.init(PrefsBoxOrderItemRow);
|
value.init(PrefsBoxOrderItemRow);
|
||||||
value.set_object(this);
|
value.set_object(this);
|
||||||
|
|
||||||
this._drag_starting_point_x = x;
|
this.#drag_starting_point_x = x;
|
||||||
this._drag_starting_point_y = y;
|
this.#drag_starting_point_y = y;
|
||||||
return Gdk.ContentProvider.new_for_value(value);
|
return Gdk.ContentProvider.new_for_value(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +84,7 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
|
|||||||
|
|
||||||
let currentDragIcon = Gtk.DragIcon.get_for_drag(drag);
|
let currentDragIcon = Gtk.DragIcon.get_for_drag(drag);
|
||||||
currentDragIcon.set_child(dragWidget);
|
currentDragIcon.set_child(dragWidget);
|
||||||
drag.set_hotspot(this._drag_starting_point_x, this._drag_starting_point_y);
|
drag.set_hotspot(this.#drag_starting_point_x, this.#drag_starting_point_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle a new drop on `this` properly.
|
// Handle a new drop on `this` properly.
|
||||||
|
|||||||
@ -23,6 +23,8 @@ var PrefsBoxOrderListBox = GObject.registerClass({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}, class PrefsBoxOrderListBox extends Gtk.ListBox {
|
}, class PrefsBoxOrderListBox extends Gtk.ListBox {
|
||||||
|
#settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} params
|
* @param {Object} params
|
||||||
*/
|
*/
|
||||||
@ -30,7 +32,7 @@ var PrefsBoxOrderListBox = GObject.registerClass({
|
|||||||
super(params);
|
super(params);
|
||||||
|
|
||||||
// Load the settings.
|
// Load the settings.
|
||||||
this._settings = ExtensionUtils.getSettings();
|
this.#settings = ExtensionUtils.getSettings();
|
||||||
|
|
||||||
// Add a placeholder widget for the case, where no GtkListBoxRows are
|
// Add a placeholder widget for the case, where no GtkListBoxRows are
|
||||||
// present.
|
// present.
|
||||||
@ -45,7 +47,7 @@ var PrefsBoxOrderListBox = GObject.registerClass({
|
|||||||
this._boxOrder = value;
|
this._boxOrder = value;
|
||||||
|
|
||||||
// Load the settings here as well, since a `CONSTRUCT_ONLY` property
|
// Load the settings here as well, since a `CONSTRUCT_ONLY` property
|
||||||
// apparently can't access `this._settings`.
|
// apparently can't access `this.#settings`.
|
||||||
const settings = ExtensionUtils.getSettings();
|
const settings = ExtensionUtils.getSettings();
|
||||||
// Get the actual box order for the given box order name from settings.
|
// Get the actual box order for the given box order name from settings.
|
||||||
const boxOrder = settings.get_strv(this._boxOrder);
|
const boxOrder = settings.get_strv(this._boxOrder);
|
||||||
@ -74,6 +76,6 @@ var PrefsBoxOrderListBox = GObject.registerClass({
|
|||||||
const item = potentialPrefsBoxOrderItemRow.item;
|
const item = potentialPrefsBoxOrderItemRow.item;
|
||||||
currentBoxOrder.push(item);
|
currentBoxOrder.push(item);
|
||||||
}
|
}
|
||||||
this._settings.set_strv(this.boxOrder, currentBoxOrder);
|
this.#settings.set_strv(this.boxOrder, currentBoxOrder);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,79 +3,83 @@
|
|||||||
const GLib = imports.gi.GLib;
|
const GLib = imports.gi.GLib;
|
||||||
|
|
||||||
var ScrollManager = class ScrollManager {
|
var ScrollManager = class ScrollManager {
|
||||||
|
#gtkScrolledWindow;
|
||||||
|
#scrollUp;
|
||||||
|
#scrollDown;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Gtk.ScrolledWindow} gtkScrolledWindow
|
* @param {Gtk.ScrolledWindow} gtkScrolledWindow
|
||||||
*/
|
*/
|
||||||
constructor(gtkScrolledWindow) {
|
constructor(gtkScrolledWindow) {
|
||||||
this._gtkScrolledWindow = gtkScrolledWindow;
|
this.#gtkScrolledWindow = gtkScrolledWindow;
|
||||||
|
|
||||||
this._scrollUp = false;
|
this.#scrollUp = false;
|
||||||
this._scrollDown = false;
|
this.#scrollDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
startScrollUp() {
|
startScrollUp() {
|
||||||
// If the scroll up is already started, don't do anything.
|
// If the scroll up is already started, don't do anything.
|
||||||
if (this._scrollUp) {
|
if (this.#scrollUp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure scroll down is stopped.
|
// Make sure scroll down is stopped.
|
||||||
this.stopScrollDown();
|
this.stopScrollDown();
|
||||||
|
|
||||||
this._scrollUp = true;
|
this.#scrollUp = true;
|
||||||
|
|
||||||
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 200, () => {
|
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 200, () => {
|
||||||
// Set the new vadjustment value to either the current value minus a
|
// Set the new vadjustment value to either the current value minus a
|
||||||
// step increment or to 0.
|
// step increment or to 0.
|
||||||
const newVAdjustementValue = Math.max(this._gtkScrolledWindow.vadjustment.get_value() - this._gtkScrolledWindow.vadjustment.get_step_increment(), 0);
|
const newVAdjustementValue = Math.max(this.#gtkScrolledWindow.vadjustment.get_value() - this.#gtkScrolledWindow.vadjustment.get_step_increment(), 0);
|
||||||
|
|
||||||
// If the new value is the old one, return and stop this interval.
|
// If the new value is the old one, return and stop this interval.
|
||||||
if (newVAdjustementValue === this._gtkScrolledWindow.vadjustment.get_value()) {
|
if (newVAdjustementValue === this.#gtkScrolledWindow.vadjustment.get_value()) {
|
||||||
this._scrollUp = false;
|
this.#scrollUp = false;
|
||||||
return this._scrollUp;
|
return this.#scrollUp;
|
||||||
}
|
}
|
||||||
// Otherwise, update the value.
|
// Otherwise, update the value.
|
||||||
this._gtkScrolledWindow.vadjustment.set_value(newVAdjustementValue);
|
this.#gtkScrolledWindow.vadjustment.set_value(newVAdjustementValue);
|
||||||
return this._scrollUp;
|
return this.#scrollUp;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
startScrollDown() {
|
startScrollDown() {
|
||||||
// If the scroll down is already started, don't do anything.
|
// If the scroll down is already started, don't do anything.
|
||||||
if (this._scrollDown) {
|
if (this.#scrollDown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure scroll up is stopped.
|
// Make sure scroll up is stopped.
|
||||||
this.stopScrollUp();
|
this.stopScrollUp();
|
||||||
|
|
||||||
this._scrollDown = true;
|
this.#scrollDown = true;
|
||||||
|
|
||||||
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 200, () => {
|
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 200, () => {
|
||||||
// Set the new vadjusment value either to the curent value plus a
|
// Set the new vadjusment value either to the curent value plus a
|
||||||
// step increment or to the upper value minus the page size.
|
// step increment or to the upper value minus the page size.
|
||||||
const newVAdjustementValue = Math.min(
|
const newVAdjustementValue = Math.min(
|
||||||
this._gtkScrolledWindow.vadjustment.get_value() + this._gtkScrolledWindow.vadjustment.get_step_increment(),
|
this.#gtkScrolledWindow.vadjustment.get_value() + this.#gtkScrolledWindow.vadjustment.get_step_increment(),
|
||||||
this._gtkScrolledWindow.vadjustment.get_upper() - this._gtkScrolledWindow.vadjustment.get_page_size()
|
this.#gtkScrolledWindow.vadjustment.get_upper() - this.#gtkScrolledWindow.vadjustment.get_page_size()
|
||||||
);
|
);
|
||||||
|
|
||||||
// If the new value is the old one, return and stop this interval.
|
// If the new value is the old one, return and stop this interval.
|
||||||
if (newVAdjustementValue === this._gtkScrolledWindow.vadjustment.get_value()) {
|
if (newVAdjustementValue === this.#gtkScrolledWindow.vadjustment.get_value()) {
|
||||||
this._scrollDown = false;
|
this.#scrollDown = false;
|
||||||
return this._scrollDown;
|
return this.#scrollDown;
|
||||||
}
|
}
|
||||||
// Otherwise, update the value.
|
// Otherwise, update the value.
|
||||||
this._gtkScrolledWindow.vadjustment.set_value(newVAdjustementValue);
|
this.#gtkScrolledWindow.vadjustment.set_value(newVAdjustementValue);
|
||||||
return this._scrollDown;
|
return this.#scrollDown;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
stopScrollUp() {
|
stopScrollUp() {
|
||||||
this._scrollUp = false;
|
this.#scrollUp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stopScrollDown() {
|
stopScrollDown() {
|
||||||
this._scrollDown = false;
|
this.#scrollDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stopScrollAll() {
|
stopScrollAll() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user