2023-11-19 02:12:44 +03:00
|
|
|
|
package Visual_DVM_2021.Passes.All;
|
2024-10-09 23:37:58 +03:00
|
|
|
|
import Common.Current_;
|
2024-10-07 14:22:52 +03:00
|
|
|
|
import Common.Utils.CommonUtils;
|
2024-10-09 22:01:19 +03:00
|
|
|
|
import _VisualDVM.Current;
|
|
|
|
|
|
import _VisualDVM.Visual.UI;
|
2024-10-08 22:33:49 +03:00
|
|
|
|
import Common.Visual.Windows.Dialog.Text.FileNameForm;
|
2024-10-09 22:01:19 +03:00
|
|
|
|
import _VisualDVM.Utils;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
2023-11-19 02:12:44 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.ChangeFilePass;
|
2024-10-09 23:37:58 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.PassCode;
|
2024-10-10 23:57:36 +03:00
|
|
|
|
import Common.Passes.PassException;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
public class RenameDirectory extends ChangeFilePass {
|
|
|
|
|
|
boolean current;
|
|
|
|
|
|
DBProjectFile old_current_file;
|
|
|
|
|
|
DBProjectFile new_current_file;
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean canStart(Object... args) {
|
|
|
|
|
|
resetArgs();
|
|
|
|
|
|
current = false;
|
|
|
|
|
|
old_current_file = null;
|
|
|
|
|
|
new_current_file = null;
|
|
|
|
|
|
dst_node = Current.getProjectNode();
|
|
|
|
|
|
if ((dst_node != null) && (dst_node.getUserObject() instanceof File)) {
|
|
|
|
|
|
target_dir = Current.getSelectedDirectory();
|
|
|
|
|
|
if (current = Current.HasFile() && Utils.isAnchestor(Current.getFile().file, target_dir)) {
|
|
|
|
|
|
old_current_file = Current.getFile();
|
|
|
|
|
|
}
|
|
|
|
|
|
if ((ff = new FileNameForm()).ShowDialog("Введите новое имя папки", target_dir.getName())) {
|
|
|
|
|
|
fileName = ff.Result;
|
|
|
|
|
|
dst = Paths.get(target_dir.getParentFile().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;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (target_dir.equals(project.Home)) {
|
|
|
|
|
|
Log.Writeln("Нельзя переименовывать домашнюю папку проекта.");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else Log.Writeln("Папка не выделена.");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void performPreparation() throws Exception {
|
|
|
|
|
|
if (current)
|
2024-10-09 23:37:58 +03:00
|
|
|
|
passes.get(PassCode.CloseCurrentFile).Do();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void body() throws Exception {
|
|
|
|
|
|
FileUtils.moveDirectory(target_dir, dst);
|
|
|
|
|
|
if (!dst.exists()) throw new PassException("Не удалось переименовать папку");
|
|
|
|
|
|
//теперь все файлы и подпапки которые были в этой папке должны быть переосмыслены.
|
|
|
|
|
|
Vector<DBProjectFile> to_rename = new Vector<>();
|
|
|
|
|
|
for (DBProjectFile file : project.db.files.Data.values()) {
|
|
|
|
|
|
if (Utils.isAnchestor(file.file, target_dir)) {
|
|
|
|
|
|
to_rename.add(file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//так как имя первичный ключ приходится удалять их из бд проекта.
|
|
|
|
|
|
for (DBProjectFile file : to_rename) {
|
|
|
|
|
|
if (current && file.file.equals(old_current_file.file)) {
|
|
|
|
|
|
new_current_file = file;
|
|
|
|
|
|
}
|
|
|
|
|
|
file.CleanAll();
|
|
|
|
|
|
file.father.db.Delete(file);
|
|
|
|
|
|
file.file = Paths.get(dst.getAbsolutePath(), Utils.getRelativeAddress(file.file, target_dir)).toFile();
|
|
|
|
|
|
file.RefreshName();
|
|
|
|
|
|
file.father.db.Insert(file);
|
|
|
|
|
|
}
|
|
|
|
|
|
dst_node.setUserObject(dst);
|
|
|
|
|
|
for (int i = 0; i < dst_node.getChildCount(); ++i)
|
|
|
|
|
|
Utils.renameSubdirs_r((DefaultMutableTreeNode) dst_node.getChildAt(i), target_dir, dst);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void performDone() throws Exception {
|
|
|
|
|
|
Current.getSapfor().ResetAllAnalyses();
|
2024-10-09 23:37:58 +03:00
|
|
|
|
Current_.set(Current.SelectedDirectory, dst);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (current && new_current_file != null)
|
2024-10-09 23:37:58 +03:00
|
|
|
|
passes.get(PassCode.OpenCurrentFile).Do(new_current_file);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void showDone() throws Exception {
|
|
|
|
|
|
UI.getMainWindow().getProjectWindow().getFilesTreeForm().getTree().RefreshNode(dst_node);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|