-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.cpp
313 lines (247 loc) · 9.66 KB
/
MainWindow.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#include "MainWindow.h"
#include "LogViewer.h"
#include "LogManager.h"
#include "ManagedLogger.h"
#include "FileViewerManager.h"
#include <fstream>
#ifdef USE_FUSE
#include "FuseProvider.h"
#include "FuseDialog.h"
#endif
MainWindow* globalWindowPointer;
MainWindow::MainWindow(){
set_border_width(10);
auto builder = Gtk::Builder::create_from_file("res/main.xml");
Glib::RefPtr<Gtk::CssProvider> cssProvider = Gtk::CssProvider::create();
cssProvider->load_from_path("res/fileExplorer.css");
// set up the logging backend
// don't set the TextBuffer yet, we'll do that once the LogViewer exists
LogManager* logManager = new LogManager(0x4000000,LOG_LEVEL_ERROR,nullptr);
ManagedLogger* libInfiniteLogger = new ManagedLogger("[libInfinite]",logManager);
ManagedLogger* fuseLogger = new ManagedLogger("[FUSE]",logManager);
ManagedLogger* assLogger = new ManagedLogger("[Assimp Exporter]",logManager);
assimpExporterIF.setLogger(assLogger);
currentExporter = &assimpExporterIF; // there currently isn't any other one, but hopefully (maybe) in the future
moduleManager = new ModuleDisplayManager((Logger*)libInfiniteLogger);
//Logger* logger = new ConsoleLogger;
//moduleManager->logger = (Logger*)libInfiniteLogger;
// logging backend is done
// load the known hashes file now, because why not
lut.setLogger(libInfiniteLogger);
std::ifstream hashLUT("res/hashes.txt");
if(hashLUT.is_open()){
std::string lutData;
std::stringstream stream;
stream << hashLUT.rdbuf();
//hashLUT >> lutData;
lut.loadMap(stream.str());
} else {
libInfiniteLogger->log(LOG_LEVEL_ERROR, "Failed to open hash lookup table\n");
}
assimpExporterIF.setStringIDLUT(lut);
// set up the basic FUSE stuff
#ifdef USE_FUSE
FuseProvider* fuseProvider = new FuseProvider(fuseLogger,&moduleManager->modMan);
FuseDialog* fuseDialog = new FuseDialog(fuseProvider);
#endif
set_icon_from_file("res/icons/ie-512x512.png");
accelGroup = Gtk::AccelGroup::create();
add_accel_group(accelGroup);
Gtk::Box* mainVBox = new Gtk::Box(); // this box contains two things. The menu bar, and a grid that contains everything else
this->add(*mainVBox);
mainVBox->set_property("orientation", Gtk::Orientation::ORIENTATION_VERTICAL);
mainVBox->show();
Gtk::MenuBar* menuBar = new Gtk::MenuBar();
Gtk::MenuItem* fileMenuItem = new Gtk::MenuItem("File");
mainVBox->add(*menuBar);
menuBar->add(*fileMenuItem);
menuBar->show();
fileMenuItem->show();
// change this once there are more tools!
Gtk::MenuItem* toolsMenuItem = new Gtk::MenuItem("Tools");
menuBar->add(*toolsMenuItem);
toolsMenuItem->show();
Gtk::Menu* fileMenu = new Gtk::Menu;
Gtk::MenuItem* openModuleItem = new Gtk::MenuItem("Open Module");
Gtk::MenuItem* openPathItem = new Gtk::MenuItem("Open Deploy Path");
Gtk::MenuItem* openFileItem = new Gtk::MenuItem("Load File");
Gtk::MenuItem* ExportItem = new Gtk::MenuItem("Export");
fileMenuItem->set_submenu(*fileMenu);
fileMenu->add(*openModuleItem);
fileMenu->add(*openPathItem);
fileMenu->add(*openFileItem);
fileMenu->add(*ExportItem);
fileMenuItem->show();
fileMenu->show();
// Tools menu
Gtk::Menu* toolsMenu = new Gtk::Menu();
toolsMenu->show();
toolsMenuItem->set_submenu(*toolsMenu);
ExportItem->show();
ExportItem->set_accel_path("</Ctrl + E");
ExportItem->add_accelerator("activate", accelGroup, GDK_KEY_E, Gdk::CONTROL_MASK, Gtk::AccelFlags::ACCEL_VISIBLE);
ExportItem->signal_activate().connect([this] {moduleManager->exportEntryDialog();});
BatchExtractTexItem.set_label("Batch Extract Textures");
toolsMenu->add(BatchExtractTexItem);
BatchExtractTexItem.show();
BatchExtractTexItem.signal_activate().connect([this]{
moduleManager->batchExtractTextures();
});
viewer3DItem.set_label("Open 3D Viewer");
viewer3DItem.show();
toolsMenu->add(viewer3DItem);
viewer3DItem.signal_activate().connect([this]{
viewer3D.createWindow(IEViewer::IEV_GLFW, 1920, 1080);
});
newSceneItem.set_label("new Exporter Scene");
newSceneItem.show();
toolsMenu->add(newSceneItem);
newSceneItem.signal_activate().connect([this]{
currentExporter->newScene();
});
exportSceneItem.set_label("Export current scene");
exportSceneItem.show();
toolsMenu->add(exportSceneItem);
exportSceneItem.signal_activate().connect([this]{
Gtk::FileChooserDialog* fileChooser = new Gtk::FileChooserDialog("Export",Gtk::FILE_CHOOSER_ACTION_SAVE);
fileChooser->add_button("_Cancel", Gtk::RESPONSE_CANCEL);
fileChooser->add_button("_Save", Gtk::RESPONSE_OK);
fileChooser->set_current_name("test.dae");
int response = fileChooser->run();
fileChooser->close();
if(response == Gtk::RESPONSE_OK){
assimpExporterIF.exportScene(fileChooser->get_filename());
}
});
exportSceneBitmapsItem.set_label("Export Bitmaps for current scene");
exportSceneBitmapsItem.show();
toolsMenu->add(exportSceneBitmapsItem);
exportSceneBitmapsItem.signal_activate().connect([this]{
Gtk::FileChooserDialog* fileChooser = new Gtk::FileChooserDialog("Export",Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
fileChooser->add_button("_Cancel", Gtk::RESPONSE_CANCEL);
fileChooser->add_button("_Save", Gtk::RESPONSE_OK);
fileChooser->set_current_name("/tmp/texout/");
int response = fileChooser->run();
fileChooser->close();
if(response == Gtk::RESPONSE_OK){
assimpExporterIF.exportBitmaps(fileChooser->get_filename(), &moduleManager->modMan, 0);
}
delete fileChooser;
});
openModuleItem->show();
openModuleItem->signal_activate().connect([this] {moduleManager->openModuleDialog();});
openModuleItem->add_accelerator("activate", accelGroup, GDK_KEY_O, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);
openPathItem->show();
openPathItem->signal_activate().connect([this] {moduleManager->openPathDialog();});
openFileItem->show();
openFileItem->signal_activate().connect([this]{
moduleManager->loadFileDialog();
});
#ifdef USE_FUSE
// FUSE stuff
Gtk::MenuItem* fuseMenuItem = new Gtk::MenuItem("Mount/Unmount");
toolsMenu->add(*fuseMenuItem);
fuseMenuItem->signal_activate().connect([fuseProvider,fuseDialog,fuseMenuItem]{
if(fuseProvider->mounted){
// already mounted, so this is now the unmount option
fuseProvider->unmount();
// assuming unmounting was successful
//fuseProvider->mounted = false;
//fuseMenuItem->set_label("Mount");
} else {
// not mounted, try to mount
int response = fuseDialog->run();
fuseDialog->close();
if(response != Gtk::RESPONSE_OK){
return;
}
fuseDialog->applySettings();
// I guess try to mount now!
fuseProvider->mount();
// assuming mounting was successful
//fuseProvider->mounted = true;
//fuseMenuItem->set_label("Unmount");
}
});
fuseMenuItem->show();
#endif
// the menu bar is done, now set up the grid
//Gtk::Grid* grid = new Gtk::Grid();
//grid->show();
// The Paned that contains the log output and another paned
Gtk::Paned* mainPaned = new Gtk::Paned(Gtk::ORIENTATION_VERTICAL);
mainPaned->show();
// The Paned inside the main paned, containing the file list and whatever editor/viewer is open
Gtk::Paned* contentPaned = new Gtk::Paned(Gtk::ORIENTATION_HORIZONTAL);
contentPaned->show();
mainVBox->add(*mainPaned);
mainPaned->pack1(*contentPaned, true, false);
// the FileList wants a container to be passed to it, and Gtk::Grid needs children added a bit differently
// so I'm putting a box into the grid, which then gets passed to the FileList. This is a bit inefficient, but not too bad
Gtk::Box* fileBox = new Gtk::Box();
fileBox->show();
contentPaned->pack1(*fileBox, false, false);
//grid->attach(*fileBox, 0, 0, 1, 1); // the file list should be on the left
FileList* filelist = new FileList(fileBox,builder);
/*FileEntry* entry1 = new FileEntry();
FileEntry* entry2 = new FileEntry();
FileEntry* entry3 = new FileEntry();
FileEntry* entry4 = new FileEntry();
std::vector<FileEntry*>* entries = new std::vector<FileEntry*>();
entry1->name = "1";
entry2->name = "Another File";
entry3->name = "YATE";
entry4->name = "ATFE";
entries->emplace_back(entry1);
entries->emplace_back(entry2);
entries->emplace_back(entry3);
entries->emplace_back(entry4);
filelist->updateFiles(*entries);*/
moduleManager->fileList = filelist;
moduleManager->setupCallbacks();
// file list is done, now set up the log front end
LogViewer* logViewer = new LogViewer(logManager);
mainPaned->pack2(*logViewer, false, true);
//grid->attach(*logViewer, 0, 1, 1, 1);
// set up the file viewer stuff
FileViewerManager* fileViewerManager = new FileViewerManager();
fileViewerManager->show();
moduleManager->fileViewerManager = fileViewerManager;
contentPaned->pack2(*fileViewerManager, true, false);
// Quit stuff
#ifdef USE_FUSE
// if FUSE is still active when quitting, display a warning
signal_delete_event().connect([this,fuseProvider](GdkEventAny* event) -> bool{
if(!fuseProvider->mounted){
// just exit, nothing is mounted
return false;
}
Gtk::Dialog exitDialog("Quit");
exitDialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
exitDialog.add_button("_Quit", Gtk::RESPONSE_YES);
Gtk::Label lab("You still have the modules mounted.\nQuitting will stop the fuse client and unmount them.\nAre you sure?");
lab.set_line_wrap_mode(Pango::WRAP_WORD);
lab.set_justify(Gtk::JUSTIFY_CENTER);
lab.set_margin_top(20);
lab.set_margin_left(10);
lab.set_margin_right(10);
lab.set_margin_bottom(10);
lab.show();
Gtk::Image icn("dialog-warning", Gtk::ICON_SIZE_DIALOG);
icn.set_margin_top(20);
icn.show();
((Gtk::Box*)exitDialog.get_child())->add(icn);
((Gtk::Box*)exitDialog.get_child())->add(lab);
int r = exitDialog.run();
exitDialog.close();
if(r != Gtk::RESPONSE_YES){
// don't exit
return true;
}
fuseProvider->unmount();
return false;
});
#endif
// set the global pointer to this instance
globalWindowPointer = this;
}