src/gui_editactions.cpp

changeset 379
f5f3faac60cd
parent 377
271d1da66b7e
child 382
c1642530ea35
equal deleted inserted replaced
378:bc3f40dcfa9e 379:f5f3faac60cd
88 g_win->sel().clear(); 88 g_win->sel().clear();
89 int num = 0; 89 int num = 0;
90 90
91 for (str line : clipboardText.split ("\n")) { 91 for (str line : clipboardText.split ("\n")) {
92 LDObject* pasted = parseLine (line); 92 LDObject* pasted = parseLine (line);
93 g_curfile->insertObj (idx++, pasted); 93 currentFile()->insertObj (idx++, pasted);
94 g_win->sel() << pasted; 94 g_win->sel() << pasted;
95 g_win->R()->compileObject (pasted); 95 g_win->R()->compileObject (pasted);
96 ++num; 96 ++num;
97 } 97 }
98 98
116 vector<LDObject*> sel = g_win->sel(); 116 vector<LDObject*> sel = g_win->sel();
117 117
118 for (LDObject* obj : sel) { 118 for (LDObject* obj : sel) {
119 // Get the index of the subfile so we know where to insert the 119 // Get the index of the subfile so we know where to insert the
120 // inlined contents. 120 // inlined contents.
121 long idx = obj->getIndex (g_curfile); 121 long idx = obj->getIndex (currentFile());
122 122
123 if (idx == -1) 123 if (idx == -1)
124 continue; 124 continue;
125 125
126 vector<LDObject*> objs; 126 vector<LDObject*> objs;
134 for (LDObject* inlineobj : objs) { 134 for (LDObject* inlineobj : objs) {
135 str line = inlineobj->raw(); 135 str line = inlineobj->raw();
136 delete inlineobj; 136 delete inlineobj;
137 137
138 LDObject* newobj = parseLine (line); 138 LDObject* newobj = parseLine (line);
139 g_curfile->insertObj (idx++, newobj); 139 currentFile()->insertObj (idx++, newobj);
140 g_win->sel() << newobj; 140 g_win->sel() << newobj;
141 } 141 }
142 142
143 // Delete the subfile now as it's been inlined. 143 // Delete the subfile now as it's been inlined.
144 g_curfile->forgetObject (obj); 144 currentFile()->forgetObject (obj);
145 delete obj; 145 delete obj;
146 } 146 }
147 147
148 g_win->fullRefresh(); 148 g_win->fullRefresh();
149 } 149 }
168 for (LDObject* obj : objs) { 168 for (LDObject* obj : objs) {
169 if (obj->getType() != LDObject::Quad) 169 if (obj->getType() != LDObject::Quad)
170 continue; 170 continue;
171 171
172 // Find the index of this quad 172 // Find the index of this quad
173 long index = obj->getIndex (g_curfile); 173 long index = obj->getIndex (currentFile());
174 174
175 if (index == -1) 175 if (index == -1)
176 return; 176 return;
177 177
178 vector<LDTriangleObject*> triangles = static_cast<LDQuadObject*> (obj)->splitToTriangles(); 178 vector<LDTriangleObject*> triangles = static_cast<LDQuadObject*> (obj)->splitToTriangles();
179 179
180 // Replace the quad with the first triangle and add the second triangle 180 // Replace the quad with the first triangle and add the second triangle
181 // after the first one. 181 // after the first one.
182 g_curfile->setObject (index, triangles[0]); 182 currentFile()->setObject (index, triangles[0]);
183 g_curfile->insertObj (index + 1, triangles[1]); 183 currentFile()->insertObj (index + 1, triangles[1]);
184 184
185 // Delete this quad now, it has been split. 185 // Delete this quad now, it has been split.
186 delete obj; 186 delete obj;
187 187
188 num++; 188 num++;
287 lines[1] = new LDLineObject (tri->getVertex (1), tri->getVertex (2)); 287 lines[1] = new LDLineObject (tri->getVertex (1), tri->getVertex (2));
288 lines[2] = new LDLineObject (tri->getVertex (2), tri->getVertex (0)); 288 lines[2] = new LDLineObject (tri->getVertex (2), tri->getVertex (0));
289 } 289 }
290 290
291 for (short i = 0; i < numLines; ++i) { 291 for (short i = 0; i < numLines; ++i) {
292 ulong idx = obj->getIndex (g_curfile) + i + 1; 292 ulong idx = obj->getIndex (currentFile()) + i + 1;
293 293
294 lines[i]->setColor (edgecolor); 294 lines[i]->setColor (edgecolor);
295 g_curfile->insertObj (idx, lines[i]); 295 currentFile()->insertObj (idx, lines[i]);
296 g_win->R()->compileObject (lines[i]); 296 g_win->R()->compileObject (lines[i]);
297 } 297 }
298 298
299 num += numLines; 299 num += numLines;
300 } 300 }
313 313
314 for (LDObject* obj : g_win->sel()) { 314 for (LDObject* obj : g_win->sel()) {
315 if (obj->vertices() < 2) 315 if (obj->vertices() < 2)
316 continue; 316 continue;
317 317
318 ulong idx = obj->getIndex (g_curfile); 318 ulong idx = obj->getIndex (currentFile());
319 319
320 for (short i = 0; i < obj->vertices(); ++i) { 320 for (short i = 0; i < obj->vertices(); ++i) {
321 LDVertexObject* vert = new LDVertexObject; 321 LDVertexObject* vert = new LDVertexObject;
322 vert->pos = obj->getVertex (i); 322 vert->pos = obj->getVertex (i);
323 vert->setColor (obj->color()); 323 vert->setColor (obj->color());
324 324
325 g_curfile->insertObj (++idx, vert); 325 currentFile()->insertObj (++idx, vert);
326 g_win->R()->compileObject (vert); 326 g_win->R()->compileObject (vert);
327 ++num; 327 ++num;
328 } 328 }
329 } 329 }
330 330
351 351
352 // ============================================================================= 352 // =============================================================================
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
354 // ============================================================================= 354 // =============================================================================
355 MAKE_ACTION (undo, "Undo", "undo", "Undo a step.", CTRL (Z)) { 355 MAKE_ACTION (undo, "Undo", "undo", "Undo a step.", CTRL (Z)) {
356 g_curfile->undo(); 356 currentFile()->undo();
357 } 357 }
358 358
359 MAKE_ACTION (redo, "Redo", "redo", "Redo a step.", CTRL_SHIFT (Z)) { 359 MAKE_ACTION (redo, "Redo", "redo", "Redo a step.", CTRL_SHIFT (Z)) {
360 g_curfile->redo(); 360 currentFile()->redo();
361 } 361 }
362 362
363 // ============================================================================= 363 // =============================================================================
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
365 // ============================================================================= 365 // =============================================================================
661 g_win->refresh(); 661 g_win->refresh();
662 } 662 }
663 663
664 // ================================================================================================= 664 // =================================================================================================
665 static bool isColorUsed (short colnum) { 665 static bool isColorUsed (short colnum) {
666 for (LDObject* obj : g_curfile->objs()) 666 for (LDObject* obj : currentFile()->objs())
667 if (obj->isColored() && obj->color() == colnum) 667 if (obj->isColored() && obj->color() == colnum)
668 return true; 668 return true;
669 669
670 return false; 670 return false;
671 } 671 }

mercurial