entry_search.vala 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 EntrySearch : Gtk.Box
  8. {
  9. public Gtk.SearchEntry _entry;
  10. public signal void search_changed();
  11. public EntrySearch()
  12. {
  13. Object(orientation: Gtk.Orientation.HORIZONTAL);
  14. _entry = new Gtk.SearchEntry();
  15. _entry.focus_in_event.connect(on_focus_in);
  16. _entry.focus_out_event.connect(on_focus_out);
  17. _entry.search_changed.connect(() => search_changed());
  18. this.pack_start(_entry);
  19. }
  20. public string text {
  21. get { return _entry.text; }
  22. set { _entry.text = value; }
  23. }
  24. public void set_placeholder_text(string text)
  25. {
  26. _entry.set_placeholder_text(text);
  27. }
  28. public bool on_focus_in(Gdk.EventFocus ev)
  29. {
  30. var app = (LevelEditorApplication)GLib.Application.get_default();
  31. app.entry_any_focus_in(_entry);
  32. return Gdk.EVENT_PROPAGATE;
  33. }
  34. public bool on_focus_out(Gdk.EventFocus ef)
  35. {
  36. var app = (LevelEditorApplication)GLib.Application.get_default();
  37. app.entry_any_focus_out(_entry);
  38. return Gdk.EVENT_PROPAGATE;
  39. }
  40. }
  41. } /* namespace Crown */