Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/CreateEmptyDirectory.java
2024-10-11 00:00:30 +03:00

42 lines
1.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package Visual_DVM_2021.Passes.All;
import Common.Utils.Utils_;
import _VisualDVM.Constants;
import _VisualDVM.Current;
import _VisualDVM.Visual.UI;
import Common.Visual.Windows.Dialog.Text.FileNameForm;
import Visual_DVM_2021.Passes.ChangeFilePass;
import Common.Passes.PassException;
import javax.swing.tree.DefaultMutableTreeNode;
import java.io.File;
import java.nio.file.Paths;
public class CreateEmptyDirectory extends ChangeFilePass {
@Override
protected boolean canStart(Object... args) {
resetArgs();
if ((ff = new FileNameForm()).ShowDialog("Введите имя создаваемой папки")) {
fileName = ff.Result;
//->
parent_node = Current.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;
}
if (fileName.equalsIgnoreCase(Constants.data)) {
Log.Writeln(Utils_.Brackets(Constants.data) + " является зарезервированным именем!");
return false;
}
return true;
}
return false;
}
@Override
protected void body() throws Exception {
if (!dst.mkdir()) throw new PassException("Не удалось создать папку.");
UI.getMainWindow().getProjectWindow().getFilesTreeForm().getTree().AddNode(parent_node, dst_node = new DefaultMutableTreeNode(dst));
}
}