Horizon
pool_browser.hpp
1 #pragma once
2 #include <gtkmm.h>
3 #include <memory>
4 #include <set>
5 #include "util/uuid.hpp"
6 #include "util/sort_controller.hpp"
7 #include "util/selection_provider.hpp"
8 #include "common/common.hpp"
9 
10 namespace horizon {
11 class PoolBrowser : public Gtk::Box, public SelectionProvider {
12 public:
13  PoolBrowser(class Pool *pool);
14  UUID get_selected() override;
15  bool get_any_selected();
16  void set_show_none(bool v);
17  void set_show_path(bool v);
18  void add_context_menu_item(const std::string &label, sigc::slot1<void, UUID> cb);
19  virtual void add_copy_name_context_menu_item(){};
20  virtual void search() = 0;
21  void search_once();
22  void clear_search_once();
23  virtual ObjectType get_type() const
24  {
25  return ObjectType::INVALID;
26  };
27  void go_to(const UUID &uu);
28  void clear_search();
29 
30  enum class PoolItemSource { LOCAL, INCLUDED, OVERRIDING };
31 
32 protected:
33  void construct(Gtk::Widget *search_box = nullptr);
34  class Pool *pool = nullptr;
35  UUID pool_uuid;
36  bool show_none = false;
37  bool show_path = false;
38  Gtk::TreeViewColumn *path_column = nullptr;
39 
40 
41  Gtk::TreeView *treeview = nullptr;
42 
43  Gtk::TreeViewColumn *append_column(const std::string &name, const Gtk::TreeModelColumnBase &column,
44  Pango::EllipsizeMode ellipsize = Pango::ELLIPSIZE_NONE);
45  Gtk::TreeViewColumn *append_column_with_item_source_cr(const std::string &name,
46  const Gtk::TreeModelColumnBase &column,
47  Pango::EllipsizeMode ellipsize = Pango::ELLIPSIZE_NONE);
48  class CellRendererColorBox *create_pool_item_source_cr(Gtk::TreeViewColumn *tvc);
49  void install_column_tooltip(Gtk::TreeViewColumn &tvc, const Gtk::TreeModelColumnBase &col);
50 
51  Gtk::Entry *create_search_entry(const std::string &label);
52  class TagEntry *create_tag_entry(const std::string &label);
53  void add_search_widget(const std::string &label, Gtk::Widget &w);
54 
55 
56  virtual Glib::RefPtr<Gtk::ListStore> create_list_store() = 0;
57  virtual void create_columns() = 0;
58  virtual void add_sort_controller_columns() = 0;
59  virtual UUID uuid_from_row(const Gtk::TreeModel::Row &row) = 0;
60 
61  Glib::RefPtr<Gtk::ListStore> store;
62  std::unique_ptr<SortController> sort_controller;
63 
64  void row_activated(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *column);
65  void selection_changed();
66 
67  void select_uuid(const UUID &uu);
68  void scroll_to_selection();
69 
70  Gtk::Menu context_menu;
71  std::set<Gtk::Entry *> search_entries;
72  std::set<TagEntry *> tag_entries;
73 
74  PoolItemSource pool_item_source_from_db(const UUID &uu, bool overridden);
75 
76  void install_pool_item_source_tooltip();
77  virtual PoolItemSource pool_item_source_from_row(const Gtk::TreeModel::Row &row);
78  bool searched_once = false;
79 
80  void set_busy(bool busy);
81  void prepare_search();
82  void finish_search();
83 
84  Gtk::Box *status_box = nullptr;
85 
86 private:
87  Gtk::Grid *grid = nullptr;
88  int grid_top = 0;
89  class CellRendererColorBox *cell_renderer_item_source = nullptr;
90  Gtk::Box *busy_box = nullptr;
91  UUID selected_uuid_before_search;
92 
93  Gtk::Label *status_label = nullptr;
94 };
95 } // namespace horizon
horizon::PoolBrowser
Definition: pool_browser.hpp:11
horizon::TagEntry
Definition: tag_entry.hpp:9
horizon::SelectionProvider
Definition: selection_provider.hpp:6
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
horizon::Pool
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:21
horizon::CellRendererColorBox
Definition: cell_renderer_color_box.hpp:6