gui_actions.cpp

changeset 141
184d117e1b12
parent 140
2e8c1626aef7
child 142
6e8aee653dab
--- a/gui_actions.cpp	Fri Apr 26 18:11:34 2013 +0300
+++ b/gui_actions.cpp	Fri Apr 26 18:28:07 2013 +0300
@@ -251,6 +251,7 @@
 // =============================================================================
 MAKE_ACTION (insertFrom, "Insert from File", "insert-from", "Insert LDraw data from a file.", (0)) {
 	str fname = QFileDialog::getOpenFileName ();
+	ulong idx = g_ForgeWindow->getInsertionPoint ();
 	
 	if (!~fname)
 		return;
@@ -263,16 +264,23 @@
 	
 	std::vector<LDObject*> historyCopies;
 	std::vector<ulong> historyIndices;
-	ulong idx;
+	std::vector<LDObject*> objs = loadFileContents (fp, null);
+	
+	g_ForgeWindow->sel.clear ();
 	
-	loadFileContents (fp, g_CurrentFile, &historyCopies, &idx);
-	
-	for (LDObject* obj : historyCopies)
-		historyIndices.push_back (idx++);
+	for (LDObject* obj : objs) {
+		historyCopies.push_back (obj->clone ());
+		historyIndices.push_back (idx);
+		g_CurrentFile->objects.insert (g_CurrentFile->objects.begin () + idx, obj);
+		g_ForgeWindow->sel.push_back (obj);
+		
+		idx++;
+	}
 	
 	if (historyCopies.size() > 0) {
 		History::addEntry (new AddHistory (historyIndices, historyCopies));
 		g_ForgeWindow->refresh ();
+		g_ForgeWindow->scrollToSelection ();
 	}
 }
 

mercurial