src/file.cpp

Mon, 15 Jul 2013 22:25:00 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 15 Jul 2013 22:25:00 +0300
changeset 385
b136331072a0
parent 383
10e60ae9ed58
child 388
7ff483614aa1
permissions
-rw-r--r--

Shortcuts are now properly loaded again

183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
4 *
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
9 *
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
14 *
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
199
10dd5909a50e Made Qt file includes more proper (<QLineEdit> instead of <qlineedit.h>), merged setContentsDialog.cpp into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 198
diff changeset
19 #include <QMessageBox>
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
20 #include <QFileDialog>
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QDir>
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
22 #include <QApplication>
202
a027f6fc6141 Un-templated CheckBoxGroup, moved it and RadioButton into widgets.cpp/widgets.h; removed license text tab because I think LICENSE is enough.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 200
diff changeset
23
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
24 #include <stdlib.h>
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "common.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "config.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "file.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "misc.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "gui.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "history.h"
200
5583af82087e Merged new part and LDraw path dialogs into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 199
diff changeset
31 #include "dialogs.h"
198
f246725199dc Split some stuff into separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 192
diff changeset
32 #include "gldraw.h"
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
34 cfg (str, io_ldpath, "");
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
35 cfg (str, io_recentfiles, "");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
37 static bool g_loadingMainFile = false;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
38 static const int g_MaxRecentFiles = 5;
320
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
39 static bool g_aborted = false;
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
40
383
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
41 DEFINE_PROPERTY (QListWidgetItem*, LDOpenFile, listItem, setListItem)
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
42
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
44 namespace LDPaths {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 static str pathError;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
47 struct {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 str LDConfigPath;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 str partsPath, primsPath;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 } pathInfo;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
52 void initPaths() {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
53 if (!tryConfigure (io_ldpath)) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 LDrawPathDialog dlg (false);
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
56 if (!dlg.exec ())
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
57 exit (0);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
59 io_ldpath = dlg.filename();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
63 bool tryConfigure (str path) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 QDir dir;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
66 if (!dir.cd (path)) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 pathError = "Directory does not exist.";
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
71 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
72 QStringList contents = dir.entryList (mustHave);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
74 if (contents.size() != mustHave.size()) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 pathError = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/.";
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
79 pathInfo.partsPath = fmt ("%1" DIRSLASH "parts", path);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
80 pathInfo.LDConfigPath = fmt ("%1" DIRSLASH "LDConfig.ldr", path);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
81 pathInfo.primsPath = fmt ("%1" DIRSLASH "p", path);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 // Accessors
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
87 str getError() { return pathError; }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
88 str ldconfig() { return pathInfo.LDConfigPath; }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
89 str prims() { return pathInfo.primsPath; }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
90 str parts() { return pathInfo.partsPath; }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
94 LDOpenFile::LDOpenFile() {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
95 setImplicit (true);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
96 setSavePos (-1);
383
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
97 setListItem (null);
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
98 m_history.setFile (this);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
102 LDOpenFile::~LDOpenFile() {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 // Clear everything from the model
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
104 for (LDObject* obj : m_objs)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 delete obj;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 // Clear the cache as well
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
108 for (LDObject* obj : m_cache)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 delete obj;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
113 LDOpenFile* findLoadedFile (str name) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
114 for (LDOpenFile* file : g_loadedFiles)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
115 if (file->name () == name)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 return file;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 return null;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
122 str dirname (str path) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
123 long lastpos = path.lastIndexOf (DIRSLASH);
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
124
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
125 if (lastpos > 0)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
126 return path.left (lastpos);
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
127
236
b58d35dc5d52 Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents: 235
diff changeset
128 #ifndef _WIN32
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
129 if (path[0] == DIRSLASH_CHAR)
236
b58d35dc5d52 Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents: 235
diff changeset
130 return DIRSLASH;
b58d35dc5d52 Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents: 235
diff changeset
131 #endif // _WIN32
b58d35dc5d52 Fixed basename (for real...) and ported ::first and ::last from my previous string class implementation, std::string::find_last_of doesn't do what I thought it did
Santeri Piippo <crimsondusk64@gmail.com>
parents: 235
diff changeset
132
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
133 return "";
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
134 }
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
135
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 // =============================================================================
234
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
137 str basename (str path) {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
138 long lastpos = path.lastIndexOf (DIRSLASH);
234
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
139
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
140 if (lastpos != -1)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
141 return path.mid (lastpos + 1);
234
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
142
235
bb0a7bcca7eb fix basename
Santeri Piippo <crimsondusk64@gmail.com>
parents: 234
diff changeset
143 return path;
234
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
144 }
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
145
79b120b0aa51 added basename since windows doesn't have it
Santeri Piippo <crimsondusk64@gmail.com>
parents: 232
diff changeset
146 // =============================================================================
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
147 File* openLDrawFile (str relpath, bool subdirs) {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
148 print ("%1: Try to open %2\n", __func__, relpath);
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
149 File* f = new File;
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
150 str fullPath;
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
151
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
152 // LDraw models use Windows-style path separators. If we're not on Windows,
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
153 // replace the path separator now before opening any files.
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 #ifndef WIN32
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
155 relpath.replace ("\\", "/");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 #endif // WIN32
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
158 if (currentFile()) {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
159 // First, try find the file in the current model's file path. We want a file
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
160 // in the immediate vicinity of the current model to override stock LDraw stuff.
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
161 str partpath = fmt ("%1" DIRSLASH "%2", dirname (currentFile()->name ()), relpath);
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
162
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
163 if (f->open (partpath, File::Read)) {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
164 return f;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
165 }
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
166 }
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
167
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
168 if (f->open (relpath, File::Read))
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
169 return f;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
171 // Try with just the LDraw path first
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
172 fullPath = fmt ("%1" DIRSLASH "%2", io_ldpath, relpath);
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
173
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
174 if (f->open (fullPath, File::Read))
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
175 return f;
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
176
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
177 if (subdirs) {
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
178 // Look in sub-directories: parts and p
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
179 for (auto subdir : initlist<const str> ({ "parts", "p" })) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
180 fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", io_ldpath, subdir, relpath);
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
181
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
182 if (f->open (fullPath, File::Read))
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
183 return f;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
184 }
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
185 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
187 // Did not find the file.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
188 print ("could not find %1\n", relpath);
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
189 delete f;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 return null;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 // =============================================================================
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
196 void FileLoader::start() {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
197 setDone (false);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
198 setProgress (0);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
199 setAborted (false);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
201 if (concurrent()) {
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
202 g_aborted = false;
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
203
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
204 // Show a progress dialog if we're loading the main file here and move
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
205 // the actual work to a separate thread as this can be a rather intensive
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
206 // operation and if we don't respond quickly enough, the program can be
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
207 // deemed inresponsive.. which is a bad thing.
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
208 dlg = new OpenProgressDialog (g_win);
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
209 dlg->setNumLines (lines().size());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
210 dlg->setModal (true);
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
211 dlg->show();
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
212
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
213 // Connect the loader in so we can show updates
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
214 connect (this, SIGNAL (workDone()), dlg, SLOT (accept()));
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
215 connect (dlg, SIGNAL (rejected()), this, SLOT (abort()));
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
216 } else
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
217 dlg = null;
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
218
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
219 work (0);
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
220 }
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
221
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
222 void FileLoader::work (ulong i) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
223 if (aborted()) {
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
224 // We were flagged for abortion, so abort.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
225 for (LDObject* obj : m_objs)
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
226 delete obj;
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
227
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
228 m_objs.clear();
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
229 setDone (true);
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
230 return;
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
231 }
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
232
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
233 ulong max = i + 300;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
234
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
235 for (; i < max && i < lines().size(); ++i) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
236 str line = lines() [i];
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
237
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 // Trim the trailing newline
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 276
diff changeset
239 qchar c;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
241 while ((c = line[line.length () - 1]) == '\n' || c == '\r')
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
242 line.chop (1);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
243
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
244 LDObject* obj = parseLine (line);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 // Check for parse errors and warn about tthem
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
247 if (obj->getType () == LDObject::Error) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
248 log ("Couldn't parse line #%1: %2", m_progress + 1, static_cast<LDErrorObject*> (obj)->reason);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
250 if (m_warningsPointer) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
251 (*m_warningsPointer) ++;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
252 }
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
253 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254
252
3f9067022d74 Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents: 251
diff changeset
255 m_objs << obj;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
256 setProgress (i);
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
257
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
258 if (concurrent())
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
259 dlg->updateProgress (i);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
262 if (i >= lines().size() - 1) {
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
263 emit workDone();
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
264 setDone (true);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
265 }
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
266
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
267 if (!done()) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
268 if (concurrent())
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
269 QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection, Q_ARG (ulong, i + 1));
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
270 else
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
271 work (i + 1);
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
272 }
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
273 }
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
274
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
275 void FileLoader::abort() {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
276 setAborted (true);
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
277
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
278 if (concurrent())
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
279 g_aborted = true;
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
280 }
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
281
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
282 // =============================================================================
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
284 // =============================================================================
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
285 vector<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok) {
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
286 vector<str> lines;
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
287 vector<LDObject*> objs;
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
288
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
289 if (numWarnings)
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
290 *numWarnings = 0;
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
291
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
292 // Calculate the amount of lines
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
293 for (str line : *f)
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
294 lines << line;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
295
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
296 f->rewind();
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
297
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
298 FileLoader* loader = new FileLoader;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
299 loader->setWarningsPointer (numWarnings);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
300 loader->setLines (lines);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
301 loader->setConcurrent (g_loadingMainFile);
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
302 loader->start();
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
303
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
304 while (loader->done() == false)
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
305 qApp->processEvents();
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
306
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
307 // If we wanted the success value, supply that now
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
308 if (ok)
371
e8ef9fb4721b make aborting work in the new setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 370
diff changeset
309 *ok = !loader->aborted();
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
310
370
843b3dbbd849 make file loading be done properly as just a QObject rather than multi-threaded..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 363
diff changeset
311 objs = loader->objs();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 return objs;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
315 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
318 LDOpenFile* openDATFile (str path, bool search) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 // Convert the file name to lowercase since some parts contain uppercase
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320 // file names. I'll assume here that the library will always use lowercase
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 // file names for the actual parts..
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
322 File* f;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
323
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
324 if (search)
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
325 f = openLDrawFile (path.toLower (), true);
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
326 else {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
327 f = new File (path, File::Read);
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
328
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
329 if (!*f) {
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
330 delete f;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
331 return null;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
332 }
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
333 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
335 if (!f)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 return null;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
338 LDOpenFile* oldLoad = currentFile();
232
4e44c92e21dd Renamed the OpenFile class to LDOpenFile as MinGW doesn't appear to like the former name
Santeri Piippo <crimsondusk64@gmail.com>
parents: 227
diff changeset
339 LDOpenFile* load = new LDOpenFile;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
340 load->setName (path);
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
341
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
342 if (g_loadingMainFile) {
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
343 setCurrentFile (load);
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
344 g_win->R()->setFile (load);
253
0737c217a54d Added ability to have multiple GLRenderers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 252
diff changeset
345 }
213
a4113545242c Look for LDraw files in the part's directory first
Santeri Piippo <crimsondusk64@gmail.com>
parents: 211
diff changeset
346
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 ulong numWarnings;
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
348 bool ok;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
349 vector<LDObject*> objs = loadFileContents (f, &numWarnings, &ok);
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
350
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
351 if (!ok) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
352 if (g_loadingMainFile) {
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
353 setCurrentFile (oldLoad);
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
354 g_win->R()->setFile (oldLoad);
320
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
355 }
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
356
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
357 return null;
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
358 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
360 for (LDObject* obj : objs)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
361 load->addObject (obj);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
363 delete f;
252
3f9067022d74 Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents: 251
diff changeset
364 g_loadedFiles << load;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
366 if (g_loadingMainFile)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
367 log (QObject::tr ("File %1 parsed successfully (%2 warnings)."), path, numWarnings);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 return load;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
375 bool LDOpenFile::safeToClose() {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
376 typedef QMessageBox msgbox;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
377 setlocale (LC_ALL, "C");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 // If we have unsaved changes, warn and give the option of saving.
383
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
380 if (hasUnsavedChanges()) {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
381 str message = fmt ("There are unsaved changes to %1. Should it be saved?",
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
382 (name().length() > 0) ? name() : "<anonymous>");
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
383
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
384 int button = msgbox::question (g_win, "Unsaved Changes", message,
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
385 (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
386
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
387 switch (button) {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
388 case msgbox::Yes:
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
389 // If we don't have a file path yet, we have to ask the user for one.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
390 if (name().length() == 0) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
391 str newpath = QFileDialog::getSaveFileName (g_win, "Save As",
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
392 currentFile()->name(), "LDraw files (*.dat *.ldr)");
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
393
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
394 if (newpath.length() == 0)
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
395 return false;
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
396
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
397 setName (newpath);
225
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
398 }
a78179b182e1 Prompt for unsaved changes in the current file if it's anonymous
Santeri Piippo <crimsondusk64@gmail.com>
parents: 224
diff changeset
399
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
400 if (!save ()) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
401 message = fmt (QObject::tr ("Failed to save %1: %2\nDo you still want to close?"),
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
402 name(), strerror (errno));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
404 if (msgbox::critical (g_win, "Save Failure", message,
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
405 (msgbox::Yes | msgbox::No), msgbox::No) == msgbox::No)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406 {
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
408 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410 break;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
412 case msgbox::Cancel:
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 default:
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416 break;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
419
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
421 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
422
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
424 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
426 void closeAll() {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
427 if (!g_loadedFiles.size())
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430 // Remove all loaded files and the objects they contain
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
431 for (LDOpenFile* file : g_loadedFiles)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 delete file;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 // Clear the array
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 g_loadedFiles.clear();
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
436 setCurrentFile (null);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
438 g_win->R()->setFile (null);
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
439 g_win->fullRefresh();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
440 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
441
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
445 void newFile () {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
446 closeAll();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
448 // Create a new anonymous file and set it to our current
232
4e44c92e21dd Renamed the OpenFile class to LDOpenFile as MinGW doesn't appear to like the former name
Santeri Piippo <crimsondusk64@gmail.com>
parents: 227
diff changeset
449 LDOpenFile* f = new LDOpenFile;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
450 f->setName ("");
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
451 f->setImplicit (false);
252
3f9067022d74 Take the aforementioned operator<< into use
Santeri Piippo <crimsondusk64@gmail.com>
parents: 251
diff changeset
452 g_loadedFiles << f;
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
453 setCurrentFile (f);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
455 g_win->R()->setFile (f);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
456 g_win->fullRefresh();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
457 g_win->updateTitle();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
458 f->history().updateActions();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
460
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
462 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
464 void addRecentFile (str path) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
465 QStringList rfiles = io_recentfiles.value.split ('@');
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
466 int idx = rfiles.indexOf (path);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468 // If this file already is in the list, pop it out.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
469 if (idx != -1) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
470 if (rfiles.size () == 1)
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
471 return; // only recent file - abort and do nothing
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
472
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
473 // Pop it out.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
474 rfiles.removeAt (idx);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
475 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
476
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
477 // If there's too many recent files, drop one out.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
478 while (rfiles.size() > (g_MaxRecentFiles - 1))
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
479 rfiles.removeAt (0);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
480
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
481 // Add the file
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
482 rfiles << path;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
483
273
0a9141118630 Restructed recent files handling, the list shouldn't screw the hell up anymore.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 272
diff changeset
484 // Rebuild the config string
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
485 io_recentfiles = rfiles.join ("@");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
487 config::save();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
488 g_win->updateRecentFilesMenu();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
492 // -----------------------------------------------------------------------------
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
493 // Open an LDraw file and set it as the main model
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
495 void openMainFile (str path) {
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
496 g_loadingMainFile = true;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
497 closeAll();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
498
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
499 LDOpenFile* file = openDATFile (path, false);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
500
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
501 if (!file) {
288
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
502 // Loading failed, thus drop down to a new file since we
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
503 // closed everything prior.
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
504 newFile ();
2980d7fd948e Converted from C-style fopen to the new File class
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
505
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
506 if (!g_aborted) {
320
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
507 // Tell the user loading failed.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
508 setlocale (LC_ALL, "C");
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
509 critical (fmt (QObject::tr ("Failed to open %1: %2"), path, strerror (errno)));
320
737e466dae72 rework aborting.. I'm still not sure I'm doing it right, though.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 319
diff changeset
510 }
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
511
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
512 g_loadingMainFile = false;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
513 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
515
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
516 file->setImplicit (false);
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
517 setCurrentFile (file);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
519 // Rebuild the object tree view now.
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
520 g_win->fullRefresh();
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
521 g_win->updateTitle();
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
522 g_win->R()->setFile (file);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
523 g_win->R()->resetAngles();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
524
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525 // Add it to the recent files list.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
526 addRecentFile (path);
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
527 g_loadingMainFile = false;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
528 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
529
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
530 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
532 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
533 bool LDOpenFile::save (str savepath) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
534 if (!savepath.length())
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
535 savepath = name();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
536
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
537 File f (savepath, File::Write);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
538
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
539 if (!f)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540 return false;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
542 // If the second object in the list holds the file name, update that now.
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
543 // Only do this if the file is explicitly open. If it's saved into a directory
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
544 // called "s" or "48", prepend that into the name.
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
545 LDCommentObject* fpathComment = null;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
546 LDObject* first = object (1);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
547
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
548 if (!implicit() && first != null && first->getType() == LDObject::Comment) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
549 fpathComment = static_cast<LDCommentObject*> (first);
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
550
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
551 if (fpathComment->text.left (6) == "Name: ") {
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
552 str newname;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
553 str dir = basename (dirname (savepath));
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
554
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
555 if (dir == "s" || dir == "48")
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
556 newname = dir + "\\";
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
557
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
558 newname += basename (savepath);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
559 fpathComment->text = fmt ("Name: %1", newname);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
560 g_win->buildObjList();
227
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
561 }
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
562 }
e13cd69b16dd Update the part's Name: field when saving
Santeri Piippo <crimsondusk64@gmail.com>
parents: 226
diff changeset
563
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
564 // File is open, now save the model to it. Note that LDraw requires files to
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
565 // have DOS line endings, so we terminate the lines with \r\n.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
566 for (LDObject* obj : objs())
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
567 f.write (obj->raw () + "\r\n");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
568
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
569 // File is saved, now clean up.
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
570 f.close();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
571
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
572 // We have successfully saved, update the save position now.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
573 setSavePos (history().pos());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
574 setName (savepath);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
575
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
576 g_win->updateTitle();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
577 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
580 // =============================================================================
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
581 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
582 // =============================================================================
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
583 #define CHECK_TOKEN_COUNT(N) \
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
584 if (tokens.size() != N) \
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
585 return new LDErrorObject (line, "Bad amount of tokens");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
586
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
587 #define CHECK_TOKEN_NUMBERS( MIN, MAX ) \
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
588 for (ushort i = MIN; i <= MAX; ++i) \
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 if (!isNumber (tokens[i])) \
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
590 return new LDErrorObject (line, fmt ("Token #%1 was `%2`, expected a number", \
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
591 (i + 1), tokens[i]));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
593 static vertex parseVertex (QStringList& s, const ushort n) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
594 vertex v;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
595
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
596 for (const Axis ax : g_Axes)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
597 v[ax] = atof (s[n + ax]);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
598
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
599 return v;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
600 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
601
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
602 // =============================================================================
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
603 // -----------------------------------------------------------------------------
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
604 // This is the LDraw code parser function. It takes in a string containing LDraw
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
605 // code and returns the object parsed from it. parseLine never returns null,
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
606 // the object will be LDError if it could not be parsed properly.
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
607 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
608 LDObject* parseLine (str line) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
609 QStringList tokens = line.split (" ", str::SkipEmptyParts);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
610
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
611 if (tokens.size() <= 0) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
612 // Line was empty, or only consisted of whitespace
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
613 return new LDEmptyObject;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
614 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
615
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
616 if (tokens[0].length() != 1 || tokens[0][0].isDigit() == false)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
617 return new LDErrorObject (line, "Illogical line code");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
618
373
91bea18bd77a Fixed compilation under windows/qt5
Santeri Piippo <crimsondusk64@gmail.com>
parents: 371
diff changeset
619 int num = tokens[0][0].digitValue();
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
620
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
621 switch (num) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
622 case 0: {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
623 // Comment
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
624 str comm = line.mid (line.indexOf ("0") + 1);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
625
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
626 // Remove any leading whitespace
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
627 while (comm[0] == ' ')
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
628 comm.remove (0, 1);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
629
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
630 // Handle BFC statements
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
631 if (tokens.size() > 2 && tokens[1] == "BFC") {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
632 for (short i = 0; i < LDBFCObject::NumStatements; ++i)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
633 if (comm == fmt ("BFC %1", LDBFCObject::statements [i]))
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
634 return new LDBFCObject ( (LDBFCObject::Type) i);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
636 // MLCAD is notorious for stuffing these statements in parts it
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
637 // creates. The above block only handles valid statements, so we
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
638 // need to handle MLCAD-style invertnext separately.
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
639 if (comm == "BFC CERTIFY INVERTNEXT")
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
640 return new LDBFCObject (LDBFCObject::InvertNext);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
641 }
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
642
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
643 if (tokens.size() > 2 && tokens[1] == "!LDFORGE") {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
644 // Handle LDForge-specific types, they're embedded into comments too
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
645 if (tokens[2] == "VERTEX") {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
646 // Vertex (0 !LDFORGE VERTEX)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
647 CHECK_TOKEN_COUNT (7)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
648 CHECK_TOKEN_NUMBERS (3, 6)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
649
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
650 LDVertexObject* obj = new LDVertexObject;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
651 obj->setColor (tokens[3].toLong ());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
652
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
653 for (const Axis ax : g_Axes)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
654 obj->pos[ax] = tokens[4 + ax].toDouble (); // 4 - 6
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
655
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
656 return obj;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
657 } elif (tokens[2] == "OVERLAY") {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
658 CHECK_TOKEN_COUNT (9);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
659 CHECK_TOKEN_NUMBERS (5, 8)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
660
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
661 LDOverlayObject* obj = new LDOverlayObject;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
662 obj->setFilename (tokens[3]);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
663 obj->setCamera (tokens[4].toLong());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
664 obj->setX (tokens[5].toLong());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
665 obj->setY (tokens[6].toLong());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
666 obj->setWidth (tokens[7].toLong());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
667 obj->setHeight (tokens[8].toLong());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
668 return obj;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
669 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
670 }
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
671
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
672 // Just a regular comment:
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
673 LDCommentObject* obj = new LDCommentObject;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
674 obj->text = comm;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
675 return obj;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
676 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
677
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
678 case 1: {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
679 // Subfile
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
680 CHECK_TOKEN_COUNT (15)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
681 CHECK_TOKEN_NUMBERS (1, 13)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
682
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
683 // Try open the file. Disable g_loadingMainFile temporarily since we're
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
684 // not loading the main file now, but the subfile in question.
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
685 bool tmp = g_loadingMainFile;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
686 g_loadingMainFile = false;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
687 LDOpenFile* load = getFile (tokens[14]);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
688 g_loadingMainFile = tmp;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
689
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
690 // If we cannot open the file, mark it an error
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
691 if (!load)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
692 return new LDErrorObject (line, "Could not open referred file");
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
693
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
694 LDSubfileObject* obj = new LDSubfileObject;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
695 obj->setColor (tokens[1].toLong());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
696 obj->setPosition (parseVertex (tokens, 2)); // 2 - 4
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
697
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
698 matrix transform;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
699
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
700 for (short i = 0; i < 9; ++i)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
701 transform[i] = tokens[i + 5].toDouble(); // 5 - 13
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
702
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
703 obj->setTransform (transform);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
704 obj->setFileInfo (load);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
705 return obj;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
706 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
707
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
708 case 2: {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
709 CHECK_TOKEN_COUNT (8)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
710 CHECK_TOKEN_NUMBERS (1, 7)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
711
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
712 // Line
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
713 LDLineObject* obj = new LDLineObject;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
714 obj->setColor (tokens[1].toLong());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
715
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
716 for (short i = 0; i < 2; ++i)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
717 obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 7
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
718
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
719 return obj;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
720 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
721
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
722 case 3: {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
723 CHECK_TOKEN_COUNT (11)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
724 CHECK_TOKEN_NUMBERS (1, 10)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
725
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
726 // Triangle
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
727 LDTriangleObject* obj = new LDTriangleObject;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
728 obj->setColor (tokens[1].toLong());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
729
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
730 for (short i = 0; i < 3; ++i)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
731 obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 10
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
732
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
733 return obj;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
734 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
735
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
736 case 4:
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
737 case 5: {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
738 CHECK_TOKEN_COUNT (14)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
739 CHECK_TOKEN_NUMBERS (1, 13)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
740
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
741 // Quadrilateral / Conditional line
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
742 LDObject* obj = (num == 4) ? ( (LDObject*) new LDQuadObject) : ( (LDObject*) new LDCondLineObject);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
743 obj->setColor (tokens[1].toLong());
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
744
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
745 for (short i = 0; i < 4; ++i)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
746 obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 13
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
747
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
748 return obj;
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
749 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
750
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
751 default: // Strange line we couldn't parse
377
271d1da66b7e Appended 'Object' to the names of all LDObject derivatives so even though the LD prefix isn't reserved for just LDObjects anymore, these classes remain distinct
Santeri Piippo <crimsondusk64@gmail.com>
parents: 373
diff changeset
752 return new LDErrorObject (line, "Unknown line code number");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
753 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
754 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
755
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
756 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
757 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
758 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
759 LDOpenFile* getFile (str filename) {
254
434c9844e45d Further work on image generation experiment
Santeri Piippo <crimsondusk64@gmail.com>
parents: 253
diff changeset
760 // Try find the file in the list of loaded files
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
761 LDOpenFile* load = findLoadedFile (filename);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
762
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
763 // If it's not loaded, try open it
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
764 if (!load)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
765 load = openDATFile (filename, true);
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
766
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
767 return load;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
768 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
769
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
770 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
771 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
772 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
773 void reloadAllSubfiles () {
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
774 if (!currentFile())
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
775 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
776
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
777 g_loadedFiles.clear();
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
778 g_loadedFiles << currentFile();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
779
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
780 // Go through all objects in the current file and reload the subfiles
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
781 for (LDObject* obj : currentFile()->objs()) {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
782 if (obj->getType() == LDObject::Subfile) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
783 LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
784 LDOpenFile* fileInfo = getFile (ref->fileInfo()->name());
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
785
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
786 if (fileInfo)
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
787 ref->setFileInfo (fileInfo);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
788 else
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
789 ref->replace (new LDErrorObject (ref->raw(), "Could not open referred file"));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
790 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
791
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
792 // Reparse gibberish files. It could be that they are invalid because
248
4431371f3ffe Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 236
diff changeset
793 // of loading errors. Circumstances may be different now.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
794 if (obj->getType() == LDObject::Error)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
795 obj->replace (parseLine (static_cast<LDErrorObject*> (obj)->contents));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
796 }
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
797
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
798 // Close all files left unused
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
799 LDOpenFile::closeUnused();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
800 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
801
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
802 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
803 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
804 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
805 ulong LDOpenFile::addObject (LDObject* obj) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
806 PROP_NAME (history).add (new AddHistory (PROP_NAME (objs).size(), obj));
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
807 PROP_NAME (objs) << obj;
271
d5ec224c1879 Laid down the foundations of the new history system
Santeri Piippo <crimsondusk64@gmail.com>
parents: 270
diff changeset
808
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
809 if (obj->getType() == LDObject::Vertex)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
810 PROP_NAME (vertices) << obj;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
811
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
812 return numObjs() - 1;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
813 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
814
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
815 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
816 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
817 // =============================================================================
232
4e44c92e21dd Renamed the OpenFile class to LDOpenFile as MinGW doesn't appear to like the former name
Santeri Piippo <crimsondusk64@gmail.com>
parents: 227
diff changeset
818 void LDOpenFile::insertObj (const ulong pos, LDObject* obj) {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
819 m_history.add (new AddHistory (pos, obj));
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
820 m_objs.insert (pos, obj);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
821 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
822
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
823 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
824 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
825 // =============================================================================
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
826 void LDOpenFile::forgetObject (LDObject* obj) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
827 ulong idx = obj->getIndex (this);
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
828 m_history.add (new DelHistory (idx, obj));
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
829 m_objs.erase (idx);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
830 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
831
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
832 // =============================================================================
226
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
833 bool safeToCloseAll () {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
834 for (LDOpenFile* f : g_loadedFiles)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
835 if (!f->safeToClose())
226
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
836 return false;
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
837
3dd9e63698cd Prompt for unsaved changes before loading or creating a new file
Santeri Piippo <crimsondusk64@gmail.com>
parents: 225
diff changeset
838 return true;
250
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
839 }
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
840
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
841 // =============================================================================
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
842 void LDOpenFile::setObject (ulong idx, LDObject* obj) {
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
843 assert (idx < numObjs());
276
a21e49914264 Made history work with most things
Santeri Piippo <crimsondusk64@gmail.com>
parents: 274
diff changeset
844
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
845 // Mark this change to history
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
846 str oldcode = object (idx)->raw ();
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
847 str newcode = obj->raw();
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
848 m_history << new EditHistory (idx, oldcode, newcode);
276
a21e49914264 Made history work with most things
Santeri Piippo <crimsondusk64@gmail.com>
parents: 274
diff changeset
849
250
6e80f038e8df Make LDOpenFile's members PROPERTIES
Santeri Piippo <crimsondusk64@gmail.com>
parents: 249
diff changeset
850 m_objs[idx] = obj;
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
851 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
852
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
853 static vector<LDOpenFile*> getFilesUsed (LDOpenFile* node) {
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
854 vector<LDOpenFile*> filesUsed;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
855
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
856 for (LDObject* obj : *node) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
857 if (obj->getType() != LDObject::Subfile)
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
858 continue;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
859
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
860 LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj);
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
861 filesUsed << ref->fileInfo();
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
862 filesUsed << getFilesUsed (ref->fileInfo());
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
863 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
864
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
865 return filesUsed;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
866 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
867
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
868 // =============================================================================
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
869 // Find out which files are unused and close them.
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
870 void LDOpenFile::closeUnused () {
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
871 vector<LDOpenFile*> filesUsed = getFilesUsed (currentFile());
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
872
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
873 // Anything that's explicitly opened must not be closed
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
874 for (LDOpenFile* file : g_loadedFiles)
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
875 if (!file->implicit())
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
876 filesUsed << file;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
877
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
878 // Remove duplicated entries
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
879 filesUsed.makeUnique();
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
880
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
881 // Close all open files that aren't in filesUsed
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
882 for (LDOpenFile* file : g_loadedFiles) {
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
883 bool isused = false;
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
884
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
885 for (LDOpenFile* usedFile : filesUsed) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
886 if (file == usedFile) {
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
887 isused = true;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
888 break;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
889 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
890 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
891
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
892 if (!isused)
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
893 delete file;
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
894 }
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
895
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
896 g_loadedFiles.clear();
269
2d71227f35cb Refactor LDSubfile
Santeri Piippo <crimsondusk64@gmail.com>
parents: 268
diff changeset
897 g_loadedFiles << filesUsed;
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
898 }
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
899
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
900 LDObject* LDOpenFile::object (ulong pos) const {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
901 if (m_objs.size() <= pos)
309
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
902 return null;
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
903
11ec6aa1f1fb restyled file.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
904 return m_objs[pos];
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
905 }
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
906
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
907 LDObject* LDOpenFile::obj (ulong pos) const {
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
908 return object (pos);
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
909 }
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
910
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
911 ulong LDOpenFile::numObjs() const {
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
912 return m_objs.size();
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
913 }
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
914
378
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
915 LDOpenFile& LDOpenFile::operator<< (vector<LDObject*> objs) {
bc3f40dcfa9e more formatting
Santeri Piippo <crimsondusk64@gmail.com>
parents: 377
diff changeset
916 for (LDObject* obj : objs)
310
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
917 m_objs << obj;
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
918
c62edce5668c Begin converting the radial type into a primitive generator
Santeri Piippo <crimsondusk64@gmail.com>
parents: 309
diff changeset
919 return *this;
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
920 }
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
921
383
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
922 bool LDOpenFile::hasUnsavedChanges() const {
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
923 return !implicit() && history().pos() != savePos();
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
924 }
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
925
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
926 // =============================================================================
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
927 class {
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
928 public:
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
929 LDOpenFile* currentFile() {
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
930 return m_curfile;
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
931 }
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
932
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
933 void setCurrentFile (LDOpenFile* f) {
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
934 m_curfile = f;
383
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
935
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
936 if (g_win)
10e60ae9ed58 File list is populated now..
Santeri Piippo <crimsondusk64@gmail.com>
parents: 381
diff changeset
937 g_win->updateFileList();
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
938 }
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
939
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
940 private:
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
941 LDOpenFile* m_curfile;
385
b136331072a0 Shortcuts are now properly loaded again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 383
diff changeset
942 } g_currentFileShell;
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
943
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
944 LDOpenFile* currentFile() {
385
b136331072a0 Shortcuts are now properly loaded again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 383
diff changeset
945 return g_currentFileShell.currentFile();
379
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
946 }
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
947
f5f3faac60cd Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 378
diff changeset
948 void setCurrentFile (LDOpenFile* f) {
385
b136331072a0 Shortcuts are now properly loaded again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 383
diff changeset
949 g_currentFileShell.setCurrentFile (f);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
950 }

mercurial