51 DEFINE_PROPERTY (QListWidgetItem*, LDFile, listItem, setListItem) |
51 DEFINE_PROPERTY (QListWidgetItem*, LDFile, listItem, setListItem) |
52 |
52 |
53 // ============================================================================= |
53 // ============================================================================= |
54 // ----------------------------------------------------------------------------- |
54 // ----------------------------------------------------------------------------- |
55 namespace LDPaths |
55 namespace LDPaths |
56 { |
56 { static str pathError; |
57 static str pathError; |
|
58 |
57 |
59 struct |
58 struct |
60 { str LDConfigPath; |
59 { str LDConfigPath; |
61 str partsPath, primsPath; |
60 str partsPath, primsPath; |
62 } pathInfo; |
61 } pathInfo; |
121 |
123 |
122 // ============================================================================= |
124 // ============================================================================= |
123 // ----------------------------------------------------------------------------- |
125 // ----------------------------------------------------------------------------- |
124 LDFile::~LDFile() |
126 LDFile::~LDFile() |
125 { // Clear everything from the model |
127 { // Clear everything from the model |
126 for (LDObject * obj : objects()) |
128 for (LDObject* obj : objects()) |
127 delete obj; |
129 delete obj; |
128 |
130 |
129 // Clear the cache as well |
131 // Clear the cache as well |
130 for (LDObject * obj : cache()) |
132 for (LDObject* obj : cache()) |
131 delete obj; |
133 delete obj; |
132 |
134 |
133 // Remove this file from the list of files |
135 // Remove this file from the list of files |
134 for (ulong i = 0; i < g_loadedFiles.size(); ++i) |
136 for (ulong i = 0; i < g_loadedFiles.size(); ++i) |
135 { if (g_loadedFiles[i] == this) |
137 { if (g_loadedFiles[i] == this) |
139 } |
141 } |
140 |
142 |
141 // If we just closed the current file, we need to set the current |
143 // If we just closed the current file, we need to set the current |
142 // file as something else. |
144 // file as something else. |
143 if (this == LDFile::current()) |
145 if (this == LDFile::current()) |
144 { // If we closed the last file, create a blank one. |
146 { bool found = false; |
145 if (countExplicitFiles() == 0) |
147 |
|
148 // Try find an explicitly loaded file - if we can't find one, |
|
149 // we need to create a new file to switch to. |
|
150 for (LDFile* file : g_loadedFiles) |
|
151 { if (!file->implicit()) |
|
152 { LDFile::setCurrent (file); |
|
153 found = true; |
|
154 break; |
|
155 } |
|
156 } |
|
157 |
|
158 if (!found) |
146 newFile(); |
159 newFile(); |
147 else |
|
148 { // Find the first explicit file loaded |
|
149 int idx = 0; |
|
150 |
|
151 while (g_loadedFiles[idx]->implicit()) |
|
152 idx++; |
|
153 |
|
154 LDFile::setCurrent (g_loadedFiles[idx]); |
|
155 } |
|
156 } |
160 } |
157 |
161 |
158 g_win->updateFileList(); |
162 g_win->updateFileList(); |
159 } |
163 } |
160 |
164 |
227 |
231 |
228 if (f->open (fullPath, File::Read)) |
232 if (f->open (fullPath, File::Read)) |
229 return f; |
233 return f; |
230 |
234 |
231 if (subdirs) |
235 if (subdirs) |
232 { // Look in sub-directories: parts and p. Also look in net_downloadpath. |
236 { // Look in sub-directories: parts and p. Also look in net_downloadpath, since that's |
233 for (const str & topdir : initlist<str> ( { io_ldpath, net_downloadpath })) |
237 // where we download parts from the PT to. |
234 |
238 for (const str& topdir : initlist<str> ({ io_ldpath, net_downloadpath })) |
235 for (const str & subdir : initlist<str> ( { "parts", "p" })) |
239 { for (const str& subdir : initlist<str> ({ "parts", "p" })) |
236 { fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath); |
240 { fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath); |
237 |
241 |
238 if (f->open (fullPath, File::Read)) |
242 if (f->open (fullPath, File::Read)) |
239 return f; |
243 return f; |
240 } |
244 } |
|
245 } |
241 } |
246 } |
242 |
247 |
243 // Did not find the file. |
248 // Did not find the file. |
244 print ("could not find %1\n", relpath); |
249 print ("could not find %1\n", relpath); |
245 delete f; |
250 delete f; |