Skip to content

Commit a9a589c

Browse files
committed
replace uses of Util.deleteFile() with Platform calls that use the Trash
1 parent 5446e22 commit a9a589c

File tree

6 files changed

+60
-10
lines changed

6 files changed

+60
-10
lines changed

app/src/processing/app/Sketch.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,12 @@ public boolean saveAs() throws IOException {
946946
// if the new folder already exists, then first remove its contents before
947947
// copying everything over (user will have already been warned).
948948
if (newFolder.exists()) {
949-
Util.removeDir(newFolder);
949+
//Util.removeDir(newFolder);
950+
try {
951+
Platform.deleteFile(newFolder);
952+
} catch (IOException e) {
953+
e.printStackTrace();
954+
}
950955
}
951956
// in fact, you can't do this on Windows because the file dialog
952957
// will instead put you inside the folder, but it happens on OS X a lot.

app/src/processing/app/Util.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,14 @@ static public void copyDirNative(File sourceDir,
305305
/**
306306
* Remove all files in a directory and the directory itself.
307307
* Prints error messages with failed filenames. Does not follow symlinks.
308+
* Use Platform.deleteFile() instead, which first attempts to use
309+
* the Trash or Recycle Bin, out of an abundance of caution.
308310
*/
309311
static public boolean removeDir(File dir) {
310312
return removeDir(dir, true);
311313
}
312314

315+
313316
/**
314317
* Remove all files in a directory and the directory itself.
315318
* Optionally, prints error messages with failed filenames.

app/src/processing/app/contrib/AvailableContribution.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ public LocalContribution install(Base base, File contribArchive,
217217
}
218218

219219
// delete the contrib folder inside the libraryXXXXXXtmp folder
220-
Util.removeDir(newContribFolder, false);
221-
220+
//Util.removeDir(newContribFolder, false);
221+
try {
222+
Platform.deleteFile(newContribFolder);
223+
} catch (IOException e) {
224+
e.printStackTrace();
225+
}
222226
} else {
223227
if (status != null) {
224228
status.setErrorMessage(Language.text("contrib.errors.overwriting_properties"));
@@ -229,7 +233,12 @@ public LocalContribution install(Base base, File contribArchive,
229233

230234
// Remove any remaining boogers
231235
if (tempFolder.exists()) {
232-
Util.removeDir(tempFolder, false);
236+
//Util.removeDir(tempFolder, false);
237+
try {
238+
Platform.deleteFile(tempFolder);
239+
} catch (IOException e) {
240+
e.printStackTrace();
241+
}
233242
}
234243
return installedContrib;
235244
}

app/src/processing/app/contrib/ContributionManager.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import processing.app.Base;
3333
import processing.app.Language;
3434
import processing.app.Messages;
35+
import processing.app.Platform;
3536
import processing.app.Util;
3637
import processing.app.ui.Editor;
3738
import processing.core.PApplet;
@@ -546,7 +547,12 @@ static private void deleteTemp(File root) {
546547
if (possible != null) {
547548
for (File f : possible) {
548549
if (f.getName().matches(pattern)) {
549-
Util.removeDir(f);
550+
//Util.removeDir(f);
551+
try {
552+
Platform.deleteFile(f);
553+
} catch (IOException e) {
554+
e.printStackTrace();
555+
}
550556
}
551557
}
552558
}
@@ -562,7 +568,12 @@ static private void deleteFlagged(File root) {
562568
);
563569
if (markedForDeletion != null) {
564570
for (File folder : markedForDeletion) {
565-
Util.removeDir(folder);
571+
//Util.removeDir(folder);
572+
try {
573+
Platform.deleteFile(folder);
574+
} catch (IOException e) {
575+
e.printStackTrace();
576+
}
566577
}
567578
}
568579
}
@@ -629,7 +640,12 @@ else if (type.equalsIgnoreCase("modes"))
629640
if (name != null) { // should not happen, but...
630641
updateContribsNames.add(name);
631642
}
632-
Util.removeDir(folder);
643+
//Util.removeDir(folder);
644+
try {
645+
Platform.deleteFile(folder);
646+
} catch (IOException e) {
647+
e.printStackTrace();
648+
}
633649
}
634650
}
635651

app/src/processing/app/contrib/LocalContribution.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,24 @@ LocalContribution copyAndLoad(Base base,
308308

309309
// At this point it should be safe to replace this fella
310310
if (contribFolder.exists()) {
311-
Util.removeDir(contribFolder);
311+
//Util.removeDir(contribFolder);
312+
try {
313+
Platform.deleteFile(contribFolder);
314+
} catch (IOException e) {
315+
e.printStackTrace();
316+
}
312317
}
313318

314319
} else {
315320
// This if should ideally never happen, since this function
316321
// is to be called only when restarting on update
317322
if (contribFolder.exists() && contribFolder.isDirectory()) {
318-
Util.removeDir(contribFolder);
323+
//Util.removeDir(contribFolder);
324+
try {
325+
Platform.deleteFile(contribFolder);
326+
} catch (IOException e) {
327+
e.printStackTrace();
328+
}
319329
}
320330
else if (contribFolder.exists()) {
321331
contribFolder.delete();
@@ -447,7 +457,12 @@ void remove(final Base base,
447457
if (doBackup) {
448458
success = backup(true, status);
449459
} else {
450-
success = Util.removeDir(getFolder(), false);
460+
try {
461+
success = Platform.deleteFile(getFolder());
462+
} catch (IOException e) {
463+
e.printStackTrace();
464+
success = false;
465+
}
451466
}
452467

453468
if (success) {

todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ X Bring back getMainProgram() for Python Mode
33
X https://github.com/processing/processing4/issues/409
44
X You must first install tweak Mode to use this sketch
55
X https://github.com/processing/processing4/issues/415
6+
X Change straight quotes to smart quotes in the PDE.properties file
7+
X look for other uses of Util.deleteFile() and replace with Platform calls
68
_ test with Python Mode before release
79

810
sketchbook/open/deletions

0 commit comments

Comments
 (0)