mirror of
https://gitlab.gnome.org/julianschacher/top-bar-organizer.git
synced 2025-10-27 15:19:09 +00:00
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:
parent
34ba8a58cd
commit
c54e24c151
@ -18,7 +18,7 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
|
|||||||
"menu-button"
|
"menu-button"
|
||||||
]
|
]
|
||||||
}, class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
}, class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
||||||
constructor(params = {}, scrollManager, item) {
|
constructor(params = {}, item) {
|
||||||
super(params);
|
super(params);
|
||||||
|
|
||||||
this._associateItem(item);
|
this._associateItem(item);
|
||||||
@ -42,7 +42,7 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
|
|||||||
let allocation = this.get_allocation();
|
let allocation = this.get_allocation();
|
||||||
dragWidget.set_size_request(allocation.width, allocation.height);
|
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.append(dragPrefsBoxOrderItemRow);
|
||||||
dragWidget.drag_highlight_row(dragPrefsBoxOrderItemRow);
|
dragWidget.drag_highlight_row(dragPrefsBoxOrderItemRow);
|
||||||
|
|
||||||
|
|||||||
@ -31,21 +31,21 @@ var PrefsPage = GObject.registerClass({
|
|||||||
// Pass `this.get_first_child()` to the ScrollManager, since this
|
// Pass `this.get_first_child()` to the ScrollManager, since this
|
||||||
// `PrefsPage` extends an `Adw.PreferencesPage` and the first child of
|
// `PrefsPage` extends an `Adw.PreferencesPage` and the first child of
|
||||||
// an `Adw.PreferencesPage` is the built-in `Gtk.ScrolledWindow`.
|
// 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();
|
let controller = new Gtk.DropControllerMotion();
|
||||||
controller.connect("motion", (_, x, y) => {
|
controller.connect("motion", (_, x, y) => {
|
||||||
// If the pointer is currently in the upper ten percent of this
|
// If the pointer is currently in the upper ten percent of this
|
||||||
// widget, then scroll up.
|
// 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
|
// If the pointer is currently in the lower ten percent of this
|
||||||
// widget, then scroll down.
|
// 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.
|
// Otherwise stop scrolling.
|
||||||
else this._scrollManager.stopScrollAll();
|
else scrollManager.stopScrollAll();
|
||||||
});
|
});
|
||||||
controller.connect("leave", () => {
|
controller.connect("leave", () => {
|
||||||
// Stop scrolling on leave.
|
// Stop scrolling on leave.
|
||||||
this._scrollManager.stopScrollAll();
|
scrollManager.stopScrollAll();
|
||||||
});
|
});
|
||||||
this.add_controller(controller);
|
this.add_controller(controller);
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ var PrefsPage = GObject.registerClass({
|
|||||||
// Add the items of the given configured box order as
|
// Add the items of the given configured box order as
|
||||||
// GtkListBoxRows.
|
// GtkListBoxRows.
|
||||||
for (const item of boxOrder) {
|
for (const item of boxOrder) {
|
||||||
const listBoxRow = new PrefsBoxOrderItemRow.PrefsBoxOrderItemRow({}, this._scrollManager, item);
|
const listBoxRow = new PrefsBoxOrderItemRow.PrefsBoxOrderItemRow({}, item);
|
||||||
gtkListBox.append(listBoxRow);
|
gtkListBox.append(listBoxRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user