gui_editactions.cpp

changeset 84
c9438ea54ed9
parent 79
f8917e9d07f6
child 85
b1541b547c8c
equal deleted inserted replaced
83:614ec2640e40 84:c9438ea54ed9
249 } 249 }
250 } 250 }
251 251
252 g_ForgeWindow->refresh (); 252 g_ForgeWindow->refresh ();
253 } 253 }
254
255 // =============================================================================
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
257 // =============================================================================
258 static void doMoveSelection (const bool bUp) {
259 vector<LDObject*> objs = g_ForgeWindow->getSelectedObjects ();
260
261 // If we move down, we need to iterate the array in reverse order.
262 const long start = bUp ? 0 : (objs.size() - 1);
263 const long end = bUp ? objs.size() : -1;
264 const long incr = bUp ? 1 : -1;
265
266 for (long i = start; i != end; i += incr) {
267 LDObject* obj = objs[i];
268
269 const long lIndex = obj->getIndex (g_CurrentFile),
270 lTarget = lIndex + (bUp ? -1 : 1);
271
272 if ((bUp == true and lIndex == 0) or
273 (bUp == false and lIndex == (long)(g_CurrentFile->objects.size() - 1)))
274 {
275 // One of the objects hit the extrema. If this happens, this should be the first
276 // object to be iterated on. Thus, nothing has changed yet and it's safe to just
277 // abort the entire operation.
278 assert (i == start);
279 return;
280 }
281
282 obj->swap (g_CurrentFile->objects[lTarget]);
283 }
284
285 g_ForgeWindow->buildObjList ();
286 }
287
288 ACTION (moveUp, "Move Up", "arrow-up", "Move the current selection up.", CTRL (Up)) {
289 doMoveSelection (true);
290 }
291
292 ACTION (moveDown, "Move Down", "arrow-down", "Move the current selection down.", CTRL (Down)) {
293 doMoveSelection (false);
294 }

mercurial