input_bool.vala 952 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2012-2026 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. namespace Crown
  6. {
  7. public class InputBool : InputField
  8. {
  9. public Gtk.CheckButton _check;
  10. public override void set_inconsistent(bool inconsistent)
  11. {
  12. _check.set_inconsistent(inconsistent);
  13. }
  14. public override bool is_inconsistent()
  15. {
  16. return _check.get_inconsistent();
  17. }
  18. public override GLib.Value union_value()
  19. {
  20. return this.value;
  21. }
  22. public override void set_union_value(GLib.Value v)
  23. {
  24. this.value = (bool)v;
  25. }
  26. public bool value
  27. {
  28. get
  29. {
  30. return _check.active;
  31. }
  32. set
  33. {
  34. _check.active = value;
  35. }
  36. }
  37. public InputBool()
  38. {
  39. _check = new Gtk.CheckButton();
  40. _check.toggled.connect(on_value_changed);
  41. this.add(_check);
  42. }
  43. public void on_value_changed()
  44. {
  45. if (_check.get_inconsistent()) {
  46. _check.set_inconsistent(false);
  47. this.value = true;
  48. }
  49. value_changed(this);
  50. }
  51. }
  52. } /* namespace Crown */