Horizon
Loading...
Searching...
No Matches
pool-prj-mgr-app_win.hpp
1#pragma once
2#include <gtkmm.h>
3#include <memory>
4#include "util/uuid.hpp"
5#include <zmq.hpp>
6#include "util/win32_undef.hpp"
7#include "nlohmann/json_fwd.hpp"
8#include "util/editor_process.hpp"
9#include "util/window_state_store.hpp"
10#include "pool-prj-mgr-process.hpp"
11#include "prj-mgr/prj-mgr_views.hpp"
12#include "pool-mgr/view_create_pool.hpp"
13#include "common/common.hpp"
14#include <thread>
15
16namespace horizon {
17using json = nlohmann::json;
18
19enum class PoolUpdateStatus;
20enum class CheckSchemaUpdateResult;
21
22class PoolProjectManagerAppWindow : public Gtk::ApplicationWindow {
25
26public:
27 PoolProjectManagerAppWindow(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &refBuilder,
30
32
33 void open_file_view(const Glib::RefPtr<Gio::File> &file);
34 void prepare_close();
35 bool close_pool_or_project();
36 bool really_close_pool_or_project();
37 void wait_for_all_processes();
38 std::string get_filename() const;
39
40 enum class SpawnFlags { NONE = 0, READ_ONLY = (1 << 0), TEMP = (1 << 1) };
41
42 struct SpawnResult {
44 bool spawned; // if false, an existing window got raised
45 };
46
47 SpawnResult spawn(PoolProjectManagerProcess::Type type, const std::vector<std::string> &args,
48 SpawnFlags flags = SpawnFlags::NONE);
49
50 std::map<UUID, PoolProjectManagerProcess *> get_processes();
51
52 class Pool *pool = nullptr;
53 class PoolParametric *pool_parametric = nullptr;
54
55 typedef sigc::signal<void, std::string, int, bool> type_signal_process_exited;
56 type_signal_process_exited signal_process_exited()
57 {
58 return s_signal_process_exited;
59 }
60
61 typedef sigc::signal<void, std::string> type_signal_process_saved;
62 type_signal_process_saved signal_process_saved()
63 {
64 return s_signal_process_saved;
65 }
66
68 public:
69 bool can_close = true;
70 std::string reason;
71 std::vector<UUID> procs_need_save;
72 };
73
74 ClosePolicy get_close_policy();
75
76 std::string get_proc_filename(const UUID &uu);
77 void process_save(const UUID &uu);
78 void process_close(const UUID &uu);
79 bool cleanup_pool_cache(Gtk::Window *parent);
80
81 enum class ViewMode { OPEN, POOL, PROJECT, CREATE_PROJECT, CREATE_POOL };
82 ViewMode get_view_mode() const;
83
84 UUID get_pool_uuid() const;
85 void pool_notebook_go_to(ObjectType type, const UUID &uu);
86 void pool_notebook_show_settings_tab();
87 void open_pool(const std::string &pool_json);
88 void update_pool_cache_status_now();
89 const std::string &get_project_title() const;
90
91 void pool_update(const std::vector<std::string> &filenames = {});
92
93 PoolProjectManagerApplication &app;
94
95private:
96 Glib::RefPtr<Gtk::Builder> builder;
97 Gtk::Stack *stack = nullptr;
98 Gtk::Button *button_open = nullptr;
99 Gtk::Button *button_close = nullptr;
100 Gtk::Button *button_update = nullptr;
101 Gtk::Button *button_cancel = nullptr;
102 Gtk::MenuButton *button_new = nullptr;
103 Gtk::Button *button_create = nullptr;
104 Gtk::Button *button_save = nullptr;
105 Gtk::MenuButton *hamburger_menu_button = nullptr;
106
107 Gtk::HeaderBar *header = nullptr;
108 Gtk::ListBox *recent_pools_listbox = nullptr;
109 Gtk::ListBox *recent_projects_listbox = nullptr;
110 Gtk::SearchEntry *recent_pools_search_entry = nullptr;
111 Gtk::SearchEntry *recent_projects_search_entry = nullptr;
112 Gtk::Stack *recent_pools_placeholder_stack = nullptr;
113 Gtk::Stack *recent_projects_placeholder_stack = nullptr;
114 std::vector<Gtk::ListBox *> recent_listboxes;
115 Gtk::Box *pool_box = nullptr;
116 class PoolNotebook *pool_notebook = nullptr;
117
118 Gtk::Label *pool_update_status_label = nullptr;
119 Gtk::Revealer *pool_update_status_rev = nullptr;
120 Gtk::Button *pool_update_status_close_button = nullptr;
121 Gtk::ProgressBar *pool_update_progress = nullptr;
122 sigc::connection pool_update_conn;
123
124 Gtk::InfoBar *info_bar = nullptr;
125 Gtk::Label *info_bar_label = nullptr;
126 Gtk::Button *show_output_button = nullptr;
127
128 Gtk::InfoBar *info_bar_pool_not_added = nullptr;
129
130 Gtk::MenuItem *menu_new_pool = nullptr;
131 Gtk::MenuItem *menu_new_project = nullptr;
132
133 class OutputWindow *output_window = nullptr;
134
135 Gtk::InfoBar *info_bar_pool_doc = nullptr;
136
137 Gtk::InfoBar *info_bar_version = nullptr;
138 Gtk::Label *version_label = nullptr;
139
140 Gtk::InfoBar *info_bar_gitignore = nullptr;
141
142 Gtk::InfoBar *info_bar_installation_uuid_mismatch = nullptr;
143
144 std::unique_ptr<class Project> project;
145 std::string project_filename;
146 bool project_needs_save = false;
147 void save_project();
148 class PartBrowserWindow *part_browser_window = nullptr;
149 void cleanup();
150#if GTK_CHECK_VERSION(3, 24, 0)
151 static gboolean part_browser_key_pressed(GtkEventControllerKey *controller, guint keyval, guint keycode,
152 GdkModifierType state, gpointer user_data);
153#endif
154
155 ViewMode view_mode = ViewMode::OPEN;
156 void set_view_mode(ViewMode mode);
157
158 void update_recent_items();
159
160 void handle_open();
161 void handle_close();
162 void handle_recent();
163 void handle_update();
164 void handle_new_project();
165 void handle_new_pool();
166 void handle_create();
167 void handle_cancel();
168 void handle_save();
169 json handle_req(const json &j);
170
171 bool on_delete_event(GdkEventAny *ev) override;
172
173 WindowStateStore state_store;
174
175 std::map<UUID, PoolProjectManagerProcess> processes;
176 std::map<int, bool> pids_need_save;
177 PoolProjectManagerProcess *find_process(const std::string &filename);
178 PoolProjectManagerProcess *find_top_schematic_process();
179 PoolProjectManagerProcess *find_board_process();
180
181 const UUID uuid_pool_manager = "1b9eecbe-7408-4b99-9aec-170d3658004a";
182 const UUID uuid_project_manager = "144a4ad6-4c7c-4136-9920-f58f954c678e";
183
184 type_signal_process_exited s_signal_process_exited;
185 type_signal_process_saved s_signal_process_saved;
186
187 PoolProjectManagerViewCreateProject view_create_project;
188 PoolProjectManagerViewProject view_project;
189 PoolProjectManagerViewCreatePool view_create_pool;
190
191 void handle_place_part(const UUID &uu);
192 void handle_assign_part(const UUID &uu);
193
194 zmq::socket_t sock_mgr;
195 std::string sock_mgr_ep;
196
197 bool check_pools();
198 bool check_schema_update(const std::string &base_path);
199
200 void check_pool_update(const std::string &base_path);
201 void check_mtimes(const std::string &base_path);
202 std::thread check_mtimes_thread;
203 Glib::Dispatcher check_mtimes_dispatcher;
204
205 bool check_autosave(PoolProjectManagerProcess::Type type, const std::vector<std::string> &filenames);
206
207 void set_version_info(const std::string &s);
208 bool project_read_only = false;
209
210 bool migrate_project(const std::string &path);
211 std::string project_title;
212
213 Glib::Dispatcher pool_update_dispatcher;
214 bool in_pool_update_handler = false;
215 std::mutex pool_update_status_queue_mutex;
216 std::list<std::tuple<PoolUpdateStatus, std::string, std::string>> pool_update_status_queue;
217 std::list<std::tuple<PoolUpdateStatus, std::string, std::string>> pool_update_error_queue;
218 bool pool_updating = false;
219 void pool_updated(bool success);
220 std::string pool_update_last_file;
221 std::string pool_update_last_info;
222 unsigned int pool_update_n_files = 0;
223 unsigned int pool_update_n_files_last = 0;
224 std::vector<std::string> pool_update_filenames;
225
226 void pool_update_thread();
227 void handle_pool_update_progress();
228 void set_pool_updating(bool v, bool success);
229 void set_pool_update_status_text(const std::string &txt);
230 void set_pool_update_progress(float progress);
231
232 std::string get_pool_base_path() const;
233
234 std::string get_gitignore_filename() const;
235
236 void update_recent_search(Gtk::SearchEntry &entry, Gtk::ListBox &lb);
237 void update_recent_searches();
238 void clear_recent_searches();
239
240 void update_recent_placeholder(Gtk::Stack &stack, Gtk::ListBox &lb);
241
242public:
243 zmq::context_t &zctx;
244};
245}; // namespace horizon
Definition pool_parametric.hpp:10
Definition pool-prj-mgr-app_win.hpp:67
Definition pool-prj-mgr-app_win.hpp:22
Definition pool-prj-mgr-app.hpp:16
Definition pool-prj-mgr-process.hpp:6
Definition prj-mgr_views.hpp:9
Definition prj-mgr_views.hpp:35
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition pool.hpp:22
This class encapsulates a UUID and allows it to be uses as a value type.
Definition uuid.hpp:16
a class to store JSON values
Definition json.hpp:177
basic_json<> json
default JSON class
Definition json_fwd.hpp:62
Definition pool-prj-mgr-app_win.hpp:42