MCPcopy Create free account
hub / github.com/benfry/processing4 / startSaveAsThread

Method startSaveAsThread

app/src/processing/app/Sketch.java:1057–1216  ·  view source on GitHub ↗

Kick off a background thread to copy everything but the .pde files. Due to the poor way (dating back to the late 90s with DBN) that our save() and saveAs() methods have been implemented to return booleans, there isn't a good way to return a value to the calling thread without a good bit of refactori

(final File newFolder, final File[] copyItems)

Source from the content-addressed store, hash-verified

1055 * <a href="https://github.com/processing/processing/issues/3843">3843</a>
1056 */
1057 void startSaveAsThread(final File newFolder, final File[] copyItems) {
1058 saving.set(true);
1059 EventQueue.invokeLater(() -> {
1060 final JFrame frame =
1061 new JFrame("Saving “" + newFolder.getName() + "“…");
1062 frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
1063
1064 Box box = Box.createVerticalBox();
1065 box.setBorder(new EmptyBorder(16, 16, 16, 16));
1066
1067 if (Platform.isMacOS()) {
1068 frame.setBackground(Color.WHITE);
1069 }
1070
1071 JLabel label =
1072 new JLabel("Saving additional files from the sketch folder...");
1073 box.add(label);
1074 box.add(Box.createVerticalStrut(8));
1075
1076 final JProgressBar progressBar = new JProgressBar(0, 100);
1077 // no luck, stuck with ugly on OS X
1078 //progressBar.putClientProperty("JComponent.sizeVariant", "regular");
1079 progressBar.setValue(0);
1080 progressBar.setStringPainted(true);
1081 box.add(progressBar);
1082
1083 frame.getContentPane().add(box);
1084 frame.pack();
1085 frame.setLocationRelativeTo(editor);
1086 Toolkit.setIcon(frame);
1087 frame.setVisible(true);
1088
1089 new SwingWorker<Void, Void>() {
1090
1091 @Override
1092 protected Void doInBackground() throws Exception {
1093 addPropertyChangeListener(evt -> {
1094 if ("progress".equals(evt.getPropertyName())) {
1095 progressBar.setValue((Integer) evt.getNewValue());
1096 }
1097 });
1098
1099 long totalSize = 0;
1100 for (File copyable : copyItems) {
1101 totalSize += Util.calcSize(copyable);
1102 }
1103
1104 long progress = 0;
1105 setProgress(0);
1106 for (File copyable : copyItems) {
1107 if (copyable.isDirectory()) {
1108 copyDir(copyable,
1109 new File(newFolder, copyable.getName()),
1110 progress, totalSize);
1111 progress += Util.calcSize(copyable);
1112 } else {
1113 copyFile(copyable,
1114 new File(newFolder, copyable.getName()),

Callers 1

saveAsMethod · 0.95

Calls 8

isMacOSMethod · 0.95
setIconMethod · 0.95
setMethod · 0.65
setVisibleMethod · 0.65
getNameMethod · 0.45
addMethod · 0.45
setValueMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected