295 } |
295 } |
296 |
296 |
297 // ============================================================================= |
297 // ============================================================================= |
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
299 // ============================================================================= |
299 // ============================================================================= |
300 MAKE_ACTION (insertFrom, "Insert from File", "insert-from", "Insert LDraw data from a file.", (0)) { |
300 MAKE_ACTION (insertFrom, "Insert from File", "file-import", "Insert LDraw data from a file.", (0)) { |
301 str fname = QFileDialog::getOpenFileName (); |
301 str fname = QFileDialog::getOpenFileName (); |
302 ulong idx = g_win->getInsertionPoint (); |
302 ulong idx = g_win->getInsertionPoint (); |
303 |
303 |
304 if (!~fname) |
304 if (!~fname) |
305 return; |
305 return; |
327 |
327 |
328 if (historyCopies.size() > 0) { |
328 if (historyCopies.size() > 0) { |
329 History::addEntry (new AddHistory (historyIndices, historyCopies)); |
329 History::addEntry (new AddHistory (historyIndices, historyCopies)); |
330 g_win->fullRefresh (); |
330 g_win->fullRefresh (); |
331 g_win->scrollToSelection (); |
331 g_win->scrollToSelection (); |
|
332 } |
|
333 } |
|
334 |
|
335 // ============================================================================= |
|
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
337 // ============================================================================= |
|
338 MAKE_ACTION (exportTo, "Export To File", "file-export", "Export current selection to file", (0)) { |
|
339 if (g_win->sel ().size () == 0) |
|
340 return; |
|
341 |
|
342 str fname = QFileDialog::getSaveFileName (); |
|
343 if (fname.len () == 0) |
|
344 return; |
|
345 |
|
346 QFile file (fname); |
|
347 if (!file.open (QIODevice::WriteOnly | QIODevice::Text)) { |
|
348 critical (fmt ("Unable to open %s for writing (%s)", fname.chars (), strerror (errno))); |
|
349 return; |
|
350 } |
|
351 |
|
352 for (LDObject* obj : g_win->sel ()) { |
|
353 str contents = obj->getContents (); |
|
354 file.write (contents, contents.len ()); |
|
355 file.write ("\r\n", 2); |
332 } |
356 } |
333 } |
357 } |
334 |
358 |
335 // ============================================================================= |
359 // ============================================================================= |
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |