override default handlers in prefs
Use GJS GObject overrides. Not to matter whether the signal exists.
This commit is contained in:
parent
c87003101c
commit
cb40739af7
45
prefs.js
45
prefs.js
|
|
@ -612,7 +612,7 @@ const PrefRow = new GObject.Class({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const PixelSpinButton = new GObject.Class(Object.assign({
|
const PixelSpinButton = new GObject.Class({
|
||||||
Name: `${UUID}-PixelSpinButton`,
|
Name: `${UUID}-PixelSpinButton`,
|
||||||
Extends: Gtk.SpinButton,
|
Extends: Gtk.SpinButton,
|
||||||
Properties: {
|
Properties: {
|
||||||
|
|
@ -638,22 +638,24 @@ const PixelSpinButton = new GObject.Class(Object.assign({
|
||||||
this.adjustment.set_page_increment(step * 10);
|
this.adjustment.set_page_increment(step * 10);
|
||||||
},
|
},
|
||||||
|
|
||||||
vfunc_constructed() {
|
on_output: function() {
|
||||||
this.parent();
|
this.text = _("%f px").format(Number(this.value).toFixed(2));
|
||||||
|
|
||||||
// No virtual functions with Gtk4 :/.
|
|
||||||
// Add 'px' unit.
|
|
||||||
this.connect('output', spinButton => {
|
|
||||||
this.text = _("%f px").format(Number(spinButton.value).toFixed(2));
|
|
||||||
return true;
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Prevent accidental scrolling (GTK 3).
|
||||||
|
on_scroll_event: function(event) {
|
||||||
|
if (this.has_focus) {
|
||||||
|
try {
|
||||||
|
GObject.signal_chain_from_overridden([this, event], false);
|
||||||
|
} catch(e) { }
|
||||||
|
|
||||||
|
return Gdk.EVENT_STOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Gdk.EVENT_PROPAGATE;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}, IS_GTK3 ? {
|
|
||||||
// Prevent accidental scrolling.
|
|
||||||
vfunc_scroll_event: function(event) {
|
|
||||||
return this.has_focus ? this.parent(event) : Gdk.EVENT_PROPAGATE;
|
|
||||||
}
|
|
||||||
} : {}));
|
|
||||||
|
|
||||||
// A color button that can be easily bound with a color string setting.
|
// A color button that can be easily bound with a color string setting.
|
||||||
const ColorStringButton = new GObject.Class({
|
const ColorStringButton = new GObject.Class({
|
||||||
|
|
@ -676,20 +678,15 @@ const ColorStringButton = new GObject.Class({
|
||||||
this.set_rgba(newRgba);
|
this.set_rgba(newRgba);
|
||||||
},
|
},
|
||||||
|
|
||||||
vfunc_constructed() {
|
on_color_set: function() {
|
||||||
this.parent();
|
|
||||||
|
|
||||||
// No virtual functions with Gtk4 :/.
|
|
||||||
// Do nothing if the new color is equivalent to the old color (e.g. "black" and "rgb(0,0,0)").
|
|
||||||
this.connect('color-set', colorButton => {
|
|
||||||
let oldRgba = new Gdk.RGBA();
|
let oldRgba = new Gdk.RGBA();
|
||||||
oldRgba.parse(colorButton.color_string);
|
oldRgba.parse(this.color_string);
|
||||||
|
|
||||||
|
// Do nothing if the new color is equivalent to the old color (e.g. "black" and "rgb(0,0,0)").
|
||||||
if (!this.rgba.equal(oldRgba)) {
|
if (!this.rgba.equal(oldRgba)) {
|
||||||
this._color_string = colorButton.rgba.to_string();
|
this._color_string = this.rgba.to_string();
|
||||||
this.notify('color-string');
|
this.notify('color-string');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue