src/actions.cc

changeset 784
f82ab4d3c7b4
parent 773
6eb3c88982ac
child 786
71d786ce0dcc
equal deleted inserted replaced
783:1db20d88650f 784:f82ab4d3c7b4
147 147
148 // ============================================================================= 148 // =============================================================================
149 // 149 //
150 DEFINE_ACTION (SaveAll, CTRL (L)) 150 DEFINE_ACTION (SaveAll, CTRL (L))
151 { 151 {
152 for (LDDocument* file : g_loadedFiles) 152 for (LDDocumentPtr file : LDDocument::explicitDocuments())
153 {
154 if (file->isImplicit())
155 continue;
156
157 save (file, false); 153 save (file, false);
158 }
159 } 154 }
160 155
161 // ============================================================================= 156 // =============================================================================
162 // 157 //
163 DEFINE_ACTION (Close, CTRL (W)) 158 DEFINE_ACTION (Close, CTRL (W))
164 { 159 {
165 if (not getCurrentDocument()->isSafeToClose()) 160 if (not getCurrentDocument()->isSafeToClose())
166 return; 161 return;
167 162
168 delete getCurrentDocument(); 163 getCurrentDocument()->dismiss();
169 } 164 }
170 165
171 // ============================================================================= 166 // =============================================================================
172 // 167 //
173 DEFINE_ACTION (CloseAll, 0) 168 DEFINE_ACTION (CloseAll, 0)
624 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery, 619 // This is a test to draw a dummy axle. Meant to be used as a primitive gallery,
625 // but I can't figure how to generate these pictures properly. Multi-threading 620 // but I can't figure how to generate these pictures properly. Multi-threading
626 // these is an immense pain. 621 // these is an immense pain.
627 DEFINE_ACTION (testpic, "Test picture", "", "", (0)) 622 DEFINE_ACTION (testpic, "Test picture", "", "", (0))
628 { 623 {
629 LDDocument* file = getFile ("axle.dat"); 624 LDDocumentPtr file = getFile ("axle.dat");
630 setlocale (LC_ALL, "C"); 625 setlocale (LC_ALL, "C");
631 626
632 if (not file) 627 if (not file)
633 { 628 {
634 critical ("couldn't load axle.dat"); 629 critical ("couldn't load axle.dat");
825 // Get the body of the document in LDraw code 820 // Get the body of the document in LDraw code
826 for (LDObjectPtr obj : selection()) 821 for (LDObjectPtr obj : selection())
827 code << obj->asText(); 822 code << obj->asText();
828 823
829 // Create the new subfile document 824 // Create the new subfile document
830 LDDocument* doc = new LDDocument; 825 LDDocumentPtr doc = LDDocument::createNew();
831 doc->setImplicit (false); 826 doc->setImplicit (false);
832 doc->setFullPath (fullsubname); 827 doc->setFullPath (fullsubname);
833 doc->setName (LDDocument::shortenName (fullsubname)); 828 doc->setName (LDDocument::shortenName (fullsubname));
834 829
835 LDObjectList objs; 830 LDObjectList objs;
859 { 854 {
860 // Save was successful. Delete the original selection now from the 855 // Save was successful. Delete the original selection now from the
861 // main document. 856 // main document.
862 for (LDObjectPtr obj : selection()) 857 for (LDObjectPtr obj : selection())
863 obj->destroy(); 858 obj->destroy();
864
865 g_loadedFiles << doc;
866 859
867 // Add a reference to the new subfile to where the selection was 860 // Add a reference to the new subfile to where the selection was
868 LDSubfilePtr ref (spawn<LDSubfile>()); 861 LDSubfilePtr ref (spawn<LDSubfile>());
869 ref->setColor (maincolor); 862 ref->setColor (maincolor);
870 ref->setFileInfo (doc); 863 ref->setFileInfo (doc);
877 doFullRefresh(); 870 doFullRefresh();
878 } 871 }
879 else 872 else
880 { 873 {
881 // Failed to save. 874 // Failed to save.
882 delete doc; 875 doc->dismiss();
883 } 876 }
884 } 877 }
885 878
886 DEFINE_ACTION (RandomColors, CTRL_SHIFT (R)) 879 DEFINE_ACTION (RandomColors, CTRL_SHIFT (R))
887 { 880 {

mercurial