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  void set_show_none(bool v);
16  void set_show_path(bool v);
17  void add_context_menu_item(const std::string &label, sigc::slot1<void, UUID> cb);
18  virtual void search() = 0;
19  virtual ObjectType get_type() const
20  {
21  return ObjectType::INVALID;
22  };
23  void go_to(const UUID &uu);
24  void clear_search();
25 
26  enum class PoolItemSource { LOCAL, INCLUDED, OVERRIDING };
27 
28 protected:
29  void construct();
30  class Pool *pool = nullptr;
31  UUID pool_uuid;
32  bool show_none = false;
33  bool show_path = false;
34  Gtk::TreeViewColumn *path_column = nullptr;
35 
36 
37  Gtk::TreeView *treeview = nullptr;
38 
39  Gtk::TreeViewColumn *append_column(const std::string &name, const Gtk::TreeModelColumnBase &column,
40  Pango::EllipsizeMode ellipsize = Pango::ELLIPSIZE_NONE);
41  Gtk::TreeViewColumn *append_column_with_item_source_cr(const std::string &name,
42  const Gtk::TreeModelColumnBase &column,
43  Pango::EllipsizeMode ellipsize = Pango::ELLIPSIZE_NONE);
44  class CellRendererColorBox *create_pool_item_source_cr(Gtk::TreeViewColumn *tvc);
45 
46  Gtk::Entry *create_search_entry(const std::string &label);
47  void add_search_widget(const std::string &label, Gtk::Widget &w);
48 
49 
50  virtual Glib::RefPtr<Gtk::ListStore> create_list_store() = 0;
51  virtual void create_columns() = 0;
52  virtual void add_sort_controller_columns() = 0;
53  virtual UUID uuid_from_row(const Gtk::TreeModel::Row &row) = 0;
54 
55  Glib::RefPtr<Gtk::ListStore> store;
56  std::unique_ptr<SortController> sort_controller;
57 
58  void row_activated(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *column);
59  void selection_changed();
60 
61  void select_uuid(const UUID &uu);
62  void scroll_to_selection();
63 
64  Gtk::Menu context_menu;
65  std::set<Gtk::Entry *> search_entries;
66 
67  PoolItemSource pool_item_source_from_db(const UUID &uu, bool overridden);
68 
69  void install_pool_item_source_tooltip();
70  virtual PoolItemSource pool_item_source_from_row(const Gtk::TreeModel::Row &row);
71 
72 private:
73  Gtk::Grid *grid = nullptr;
74  int grid_top = 0;
75 };
76 } // namespace horizon
Definition: selection_provider.hpp:6
Definition: cell_renderer_color_box.hpp:6
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: pool_browser.hpp:11
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:19
Definition: block.cpp:9