Wed, 08 Jan 2014 13:57:10 +0200
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
600
209e3f1f7b2c
- updated copyright year. Best wishes for 2014!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
590
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Santeri Piippo |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QMessageBox> |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QFileDialog> |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QDir> |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <QApplication> |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "main.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "config.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "document.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include "misc.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #include "gui.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | #include "history.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #include "dialogs.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "gldraw.h" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include "moc_document.cpp" |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | cfg (String, io_ldpath, ""); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | cfg (List, io_recentfiles, {}); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | extern_cfg (String, net_downloadpath); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | extern_cfg (Bool, gl_logostuds); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | static bool g_loadingMainFile = false; |
576
d26334c6b7fd
- bumped max amount of recent files from 5 to 10
Santeri Piippo <crimsondusk64@gmail.com>
parents:
575
diff
changeset
|
39 | static const int g_maxRecentFiles = 10; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | static bool g_aborted = false; |
583
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
41 | static LDDocumentPointer g_logoedStud = null; |
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
42 | static LDDocumentPointer g_logoedStud2 = null; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | LDDocument* LDDocument::m_curdoc = null; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
588
720f7480c6b7
- now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
583
diff
changeset
|
46 | const QStringList g_specialSubdirectories ({ "s", "48", "8" }); |
720f7480c6b7
- now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
583
diff
changeset
|
47 | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | namespace LDPaths |
603 | 51 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
52 | static QString pathError; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | struct |
603 | 55 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
56 | QString LDConfigPath; |
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
57 | QString partsPath, primsPath; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | } pathInfo; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | void initPaths() |
603 | 61 | { |
62 | if (!tryConfigure (io_ldpath)) | |
63 | { | |
64 | LDrawPathDialog dlg (false); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | if (!dlg.exec()) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | exit (0); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | io_ldpath = dlg.filename(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
73 | bool tryConfigure (QString path) |
603 | 74 | { |
75 | QDir dir; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | if (!dir.cd (path)) |
603 | 78 | { |
79 | pathError = "Directory does not exist."; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | return false; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | QStringList mustHave = { "LDConfig.ldr", "parts", "p" }; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | QStringList contents = dir.entryList (mustHave); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | if (contents.size() != mustHave.size()) |
603 | 87 | { |
88 | pathError = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/."; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | return false; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | pathInfo.partsPath = fmt ("%1" DIRSLASH "parts", path); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | pathInfo.LDConfigPath = fmt ("%1" DIRSLASH "LDConfig.ldr", path); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | pathInfo.primsPath = fmt ("%1" DIRSLASH "p", path); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | return true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | // Accessors |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
100 | QString getError() |
603 | 101 | { |
102 | return pathError; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
105 | QString ldconfig() |
603 | 106 | { |
107 | return pathInfo.LDConfigPath; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
110 | QString prims() |
603 | 111 | { |
112 | return pathInfo.primsPath; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
115 | QString parts() |
603 | 116 | { |
117 | return pathInfo.partsPath; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | LDDocument::LDDocument() |
603 | 124 | { |
125 | setImplicit (true); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | setSavePosition (-1); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | setListItem (null); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | setHistory (new History); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | m_History->setFile (this); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | LDDocument::~LDDocument() |
603 | 135 | { |
136 | // Remove this file from the list of files. This MUST be done FIRST, otherwise | |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
137 | // a ton of other functions will think this file is still valid when it is not! |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
138 | g_loadedFiles.removeOne (this); |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
139 | |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
140 | m_History->setIgnoring (true); |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
141 | |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
142 | // Clear everything from the model |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | for (LDObject* obj : getObjects()) |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
144 | obj->deleteSelf(); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | // Clear the cache as well |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | for (LDObject* obj : getCache()) |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
148 | obj->deleteSelf(); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | delete m_History; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | // If we just closed the current file, we need to set the current |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | // file as something else. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | if (this == getCurrentDocument()) |
603 | 155 | { |
156 | bool found = false; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | // Try find an explicitly loaded file - if we can't find one, |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | // we need to create a new file to switch to. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | for (LDDocument* file : g_loadedFiles) |
603 | 161 | { |
162 | if (!file->isImplicit()) | |
163 | { | |
164 | LDDocument::setCurrent (file); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | found = true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | break; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | if (!found) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | newFile(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
174 | if (this == g_logoedStud) |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
175 | g_logoedStud = null; |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
176 | elif (this == g_logoedStud2) |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
177 | g_logoedStud2 = null; |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
178 | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | g_win->updateDocumentList(); |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
180 | log ("Closed %1", getName()); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
185 | LDDocument* findDocument (QString name) |
603 | 186 | { |
187 | for (LDDocument * file : g_loadedFiles) | |
577
17a88e2470c9
removed some debug code
Santeri Piippo <crimsondusk64@gmail.com>
parents:
576
diff
changeset
|
188 | if (!file->getName().isEmpty() && file->getName() == name) |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | return file; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | return null; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
196 | QString dirname (QString path) |
603 | 197 | { |
198 | long lastpos = path.lastIndexOf (DIRSLASH); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | if (lastpos > 0) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | return path.left (lastpos); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | #ifndef _WIN32 |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | if (path[0] == DIRSLASH_CHAR) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | return DIRSLASH; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | #endif // _WIN32 |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | return ""; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
213 | QString basename (QString path) |
603 | 214 | { |
215 | long lastpos = path.lastIndexOf (DIRSLASH); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | if (lastpos != -1) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | return path.mid (lastpos + 1); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | return path; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
225 | File* openLDrawFile (QString relpath, bool subdirs) |
603 | 226 | { |
227 | log ("Opening %1...\n", relpath); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | File* f = new File; |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
229 | QString fullPath; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | // LDraw models use Windows-style path separators. If we're not on Windows, |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | // replace the path separator now before opening any files. Qt expects |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | // forward-slashes as directory separators. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | #ifndef WIN32 |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | relpath.replace ("\\", "/"); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | #endif // WIN32 |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | |
579
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
238 | // Try find it relative to other currently open documents. We want a file |
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
239 | // in the immediate vicinity of a current model to override stock LDraw stuff. |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
240 | QString reltop = basename (dirname (relpath)); |
579
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
241 | for (LDDocument* doc : g_loadedFiles) |
603 | 242 | { |
243 | if (doc->getFullPath().isEmpty()) | |
579
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
244 | continue; |
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
245 | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
246 | QString partpath = fmt ("%1/%2", dirname (doc->getFullPath()), relpath); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | if (f->open (partpath, File::Read)) |
603 | 249 | { |
250 | // ensure we don't mix subfiles and 48-primitives with non-subfiles and non-48 | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
251 | QString proptop = basename (dirname (partpath)); |
581
c57ddcaf1b58
- fixed configuration dialog not accepting values past 99.99 for grid angles
Santeri Piippo <crimsondusk64@gmail.com>
parents:
579
diff
changeset
|
252 | |
588
720f7480c6b7
- now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
583
diff
changeset
|
253 | bool bogus = false; |
720f7480c6b7
- now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
583
diff
changeset
|
254 | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
255 | for (QString s : g_specialSubdirectories) |
603 | 256 | { |
257 | if ((proptop == s && reltop != s) || (reltop == s && proptop != s)) | |
258 | { | |
259 | bogus = true; | |
588
720f7480c6b7
- now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
583
diff
changeset
|
260 | break; |
720f7480c6b7
- now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
583
diff
changeset
|
261 | } |
720f7480c6b7
- now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
583
diff
changeset
|
262 | } |
581
c57ddcaf1b58
- fixed configuration dialog not accepting values past 99.99 for grid angles
Santeri Piippo <crimsondusk64@gmail.com>
parents:
579
diff
changeset
|
263 | |
c57ddcaf1b58
- fixed configuration dialog not accepting values past 99.99 for grid angles
Santeri Piippo <crimsondusk64@gmail.com>
parents:
579
diff
changeset
|
264 | if (!bogus) |
c57ddcaf1b58
- fixed configuration dialog not accepting values past 99.99 for grid angles
Santeri Piippo <crimsondusk64@gmail.com>
parents:
579
diff
changeset
|
265 | return f; |
c57ddcaf1b58
- fixed configuration dialog not accepting values past 99.99 for grid angles
Santeri Piippo <crimsondusk64@gmail.com>
parents:
579
diff
changeset
|
266 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | if (f->open (relpath, File::Read)) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | return f; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | // Try with just the LDraw path first |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | fullPath = fmt ("%1" DIRSLASH "%2", io_ldpath, relpath); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | if (f->open (fullPath, File::Read)) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | return f; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | if (subdirs) |
603 | 279 | { |
280 | // Look in sub-directories: parts and p. Also look in net_downloadpath, since that's | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | // where we download parts from the PT to. |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
282 | for (const QString& topdir : initlist<QString> ({ io_ldpath, net_downloadpath })) |
603 | 283 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
284 | for (const QString& subdir : initlist<QString> ({ "parts", "p" })) |
603 | 285 | { |
286 | fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | if (f->open (fullPath, File::Read)) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | return f; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | // Did not find the file. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | log ("Could not find %1.\n", relpath); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | delete f; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | return null; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | void LDFileLoader::start() |
603 | 303 | { |
304 | setDone (false); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | setProgress (0); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | setAborted (false); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | if (isOnForeground()) |
603 | 309 | { |
310 | g_aborted = false; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
312 | // Show a progress dialog if we're loading the main document.here so we can |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
313 | // show progress updates and keep the WM posted that we're still here. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | // Of course we cannot exec() the dialog because then the dialog would |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | // block. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | dlg = new OpenProgressDialog (g_win); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
317 | dlg->setNumLines (getLines().size()); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | dlg->setModal (true); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
319 | dlg->show(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | // Connect the loader in so we can show updates |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | connect (this, SIGNAL (workDone()), dlg, SLOT (accept())); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
323 | connect (dlg, SIGNAL (rejected()), this, SLOT (abort())); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
324 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
325 | else |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
326 | dlg = null; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
327 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
328 | // Begin working |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | work (0); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
330 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
331 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
332 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
333 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | void LDFileLoader::work (int i) |
603 | 335 | { |
336 | // User wishes to abort, so stop here now. | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | if (isAborted()) |
603 | 338 | { |
339 | for (LDObject* obj : m_Objects) | |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
340 | obj->deleteSelf(); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
341 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | m_Objects.clear(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | setDone (true); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
344 | return; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
345 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
346 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
347 | // Parse up to 300 lines per iteration |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
348 | int max = i + 300; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
349 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | for (; i < max && i < (int) getLines().size(); ++i) |
603 | 351 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
352 | QString line = getLines()[i]; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
354 | // Trim the trailing newline |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | QChar c; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
356 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
357 | while (!line.isEmpty() && ((c = line[line.length() - 1]) == '\n' || c == '\r')) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
358 | line.chop (1); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
359 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
360 | LDObject* obj = parseLine (line); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
361 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
362 | // Check for parse errors and warn about tthem |
604 | 363 | if (obj->getType() == LDObject::EError) |
603 | 364 | { |
365 | log ("Couldn't parse line #%1: %2", getProgress() + 1, static_cast<LDError*> (obj)->reason); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
366 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
367 | if (getWarnings() != null) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
368 | (*getWarnings())++; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
369 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
371 | m_Objects << obj; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
372 | setProgress (i); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
373 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
374 | // If we have a dialog pointer, update the progress now |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
375 | if (isOnForeground()) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
376 | dlg->updateProgress (i); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
377 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
378 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
379 | // If we're done now, tell the environment we're done and stop. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
380 | if (i >= ((int) getLines().size()) - 1) |
603 | 381 | { |
382 | emit workDone(); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
383 | setDone (true); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | return; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
385 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
386 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
387 | // Otherwise, continue, by recursing back. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
388 | if (!isDone()) |
603 | 389 | { |
390 | // If we have a dialog to show progress output to, we cannot just call | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
391 | // work() again immediately as the dialog needs some processor cycles as |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
392 | // well. Thus, take a detour through the event loop by using the |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
393 | // meta-object system. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
394 | // |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
395 | // This terminates the loop here and control goes back to the function |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
396 | // which called the file loader. It will keep processing the event loop |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
397 | // until we're ready (see loadFileContents), thus the event loop will |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
398 | // eventually catch the invokation we throw here and send us back. Though |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
399 | // it's not technically recursion anymore, more like a for loop. :P |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
400 | if (isOnForeground()) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
401 | QMetaObject::invokeMethod (this, "work", Qt::QueuedConnection, Q_ARG (int, i)); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
402 | else |
582
5510207c2396
- OH MY FORKING GOD
Santeri Piippo <crimsondusk64@gmail.com>
parents:
581
diff
changeset
|
403 | work (i); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
404 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
405 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
406 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
407 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
408 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
409 | void LDFileLoader::abort() |
603 | 410 | { |
411 | setAborted (true); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
412 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
413 | if (isOnForeground()) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
414 | g_aborted = true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
415 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
416 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
417 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
418 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
419 | QList<LDObject*> loadFileContents (File* f, int* numWarnings, bool* ok) |
603 | 420 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
421 | QList<QString> lines; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
422 | QList<LDObject*> objs; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
423 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
424 | if (numWarnings) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
425 | *numWarnings = 0; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
426 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
427 | // Read in the lines |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
428 | for (QString line : *f) |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
429 | lines << line; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
430 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
431 | LDFileLoader* loader = new LDFileLoader; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
432 | loader->setWarnings (numWarnings); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
433 | loader->setLines (lines); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
434 | loader->setOnForeground (g_loadingMainFile); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
435 | loader->start(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
436 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
437 | // After start() returns, if the loader isn't done yet, it's delaying |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
438 | // its next iteration through the event loop. We need to catch this here |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
439 | // by telling the event loop to tick, which will tick the file loader again. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
440 | // We keep doing this until the file loader is ready. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
441 | while (loader->isDone() == false) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
442 | qApp->processEvents(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
443 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
444 | // If we wanted the success value, supply that now |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
445 | if (ok) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
446 | *ok = !loader->isAborted(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
447 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
448 | objs = loader->getObjects(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
449 | return objs; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
450 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
451 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
452 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
453 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
454 | LDDocument* openDocument (QString path, bool search) |
603 | 455 | { |
456 | // Convert the file name to lowercase since some parts contain uppercase | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
457 | // file names. I'll assume here that the library will always use lowercase |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
458 | // file names for the actual parts.. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
459 | File* f; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
460 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
461 | if (search) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
462 | f = openLDrawFile (path.toLower(), true); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
463 | else |
603 | 464 | { |
465 | f = new File (path, File::Read); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
466 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
467 | if (!*f) |
603 | 468 | { |
469 | delete f; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
470 | return null; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
471 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
472 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
473 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
474 | if (!f) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
475 | return null; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
476 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
477 | LDDocument* load = new LDDocument; |
579
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
478 | load->setFullPath (f->getPath()); |
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
479 | load->setName (LDDocument::shortenName (load->getFullPath())); |
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
480 | dlog ("name: %1 (%2)", load->getName(), load->getFullPath()); |
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
481 | g_loadedFiles << load; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
482 | |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
483 | // Don't take the file loading as actual edits to the file |
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
484 | load->getHistory()->setIgnoring (true); |
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
485 | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
486 | int numWarnings; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
487 | bool ok; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
488 | QList<LDObject*> objs = loadFileContents (f, &numWarnings, &ok); |
579
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
489 | delete f; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
490 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
491 | if (!ok) |
603 | 492 | { |
493 | g_loadedFiles.removeOne (load); | |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
494 | delete load; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
495 | return null; |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
496 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
497 | |
579
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
498 | load->addObjects (objs); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
499 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
500 | if (g_loadingMainFile) |
603 | 501 | { |
502 | LDDocument::setCurrent (load); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
503 | g_win->R()->setFile (load); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
504 | log (QObject::tr ("File %1 parsed successfully (%2 errors)."), path, numWarnings); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
505 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
506 | |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
507 | load->getHistory()->setIgnoring (false); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
508 | return load; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
509 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
510 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
511 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
512 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
513 | bool LDDocument::isSafeToClose() |
603 | 514 | { |
515 | typedef QMessageBox msgbox; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
516 | setlocale (LC_ALL, "C"); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
517 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
518 | // If we have unsaved changes, warn and give the option of saving. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
519 | if (hasUnsavedChanges()) |
603 | 520 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
521 | QString message = fmt (tr ("There are unsaved changes to %1. Should it be saved?"), |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
522 | (getName().length() > 0) ? getName() : tr ("<anonymous>")); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
523 | |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
524 | int button = msgbox::question (g_win, tr ("Unsaved Changes"), message, |
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
525 | (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
526 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
527 | switch (button) |
603 | 528 | { |
529 | case msgbox::Yes: | |
530 | { | |
531 | // If we don't have a file path yet, we have to ask the user for one. | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
532 | if (getName().length() == 0) |
603 | 533 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
534 | QString newpath = QFileDialog::getSaveFileName (g_win, tr ("Save As"), |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
535 | getCurrentDocument()->getName(), tr ("LDraw files (*.dat *.ldr)")); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
536 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
537 | if (newpath.length() == 0) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
538 | return false; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
539 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
540 | setName (newpath); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
541 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
542 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
543 | if (!save()) |
603 | 544 | { |
545 | message = fmt (tr ("Failed to save %1 (%2)\nDo you still want to close?"), | |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
546 | getName(), strerror (errno)); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
547 | |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
548 | if (msgbox::critical (g_win, tr ("Save Failure"), message, |
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
549 | (msgbox::Yes | msgbox::No), msgbox::No) == msgbox::No) |
603 | 550 | { |
551 | return false; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
552 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
553 | } |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
554 | } break; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
555 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
556 | case msgbox::Cancel: |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
557 | return false; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
558 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
559 | default: |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
560 | break; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
561 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
562 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
563 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
564 | return true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
565 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
566 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
567 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
568 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
569 | void closeAll() |
603 | 570 | { |
571 | // Remove all loaded files and the objects they contain | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
572 | QList<LDDocument*> files = g_loadedFiles; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
573 | |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
574 | for (LDDocument* file : files) |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
575 | delete file; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
576 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
577 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
578 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
579 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
580 | void newFile() |
603 | 581 | { |
582 | // Create a new anonymous file and set it to our current | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
583 | LDDocument* f = new LDDocument; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
584 | f->setName (""); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
585 | f->setImplicit (false); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
586 | g_loadedFiles << f; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
587 | LDDocument::setCurrent (f); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
588 | LDDocument::closeInitialFile(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
589 | g_win->R()->setFile (f); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
590 | g_win->doFullRefresh(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
591 | g_win->updateTitle(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
592 | g_win->updateActions(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
593 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
594 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
595 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
596 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
597 | void addRecentFile (QString path) |
603 | 598 | { |
599 | auto& rfiles = io_recentfiles; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
600 | int idx = rfiles.indexOf (path); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
601 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
602 | // If this file already is in the list, pop it out. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
603 | if (idx != -1) |
603 | 604 | { |
605 | if (rfiles.size() == 1) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
606 | return; // only recent file - abort and do nothing |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
607 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
608 | // Pop it out. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
609 | rfiles.removeAt (idx); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
610 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
611 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
612 | // If there's too many recent files, drop one out. |
576
d26334c6b7fd
- bumped max amount of recent files from 5 to 10
Santeri Piippo <crimsondusk64@gmail.com>
parents:
575
diff
changeset
|
613 | while (rfiles.size() > (g_maxRecentFiles - 1)) |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
614 | rfiles.removeAt (0); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
615 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
616 | // Add the file |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
617 | rfiles << path; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
618 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
619 | Config::save(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
620 | g_win->updateRecentFilesMenu(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
621 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
622 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
623 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
624 | // Open an LDraw file and set it as the main model |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
625 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
626 | void openMainFile (QString path) |
603 | 627 | { |
628 | g_loadingMainFile = true; | |
607
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
629 | |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
630 | // If there's already a file with the same name, this file must replace it. |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
631 | LDDocument* documentToReplace = null; |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
632 | QString shortName = LDDocument::shortenName (path); |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
633 | |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
634 | for (LDDocument* doc : g_loadedFiles) |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
635 | { |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
636 | if (doc->getName() == shortName) |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
637 | { |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
638 | documentToReplace = doc; |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
639 | break; |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
640 | } |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
641 | } |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
642 | |
608
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
643 | // We cannot open this file if the document this would replace is not |
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
644 | // safe to close. |
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
645 | if (documentToReplace != null && documentToReplace->isSafeToClose() == false) |
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
646 | { |
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
647 | g_loadingMainFile = false; |
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
648 | return; |
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
649 | } |
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
650 | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
651 | LDDocument* file = openDocument (path, false); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
652 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
653 | if (!file) |
603 | 654 | { |
655 | // Loading failed, thus drop down to a new file since we | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
656 | // closed everything prior. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
657 | newFile(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
658 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
659 | if (!g_aborted) |
603 | 660 | { |
661 | // Tell the user loading failed. | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
662 | setlocale (LC_ALL, "C"); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
663 | critical (fmt (QObject::tr ("Failed to open %1: %2"), path, strerror (errno))); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
664 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
665 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
666 | g_loadingMainFile = false; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
667 | return; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
668 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
669 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
670 | file->setImplicit (false); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
671 | |
607
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
672 | // Replace references to the old file with the new file. |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
673 | if (documentToReplace != null) |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
674 | { |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
675 | for (LDDocumentPointer* ptr : documentToReplace->getReferences()) |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
676 | { dlog ("ptr: %1 (%2)\n", |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
677 | ptr, ptr->getPointer() ? ptr->getPointer()->getName() : "<null>"); |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
678 | |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
679 | ptr->operator= (file); |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
680 | } |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
681 | |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
682 | assert (documentToReplace->countReferences() == 0); |
608
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
683 | delete documentToReplace; |
607
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
684 | } |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
685 | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
686 | // If we have an anonymous, unchanged file open as the only open file |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
687 | // (aside of the one we just opened), close it now. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
688 | LDDocument::closeInitialFile(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
689 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
690 | // Rebuild the object tree view now. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
691 | LDDocument::setCurrent (file); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
692 | g_win->doFullRefresh(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
693 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
694 | // Add it to the recent files list. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
695 | addRecentFile (path); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
696 | g_loadingMainFile = false; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
697 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
698 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
699 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
700 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
701 | bool LDDocument::save (QString savepath) |
603 | 702 | { |
703 | if (!savepath.length()) | |
608
487db37f0bb3
- if loading another file to replace an explicitly loaded file, this file won't get closed automatically and thus needs to be manually closed. We also need to check that it's safe to close before doing this. Also fixed a rather argh problem with ::save not using the proper path...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
607
diff
changeset
|
704 | savepath = getFullPath(); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
705 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
706 | File f (savepath, File::Write); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
707 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
708 | if (!f) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
709 | return false; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
710 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
711 | // If the second object in the list holds the file name, update that now. |
588
720f7480c6b7
- now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
583
diff
changeset
|
712 | // Only do this if the file is explicitly open. |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
713 | LDComment* fpathComment = null; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
714 | LDObject* first = getObject (1); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
715 | |
604 | 716 | if (!isImplicit() && first != null && first->getType() == LDObject::EComment) |
603 | 717 | { |
718 | fpathComment = static_cast<LDComment*> (first); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
719 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
720 | if (fpathComment->text.left (6) == "Name: ") |
603 | 721 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
722 | QString newname = shortenName (savepath); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
723 | fpathComment->text = fmt ("Name: %1", newname); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
724 | g_win->buildObjList(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
725 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
726 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
727 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
728 | // File is open, now save the model to it. Note that LDraw requires files to |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
729 | // have DOS line endings, so we terminate the lines with \r\n. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
730 | for (LDObject* obj : getObjects()) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
731 | f.write (obj->raw() + "\r\n"); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
732 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
733 | // File is saved, now clean up. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
734 | f.close(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
735 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
736 | // We have successfully saved, update the save position now. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
737 | setSavePosition (getHistory()->getPosition()); |
575
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
738 | setFullPath (savepath); |
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
739 | setName (shortenName (savepath)); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
740 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
741 | g_win->updateDocumentListItem (this); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
742 | g_win->updateTitle(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
743 | return true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
744 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
745 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
746 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
747 | // ----------------------------------------------------------------------------- |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
748 | class LDParseError : public std::exception |
603 | 749 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
750 | PROPERTY (private, QString, Error, STR_OPS, STOCK_WRITE) |
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
751 | PROPERTY (private, QString, Line, STR_OPS, STOCK_WRITE) |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
752 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
753 | public: |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
754 | LDParseError (QString line, QString a) : m_Error (a), m_Line (line) {} |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
755 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
756 | const char* what() const throw() |
603 | 757 | { |
758 | return getError().toLocal8Bit().constData(); | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
759 | } |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
760 | }; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
761 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
762 | // ============================================================================= |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
763 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
764 | void checkTokenCount (QString line, const QStringList& tokens, int num) |
603 | 765 | { |
766 | if (tokens.size() != num) | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
767 | throw LDParseError (line, fmt ("Bad amount of tokens, expected %1, got %2", num, tokens.size())); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
768 | } |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
769 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
770 | // ============================================================================= |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
771 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
772 | void checkTokenNumbers (QString line, const QStringList& tokens, int min, int max) |
603 | 773 | { |
774 | bool ok; | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
775 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
776 | // Check scientific notation, e.g. 7.99361e-15 |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
777 | QRegExp scient ("\\-?[0-9]+\\.[0-9]+e\\-[0-9]+"); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
778 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
779 | for (int i = min; i <= max; ++i) |
603 | 780 | { |
781 | tokens[i].toDouble (&ok); | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
782 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
783 | if (!ok && !scient.exactMatch (tokens[i])) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
784 | throw LDParseError (line, fmt ("Token #%1 was `%2`, expected a number (matched length: %3)", (i + 1), tokens[i], scient.matchedLength())); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
785 | } |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
786 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
787 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
788 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
789 | // ----------------------------------------------------------------------------- |
604 | 790 | static Vertex parseVertex (QStringList& s, const int n) |
603 | 791 | { |
604 | 792 | Vertex v; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
793 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
794 | for_axes (ax) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
795 | v[ax] = s[n + ax].toDouble(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
796 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
797 | return v; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
798 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
799 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
800 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
801 | // This is the LDraw code parser function. It takes in a string containing LDraw |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
802 | // code and returns the object parsed from it. parseLine never returns null, |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
803 | // the object will be LDError if it could not be parsed properly. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
804 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
805 | LDObject* parseLine (QString line) |
603 | 806 | { |
807 | try | |
808 | { | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
809 | QStringList tokens = line.split (" ", QString::SkipEmptyParts); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
810 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
811 | if (tokens.size() <= 0) |
603 | 812 | { |
813 | // Line was empty, or only consisted of whitespace | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
814 | return new LDEmpty; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
815 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
816 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
817 | if (tokens[0].length() != 1 || tokens[0][0].isDigit() == false) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
818 | throw LDParseError (line, "Illogical line code"); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
819 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
820 | int num = tokens[0][0].digitValue(); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
821 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
822 | switch (num) |
603 | 823 | { |
824 | case 0: | |
825 | { | |
826 | // Comment | |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
827 | QString comm = line.mid (line.indexOf ("0") + 1).simplified(); |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
828 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
829 | // Handle BFC statements |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
830 | if (tokens.size() > 2 && tokens[1] == "BFC") |
603 | 831 | { |
832 | for (int i = 0; i < LDBFC::NumStatements; ++i) | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
833 | if (comm == fmt ("BFC %1", LDBFC::statements [i])) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
834 | return new LDBFC ( (LDBFC::Type) i); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
835 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
836 | // MLCAD is notorious for stuffing these statements in parts it |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
837 | // creates. The above block only handles valid statements, so we |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
838 | // need to handle MLCAD-style invertnext, clip and noclip separately. |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
839 | struct |
603 | 840 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
841 | QString a; |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
842 | LDBFC::Type b; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
843 | } BFCData[] = |
603 | 844 | { |
845 | { "INVERTNEXT", LDBFC::InvertNext }, | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
846 | { "NOCLIP", LDBFC::NoClip }, |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
847 | { "CLIP", LDBFC::Clip } |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
848 | }; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
849 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
850 | for (const auto& i : BFCData) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
851 | if (comm == "BFC CERTIFY " + i.a) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
852 | return new LDBFC (i.b); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
853 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
854 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
855 | if (tokens.size() > 2 && tokens[1] == "!LDFORGE") |
603 | 856 | { |
857 | // Handle LDForge-specific types, they're embedded into comments too | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
858 | if (tokens[2] == "VERTEX") |
603 | 859 | { |
860 | // Vertex (0 !LDFORGE VERTEX) | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
861 | checkTokenCount (line, tokens, 7); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
862 | checkTokenNumbers (line, tokens, 3, 6); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
863 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
864 | LDVertex* obj = new LDVertex; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
865 | obj->setColor (tokens[3].toLong()); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
866 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
867 | for_axes (ax) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
868 | obj->pos[ax] = tokens[4 + ax].toDouble(); // 4 - 6 |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
869 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
870 | return obj; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
871 | } elif (tokens[2] == "OVERLAY") |
603 | 872 | { |
873 | checkTokenCount (line, tokens, 9);; | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
874 | checkTokenNumbers (line, tokens, 5, 8); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
875 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
876 | LDOverlay* obj = new LDOverlay; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
877 | obj->setFileName (tokens[3]); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
878 | obj->setCamera (tokens[4].toLong()); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
879 | obj->setX (tokens[5].toLong()); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
880 | obj->setY (tokens[6].toLong()); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
881 | obj->setWidth (tokens[7].toLong()); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
882 | obj->setHeight (tokens[8].toLong()); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
883 | return obj; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
884 | } |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
885 | } |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
886 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
887 | // Just a regular comment: |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
888 | LDComment* obj = new LDComment; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
889 | obj->text = comm; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
890 | return obj; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
891 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
892 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
893 | case 1: |
603 | 894 | { |
895 | // Subfile | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
896 | checkTokenCount (line, tokens, 15); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
897 | checkTokenNumbers (line, tokens, 1, 13); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
898 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
899 | // Try open the file. Disable g_loadingMainFile temporarily since we're |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
900 | // not loading the main file now, but the subfile in question. |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
901 | bool tmp = g_loadingMainFile; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
902 | g_loadingMainFile = false; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
903 | LDDocument* load = getDocument (tokens[14]); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
904 | g_loadingMainFile = tmp; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
905 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
906 | // If we cannot open the file, mark it an error. Note we cannot use LDParseError |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
907 | // here because the error object needs the document reference. |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
908 | if (!load) |
603 | 909 | { |
910 | LDError* obj = new LDError (line, fmt ("Could not open %1", tokens[14])); | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
911 | obj->setFileReferenced (tokens[14]); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
912 | return obj; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
913 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
914 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
915 | LDSubfile* obj = new LDSubfile; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
916 | obj->setColor (tokens[1].toLong()); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
917 | obj->setPosition (parseVertex (tokens, 2)); // 2 - 4 |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
918 | |
604 | 919 | Matrix transform; |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
920 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
921 | for (int i = 0; i < 9; ++i) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
922 | transform[i] = tokens[i + 5].toDouble(); // 5 - 13 |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
923 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
924 | obj->setTransform (transform); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
925 | obj->setFileInfo (load); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
926 | return obj; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
927 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
928 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
929 | case 2: |
603 | 930 | { |
931 | checkTokenCount (line, tokens, 8); | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
932 | checkTokenNumbers (line, tokens, 1, 7); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
933 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
934 | // Line |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
935 | LDLine* obj = new LDLine; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
936 | obj->setColor (tokens[1].toLong()); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
937 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
938 | for (int i = 0; i < 2; ++i) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
939 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 7 |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
940 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
941 | return obj; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
942 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
943 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
944 | case 3: |
603 | 945 | { |
946 | checkTokenCount (line, tokens, 11); | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
947 | checkTokenNumbers (line, tokens, 1, 10); |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
948 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
949 | // Triangle |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
950 | LDTriangle* obj = new LDTriangle; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
951 | obj->setColor (tokens[1].toLong()); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
952 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
953 | for (int i = 0; i < 3; ++i) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
954 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 10 |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
955 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
956 | return obj; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
957 | } |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
958 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
959 | case 4: |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
960 | case 5: |
603 | 961 | { |
962 | checkTokenCount (line, tokens, 14); | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
963 | checkTokenNumbers (line, tokens, 1, 13); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
964 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
965 | // Quadrilateral / Conditional line |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
966 | LDObject* obj; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
967 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
968 | if (num == 4) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
969 | obj = new LDQuad; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
970 | else |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
971 | obj = new LDCondLine; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
972 | |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
973 | obj->setColor (tokens[1].toLong()); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
974 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
975 | for (int i = 0; i < 4; ++i) |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
976 | obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 13 |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
977 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
978 | return obj; |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
979 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
980 | |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
981 | default: // Strange line we couldn't parse |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
982 | throw LDError (line, "Unknown line code number"); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
983 | } |
572
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
984 | } |
5a08d67ed770
- code parser no longer complains about scientific notation
Santeri Piippo <crimsondusk64@gmail.com>
parents:
571
diff
changeset
|
985 | catch (LDParseError& e) |
603 | 986 | { |
987 | return new LDError (e.getLine(), e.getError()); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
988 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
989 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
990 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
991 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
992 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
993 | LDDocument* getDocument (QString filename) |
603 | 994 | { |
995 | // Try find the file in the list of loaded files | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
996 | LDDocument* doc = findDocument (filename); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
997 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
998 | // If it's not loaded, try open it |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
999 | if (!doc) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1000 | doc = openDocument (filename, true); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1001 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1002 | return doc; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1003 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1004 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1005 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1006 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1007 | void reloadAllSubfiles() |
603 | 1008 | { |
1009 | if (!getCurrentDocument()) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1010 | return; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1011 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1012 | g_loadedFiles.clear(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1013 | g_loadedFiles << getCurrentDocument(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1014 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1015 | // Go through all objects in the current file and reload the subfiles |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1016 | for (LDObject* obj : getCurrentDocument()->getObjects()) |
603 | 1017 | { |
604 | 1018 | if (obj->getType() == LDObject::ESubfile) |
603 | 1019 | { |
1020 | LDSubfile* ref = static_cast<LDSubfile*> (obj); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1021 | LDDocument* fileInfo = getDocument (ref->getFileInfo()->getName()); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1022 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1023 | if (fileInfo) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1024 | ref->setFileInfo (fileInfo); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1025 | else |
579
4e140de264d2
further improved file behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
577
diff
changeset
|
1026 | ref->replace (new LDError (ref->raw(), fmt ("Could not open %1", ref->getFileInfo()->getName()))); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1027 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1028 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1029 | // Reparse gibberish files. It could be that they are invalid because |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1030 | // of loading errors. Circumstances may be different now. |
604 | 1031 | if (obj->getType() == LDObject::EError) |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1032 | obj->replace (parseLine (static_cast<LDError*> (obj)->contents)); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1033 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1034 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1035 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1036 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1037 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1038 | int LDDocument::addObject (LDObject* obj) |
603 | 1039 | { |
1040 | getHistory()->add (new AddHistory (getObjects().size(), obj)); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1041 | m_Objects << obj; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1042 | |
604 | 1043 | if (obj->getType() == LDObject::EVertex) |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1044 | m_Vertices << obj; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1045 | |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1046 | #ifdef DEBUG |
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1047 | if (!isImplicit()) |
562
c4ff45e98551
- fixed: LDObject methods still used operator delete directly, causing *a very frustrating* crash to debug
Santeri Piippo <crimsondusk64@gmail.com>
parents:
560
diff
changeset
|
1048 | dlog ("Added object #%1 (%2)\n", obj->getID(), obj->getTypeName()); |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1049 | #endif |
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1050 | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1051 | obj->setFile (this); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1052 | return getObjectCount() - 1; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1053 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1054 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1055 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1056 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1057 | void LDDocument::addObjects (const QList<LDObject*> objs) |
603 | 1058 | { |
1059 | for (LDObject* obj : objs) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1060 | if (obj) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1061 | addObject (obj); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1062 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1063 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1064 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1065 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1066 | void LDDocument::insertObj (int pos, LDObject* obj) |
603 | 1067 | { |
1068 | getHistory()->add (new AddHistory (pos, obj)); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1069 | m_Objects.insert (pos, obj); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1070 | obj->setFile (this); |
562
c4ff45e98551
- fixed: LDObject methods still used operator delete directly, causing *a very frustrating* crash to debug
Santeri Piippo <crimsondusk64@gmail.com>
parents:
560
diff
changeset
|
1071 | |
c4ff45e98551
- fixed: LDObject methods still used operator delete directly, causing *a very frustrating* crash to debug
Santeri Piippo <crimsondusk64@gmail.com>
parents:
560
diff
changeset
|
1072 | #ifdef DEBUG |
c4ff45e98551
- fixed: LDObject methods still used operator delete directly, causing *a very frustrating* crash to debug
Santeri Piippo <crimsondusk64@gmail.com>
parents:
560
diff
changeset
|
1073 | if (!isImplicit()) |
c4ff45e98551
- fixed: LDObject methods still used operator delete directly, causing *a very frustrating* crash to debug
Santeri Piippo <crimsondusk64@gmail.com>
parents:
560
diff
changeset
|
1074 | dlog ("Inserted object #%1 (%2) at %3\n", obj->getID(), obj->getTypeName(), pos); |
c4ff45e98551
- fixed: LDObject methods still used operator delete directly, causing *a very frustrating* crash to debug
Santeri Piippo <crimsondusk64@gmail.com>
parents:
560
diff
changeset
|
1075 | #endif |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1076 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1077 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1078 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1079 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1080 | void LDDocument::forgetObject (LDObject* obj) |
603 | 1081 | { |
1082 | int idx = obj->getIndex(); | |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1083 | obj->unselect(); |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1084 | assert (m_Objects[idx] == obj); |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1085 | |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1086 | if (!getHistory()->isIgnoring()) |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1087 | getHistory()->add (new DelHistory (idx, obj)); |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1088 | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1089 | m_Objects.removeAt (idx); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1090 | obj->setFile (null); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1091 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1092 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1093 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1094 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1095 | bool safeToCloseAll() |
603 | 1096 | { |
1097 | for (LDDocument* f : g_loadedFiles) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1098 | if (!f->isSafeToClose()) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1099 | return false; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1100 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1101 | return true; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1102 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1103 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1104 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1105 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1106 | void LDDocument::setObject (int idx, LDObject* obj) |
603 | 1107 | { |
1108 | assert (idx >= 0 && idx < m_Objects.size()); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1109 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1110 | // Mark this change to history |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
1111 | if (!m_History->isIgnoring()) |
603 | 1112 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
1113 | QString oldcode = getObject (idx)->raw(); |
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
1114 | QString newcode = obj->raw(); |
563
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
1115 | *m_History << new EditHistory (idx, oldcode, newcode); |
10939452bf86
- made history ignore file loading and undo/redo calls instead of having hard-coded ignore on the actions, this will probably save a lot of hair
Santeri Piippo <crimsondusk64@gmail.com>
parents:
562
diff
changeset
|
1116 | } |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1117 | |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1118 | m_Objects[idx]->unselect(); |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1119 | m_Objects[idx]->setFile (null); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1120 | obj->setFile (this); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1121 | m_Objects[idx] = obj; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1122 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1123 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1124 | // ============================================================================= |
583
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1125 | // Close all implicit files with no references |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1126 | // ----------------------------------------------------------------------------- |
571
ec534922f693
- cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
566
diff
changeset
|
1127 | void LDDocument::closeUnused() |
603 | 1128 | { |
1129 | for (LDDocument* file : g_loadedFiles) | |
607
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1130 | if (file->isImplicit() && file->countReferences() == 0) |
583
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1131 | delete file; |
571
ec534922f693
- cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
566
diff
changeset
|
1132 | } |
ec534922f693
- cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
566
diff
changeset
|
1133 | |
ec534922f693
- cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
566
diff
changeset
|
1134 | // ============================================================================= |
ec534922f693
- cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
566
diff
changeset
|
1135 | // ----------------------------------------------------------------------------- |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1136 | LDObject* LDDocument::getObject (int pos) const |
603 | 1137 | { |
1138 | if (m_Objects.size() <= pos) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1139 | return null; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1140 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1141 | return m_Objects[pos]; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1142 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1143 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1144 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1145 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1146 | int LDDocument::getObjectCount() const |
603 | 1147 | { |
1148 | return getObjects().size(); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1149 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1150 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1151 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1152 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1153 | bool LDDocument::hasUnsavedChanges() const |
603 | 1154 | { |
1155 | return !isImplicit() && getHistory()->getPosition() != getSavePosition(); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1156 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1157 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1158 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1159 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
1160 | QString LDDocument::getDisplayName() |
603 | 1161 | { |
1162 | if (!getName().isEmpty()) | |
575
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1163 | return getName(); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1164 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1165 | if (!getDefaultName().isEmpty()) |
575
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1166 | return "[" + getDefaultName() + "]"; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1167 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1168 | return tr ("<anonymous>"); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1169 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1170 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1171 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1172 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1173 | QList<LDObject*> LDDocument::inlineContents (LDSubfile::InlineFlags flags) |
603 | 1174 | { |
1175 | // Possibly substitute with logoed studs: | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1176 | // stud.dat -> stud-logo.dat |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1177 | // stud2.dat -> stud-logo2.dat |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1178 | if (gl_logostuds && (flags & LDSubfile::RendererInline)) |
603 | 1179 | { |
1180 | // Ensure logoed studs are loaded first | |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1181 | loadLogoedStuds(); |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1182 | |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1183 | if (getName() == "stud.dat" && g_logoedStud) |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1184 | return g_logoedStud->inlineContents (flags); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1185 | elif (getName() == "stud2.dat" && g_logoedStud2) |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1186 | return g_logoedStud2->inlineContents (flags); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1187 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1188 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1189 | QList<LDObject*> objs, objcache; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1190 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1191 | bool deep = flags & LDSubfile::DeepInline, |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1192 | doCache = flags & LDSubfile::CacheInline; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1193 | |
607
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1194 | if (m_needsCache) |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1195 | { |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1196 | clearCache(); |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1197 | doCache = true; |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1198 | } |
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1199 | |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1200 | // If we have this cached, just create a copy of that |
607
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1201 | if (deep && getCache().isEmpty() == false) |
603 | 1202 | { |
1203 | for (LDObject* obj : getCache()) | |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1204 | objs << obj->createCopy(); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1205 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1206 | else |
603 | 1207 | { |
1208 | if (!deep) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1209 | doCache = false; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1210 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1211 | for (LDObject* obj : getObjects()) |
603 | 1212 | { |
1213 | // Skip those without scemantic meaning | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1214 | if (!obj->isScemantic()) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1215 | continue; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1216 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1217 | // Got another sub-file reference, inline it if we're deep-inlining. If not, |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1218 | // just add it into the objects normally. Also, we only cache immediate |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1219 | // subfiles and this is not one. Yay, recursion! |
604 | 1220 | if (deep && obj->getType() == LDObject::ESubfile) |
603 | 1221 | { |
1222 | LDSubfile* ref = static_cast<LDSubfile*> (obj); | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1223 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1224 | // We only want to cache immediate subfiles, so shed the caching |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1225 | // flag when recursing deeper in hierarchy. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1226 | QList<LDObject*> otherobjs = ref->inlineContents (flags & ~ (LDSubfile::CacheInline)); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1227 | |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1228 | for (LDObject* otherobj : otherobjs) |
603 | 1229 | { |
1230 | // Cache this object, if desired | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1231 | if (doCache) |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1232 | objcache << otherobj->createCopy(); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1233 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1234 | objs << otherobj; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1235 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1236 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1237 | else |
603 | 1238 | { |
1239 | if (doCache) | |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1240 | objcache << obj->createCopy(); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1241 | |
560
39085791128f
- corrected history behavior. LDObject::clone() is now off-limits, createCopy() must be used instead. LDObject::deleteSelf() must be used to delete LDObjects (destructor is protected now)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
557
diff
changeset
|
1242 | objs << obj->createCopy(); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1243 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1244 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1245 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1246 | if (doCache) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1247 | setCache (objcache); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1248 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1249 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1250 | return objs; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1251 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1252 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1253 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1254 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1255 | LDDocument* LDDocument::current() |
603 | 1256 | { |
1257 | return m_curdoc; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1258 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1259 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1260 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1261 | // Sets the given file as the current one on display. At some point in time this |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1262 | // was an operation completely unheard of. ;) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1263 | // |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1264 | // FIXME: f can be temporarily null. This probably should not be the case. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1265 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1266 | void LDDocument::setCurrent (LDDocument* f) |
603 | 1267 | { |
1268 | // Implicit files were loaded for caching purposes and must never be set | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1269 | // current. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1270 | if (f && f->isImplicit()) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1271 | return; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1272 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1273 | m_curdoc = f; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1274 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1275 | if (g_win && f) |
603 | 1276 | { |
1277 | // A ton of stuff needs to be updated | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1278 | g_win->updateDocumentListItem (f); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1279 | g_win->buildObjList(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1280 | g_win->updateTitle(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1281 | g_win->R()->setFile (f); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1282 | g_win->R()->resetAllAngles(); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1283 | g_win->R()->repaint(); |
575
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1284 | log ("Changed file to %1", f->getDisplayName()); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1285 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1286 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1287 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1288 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1289 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1290 | int LDDocument::countExplicitFiles() |
603 | 1291 | { |
1292 | int count = 0; | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1293 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1294 | for (LDDocument* f : g_loadedFiles) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1295 | if (f->isImplicit() == false) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1296 | count++; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1297 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1298 | return count; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1299 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1300 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1301 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1302 | // This little beauty closes the initial file that was open at first when opening |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1303 | // a new file over it. |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1304 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1305 | void LDDocument::closeInitialFile() |
603 | 1306 | { |
1307 | if ( | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1308 | countExplicitFiles() == 2 && |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1309 | g_loadedFiles[0]->getName().isEmpty() && |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1310 | g_loadedFiles[1]->getName().isEmpty() == false && |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1311 | !g_loadedFiles[0]->hasUnsavedChanges() |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1312 | ) |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1313 | delete g_loadedFiles[0]; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1314 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1315 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1316 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1317 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1318 | void loadLogoedStuds() |
603 | 1319 | { |
1320 | if (g_logoedStud && g_logoedStud2) | |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1321 | return; |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1322 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1323 | delete g_logoedStud; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1324 | delete g_logoedStud2; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1325 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1326 | g_logoedStud = openDocument ("stud-logo.dat", true); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1327 | g_logoedStud2 = openDocument ("stud2-logo.dat", true); |
564
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1328 | |
79b23e02dcf1
- implicit documents are now auto-closed when rendered unused, in general, a LOT better document closing behavior
Santeri Piippo <crimsondusk64@gmail.com>
parents:
563
diff
changeset
|
1329 | log (LDDocument::tr ("Logoed studs loaded.\n")); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1330 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1331 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1332 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1333 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1334 | void LDDocument::addToSelection (LDObject* obj) // [protected] |
603 | 1335 | { |
1336 | if (obj->isSelected()) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1337 | return; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1338 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1339 | assert (obj->getFile() == this); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1340 | m_sel << obj; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1341 | obj->setSelected (true); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1342 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1343 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1344 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1345 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1346 | void LDDocument::removeFromSelection (LDObject* obj) // [protected] |
603 | 1347 | { |
1348 | if (!obj->isSelected()) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1349 | return; |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1350 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1351 | assert (obj->getFile() == this); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1352 | m_sel.removeOne (obj); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1353 | obj->setSelected (false); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1354 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1355 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1356 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1357 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1358 | void LDDocument::clearSelection() |
603 | 1359 | { |
1360 | for (LDObject* obj : m_sel) | |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1361 | removeFromSelection (obj); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1362 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1363 | assert (m_sel.isEmpty()); |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1364 | } |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1365 | |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1366 | // ============================================================================= |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1367 | // ----------------------------------------------------------------------------- |
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1368 | const QList<LDObject*>& LDDocument::getSelection() const |
603 | 1369 | { |
1370 | return m_sel; | |
565
e403aad83f60
- history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents:
564
diff
changeset
|
1371 | } |
e403aad83f60
- history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents:
564
diff
changeset
|
1372 | |
e403aad83f60
- history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents:
564
diff
changeset
|
1373 | // ============================================================================= |
e403aad83f60
- history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents:
564
diff
changeset
|
1374 | // ----------------------------------------------------------------------------- |
e403aad83f60
- history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents:
564
diff
changeset
|
1375 | void LDDocument::swapObjects (LDObject* one, LDObject* other) |
603 | 1376 | { |
1377 | int a = m_Objects.indexOf (one); | |
565
e403aad83f60
- history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents:
564
diff
changeset
|
1378 | int b = m_Objects.indexOf (other); |
566
549c63863544
- removed the version monikers, new version is now just 0.3 instead of 0.3-alpha. BUILD_ID can now only be INTERNAL and RELEASE. It was way too complicated to my tastes.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
565
diff
changeset
|
1379 | assert (a != b && a != -1 && b != -1); |
565
e403aad83f60
- history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents:
564
diff
changeset
|
1380 | m_Objects[b] = one; |
e403aad83f60
- history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents:
564
diff
changeset
|
1381 | m_Objects[a] = other; |
e403aad83f60
- history now works on object list moving as well
Santeri Piippo <crimsondusk64@gmail.com>
parents:
564
diff
changeset
|
1382 | addToHistory (new SwapHistory (one->getID(), other->getID())); |
575
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1383 | } |
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1384 | |
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1385 | // ============================================================================= |
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1386 | // ----------------------------------------------------------------------------- |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
1387 | QString LDDocument::shortenName (QString a) // [static] |
603 | 1388 | { |
606
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
1389 | QString shortname = basename (a); |
3dd6f343ec06
- removed the 'str' typedef, use QString directly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
604
diff
changeset
|
1390 | QString topdirname = basename (dirname (a)); |
575
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1391 | |
588
720f7480c6b7
- now recognizes the recently added 8\ subdirectory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
583
diff
changeset
|
1392 | if (g_specialSubdirectories.contains (topdirname)) |
575
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1393 | shortname.prepend (topdirname + "\\"); |
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1394 | |
59c0b57e843b
- added selection auto-subfiling(!)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
572
diff
changeset
|
1395 | return shortname; |
583
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1396 | } |
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1397 | |
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1398 | // ============================================================================= |
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1399 | // ----------------------------------------------------------------------------- |
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1400 | void LDDocument::addReference (LDDocumentPointer* ptr) |
603 | 1401 | { |
607
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1402 | pushToReferences (ptr); |
583
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1403 | } |
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1404 | |
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1405 | // ============================================================================= |
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1406 | // ----------------------------------------------------------------------------- |
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1407 | void LDDocument::removeReference (LDDocumentPointer* ptr) |
603 | 1408 | { |
607
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1409 | removeFromReferences (ptr); |
583
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1410 | |
607
353e418f161a
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
606
diff
changeset
|
1411 | if (getReferences().size() == 0) |
583
4906c5c1670f
- documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
582
diff
changeset
|
1412 | invokeLater (closeUnused); |
557
04e140bdeb0b
- changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1413 | } |