2023-11-19 02:12:44 +03:00
|
|
|
|
package Visual_DVM_2021.Passes.All;
|
2024-10-07 14:22:52 +03:00
|
|
|
|
import Common.Utils.CommonUtils;
|
2024-10-08 22:33:49 +03:00
|
|
|
|
import Common.Visual.CommonUI;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import _VisualDVM.Global;
|
2024-10-08 22:33:49 +03:00
|
|
|
|
import Common.Visual.Windows.Dialog.Dialog;
|
2024-10-09 22:01:19 +03:00
|
|
|
|
import _VisualDVM.Utils;
|
2023-11-19 02:12:44 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.CurrentProjectPass;
|
|
|
|
|
|
import Visual_DVM_2021.Passes.PassCode_2021;
|
|
|
|
|
|
import Visual_DVM_2021.Passes.UI.CopyProjectFields;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
public class CopyProject extends CurrentProjectPass {
|
|
|
|
|
|
protected File dstFile = null;
|
|
|
|
|
|
protected boolean migrateData = false;
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean hasStats() {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean canStart(Object... args) throws Exception {
|
|
|
|
|
|
if (super.canStart(args)) {
|
|
|
|
|
|
Dialog<Object, CopyProjectFields> dialog = new Dialog<Object, CopyProjectFields>(CopyProjectFields.class) {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public int getDefaultHeight() {
|
|
|
|
|
|
return 230;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void Init(Object... params) {
|
|
|
|
|
|
fields.tfParent.setText(Global.visualiser.getWorkspace().getAbsolutePath());
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void validateFields() {
|
|
|
|
|
|
Utils.validateFileShortNewName(fields.tfName.getText(), Log);
|
|
|
|
|
|
if (!fields.tfParent.getText().isEmpty()) {
|
2024-10-07 14:22:52 +03:00
|
|
|
|
if (CommonUtils.ContainsCyrillic(fields.tfParent.getText()))
|
2023-09-17 22:13:42 +03:00
|
|
|
|
Log.Writeln_("Путь к целевой папке не может содержать кириллицу!");
|
|
|
|
|
|
} else Log.Writeln_("Путь к целевой папке не может быть пустым!");
|
|
|
|
|
|
if (Log.isEmpty()) {
|
|
|
|
|
|
dstFile = Paths.get(fields.tfParent.getText(), fields.tfName.getText()).toFile();
|
|
|
|
|
|
if (dstFile.exists())
|
|
|
|
|
|
Log.Writeln_("Файл " + dstFile.getAbsolutePath() + " уже существует!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
if (dialog.ShowDialog(getDescription())) {
|
|
|
|
|
|
migrateData = dialog.fields.MigrateData.isSelected();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getIconPath() {
|
|
|
|
|
|
return "/icons/Transformations/CopyProject.png";
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void body() throws Exception {
|
|
|
|
|
|
FileUtils.forceMkdir(dstFile);
|
|
|
|
|
|
target.Clone(dstFile, migrateData);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void performDone() throws Exception {
|
2024-10-08 22:33:49 +03:00
|
|
|
|
if (CommonUI.Question("копия текущего проекта успешно создана по адресу\n" + dstFile.getAbsolutePath() + "\nОткрыть её")) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
passes.get(PassCode_2021.CloseCurrentProject).Do();
|
|
|
|
|
|
passes.get(PassCode_2021.OpenCurrentProject).Do(dstFile);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|