-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectMgrEditor.cpp
244 lines (197 loc) · 5.17 KB
/
ProjectMgrEditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include <cassert>
#include <format>
#include <iostream>
#include "Controller.hpp"
#include "ProjectMgr.hpp"
#include "ProjectMgrEditor.hpp"
namespace wayround_i2p::ccedit
{
ProjectMgrEditor_shared ProjectMgrEditor::create(
ProjectMgr_shared p_mgr,
std::string proj_name,
std::filesystem::path proj_path
)
{
auto ret = ProjectMgrEditor_shared(
new ProjectMgrEditor(
p_mgr,
proj_name,
proj_path
)
);
ret->own_ptr = ret;
return ret;
}
ProjectMgrEditor::ProjectMgrEditor(
ProjectMgr_shared p_mgr,
std::string proj_name,
std::filesystem::path proj_path
) :
destroyer(
[this]()
{
win.destroy();
destroy();
own_ptr.reset();
}
)
{
if (!p_mgr)
{
throw "p_mgr is required";
}
this->p_mgr = p_mgr;
this->controller = this->p_mgr->getController();
win.set_transient_for(this->p_mgr->getWindowRef());
win.set_destroy_with_parent(true);
this->controller->registerWindow(&win);
// TODO: use set_titlebar and put buttons to title
{
std::string wt = "adding new project - Code Editor";
if (proj_name.length() != 0)
{
wt = std::format("rename project {} - Code Editor", proj_name);
}
win.set_title(wt);
}
win.set_child(main_box);
main_box.set_vexpand(true);
main_box.set_hexpand(true);
main_box.set_orientation(Gtk::Orientation::VERTICAL);
main_box.set_spacing(5);
main_box.set_margin_top(5);
main_box.set_margin_start(5);
main_box.set_margin_end(5);
main_box.set_margin_bottom(5);
main_box.append(main_grid);
main_box.append(button_box);
proj_name_orig = proj_name;
proj_path_orig = proj_path;
main_grid.set_vexpand(true);
main_grid.set_hexpand(true);
main_grid.set_row_spacing(5);
main_grid.set_column_spacing(5);
main_grid.attach(name_label, 0, 0, 1, 1);
main_grid.attach(path_label, 0, 1, 1, 1);
main_grid.attach(project_name, 1, 0, 2, 1);
main_grid.attach(project_path, 1, 1, 1, 1);
main_grid.attach(btn_browse, 2, 1, 1, 1);
name_label.set_text("name");
path_label.set_text("path");
btn_browse.set_label("browse..");
project_name.set_text(proj_name);
project_path.set_text(proj_path.string());
project_name.set_hexpand(true);
project_path.set_hexpand(true);
btn_ok.set_label("ok");
btn_cancel.set_label("cancel");
button_box.set_spacing(5);
button_box.append(btn_ok);
button_box.append(btn_cancel);
btn_ok.signal_clicked().connect(
[this]()
{ on_ok_click(); }
);
btn_cancel.signal_clicked().connect(
[this]()
{ on_cancel_click(); }
);
btn_browse.signal_clicked().connect(
[this]()
{ on_browse_click(); }
);
win.signal_destroy().connect(
[this]()
{ on_destroy_sig(); }
);
win.signal_close_request().connect(
[this]() -> bool
{ return on_signal_close_request(); },
true
);
}
ProjectMgrEditor::~ProjectMgrEditor()
{
std::cout << "ProjectMgrEditor::~ProjectMgrEditor()" << std::endl;
}
void ProjectMgrEditor::on_destroy_sig()
{
std::cout << "ProjectMgrEditor::on_destroy_sig()" << std::endl;
destroyer.run();
}
bool ProjectMgrEditor::on_signal_close_request()
{
std::cout << "ProjectMgrEditor::on_signal_close_request()" << std::endl;
destroyer.run();
return false;
}
void ProjectMgrEditor::show()
{
win.present();
}
void ProjectMgrEditor::destroy()
{
destroyer.run();
}
void ProjectMgrEditor::on_ok_click()
{
assert(controller != NULL);
auto new_name = project_name.get_text();
auto new_path = project_path.get_text();
if (proj_name_orig == "")
{
auto err = controller->createProject(
new_name,
std::filesystem::path(new_path),
false
);
}
else
{
// todo: force ColumnView redraw
auto err = controller->editProject(
proj_name_orig,
new_name,
std::filesystem::path(new_path)
);
}
destroy();
}
void ProjectMgrEditor::on_cancel_click()
{
destroy();
}
void ProjectMgrEditor::on_browse_click()
{
select_dir_dialog = Gtk::FileDialog::create();
select_dir_dialog->set_title("select a project directory");
select_dir_dialog->select_folder(
win,
sigc::mem_fun(*this, &ProjectMgrEditor::on_browse_click_finish)
);
}
void ProjectMgrEditor::on_browse_click_finish(
std::shared_ptr<Gio::AsyncResult> res
)
{
if (res == NULL)
{
// std::cout << "res == NULL\n";
return;
}
// std::cout << "on_browse_click_finish\n";
auto result = select_dir_dialog->select_folder_finish(res);
if (result == NULL)
{
// std::cout << "result == NULL\n";
return;
}
// std::cout << format("path: {}\n", result->get_path());
// // cout << format("path: {}",result->get_path());
// std::cout.flush();
// //
//
project_path.set_text(result->get_path());
select_dir_dialog.reset();
}
} // namespace wayround_i2p::ccedit