Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/shared/lib/languages/PDE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ menu.file.close = Close
menu.file.save = Save
menu.file.save_as = Save As...
menu.file.export_application = Export Application...
menu.file.export_pdez = Export as PDEZ...
menu.file.page_setup = Page Setup
menu.file.print = Print...
menu.file.preferences = Preferences...
Expand Down
62 changes: 61 additions & 1 deletion java/src/processing/mode/java/JavaEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import javax.swing.*;
import javax.swing.event.*;
Expand Down Expand Up @@ -228,7 +232,17 @@ public JMenu buildFileMenu() {
}
});

return buildFileMenu(new JMenuItem[] { exportApplication });
var exportPDEZ = new JMenuItem(Language.text("menu.file.export_pdez"));
exportPDEZ.addActionListener(e -> {
if (sketch.isUntitled() || sketch.isReadOnly()) {
Messages.showMessage("Save First", "Please first save the sketch.");
} else {
handleExportPDEZ();
}
});


return buildFileMenu(new JMenuItem[] { exportApplication, exportPDEZ });
}


Expand Down Expand Up @@ -489,6 +503,52 @@ public void handleExportApplication() {
}
}

/**
* Handler for File → Export PDEZ
*/
public void handleExportPDEZ() {
if (handleExportCheckModified()) {
var sketch = getSketch();
var folder = sketch.getFolder().toPath();
var target = new File(folder + ".pdez").toPath();
if (Files.exists(target)) {
try {
Platform.deleteFile(target.toFile());
} catch (IOException e) {
Messages.showError("Export Error", "Could not delete existing file: " + target, e);
}
}

try (var zs = new ZipOutputStream(Files.newOutputStream(target))) {
Files.walk(folder)
.filter(path -> !Files.isDirectory(path))
.forEach(path -> {
var zipEntry = new ZipEntry(folder.getParent().relativize(path).toString());
try {
zs.putNextEntry(zipEntry);
Files.copy(path, zs);
zs.closeEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
if (Desktop.isDesktopSupported()) {
var desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE_FILE_DIR)) {
desktop.browseFileDirectory(target.toFile());
} else {
try {
desktop.open(target.getParent().toFile());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
}

/**
* Checks to see if the sketch has been modified, and if so,
Expand Down
Loading