Tue, 09 Apr 2013 21:59:56 +0300
Added move up/down actions.
gui.cpp | file | annotate | diff | comparison | revisions | |
gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
icons/arrow-down.png | file | annotate | diff | comparison | revisions | |
icons/arrow-left.png | file | annotate | diff | comparison | revisions | |
icons/arrow-right.png | file | annotate | diff | comparison | revisions | |
icons/arrow-up.png | file | annotate | diff | comparison | revisions | |
ldtypes.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.h | file | annotate | diff | comparison | revisions |
--- a/gui.cpp Tue Apr 09 18:23:07 2013 +0300 +++ b/gui.cpp Tue Apr 09 21:59:56 2013 +0300 @@ -43,6 +43,8 @@ EXTERN_ACTION (splitQuads) EXTERN_ACTION (setContents) EXTERN_ACTION (makeBorders) +EXTERN_ACTION (moveUp) +EXTERN_ACTION (moveDown) EXTERN_ACTION (newSubfile) EXTERN_ACTION (newLine) EXTERN_ACTION (newCondLine) @@ -154,6 +156,9 @@ ADD_MENU_ITEM (Edit, paste) // Paste ADD_MENU_ITEM (Edit, del) // Delete qEditMenu->addSeparator (); // ----- + ADD_MENU_ITEM (Edit, moveUp) // Move Up + ADD_MENU_ITEM (Edit, moveDown) // Move Down + qEditMenu->addSeparator (); // ----- ADD_MENU_ITEM (Edit, setColor) // Set Color qEditMenu->addSeparator (); // ----- ADD_MENU_ITEM (Edit, inlineContents) // Inline @@ -198,6 +203,8 @@ ADD_TOOLBAR_ITEM (Edit, copy) ADD_TOOLBAR_ITEM (Edit, paste) ADD_TOOLBAR_ITEM (Edit, del) + ADD_TOOLBAR_ITEM (Edit, moveUp) + ADD_TOOLBAR_ITEM (Edit, moveDown) ADD_TOOLBAR_ITEM (Edit, setColor) ADD_TOOLBAR_ITEM (Edit, inlineContents) ADD_TOOLBAR_ITEM (Edit, splitQuads)
--- a/gui_editactions.cpp Tue Apr 09 18:23:07 2013 +0300 +++ b/gui_editactions.cpp Tue Apr 09 21:59:56 2013 +0300 @@ -251,3 +251,44 @@ g_ForgeWindow->refresh (); } + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +static void doMoveSelection (const bool bUp) { + vector<LDObject*> objs = g_ForgeWindow->getSelectedObjects (); + + // If we move down, we need to iterate the array in reverse order. + const long start = bUp ? 0 : (objs.size() - 1); + const long end = bUp ? objs.size() : -1; + const long incr = bUp ? 1 : -1; + + for (long i = start; i != end; i += incr) { + LDObject* obj = objs[i]; + + const long lIndex = obj->getIndex (g_CurrentFile), + lTarget = lIndex + (bUp ? -1 : 1); + + if ((bUp == true and lIndex == 0) or + (bUp == false and lIndex == (long)(g_CurrentFile->objects.size() - 1))) + { + // One of the objects hit the extrema. If this happens, this should be the first + // object to be iterated on. Thus, nothing has changed yet and it's safe to just + // abort the entire operation. + assert (i == start); + return; + } + + obj->swap (g_CurrentFile->objects[lTarget]); + } + + g_ForgeWindow->buildObjList (); +} + +ACTION (moveUp, "Move Up", "arrow-up", "Move the current selection up.", CTRL (Up)) { + doMoveSelection (true); +} + +ACTION (moveDown, "Move Down", "arrow-down", "Move the current selection down.", CTRL (Down)) { + doMoveSelection (false); +} \ No newline at end of file
--- a/ldtypes.cpp Tue Apr 09 18:23:07 2013 +0300 +++ b/ldtypes.cpp Tue Apr 09 21:59:56 2013 +0300 @@ -226,15 +226,26 @@ // ============================================================================= void LDObject::replace (LDObject* replacement) { // Replace all instances of the old object with the new object - for (ulong i = 0; i < g_CurrentFile->objects.size(); ++i) { - if (g_CurrentFile->objects[i] == this) - g_CurrentFile->objects[i] = replacement; - } + for (LDObject* obj : g_CurrentFile->objects) + if (obj == this) + obj = replacement; // Remove the old object delete this; } +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +void LDObject::swap (LDObject* other) { + for (LDObject*& obj : g_CurrentFile->objects) { + if (obj == this) + obj = other; + else if (obj == other) + obj = this; + } +} + LDLine::LDLine (vertex v1, vertex v2) { commonInit ();
--- a/ldtypes.h Tue Apr 09 18:23:07 2013 +0300 +++ b/ldtypes.h Tue Apr 09 21:59:56 2013 +0300 @@ -95,6 +95,9 @@ // object and any pointers to it become invalid. void replace (LDObject* replacement); + // Swap this object with another. + void swap (LDObject* other); + QTreeWidgetItem* qObjListEntry; };