Tooth/src/Widgets/LockableToggleButton.vala

39 lines
707 B
Vala
Raw Normal View History

2021-07-23 11:41:03 +00:00
using Gtk;
// This button prevents changes to its "active" property while it's locked.
//
// This widget is intended to be used with Statuses where their properties
// can be used to drive network requests.
2022-11-13 20:57:43 +00:00
public abstract class Tooth.LockableToggleButton : ToggleButton {
2021-07-23 11:41:03 +00:00
uint _locks = 0;
public bool locked {
get { return this._locks > 0; }
}
construct {
this.toggled.connect (on_toggled);
}
protected void set_locked (bool is_locked) {
if (is_locked)
_locks++;
else
_locks--;
}
protected virtual bool can_change () {
return true;
}
protected void on_toggled () {
if (!locked && can_change()) {
commit_change ();
}
}
protected abstract void commit_change ();
}