no message
This commit is contained in:
70
src/_VisualDVM/Passes/All/RenameFile.java
Normal file
70
src/_VisualDVM/Passes/All/RenameFile.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package _VisualDVM.Passes.All;
|
||||
import Common.Utils.Utils_;
|
||||
import _VisualDVM.Current;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Visual.UI;
|
||||
import Common.Visual.Windows.Dialog.Text.FileNameForm;
|
||||
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
||||
import _VisualDVM.ProjectData.Files.FileType;
|
||||
import _VisualDVM.Passes.Project.ChangeFilePass;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
import Common.Passes.PassException;
|
||||
|
||||
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;
|
||||
if (Global.mainModule.Check(Log, Current.SelectedFile)) {
|
||||
old = Global.mainModule.getSelectedFile();
|
||||
current = Global.mainModule.HasFile() && Global.mainModule.getFile().file.equals(old.file);
|
||||
if ((ff = new FileNameForm()).ShowDialog("Введите новое имя файла", old.file.getName())) {
|
||||
fileName = ff.Result;
|
||||
//->
|
||||
parent_node = Global.mainModule.getProjectCurrentParentNode();
|
||||
target_dir = (File) parent_node.getUserObject();
|
||||
//->
|
||||
dst = Paths.get(target_dir.getAbsolutePath(), fileName).toFile();
|
||||
if (dst.exists()) {
|
||||
Log.Writeln_("Файл с именем " + Utils_.Brackets(fileName) + " уже существует");
|
||||
return false;
|
||||
}
|
||||
target = new DBProjectFile(dst, project);
|
||||
if (target.fileType == FileType.forbidden)
|
||||
Log.Writeln_("Расширение " + Utils_.Brackets(Utils_.getExtension(dst)) + " недопустимо");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void performPreparation() throws Exception {
|
||||
if (current)
|
||||
Global.mainModule.getPass(PassCode.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 {
|
||||
Global.mainModule.getSapfor().ResetAllAnalyses();
|
||||
Global.mainModule.set(Current.SelectedFile, target);
|
||||
if (current)
|
||||
Global.mainModule.getPass(PassCode.OpenCurrentFile).Do(target);
|
||||
}
|
||||
@Override
|
||||
protected void showDone() throws Exception {
|
||||
UI.getMainWindow().getProjectWindow().getFilesTreeForm().getTree().RefreshNode(target.node);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user