use system trash to delete left-behind empty folders / hidden files
This commit is contained in:
parent
5974367fd1
commit
935c01a6ed
|
@ -120,6 +120,14 @@ public class MacAppUtilities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void moveToTrash(File file) {
|
||||||
|
try {
|
||||||
|
FileManager.moveToTrash(file);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
debug.log(Level.WARNING, t.getMessage(), t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void setDefaultMenuBar(JMenuBar menu) {
|
public static void setDefaultMenuBar(JMenuBar menu) {
|
||||||
try {
|
try {
|
||||||
Application.getApplication().setDefaultMenuBar(menu);
|
Application.getApplication().setDefaultMenuBar(menu);
|
||||||
|
|
|
@ -18,10 +18,10 @@ import java.awt.event.ActionEvent;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
import java.util.AbstractMap.SimpleEntry;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -182,13 +182,19 @@ class RenameAction extends AbstractAction {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (File f : empty) {
|
// use system trash to delete left-behind empty folders / hidden files
|
||||||
try {
|
moveToTrash(empty);
|
||||||
debug.finest(format("Delete empty folder: %s", f));
|
|
||||||
Files.delete(f.toPath());
|
|
||||||
} catch (Exception e) {
|
|
||||||
debug.warning(e::toString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void moveToTrash(Collection<File> files) {
|
||||||
|
try {
|
||||||
|
if (isMacApp()) {
|
||||||
|
files.stream().forEach(MacAppUtilities::moveToTrash);
|
||||||
|
} else {
|
||||||
|
com.sun.jna.platform.FileUtils.getInstance().moveToTrash(files.toArray(new File[0]));
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
debug.log(Level.WARNING, e, e::getMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue