2023-11-19 02:12:44 +03:00
|
|
|
|
package Visual_DVM_2021.Passes.All;
|
2024-10-08 00:39:13 +03:00
|
|
|
|
import Common.CurrentAnchestor;
|
2024-10-07 14:22:52 +03:00
|
|
|
|
import Common.Utils.CommonUtils;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import Common_old.Current;
|
|
|
|
|
|
import Common_old.UI.UI;
|
2024-10-08 22:33:49 +03:00
|
|
|
|
import Common.Visual.Windows.Dialog.Text.FileNameForm;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import ProjectData.Files.DBProjectFile;
|
|
|
|
|
|
import ProjectData.Files.FileType;
|
2023-11-19 02:12:44 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.ChangeFilePass;
|
|
|
|
|
|
import Visual_DVM_2021.Passes.PassCode_2021;
|
|
|
|
|
|
import Visual_DVM_2021.Passes.PassException;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
public class RenameFile extends ChangeFilePass<DBProjectFile> {
|
|
|
|
|
|
DBProjectFile old;
|
|
|
|
|
|
boolean current;
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean canStart(Object... args) {
|
|
|
|
|
|
resetArgs();
|
|
|
|
|
|
current = false;
|
2024-10-08 00:39:13 +03:00
|
|
|
|
if (CurrentAnchestor.Check(Log, Current.SelectedFile)) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
old = Current.getSelectedFile();
|
|
|
|
|
|
current = Current.HasFile() && Current.getFile().file.equals(old.file);
|
|
|
|
|
|
if ((ff = new FileNameForm()).ShowDialog("Введите новое имя файла", old.file.getName())) {
|
|
|
|
|
|
fileName = ff.Result;
|
|
|
|
|
|
//->
|
|
|
|
|
|
parent_node = Current.getProjectCurrentParentNode();
|
|
|
|
|
|
target_dir = (File) parent_node.getUserObject();
|
|
|
|
|
|
//->
|
|
|
|
|
|
dst = Paths.get(target_dir.getAbsolutePath(), fileName).toFile();
|
|
|
|
|
|
if (dst.exists()) {
|
2024-10-07 14:22:52 +03:00
|
|
|
|
Log.Writeln_("Файл с именем " + CommonUtils.Brackets(fileName) + " уже существует");
|
2023-09-17 22:13:42 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
target = new DBProjectFile(dst, project);
|
|
|
|
|
|
if (target.fileType == FileType.forbidden)
|
2024-10-07 14:22:52 +03:00
|
|
|
|
Log.Writeln_("Расширение " + CommonUtils.Brackets(CommonUtils.getExtension(dst)) + " недопустимо");
|
2023-09-17 22:13:42 +03:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void performPreparation() throws Exception {
|
|
|
|
|
|
if (current)
|
|
|
|
|
|
passes.get(PassCode_2021.CloseCurrentFile).Do();
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void body() throws Exception {
|
|
|
|
|
|
if (!old.file.renameTo(dst)) throw new PassException("Не удалось переименовать файл");
|
|
|
|
|
|
project.db.Delete(old);
|
|
|
|
|
|
old.node.setUserObject(target);
|
|
|
|
|
|
target.node = old.node;
|
|
|
|
|
|
target.file = dst;
|
|
|
|
|
|
target.RefreshName();
|
|
|
|
|
|
project.db.Insert(target);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void performDone() throws Exception {
|
|
|
|
|
|
Current.getSapfor().ResetAllAnalyses();
|
2024-10-08 00:39:13 +03:00
|
|
|
|
CurrentAnchestor.set(Current.SelectedFile, target);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (current)
|
|
|
|
|
|
passes.get(PassCode_2021.OpenCurrentFile).Do(target);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void showDone() throws Exception {
|
|
|
|
|
|
UI.getMainWindow().getProjectWindow().getFilesTreeForm().getTree().RefreshNode(target.node);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|