src/extprogs.cpp

changeset 522
afa691788bdb
parent 513
29eb671b34f6
child 526
b29b6fc45ba9
equal deleted inserted replaced
521:b85554206155 522:afa691788bdb
146 return true; 146 return true;
147 } 147 }
148 148
149 // ============================================================================= 149 // =============================================================================
150 // ----------------------------------------------------------------------------- 150 // -----------------------------------------------------------------------------
151 void writeObjects (QList<LDObject*>& objects, File& f) 151 static void writeObjects (const QList<LDObject*>& objects, File& f)
152 { for (LDObject * obj : objects) 152 { for (LDObject* obj : objects)
153 { if (obj->getType() == LDObject::Subfile) 153 { if (obj->getType() == LDObject::Subfile)
154 { LDSubfile* ref = static_cast<LDSubfile*> (obj); 154 { LDSubfile* ref = static_cast<LDSubfile*> (obj);
155 QList<LDObject*> objs = ref->inlineContents (LDSubfile::DeepInline); 155 QList<LDObject*> objs = ref->inlineContents (LDSubfile::DeepInline);
156 156
157 writeObjects (objs, f); 157 writeObjects (objs, f);
158 158
159 for (LDObject * obj : objs) 159 for (LDObject* obj : objs)
160 delete obj; 160 delete obj;
161 } 161 }
162 else 162 else
163 f.write (obj->raw() + "\r\n"); 163 f.write (obj->raw() + "\r\n");
164 } 164 }
165 } 165 }
166 166
167 // ============================================================================= 167 // =============================================================================
168 // ----------------------------------------------------------------------------- 168 // -----------------------------------------------------------------------------
169 void writeObjects (QList<LDObject*>& objects, str fname) 169 static void writeObjects (const QList<LDObject*>& objects, str fname)
170 { // Write the input file 170 { // Write the input file
171 File f (fname, File::Write); 171 File f (fname, File::Write);
172 172
173 if (!f) 173 if (!f)
174 { critical (fmt ("Couldn't open temporary file %1 for writing.\n", fname)); 174 { critical (fmt ("Couldn't open temporary file %1 for writing.\n", fname));
180 } 180 }
181 181
182 // ============================================================================= 182 // =============================================================================
183 // ----------------------------------------------------------------------------- 183 // -----------------------------------------------------------------------------
184 void writeSelection (str fname) 184 void writeSelection (str fname)
185 { writeObjects (g_win->sel(), fname); 185 { writeObjects (selection(), fname);
186 } 186 }
187 187
188 // ============================================================================= 188 // =============================================================================
189 // ----------------------------------------------------------------------------- 189 // -----------------------------------------------------------------------------
190 void writeColorGroup (const short colnum, str fname) 190 void writeColorGroup (const short colnum, str fname)
191 { QList<LDObject*> objects; 191 { QList<LDObject*> objects;
192 192
193 for (LDObject * obj : LDFile::current()->objects()) 193 for (LDObject* obj : LDFile::current()->objects())
194 { if (obj->isColored() == false || obj->color() != colnum) 194 { if (obj->isColored() == false || obj->color() != colnum)
195 continue; 195 continue;
196 196
197 objects << obj; 197 objects << obj;
198 } 198 }
278 278
279 // If we replace the objects, delete the selection now. 279 // If we replace the objects, delete the selection now.
280 if (replace) 280 if (replace)
281 g_win->deleteSelection(); 281 g_win->deleteSelection();
282 282
283 for (const short colnum : colorsToReplace) 283 for (const short colnum : colorsToReplace)
284 g_win->deleteByColor (colnum); 284 g_win->deleteByColor (colnum);
285 285
286 // Insert the new objects 286 // Insert the new objects
287 g_win->sel().clear(); 287 LDFile::current()->clearSelection();
288 288
289 for (LDObject * obj : objs) 289 for (LDObject * obj : objs)
290 { if (!obj->isScemantic()) 290 { if (!obj->isScemantic())
291 { delete obj; 291 { delete obj;
292 continue; 292 continue;
293 } 293 }
294 294
295 LDFile::current()->addObject (obj); 295 LDFile::current()->addObject (obj);
296 g_win->sel() << obj; 296 obj->select();
297 } 297 }
298 298
299 g_win->fullRefresh(); 299 g_win->fullRefresh();
300 } 300 }
301 301

mercurial