Insertion point calculations fixed, make pasting objects cause the new objects be selected.

Fri, 26 Apr 2013 03:44:34 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 26 Apr 2013 03:44:34 +0300
changeset 139
5e31a96adaa2
parent 138
d22d5c1d9e8a
child 140
2e8c1626aef7

Insertion point calculations fixed, make pasting objects cause the new objects be selected.

gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
gui_editactions.cpp file | annotate | diff | comparison | revisions
--- a/gui.cpp	Fri Apr 26 03:27:56 2013 +0300
+++ b/gui.cpp	Fri Apr 26 03:44:34 2013 +0300
@@ -684,6 +684,17 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+void ForgeWindow::scrollToSelection () {
+	if (sel.size() == 0)
+		return;
+	
+	LDObject* obj = sel[sel.size () - 1];
+	qObjList->scrollToItem (obj->qObjListEntry);
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 void ForgeWindow::slot_selectionChanged () {
 	if (g_bSelectionLocked == true)
 		return;
@@ -759,16 +770,9 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 ulong ForgeWindow::getInsertionPoint () {
-	ulong ulIndex;
-	
-	if (qObjList->selectedItems().size() == 1) {
+	if (sel.size () > 0) {
 		// If we have a selection, put the item after it.
-		for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex)
-			if (g_CurrentFile->objects[ulIndex]->qObjListEntry == qObjList->selectedItems()[0])
-				break;
-		
-		if (ulIndex >= g_CurrentFile->objects.size())
-			return ulIndex + 1;
+		return (sel[sel.size() - 1]->getIndex (g_CurrentFile)) + 1;
 	}
 	
 	// Otherwise place the object at the end.
@@ -811,6 +815,7 @@
 void ForgeWindow::updateSelection () {
 	g_bSelectionLocked = true;
 	
+	qObjList->clearSelection ();
 	for (LDObject* obj : sel)
 		obj->qObjListEntry->setSelected (true);
 	
--- a/gui.h	Fri Apr 26 03:27:56 2013 +0300
+++ b/gui.h	Fri Apr 26 03:44:34 2013 +0300
@@ -143,6 +143,7 @@
 	bool isSelected (LDObject* obj);
 	short getSelectedColor();
 	LDObjectType_e uniformSelectedType ();
+	void scrollToSelection ();
 	
 protected:
 	void closeEvent (QCloseEvent* ev);
--- a/gui_editactions.cpp	Fri Apr 26 03:27:56 2013 +0300
+++ b/gui_editactions.cpp	Fri Apr 26 03:44:34 2013 +0300
@@ -78,20 +78,24 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 MAKE_ACTION (paste, "Paste", "paste", "Paste clipboard contents.", CTRL (V)) {
-	vector<ulong> ulaIndices;
-	vector<LDObject*> paCopies;
+	vector<ulong> historyIndices;
+	vector<LDObject*> historyCopies;
 	
 	ulong idx = g_ForgeWindow->getInsertionPoint ();
+	g_ForgeWindow->sel.clear ();
 	
 	for (LDObject* obj : g_Clipboard) {
-		ulaIndices.push_back (idx);
-		paCopies.push_back (obj->clone ());
+		historyIndices.push_back (idx);
+		historyCopies.push_back (obj->clone ());
 		
-		g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx++, obj->clone ());
+		LDObject* copy = obj->clone ();
+		g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx++, copy);
+		g_ForgeWindow->sel.push_back (copy);
 	}
 	
-	History::addEntry (new AddHistory (ulaIndices, paCopies, AddHistory::Paste));
+	History::addEntry (new AddHistory (historyIndices, historyCopies, AddHistory::Paste));
 	g_ForgeWindow->refresh ();
+	g_ForgeWindow->scrollToSelection ();
 }
 
 // =============================================================================

mercurial