A folder can now be created on all levels

It creates a folder below the folder/project that is selected. ProjectFolder is now no longer set when the project is selected; this allows folder creation at the highest level (i.e. myproj/views instead of myproj/source/views). It is created on disk, but doesn't show up in the workspace yet.
This commit is contained in:
Zevenberge 2017-11-30 21:21:24 +01:00
parent 3900fd4a34
commit 2bf34ed691
3 changed files with 207 additions and 20 deletions

View File

@ -443,6 +443,7 @@
<Link>3rdparty\dsymbol\symbols.d</Link>
</Compile>
<Compile Include="src\dlangide\ui\terminal.d" />
<Compile Include="src\dlangide\ui\newfolder.d" />
</ItemGroup>
<ItemGroup>
<Folder Include="src\ddebug\gdb\" />

View File

@ -21,6 +21,7 @@ import dlangide.ui.commands;
import dlangide.ui.wspanel;
import dlangide.ui.outputpanel;
import dlangide.ui.newfile;
import dlangide.ui.newfolder;
import dlangide.ui.newproject;
import dlangide.ui.dsourceedit;
import dlangide.ui.homescreen;
@ -1365,10 +1366,10 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
createNewProject(false);
return true;
case IDEActions.FileNew:
addProjectItem(cast(Object)a.objectParam);
addFile(cast(Object)a.objectParam);
return true;
case IDEActions.FileNewDirectory:
//static assert(false);
addDirectory(cast(Object)a.objectParam);
return true;
case IDEActions.ProjectFolderRemoveItem:
removeProjectItem(a.objectParam);
@ -1490,8 +1491,47 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
}
private void addFile(Object obj) {
Dialog createNewFileDialog(Project project, ProjectFolder folder) {
NewFileDlg dialog = new NewFileDlg(this, project, folder);
dialog.dialogResult = delegate(Dialog dlg, const Action result) {
if (result.id == ACTION_FILE_NEW_SOURCE_FILE.id) {
FileCreationResult res = cast(FileCreationResult)result.objectParam;
if (res) {
//res.project.reload();
res.project.refresh();
refreshWorkspace();
if (isSupportedSourceTextFileFormat(res.filename)) {
openSourceFile(res.filename, null, true);
}
}
}
};
return dialog;
}
addProjectItem(&createNewFileDialog, obj);
}
private void addDirectory(Object obj) {
Dialog createNewDirectoryDialog(Project project, ProjectFolder folder) {
NewFolderDialog dialog = new NewFolderDialog(this, project, folder);
dialog.dialogResult = delegate(Dialog dlg, const Action result) {
if(result.id == ACTION_FILE_NEW_DIRECTORY.id) {
FileCreationResult res = cast(FileCreationResult)result.objectParam;
if (res) {
//res.project.reload();
res.project.refresh();
refreshWorkspace();
}
}
};
return dialog;
}
addProjectItem(&createNewDirectoryDialog, obj);
}
/// add new file to project
private void addProjectItem(Object obj) {
private void addProjectItem(Dialog delegate(Project, ProjectFolder) dialogFactory, Object obj) {
if (currentWorkspace is null)
return;
if (obj is null && _wsPanel !is null && !currentEditorSourceFile) {
@ -1503,7 +1543,6 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
ProjectFolder folder;
if (cast(Project)obj) {
project = cast(Project)obj;
folder = project.firstSourceFolder;
} else if (cast(ProjectFolder)obj) {
folder = cast(ProjectFolder)obj;
project = folder.project;
@ -1518,22 +1557,8 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
project = srcfile.project;
}
}
//static assert(false, "hier verdergaan okdoei");
if (project && folder && project.workspace is currentWorkspace) {
NewFileDlg dlg = new NewFileDlg(this, project, folder);
dlg.dialogResult = delegate(Dialog dlg, const Action result) {
if (result.id == ACTION_FILE_NEW_SOURCE_FILE.id) {
FileCreationResult res = cast(FileCreationResult)result.objectParam;
if (res) {
//res.project.reload();
res.project.refresh();
refreshWorkspace();
if (isSupportedSourceTextFileFormat(res.filename)) {
openSourceFile(res.filename, null, true);
}
}
}
};
if (project && project.workspace is currentWorkspace) {
Dialog dlg = dialogFactory(project, folder);
dlg.show();
}
}

161
src/dlangide/ui/newfolder.d Normal file
View File

@ -0,0 +1,161 @@
module dlangide.ui.newfolder;
import std.array : empty;
import std.file : mkdir, exists;
import std.path : buildNormalizedPath;
import std.utf : toUTF32;
import dlangui.core.logger;
import dlangui.core.stdaction;
import dlangui.dialogs.dialog;
import dlangui.dml.parser;
import dlangui.widgets.controls;
import dlangui.widgets.editors;
import dlangui.widgets.widget;
import dlangide.ui.commands;
import dlangide.ui.frame;
import dlangide.ui.newfile;
import dlangide.workspace.project;
class NewFolderDialog : Dialog {
private {
IDEFrame _ide;
Project _project;
ProjectFolder _folder;
string _location;
}
this(IDEFrame parent, Project currentProject, ProjectFolder folder) {
super(UIString.fromId("OPTION_NEW_SOURCE_FILE"c), parent.window,
DialogFlag.Modal | DialogFlag.Resizable | DialogFlag.Popup, 500, 400);
_ide = parent;
_icon = "dlangui-logo1";
this._project = currentProject;
this._folder = folder;
if (folder){
_location = folder.filename;
}
else {
_location = currentProject.dir;
}
}
override void initialize() {
super.initialize();
Widget content;
try {
content = parseML(q{
VerticalLayout {
id: vlayout
padding: Rect { 5, 5, 5, 5 }
layoutWidth: fill; layoutHeight: fill
TableLayout {
margins: 5
colCount: 2
layoutWidth: fill; layoutHeight: wrap
TextWidget { text: NAME }
EditLine { id: edName; text: "newfolder"; layoutWidth: fill }
TextWidget { text: OPTION_FILE_PATH }
EditLine { id: edFilePath; text: ""; layoutWidth: fill; readOnly: true }
}
TextWidget { id: statusText; text: ""; layoutWidth: fill; textColor: #FF0000 }
}
});
} catch (Exception e) {
Log.e("Exceptin while parsing DML", e);
throw e;
}
_edFileName = content.childById!EditLine("edName");
_edFilePath = content.childById!EditLine("edFilePath");
_statusText = content.childById!TextWidget("statusText");
_edFileName.enterKey.connect(&onEnterKey);
_edFilePath.enterKey.connect(&onEnterKey);
_edFileName.setDefaultPopupMenu();
_edFilePath.setDefaultPopupMenu();
_edFileName.contentChange = delegate (EditableContent source) {
updateValues(source.text);
validate();
};
addChild(content);
addChild(createButtonsPanel([ACTION_FILE_NEW_DIRECTORY, ACTION_CANCEL], 0, 0));
updateValues(_edFileName.text);
}
override void onShow() {
super.onShow();
_edFileName.selectAll();
_edFileName.setFocus();
}
protected bool onEnterKey(EditWidgetBase editor) {
if (!validate())
return false;
close(_buttonActions[0]);
return true;
}
private bool validate() {
if (!isValidModuleName(_fileName))
return setError("Invalid folder name");
return setError(null);
}
private void updateValues(dstring fileName) {
_fileName = toUTF8(fileName);
_edFilePath.text = toUTF32(fullPathName);
}
private bool setError(dstring msg) {
_statusText.text = msg;
return msg.empty;
}
private {
EditLine _edFileName;
EditLine _edFilePath;
TextWidget _statusText;
string _fileName = "newfile";
FileCreationResult _result;
string fullPathName() @property {
return buildNormalizedPath(_location, _fileName);
}
}
private bool createItem() {
string fullPathName = this.fullPathName;
if(exists(fullPathName))
return setError("Folder already exists");
try {
mkdir(fullPathName);
} catch (Exception e) {
Log.e("Cannot create folder", e);
return setError("Cannot create folder");
}
_result = new FileCreationResult(_project, fullPathName);
return true;
}
override void close(const Action action) {
Action newaction = action.clone();
if (action.id == IDEActions.FileNewDirectory) {
if (!validate()) {
window.showMessageBox(UIString.fromId("ERROR"c), UIString.fromId("ERROR_INVALID_PARAMETERS"c));
return;
}
if (!createItem()) {
window.showMessageBox(UIString.fromId("ERROR"c), UIString.fromId("ERROR_INVALID_PARAMETERS"c));
return;
}
newaction.objectParam = _result;
}
super.close(newaction);
}
}