Refactor: Add ScrollManager instance to globalThis

Do this so that we don't have to pass the `ScrollManager` instance to
each `PrefsBoxOrderItemRow` instance. This is useful for future
refactors.
This commit is contained in:
Julian 2023-01-22 19:28:49 +01:00
parent 34ba8a58cd
commit c54e24c151
Signed by: julian
GPG Key ID: 094C2AC34192FA11
2 changed files with 8 additions and 8 deletions

View File

@ -18,7 +18,7 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
"menu-button"
]
}, class PrefsBoxOrderItemRow extends Adw.ActionRow {
constructor(params = {}, scrollManager, item) {
constructor(params = {}, item) {
super(params);
this._associateItem(item);
@ -42,7 +42,7 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
let allocation = this.get_allocation();
dragWidget.set_size_request(allocation.width, allocation.height);
let dragPrefsBoxOrderItemRow = new PrefsBoxOrderItemRow({}, null, this.item)
let dragPrefsBoxOrderItemRow = new PrefsBoxOrderItemRow({}, this.item)
dragWidget.append(dragPrefsBoxOrderItemRow);
dragWidget.drag_highlight_row(dragPrefsBoxOrderItemRow);

View File

@ -31,21 +31,21 @@ var PrefsPage = GObject.registerClass({
// Pass `this.get_first_child()` to the ScrollManager, since this
// `PrefsPage` extends an `Adw.PreferencesPage` and the first child of
// an `Adw.PreferencesPage` is the built-in `Gtk.ScrolledWindow`.
this._scrollManager = new ScrollManager.ScrollManager(this.get_first_child());
globalThis.scrollManager = new ScrollManager.ScrollManager(this.get_first_child());
let controller = new Gtk.DropControllerMotion();
controller.connect("motion", (_, x, y) => {
// If the pointer is currently in the upper ten percent of this
// widget, then scroll up.
if (y <= this.get_allocated_height() * 0.1) this._scrollManager.startScrollUp();
if (y <= this.get_allocated_height() * 0.1) scrollManager.startScrollUp();
// If the pointer is currently in the lower ten percent of this
// widget, then scroll down.
else if (y >= this.get_allocated_height() * 0.9) this._scrollManager.startScrollDown();
else if (y >= this.get_allocated_height() * 0.9) scrollManager.startScrollDown();
// Otherwise stop scrolling.
else this._scrollManager.stopScrollAll();
else scrollManager.stopScrollAll();
});
controller.connect("leave", () => {
// Stop scrolling on leave.
this._scrollManager.stopScrollAll();
scrollManager.stopScrollAll();
});
this.add_controller(controller);
@ -62,7 +62,7 @@ var PrefsPage = GObject.registerClass({
// Add the items of the given configured box order as
// GtkListBoxRows.
for (const item of boxOrder) {
const listBoxRow = new PrefsBoxOrderItemRow.PrefsBoxOrderItemRow({}, this._scrollManager, item);
const listBoxRow = new PrefsBoxOrderItemRow.PrefsBoxOrderItemRow({}, item);
gtkListBox.append(listBoxRow);
}