42 lines
1.6 KiB
Java
42 lines
1.6 KiB
Java
package Common.Passes.All;
|
||
import Common.Constants;
|
||
import Common.Current;
|
||
import Common.UI.UI;
|
||
import Common.UI.Windows.Dialog.Text.FileNameForm;
|
||
import Common.Utils.Utils;
|
||
import Common.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));
|
||
}
|
||
}
|