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

152 lines
6.0 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.Constants;
import Common_old.Current;
import _VisualDVM.Global;
import Common_old.UI.DebugPrintLevel;
import Common_old.UI.UI;
import Common_old.Utils.Files.VDirectoryChooser;
import Common_old.Utils.Utils;
2023-09-17 22:13:42 +03:00
import GlobalData.DBLastProject.DBLastProject;
import GlobalData.Settings.SettingName;
import ProjectData.Files.LanguageStyle;
import ProjectData.Project.db_project_info;
2023-11-22 02:24:55 +03:00
import ProjectData.ProjectView;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
2023-09-17 22:13:42 +03:00
import java.io.File;
public class OpenCurrentProject extends Pass_2021<db_project_info> {
Mode mode = Mode.Undefined;
File dir = null;
boolean root_changes;
db_project_info new_root = null;
VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор домашней папки проекта");
@Override
public String getIconPath() {
return "/icons/OpenProject.png";
}
@Override
public String getButtonText() {
return "";
}
@Override
protected boolean needsAnimation() {
return true;
}
boolean needsOpen() {
return !Current.HasProject() || !Current.getProject().Home.equals(dir);
}
//-----------------
@Override
protected boolean canStart(Object... args) throws Exception {
mode = Mode.Directory;
dir = null;
target = null;
if (args.length == 0) {
Utils.RestoreSelectedDirectory(directoryChooser);
2023-09-17 22:13:42 +03:00
dir = directoryChooser.ShowDialog();
} else {
Object arg = args[0];
if (arg instanceof File) {
dir = (File) arg;
} else if (arg instanceof db_project_info) {
mode = Mode.ProjectInfo;
target = (db_project_info) arg;
dir = target.Home;
2024-10-07 22:04:09 +03:00
CommonUtils.MainLog.Print(DebugPrintLevel.Project, "готовая версия " + CommonUtils.Brackets(dir.getAbsolutePath()));
2023-09-17 22:13:42 +03:00
return needsOpen();
}
}
if ((dir != null) && needsOpen()) {
2024-10-07 22:04:09 +03:00
CommonUtils.MainLog.Print(DebugPrintLevel.Project, CommonUtils.Brackets(dir.toString()));
2023-09-17 22:13:42 +03:00
if (!dir.isDirectory()) {
2024-10-07 14:22:52 +03:00
Log.Writeln_(CommonUtils.Brackets(dir) + "\е является папкой!");
2023-09-17 22:13:42 +03:00
return false;
}
if (dir.getName().equals(Constants.data)) {
2024-10-07 14:22:52 +03:00
Log.Writeln_(CommonUtils.Brackets(dir) + "\nявляется служебной папкой визуализатора!");
2023-09-17 22:13:42 +03:00
return false;
}
return Utils.validateProjectFolder(dir, Log) && Utils.containsSource(dir, true);
}
return false;
}
@Override
protected void performPreparation() throws Exception {
passes.get(PassCode_2021.CloseCurrentProject).Do();
}
@Override
protected void body() throws Exception {
root_changes = true;
switch (mode) {
case Directory:
if (Current.HasRoot()) {
db_project_info root = Current.getRoot();
db_project_info project = root.find_version_r(dir);
if (project != null) {
2024-10-07 22:04:09 +03:00
CommonUtils.MainLog.Print("версия найдена в текущем корне");
2023-09-17 22:13:42 +03:00
//версия уже существует. и выстраивать дерево второй раз не нужно.
//как и отображать дерево.
target = project;
target.Open();
root_changes = false;
return;
}
}
2024-10-07 22:04:09 +03:00
CommonUtils.MainLog.Print(DebugPrintLevel.Project, "построение дерева версий");
2023-09-17 22:13:42 +03:00
target = new db_project_info(dir);
new_root = target.CreateVersionsTree();
target.Open();
break;
case ProjectInfo:
//если нам суют версию. значит уже априори корень не сменится.
root_changes = false;
target.Open();
break;
}
}
@Override
protected void performDone() throws Exception {
CurrentAnchestor.set(Current.Project, target);
CurrentAnchestor.set(Current.ProjectView, ProjectView.Files);
2023-09-17 22:13:42 +03:00
if (root_changes)
CurrentAnchestor.set(Current.Root, new_root);
2023-11-20 22:29:38 +03:00
Pass_2021.passes.get(PassCode_2021.UpdateSetting).Do(SettingName.ProjectsSearchDirectory, dir.getParent());
2023-09-17 22:13:42 +03:00
Pass_2021.passes.get(PassCode_2021.UpdateSetting).Do(
SettingName.FREE_FORM, target.style.equals(LanguageStyle.free) ? "1" : "0")
;
DBLastProject lastProject;
if (Global.db.lastProjects.containsKey(target.Home.getAbsolutePath())) {
lastProject = Global.db.lastProjects.get(target.Home.getAbsolutePath());
lastProject.RefreshOpenTime();
Global.db.Update(lastProject);
} else {
lastProject = new DBLastProject(target);
Global.db.Insert(lastProject);
}
target.setInfo(lastProject);
}
@Override
protected void showDone() throws Exception {
if (root_changes)
UI.CreateVersionsWindow();
UI.getVersionsWindow().ShowProjectVariants();
UI.getVersionsWindow().BlockVariants();
//-
UI.getMainWindow().ShowProject();
//криво. но при тихом режиме открытие файлов все равно не понадобится.
passes.get(PassCode_2021.OpenCurrentFile).Do(target.getLastOpenedFile());
}
@Override
protected void FocusResult() {
UI.getMainWindow().FocusProject();
}
enum Mode {
Undefined,
Directory,
ProjectInfo
}
}