|
28 | 28 | import java.io.*;
|
29 | 29 | import java.net.HttpURLConnection;
|
30 | 30 | import java.net.URL;
|
| 31 | +import java.nio.file.Files; |
| 32 | +import java.nio.file.Path; |
31 | 33 | import java.util.ArrayList;
|
32 | 34 | import java.util.List;
|
33 | 35 | import java.util.Map;
|
| 36 | +import java.util.zip.ZipEntry; |
| 37 | +import java.util.zip.ZipOutputStream; |
34 | 38 |
|
35 | 39 | import javax.swing.*;
|
36 | 40 | import javax.swing.event.*;
|
@@ -228,7 +232,17 @@ public JMenu buildFileMenu() {
|
228 | 232 | }
|
229 | 233 | });
|
230 | 234 |
|
231 |
| - return buildFileMenu(new JMenuItem[] { exportApplication }); |
| 235 | + var exportPDEZ = new JMenuItem(Language.text("menu.file.export_pdez")); |
| 236 | + exportPDEZ.addActionListener(e -> { |
| 237 | + if (sketch.isUntitled() || sketch.isReadOnly()) { |
| 238 | + Messages.showMessage("Save First", "Please first save the sketch."); |
| 239 | + } else { |
| 240 | + handleExportPDEZ(); |
| 241 | + } |
| 242 | + }); |
| 243 | + |
| 244 | + |
| 245 | + return buildFileMenu(new JMenuItem[] { exportApplication, exportPDEZ }); |
232 | 246 | }
|
233 | 247 |
|
234 | 248 |
|
@@ -489,6 +503,52 @@ public void handleExportApplication() {
|
489 | 503 | }
|
490 | 504 | }
|
491 | 505 |
|
| 506 | + /** |
| 507 | + * Handler for File → Export PDEZ |
| 508 | + */ |
| 509 | + public void handleExportPDEZ() { |
| 510 | + if (handleExportCheckModified()) { |
| 511 | + var sketch = getSketch(); |
| 512 | + var folder = sketch.getFolder().toPath(); |
| 513 | + var target = new File(folder + ".pdez").toPath(); |
| 514 | + if (Files.exists(target)) { |
| 515 | + try { |
| 516 | + Platform.deleteFile(target.toFile()); |
| 517 | + } catch (IOException e) { |
| 518 | + Messages.showError("Export Error", "Could not delete existing file: " + target, e); |
| 519 | + } |
| 520 | + } |
| 521 | + |
| 522 | + try (var zs = new ZipOutputStream(Files.newOutputStream(target))) { |
| 523 | + Files.walk(folder) |
| 524 | + .filter(path -> !Files.isDirectory(path)) |
| 525 | + .forEach(path -> { |
| 526 | + var zipEntry = new ZipEntry(folder.getParent().relativize(path).toString()); |
| 527 | + try { |
| 528 | + zs.putNextEntry(zipEntry); |
| 529 | + Files.copy(path, zs); |
| 530 | + zs.closeEntry(); |
| 531 | + } catch (IOException e) { |
| 532 | + throw new RuntimeException(e); |
| 533 | + } |
| 534 | + }); |
| 535 | + } catch (IOException e) { |
| 536 | + throw new RuntimeException(e); |
| 537 | + } |
| 538 | + if (Desktop.isDesktopSupported()) { |
| 539 | + var desktop = Desktop.getDesktop(); |
| 540 | + if (desktop.isSupported(Desktop.Action.BROWSE_FILE_DIR)) { |
| 541 | + desktop.browseFileDirectory(target.toFile()); |
| 542 | + } else { |
| 543 | + try { |
| 544 | + desktop.open(target.getParent().toFile()); |
| 545 | + } catch (IOException e) { |
| 546 | + throw new RuntimeException(e); |
| 547 | + } |
| 548 | + } |
| 549 | + } |
| 550 | + } |
| 551 | + } |
492 | 552 |
|
493 | 553 | /**
|
494 | 554 | * Checks to see if the sketch has been modified, and if so,
|
|
0 commit comments