| 236 void MainWindow::slot_actionEdit() |
236 void MainWindow::slot_actionEdit() |
| 237 { |
237 { |
| 238 if (Selection().size() != 1) |
238 if (Selection().size() != 1) |
| 239 return; |
239 return; |
| 240 |
240 |
| 241 LDObjectPtr obj = Selection() [0]; |
241 LDObject* obj = Selection() [0]; |
| 242 AddObjectDialog::staticDialog (obj->type(), obj); |
242 AddObjectDialog::staticDialog (obj->type(), obj); |
| 243 } |
243 } |
| 244 |
244 |
| 245 // ============================================================================= |
245 // ============================================================================= |
| 246 // |
246 // |
| 277 if (Selection().isEmpty()) |
277 if (Selection().isEmpty()) |
| 278 return; |
278 return; |
| 279 |
279 |
| 280 QList<LDColor> colors; |
280 QList<LDColor> colors; |
| 281 |
281 |
| 282 for (LDObjectPtr obj : Selection()) |
282 for (LDObject* obj : Selection()) |
| 283 { |
283 { |
| 284 if (obj->isColored()) |
284 if (obj->isColored()) |
| 285 colors << obj->color(); |
285 colors << obj->color(); |
| 286 } |
286 } |
| 287 |
287 |
| 288 RemoveDuplicates (colors); |
288 RemoveDuplicates (colors); |
| 289 CurrentDocument()->clearSelection(); |
289 CurrentDocument()->clearSelection(); |
| 290 |
290 |
| 291 for (LDObjectPtr obj : CurrentDocument()->objects()) |
291 for (LDObject* obj : CurrentDocument()->objects()) |
| 292 { |
292 { |
| 293 if (colors.contains (obj->color())) |
293 if (colors.contains (obj->color())) |
| 294 obj->select(); |
294 obj->select(); |
| 295 } |
295 } |
| 296 } |
296 } |
| 303 return; |
303 return; |
| 304 |
304 |
| 305 QList<LDObjectType> types; |
305 QList<LDObjectType> types; |
| 306 QStringList subfilenames; |
306 QStringList subfilenames; |
| 307 |
307 |
| 308 for (LDObjectPtr obj : Selection()) |
308 for (LDObject* obj : Selection()) |
| 309 { |
309 { |
| 310 types << obj->type(); |
310 types << obj->type(); |
| 311 |
311 |
| 312 if (types.last() == OBJ_Subfile) |
312 if (types.last() == OBJ_Subfile) |
| 313 subfilenames << obj.staticCast<LDSubfile>()->fileInfo()->name(); |
313 subfilenames << static_cast<LDSubfile*> (obj)->fileInfo()->name(); |
| 314 } |
314 } |
| 315 |
315 |
| 316 RemoveDuplicates (types); |
316 RemoveDuplicates (types); |
| 317 RemoveDuplicates (subfilenames); |
317 RemoveDuplicates (subfilenames); |
| 318 CurrentDocument()->clearSelection(); |
318 CurrentDocument()->clearSelection(); |
| 319 |
319 |
| 320 for (LDObjectPtr obj : CurrentDocument()->objects()) |
320 for (LDObject* obj : CurrentDocument()->objects()) |
| 321 { |
321 { |
| 322 LDObjectType type = obj->type(); |
322 LDObjectType type = obj->type(); |
| 323 |
323 |
| 324 if (not types.contains (type)) |
324 if (not types.contains (type)) |
| 325 continue; |
325 continue; |
| 326 |
326 |
| 327 // For subfiles, type check is not enough, we check the name of the document as well. |
327 // For subfiles, type check is not enough, we check the name of the document as well. |
| 328 if (type == OBJ_Subfile and not subfilenames.contains (obj.staticCast<LDSubfile>()->fileInfo()->name())) |
328 if (type == OBJ_Subfile and not subfilenames.contains (static_cast<LDSubfile*> (obj)->fileInfo()->name())) |
| 329 continue; |
329 continue; |
| 330 |
330 |
| 331 obj->select(); |
331 obj->select(); |
| 332 } |
332 } |
| 333 } |
333 } |
| 380 |
380 |
| 381 LDObjectList objs = LoadFileContents (&f, null); |
381 LDObjectList objs = LoadFileContents (&f, null); |
| 382 |
382 |
| 383 CurrentDocument()->clearSelection(); |
383 CurrentDocument()->clearSelection(); |
| 384 |
384 |
| 385 for (LDObjectPtr obj : objs) |
385 for (LDObject* obj : objs) |
| 386 { |
386 { |
| 387 CurrentDocument()->insertObj (idx, obj); |
387 CurrentDocument()->insertObj (idx, obj); |
| 388 obj->select(); |
388 obj->select(); |
| 389 R()->compileObject (obj); |
389 R()->compileObject (obj); |
| 390 |
390 |
| 413 { |
413 { |
| 414 Critical (format ("Unable to open %1 for writing (%2)", fname, file.errorString())); |
414 Critical (format ("Unable to open %1 for writing (%2)", fname, file.errorString())); |
| 415 return; |
415 return; |
| 416 } |
416 } |
| 417 |
417 |
| 418 for (LDObjectPtr obj : Selection()) |
418 for (LDObject* obj : Selection()) |
| 419 { |
419 { |
| 420 QString contents = obj->asText(); |
420 QString contents = obj->asText(); |
| 421 QByteArray data = contents.toUtf8(); |
421 QByteArray data = contents.toUtf8(); |
| 422 file.write (data, data.size()); |
422 file.write (data, data.size()); |
| 423 file.write ("\r\n", 2); |
423 file.write ("\r\n", 2); |
| 496 |
496 |
| 497 // ============================================================================= |
497 // ============================================================================= |
| 498 // |
498 // |
| 499 void MainWindow::slot_actionVisibilityToggle() |
499 void MainWindow::slot_actionVisibilityToggle() |
| 500 { |
500 { |
| 501 for (LDObjectPtr obj : Selection()) |
501 for (LDObject* obj : Selection()) |
| 502 obj->setHidden (not obj->isHidden()); |
502 obj->setHidden (not obj->isHidden()); |
| 503 |
503 |
| 504 refresh(); |
504 refresh(); |
| 505 } |
505 } |
| 506 |
506 |
| 507 // ============================================================================= |
507 // ============================================================================= |
| 508 // |
508 // |
| 509 void MainWindow::slot_actionVisibilityHide() |
509 void MainWindow::slot_actionVisibilityHide() |
| 510 { |
510 { |
| 511 for (LDObjectPtr obj : Selection()) |
511 for (LDObject* obj : Selection()) |
| 512 obj->setHidden (true); |
512 obj->setHidden (true); |
| 513 |
513 |
| 514 refresh(); |
514 refresh(); |
| 515 } |
515 } |
| 516 |
516 |
| 517 // ============================================================================= |
517 // ============================================================================= |
| 518 // |
518 // |
| 519 void MainWindow::slot_actionVisibilityReveal() |
519 void MainWindow::slot_actionVisibilityReveal() |
| 520 { |
520 { |
| 521 for (LDObjectPtr obj : Selection()) |
521 for (LDObject* obj : Selection()) |
| 522 obj->setHidden (false); |
522 obj->setHidden (false); |
| 523 refresh(); |
523 refresh(); |
| 524 } |
524 } |
| 525 |
525 |
| 526 // ============================================================================= |
526 // ============================================================================= |
| 688 // |
688 // |
| 689 void MainWindow::slot_actionJumpTo() |
689 void MainWindow::slot_actionJumpTo() |
| 690 { |
690 { |
| 691 bool ok; |
691 bool ok; |
| 692 int defval = 0; |
692 int defval = 0; |
| 693 LDObjectPtr obj; |
693 LDObject* obj; |
| 694 |
694 |
| 695 if (Selection().size() == 1) |
695 if (Selection().size() == 1) |
| 696 defval = Selection()[0]->lineNumber(); |
696 defval = Selection()[0]->lineNumber(); |
| 697 |
697 |
| 698 int idx = QInputDialog::getInt (null, "Go to line", "Go to line:", defval, |
698 int idx = QInputDialog::getInt (null, "Go to line", "Go to line:", defval, |
| 723 |
723 |
| 724 // Title of the new subfile |
724 // Title of the new subfile |
| 725 QString subtitle; |
725 QString subtitle; |
| 726 |
726 |
| 727 // Comment containing the title of the parent document |
727 // Comment containing the title of the parent document |
| 728 LDCommentPtr titleobj (CurrentDocument()->getObject (0).dynamicCast<LDComment>()); |
728 LDCommentPtr titleobj = dynamic_cast<LDComment*> (CurrentDocument()->getObject (0)); |
| 729 |
729 |
| 730 // License text for the subfile |
730 // License text for the subfile |
| 731 QString license (PreferredLicenseText()); |
731 QString license (PreferredLicenseText()); |
| 732 |
732 |
| 733 // LDraw code body of the new subfile (i.e. code of the selection) |
733 // LDraw code body of the new subfile (i.e. code of the selection) |
| 812 Break(); |
812 Break(); |
| 813 } |
813 } |
| 814 }); |
814 }); |
| 815 |
815 |
| 816 // Get the body of the document in LDraw code |
816 // Get the body of the document in LDraw code |
| 817 for (LDObjectPtr obj : Selection()) |
817 for (LDObject* obj : Selection()) |
| 818 code << obj->asText(); |
818 code << obj->asText(); |
| 819 |
819 |
| 820 // Create the new subfile document |
820 // Create the new subfile document |
| 821 LDDocumentPtr doc = LDDocument::createNew(); |
821 LDDocumentPtr doc = LDDocument::createNew(); |
| 822 doc->setImplicit (false); |
822 doc->setImplicit (false); |
| 839 doc->addObjects (objs); |
839 doc->addObjects (objs); |
| 840 |
840 |
| 841 // Add the actual subfile code to the new document |
841 // Add the actual subfile code to the new document |
| 842 for (QString line : code) |
842 for (QString line : code) |
| 843 { |
843 { |
| 844 LDObjectPtr obj = ParseLine (line); |
844 LDObject* obj = ParseLine (line); |
| 845 doc->addObject (obj); |
845 doc->addObject (obj); |
| 846 } |
846 } |
| 847 |
847 |
| 848 // Try save it |
848 // Try save it |
| 849 if (save (doc, true)) |
849 if (save (doc, true)) |
| 850 { |
850 { |
| 851 // Save was successful. Delete the original selection now from the |
851 // Save was successful. Delete the original selection now from the |
| 852 // main document. |
852 // main document. |
| 853 for (LDObjectPtr obj : Selection()) |
853 for (LDObject* obj : Selection()) |
| 854 obj->destroy(); |
854 obj->destroy(); |
| 855 |
855 |
| 856 // Add a reference to the new subfile to where the selection was |
856 // Add a reference to the new subfile to where the selection was |
| 857 LDSubfilePtr ref (LDSpawn<LDSubfile>()); |
857 LDSubfilePtr ref (LDSpawn<LDSubfile>()); |
| 858 ref->setColor (MainColor()); |
858 ref->setColor (MainColor()); |
| 883 R()->refresh(); |
883 R()->refresh(); |
| 884 } |
884 } |
| 885 |
885 |
| 886 void MainWindow::slot_actionOpenSubfiles() |
886 void MainWindow::slot_actionOpenSubfiles() |
| 887 { |
887 { |
| 888 for (LDObjectPtr obj : Selection()) |
888 for (LDObject* obj : Selection()) |
| 889 { |
889 { |
| 890 LDSubfilePtr ref = obj.dynamicCast<LDSubfile>(); |
890 LDSubfilePtr ref = dynamic_cast<LDSubfile*> (obj); |
| 891 |
891 |
| 892 if (ref == null or not ref->fileInfo()->isImplicit()) |
892 if (ref == null or not ref->fileInfo()->isImplicit()) |
| 893 continue; |
893 continue; |
| 894 |
894 |
| 895 ref->fileInfo()->setImplicit (false); |
895 ref->fileInfo()->setImplicit (false); |