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 IPool &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 IPool &pool;
35  UUID pool_uuid;
36  bool pools_included = false;
37  bool show_none = false;
38  bool show_path = false;
39  Gtk::TreeViewColumn *path_column = nullptr;
40 
41 
42  Gtk::TreeView *treeview = nullptr;
43  Gtk::ScrolledWindow *scrolled_window = nullptr;
44 
45  Gtk::TreeViewColumn *append_column(const std::string &name, const Gtk::TreeModelColumnBase &column,
46  Pango::EllipsizeMode ellipsize = Pango::ELLIPSIZE_NONE);
47  Gtk::TreeViewColumn *append_column_with_item_source_cr(const std::string &name,
48  const Gtk::TreeModelColumnBase &column,
49  Pango::EllipsizeMode ellipsize = Pango::ELLIPSIZE_NONE);
50  class CellRendererColorBox *create_pool_item_source_cr(Gtk::TreeViewColumn *tvc);
51  void install_column_tooltip(Gtk::TreeViewColumn &tvc, const Gtk::TreeModelColumnBase &col);
52 
53  Gtk::Entry *create_search_entry(const std::string &label);
54  class TagEntry *create_tag_entry(const std::string &label);
55  void add_search_widget(const std::string &label, Gtk::Widget &w);
56 
57 
58  virtual Glib::RefPtr<Gtk::ListStore> create_list_store() = 0;
59  virtual void create_columns() = 0;
60  virtual void add_sort_controller_columns() = 0;
61  virtual UUID uuid_from_row(const Gtk::TreeModel::Row &row) = 0;
62 
63  Glib::RefPtr<Gtk::ListStore> store;
64  std::unique_ptr<SortController> sort_controller;
65 
66  void row_activated(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *column);
67  void selection_changed();
68 
69  void select_uuid(const UUID &uu);
70  void scroll_to_selection();
71 
72  Gtk::Menu context_menu;
73  std::set<Gtk::Entry *> search_entries;
74  std::set<TagEntry *> tag_entries;
75 
76  PoolItemSource pool_item_source_from_db(const UUID &uu, bool overridden);
77 
78  void install_pool_item_source_tooltip();
79  virtual PoolItemSource pool_item_source_from_row(const Gtk::TreeModel::Row &row);
80  bool searched_once = false;
81 
82  void set_busy(bool busy);
83  void prepare_search();
84  void finish_search();
85 
86  Gtk::Box *status_box = nullptr;
87 
88 private:
89  Gtk::Grid *grid = nullptr;
90  int grid_top = 0;
91  class CellRendererColorBox *cell_renderer_item_source = nullptr;
92  Gtk::Box *busy_box = nullptr;
93  UUID selected_uuid_before_search;
94 
95  Gtk::Label *status_label = nullptr;
96 };
97 } // namespace horizon
Definition: cell_renderer_color_box.hpp:6
Definition: ipool.hpp:12
Definition: pool_browser.hpp:11
Definition: selection_provider.hpp:6
Definition: tag_entry.hpp:9
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16