2024-10-14 12:14:01 +03:00
|
|
|
|
package _VisualDVM.Passes.All;
|
2024-10-11 00:00:30 +03:00
|
|
|
|
import Common.Utils.Utils_;
|
|
|
|
|
|
import Common.Visual.UI_;
|
2024-10-09 22:01:19 +03:00
|
|
|
|
import _VisualDVM.Current;
|
2024-10-13 22:08:13 +03:00
|
|
|
|
import _VisualDVM.Global;
|
2024-10-09 22:01:19 +03:00
|
|
|
|
import _VisualDVM.Visual.UI;
|
|
|
|
|
|
import _VisualDVM.Utils;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
2024-10-14 12:14:01 +03:00
|
|
|
|
import _VisualDVM.Passes.Project.ChangeFilePass;
|
|
|
|
|
|
import _VisualDVM.Passes.PassCode;
|
2024-10-10 23:57:36 +03:00
|
|
|
|
import Common.Passes.PassException;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
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();
|
2024-10-13 22:08:13 +03:00
|
|
|
|
dst_node = Global.mainModule.getProjectNode();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if ((dst_node != null) && (dst_node.getUserObject() instanceof File)) {
|
2024-10-13 22:08:13 +03:00
|
|
|
|
target_dir = Global.mainModule.getSelectedDirectory();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (target_dir.equals(project.Home)) {
|
|
|
|
|
|
Log.Writeln("Нельзя удалять домашнюю папку проекта.");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2024-10-11 00:00:30 +03:00
|
|
|
|
return (UI_.Warning("Удалить папку\n" + Utils_.Brackets(target_dir.getAbsolutePath())
|
2023-09-17 22:13:42 +03:00
|
|
|
|
+ "\n и всё её содержимое."));
|
|
|
|
|
|
} else Log.Writeln_("Папка не выделена.");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void performPreparation() throws Exception {
|
2024-10-13 22:08:13 +03:00
|
|
|
|
if (Global.mainModule.HasFile() && (Utils.isAnchestor(Global.mainModule.getFile().file, target_dir)))
|
2024-10-13 23:55:03 +03:00
|
|
|
|
Global.mainModule.getPass(PassCode.CloseCurrentFile).Do();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
@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 {
|
2024-10-13 22:08:13 +03:00
|
|
|
|
Global.mainModule.set(Current.SelectedDirectory, null);
|
|
|
|
|
|
Global.mainModule.set(Current.ProjectNode, null);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|