src/file.cpp

changeset 393
01fffd08c25a
parent 391
beef61ce962a
child 400
af39fae829f6
--- a/src/file.cpp	Tue Jul 16 02:47:11 2013 +0300
+++ b/src/file.cpp	Tue Jul 16 03:12:03 2013 +0300
@@ -102,7 +102,7 @@
 
 // =============================================================================
 LDOpenFile::~LDOpenFile() {
-	ulong i;
+	ulong currentIndex = 0;
 	
 	// Clear everything from the model
 	for (LDObject* obj : m_objs)
@@ -113,8 +113,9 @@
 		delete obj;
 	
 	// Remove this file from the list of files
-	for (i = 0; i < g_loadedFiles.size(); ++i) {
+	for (ulong i = 0; i < g_loadedFiles.size(); ++i) {
 		if (g_loadedFiles[i] == this) {
+			currentIndex = i;
 			g_loadedFiles.erase (i);
 			break;
 		}
@@ -123,11 +124,15 @@
 	// If we just closed the current file, we need to set the current
 	// file as something else.
 	if (this == LDOpenFile::current()) {
+		ulong i = currentIndex;
 		if (i > 0)
 			i--;
 		
+		while (i != -1u && g_loadedFiles[i]->implicit())
+			--i;
+		
 		// If we closed the last file, create a blank one.
-		if (g_loadedFiles.size() < i + 1)
+		if (i == -1u)
 			newFile();
 		else
 			LDOpenFile::setCurrent (g_loadedFiles[i]);

mercurial