Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/DeleteVersion.java

62 lines
2.3 KiB
Java
Raw Normal View History

package Visual_DVM_2021.Passes.All;
import Common.CurrentAnchestor;
2024-10-07 14:22:52 +03:00
import Common.Utils.CommonUtils;
import Common_old.Current;
import Common_old.UI.UI;
import Common_old.Utils.Utils;
2023-09-17 22:13:42 +03:00
import ProjectData.Project.db_project_info;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
2023-09-17 22:13:42 +03:00
public class DeleteVersion extends Pass_2021<db_project_info> {
db_project_info parent;
boolean current;
@Override
public String getIconPath() {
return "/icons/Delete.png";
}
@Override
protected boolean canStart(Object... args) {
if (args.length > 0) {
target = (db_project_info) args[0];
current = (Current.getVersion() != null) && Current.getVersion().Home.equals(target.Home);
return true;
} else {
if (((target = Current.getVersion()) != null) && (!Current.hasUI() ||
UI.Warning("Удалить " +
((Current.HasProject() && target.Home.equals(Current.getProject().Home)) ? "текущий проект" : "версию ")
2024-10-07 14:22:52 +03:00
+ CommonUtils.Brackets(target.name)))) {
2023-09-17 22:13:42 +03:00
current = true;
return true;
}
}
return false;
}
@Override
protected void performPreparation() throws Exception {
if (target.parent != null)
target.parent.checkLastModification(target);
if (Current.HasProject()) {
if ((Current.getProject().Home.getAbsolutePath().startsWith(target.Home.getAbsolutePath())))
passes.get(PassCode_2021.CloseCurrentProject).Do();
}
if (Current.hasUI()) {
UI.getVersionsWindow().RemoveVersionFromComparison(target);
}
}
@Override
protected void body() throws Exception {
Utils.forceDeleteWithCheck(target.Home);
}
@Override
protected void performDone() throws Exception {
parent = target.parent;
if (current)
CurrentAnchestor.set(Current.Version, null);
2023-09-17 22:13:42 +03:00
if (parent != null) {
UI.getVersionsWindow().getVersionsForm().getTree().RemoveNode(target.node);
parent.versions.remove(target.name);
} else
CurrentAnchestor.set(Current.Root, null);
2023-09-17 22:13:42 +03:00
}
}