no message
This commit is contained in:
62
src/_VisualDVM/Passes/All/DeleteDirectory.java
Normal file
62
src/_VisualDVM/Passes/All/DeleteDirectory.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package _VisualDVM.Passes.All;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI_;
|
||||
import _VisualDVM.Current;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Visual.UI;
|
||||
import _VisualDVM.Utils;
|
||||
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
||||
import _VisualDVM.Passes.Project.ChangeFilePass;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
import Common.Passes.PassException;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
public class DeleteDirectory extends ChangeFilePass {
|
||||
@Override
|
||||
public String getIconPath() {
|
||||
return "/icons/Delete.png";
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) {
|
||||
resetArgs();
|
||||
dst_node = Global.mainModule.getProjectNode();
|
||||
if ((dst_node != null) && (dst_node.getUserObject() instanceof File)) {
|
||||
target_dir = Global.mainModule.getSelectedDirectory();
|
||||
if (target_dir.equals(project.Home)) {
|
||||
Log.Writeln("Нельзя удалять домашнюю папку проекта.");
|
||||
return false;
|
||||
}
|
||||
return (UI_.Warning("Удалить папку\n" + Utils_.Brackets(target_dir.getAbsolutePath())
|
||||
+ "\n и всё её содержимое."));
|
||||
} else Log.Writeln_("Папка не выделена.");
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void performPreparation() throws Exception {
|
||||
if (Global.mainModule.HasFile() && (Utils.isAnchestor(Global.mainModule.getFile().file, target_dir)))
|
||||
Global.mainModule.getPass(PassCode.CloseCurrentFile).Do();
|
||||
}
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
FileUtils.deleteDirectory(target_dir);
|
||||
if (target_dir.exists()) throw new PassException("Не удалось удалить папку");
|
||||
UI.getMainWindow().getProjectWindow().getFilesTreeForm().getTree().RemoveNode(dst_node);
|
||||
Vector<DBProjectFile> to_delete = new Vector<>();
|
||||
for (DBProjectFile file : project.db.files.Data.values()) {
|
||||
if (Utils.isAnchestor(file.file, target_dir))
|
||||
to_delete.add(file);
|
||||
}
|
||||
//так как имя первичный ключ приходится удалять их из бд проекта.
|
||||
for (DBProjectFile file : to_delete) {
|
||||
file.CleanAll();
|
||||
file.father.db.Delete(file);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void performDone() throws Exception {
|
||||
Global.mainModule.set(Current.SelectedDirectory, null);
|
||||
Global.mainModule.set(Current.ProjectNode, null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user