src/toolsets/filetoolset.cpp

changeset 978
4603d8fd063e
parent 975
24ba5aa3393f
child 979
880d3fe9ac7c
equal deleted inserted replaced
977:dc3ceb65cda7 978:4603d8fd063e
37 { 37 {
38 NewPartDialog* dlg = new NewPartDialog (m_window); 38 NewPartDialog* dlg = new NewPartDialog (m_window);
39 39
40 if (dlg->exec() == QDialog::Accepted) 40 if (dlg->exec() == QDialog::Accepted)
41 { 41 {
42 newFile(); 42 m_window->createBlankDocument();
43 dlg->fillHeader (CurrentDocument()); 43 dlg->fillHeader (currentDocument());
44 m_window->doFullRefresh(); 44 m_window->doFullRefresh();
45 } 45 }
46 } 46 }
47 47
48 void FileToolset::newFile() 48 void FileToolset::newFile()
49 { 49 {
50 newFile(); 50 m_window->createBlankDocument();
51 } 51 }
52 52
53 void FileToolset::open() 53 void FileToolset::open()
54 { 54 {
55 QString name = QFileDialog::getOpenFileName (m_window, "Open File", "", "LDraw files (*.dat *.ldr)"); 55 QString name = QFileDialog::getOpenFileName (m_window, "Open File", "", "LDraw files (*.dat *.ldr)");
60 OpenMainModel (name); 60 OpenMainModel (name);
61 } 61 }
62 62
63 void FileToolset::save() 63 void FileToolset::save()
64 { 64 {
65 m_window->save (CurrentDocument(), false); 65 m_window->save (currentDocument(), false);
66 } 66 }
67 67
68 void FileToolset::saveAs() 68 void FileToolset::saveAs()
69 { 69 {
70 m_window->save (CurrentDocument(), true); 70 m_window->save (currentDocument(), true);
71 } 71 }
72 72
73 void FileToolset::saveAll() 73 void FileToolset::saveAll()
74 { 74 {
75 for (LDDocument* file : LDDocument::explicitDocuments()) 75 for (LDDocument* file : m_window->allDocuments())
76 m_window->save (file, false); 76 m_window->save (file, false);
77 } 77 }
78 78
79 void FileToolset::close() 79 void FileToolset::close()
80 { 80 {
81 if (not CurrentDocument()->isSafeToClose()) 81 if (not currentDocument()->isSafeToClose())
82 return; 82 return;
83 83
84 CurrentDocument()->dismiss(); 84 currentDocument()->dismiss();
85 } 85 }
86 86
87 void FileToolset::closeAll() 87 void FileToolset::closeAll()
88 { 88 {
89 if (not IsSafeToCloseAll()) 89 if (not IsSafeToCloseAll())
126 return; 126 return;
127 } 127 }
128 128
129 LDObjectList objs = LoadFileContents (&f, null); 129 LDObjectList objs = LoadFileContents (&f, null);
130 130
131 CurrentDocument()->clearSelection(); 131 currentDocument()->clearSelection();
132 132
133 for (LDObject* obj : objs) 133 for (LDObject* obj : objs)
134 { 134 {
135 CurrentDocument()->insertObj (idx, obj); 135 currentDocument()->insertObj (idx, obj);
136 obj->select(); 136 obj->select();
137 m_window->R()->compileObject (obj); 137 m_window->R()->compileObject (obj);
138 138
139 idx++; 139 idx++;
140 } 140 }
143 m_window->scrollToSelection(); 143 m_window->scrollToSelection();
144 } 144 }
145 145
146 void FileToolset::exportTo() 146 void FileToolset::exportTo()
147 { 147 {
148 if (Selection().isEmpty()) 148 if (selectedObjects().isEmpty())
149 return; 149 return;
150 150
151 QString fname = QFileDialog::getSaveFileName(); 151 QString fname = QFileDialog::getSaveFileName();
152 152
153 if (fname.length() == 0) 153 if (fname.length() == 0)
159 { 159 {
160 Critical (format ("Unable to open %1 for writing (%2)", fname, file.errorString())); 160 Critical (format ("Unable to open %1 for writing (%2)", fname, file.errorString()));
161 return; 161 return;
162 } 162 }
163 163
164 for (LDObject* obj : Selection()) 164 for (LDObject* obj : selectedObjects())
165 { 165 {
166 QString contents = obj->asText(); 166 QString contents = obj->asText();
167 QByteArray data = contents.toUtf8(); 167 QByteArray data = contents.toUtf8();
168 file.write (data, data.size()); 168 file.write (data, data.size());
169 file.write ("\r\n", 2); 169 file.write ("\r\n", 2);
175 PrimitiveScanner::start(); 175 PrimitiveScanner::start();
176 } 176 }
177 177
178 void FileToolset::openSubfiles() 178 void FileToolset::openSubfiles()
179 { 179 {
180 for (LDObject* obj : Selection()) 180 for (LDObject* obj : selectedObjects())
181 { 181 {
182 LDSubfile* ref = dynamic_cast<LDSubfile*> (obj); 182 LDSubfile* ref = dynamic_cast<LDSubfile*> (obj);
183 183
184 if (ref == null or not ref->fileInfo()->isImplicit()) 184 if (ref == null or not ref->fileInfo()->isImplicit())
185 continue; 185 continue;

mercurial