52 m_window->createBlankDocument(); |
52 m_window->createBlankDocument(); |
53 } |
53 } |
54 |
54 |
55 void FileToolset::open() |
55 void FileToolset::open() |
56 { |
56 { |
57 QString name = QFileDialog::getOpenFileName (m_window, "Open File", "", "LDraw files (*.dat *.ldr)"); |
57 QString name = QFileDialog::getOpenFileName(m_window, "Open File", "", "LDraw files (*.dat *.ldr)"); |
58 |
58 |
59 if (name.isEmpty()) |
59 if (not name.isEmpty()) |
60 return; |
60 m_documents->openMainModel (name); |
61 |
|
62 m_documents->openMainModel (name); |
|
63 } |
61 } |
64 |
62 |
65 void FileToolset::save() |
63 void FileToolset::save() |
66 { |
64 { |
67 m_window->save (currentDocument(), false); |
65 m_window->save(currentDocument(), false); |
68 } |
66 } |
69 |
67 |
70 void FileToolset::saveAs() |
68 void FileToolset::saveAs() |
71 { |
69 { |
72 m_window->save (currentDocument(), true); |
70 m_window->save(currentDocument(), true); |
73 } |
71 } |
74 |
72 |
75 void FileToolset::saveAll() |
73 void FileToolset::saveAll() |
76 { |
74 { |
77 for (LDDocument* file : m_documents->allDocuments()) |
75 for (LDDocument* document : m_documents->allDocuments()) |
78 m_window->save (file, false); |
76 m_window->save(document, false); |
79 } |
77 } |
80 |
78 |
81 void FileToolset::close() |
79 void FileToolset::close() |
82 { |
80 { |
83 if (not currentDocument()->isSafeToClose()) |
81 if (currentDocument()->isSafeToClose()) |
84 return; |
82 currentDocument()->close(); |
85 |
|
86 currentDocument()->close(); |
|
87 } |
83 } |
88 |
84 |
89 void FileToolset::closeAll() |
85 void FileToolset::closeAll() |
90 { |
86 { |
91 if (m_documents->isSafeToCloseAll()) |
87 if (m_documents->isSafeToCloseAll()) |
92 m_documents->clear(); |
88 m_documents->clear(); |
93 } |
89 } |
94 |
90 |
95 void FileToolset::settings() |
91 void FileToolset::settings() |
96 { |
92 { |
97 (new ConfigDialog (m_window))->exec(); |
93 (new ConfigDialog {m_window})->exec(); |
98 } |
94 } |
99 |
95 |
100 void FileToolset::setLDrawPath() |
96 void FileToolset::setLDrawPath() |
101 { |
97 { |
102 LDrawPathDialog* dialog = new LDrawPathDialog (m_config->lDrawPath(), true); |
98 LDrawPathDialog* dialog = new LDrawPathDialog {m_config->lDrawPath(), true}; |
103 |
99 |
104 if (dialog->exec()) |
100 if (dialog->exec()) |
105 m_config->setLDrawPath (dialog->path()); |
101 m_config->setLDrawPath (dialog->path()); |
106 } |
102 } |
107 |
103 |
108 void FileToolset::exit() |
104 void FileToolset::exit() |
109 { |
105 { |
110 ::exit (EXIT_SUCCESS); |
106 ::exit(EXIT_SUCCESS); |
111 } |
107 } |
112 |
108 |
113 void FileToolset::insertFrom() |
109 void FileToolset::insertFrom() |
114 { |
110 { |
115 QString fname = QFileDialog::getOpenFileName(); |
111 QString filePath = QFileDialog::getOpenFileName(); |
116 int idx = m_window->suggestInsertPoint(); |
112 int position = m_window->suggestInsertPoint(); |
117 |
113 |
118 if (not fname.length()) |
114 if (not filePath.isEmpty()) |
119 return; |
115 { |
120 |
116 QFile file = {filePath}; |
121 QFile f (fname); |
117 |
122 |
118 if (file.open(QIODevice::ReadOnly)) |
123 if (not f.open (QIODevice::ReadOnly)) |
119 { |
124 { |
120 // TODO: shouldn't need to go to the document manager to parse a file |
125 Critical (format ("Couldn't open %1 (%2)", fname, f.errorString())); |
121 LDObjectList objects = m_documents->loadFileContents(&file, nullptr, nullptr); |
126 return; |
122 |
127 } |
123 currentDocument()->clearSelection(); |
128 |
124 |
129 // TODO: shouldn't need to go to the document manager to parse a file |
125 for (LDObject* object : objects) |
130 LDObjectList objs = m_documents->loadFileContents (&f, nullptr, nullptr); |
126 { |
131 |
127 currentDocument()->insertObject (position, object); |
132 currentDocument()->clearSelection(); |
128 object->select(); |
133 |
129 m_window->renderer()->compileObject (object); |
134 for (LDObject* obj : objs) |
130 position++; |
135 { |
131 } |
136 currentDocument()->insertObject (idx, obj); |
132 |
137 obj->select(); |
133 m_window->refresh(); |
138 m_window->renderer()->compileObject (obj); |
134 m_window->scrollToSelection(); |
139 |
135 } |
140 idx++; |
136 else |
141 } |
137 { |
142 |
138 Critical(format("Couldn't open %1 (%2)", filePath, file.errorString())); |
143 m_window->refresh(); |
139 } |
144 m_window->scrollToSelection(); |
140 } |
145 } |
141 } |
146 |
142 |
147 void FileToolset::exportTo() |
143 void FileToolset::exportTo() |
148 { |
144 { |
149 if (selectedObjects().isEmpty()) |
145 if (selectedObjects().isEmpty()) |
150 return; |
146 return; |
151 |
147 |
152 QString fname = QFileDialog::getSaveFileName(); |
148 QString filePath = QFileDialog::getSaveFileName(); |
153 |
149 |
154 if (fname.length() == 0) |
150 if (filePath.length() == 0) |
155 return; |
151 return; |
156 |
152 |
157 QFile file (fname); |
153 QFile file = {filePath}; |
158 |
154 |
159 if (not file.open (QIODevice::WriteOnly | QIODevice::Text)) |
155 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) |
160 { |
156 { |
161 Critical (format ("Unable to open %1 for writing (%2)", fname, file.errorString())); |
157 for (LDObject* obj : selectedObjects()) |
162 return; |
158 { |
163 } |
159 QString contents = obj->asText(); |
164 |
160 QByteArray data = contents.toUtf8(); |
165 for (LDObject* obj : selectedObjects()) |
161 file.write(data, data.size()); |
166 { |
162 file.write("\r\n", 2); |
167 QString contents = obj->asText(); |
163 } |
168 QByteArray data = contents.toUtf8(); |
164 } |
169 file.write (data, data.size()); |
165 else |
170 file.write ("\r\n", 2); |
166 { |
|
167 Critical(format("Unable to open %1 for writing (%2)", filePath, file.errorString())); |
171 } |
168 } |
172 } |
169 } |
173 |
170 |
174 void FileToolset::scanPrimitives() |
171 void FileToolset::scanPrimitives() |
175 { |
172 { |
176 primitives()->startScan(); |
173 primitives()->startScan(); |
177 } |
174 } |
178 |
175 |
179 void FileToolset::openSubfiles() |
176 void FileToolset::openSubfiles() |
180 { |
177 { |
181 for (LDObject* obj : selectedObjects()) |
178 for (LDObject* object : selectedObjects()) |
182 { |
179 { |
183 LDSubfileReference* ref = dynamic_cast<LDSubfileReference*> (obj); |
180 LDSubfileReference* reference = dynamic_cast<LDSubfileReference*>(object); |
184 |
181 |
185 if (ref and ref->fileInfo()->isCache()) |
182 if (reference and reference->fileInfo()->isCache()) |
186 ref->fileInfo()->openForEditing(); |
183 reference->fileInfo()->openForEditing(); |
187 } |
184 } |
188 } |
185 } |
189 |
186 |
190 void FileToolset::downloadFrom() |
187 void FileToolset::downloadFrom() |
191 { |
188 { |
192 PartDownloader* dialog = new PartDownloader (m_window); |
189 PartDownloader* dialog = new PartDownloader (m_window); |
193 connect (dialog, &PartDownloader::primaryFileDownloaded, [&]() |
190 connect(dialog, &PartDownloader::primaryFileDownloaded, [&]() |
194 { |
191 { |
195 m_window->changeDocument (dialog->primaryFile()); |
192 m_window->changeDocument (dialog->primaryFile()); |
196 m_window->doFullRefresh(); |
193 m_window->doFullRefresh(); |
197 m_window->renderer()->resetAngles(); |
194 m_window->renderer()->resetAngles(); |
198 }); |
195 }); |