mirror of
https://github.com/buggins/dlangide.git
synced 2025-04-29 14:39:54 +03:00
Merge pull request #374 from Zevenberge/feature/add_folder
Create a directory and package.d
This commit is contained in:
commit
6c32105caf
10 changed files with 560 additions and 295 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -20,3 +20,7 @@ index.html
|
|||
api.html
|
||||
screenshots.html
|
||||
*.log
|
||||
|
||||
*.userprefs
|
||||
|
||||
\.dlangidews\.wssettings
|
||||
|
|
|
@ -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\" />
|
||||
|
|
|
@ -938,6 +938,7 @@
|
|||
<File path="src\dlangide\ui\frame.d" />
|
||||
<File path="src\dlangide\ui\homescreen.d" />
|
||||
<File path="src\dlangide\ui\newfile.d" />
|
||||
<File path="src\dlangide\ui\newfolder.d" />
|
||||
<File path="src\dlangide\ui\newproject.d" />
|
||||
<File path="src\dlangide\ui\outputpanel.d" />
|
||||
<File path="src\dlangide\ui\searchPanel.d" />
|
||||
|
|
|
@ -6,6 +6,7 @@ import dlangui.widgets.editors;
|
|||
enum IDEActions : int {
|
||||
//ProjectOpen = 1010000,
|
||||
FileNew = 1010000,
|
||||
FileNewDirectory,
|
||||
FileNewWorkspace,
|
||||
FileNewProject,
|
||||
FileOpen,
|
||||
|
@ -100,6 +101,7 @@ const Action ACTION_PROJECT_FOLDER_COLLAPSE_ALL = new Action(IDEActions.ProjectF
|
|||
|
||||
const Action ACTION_FILE_WORKSPACE_CLOSE = new Action(IDEActions.CloseWorkspace, "MENU_FILE_WORKSPACE_CLOSE"c).disableByDefault();
|
||||
|
||||
const Action ACTION_FILE_NEW_DIRECTORY = new Action(IDEActions.FileNewDirectory, "MENU_FILE_NEW_DIRECTORY"c);
|
||||
const Action ACTION_FILE_NEW_SOURCE_FILE = new Action(IDEActions.FileNew, "MENU_FILE_NEW_SOURCE_FILE"c, "document-new", KeyCode.KEY_N, KeyFlag.Control);
|
||||
const Action ACTION_FILE_NEW_PROJECT = new Action(IDEActions.FileNewProject, "MENU_FILE_NEW_PROJECT"c);
|
||||
const Action ACTION_FILE_NEW_WORKSPACE = new Action(IDEActions.FileNewWorkspace, "MENU_FILE_NEW_WORKSPACE"c);
|
||||
|
|
|
@ -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;
|
||||
|
@ -416,6 +417,13 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
}
|
||||
}
|
||||
|
||||
bool tryOpenSourceFile(string filename) {
|
||||
if (isSupportedSourceTextFileFormat(filename)) {
|
||||
return openSourceFile(filename, null, true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool openSourceFile(string filename, ProjectSourceFile file = null, bool activate = true) {
|
||||
if (!file && !filename)
|
||||
return false;
|
||||
|
@ -1137,7 +1145,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
else
|
||||
ed.editorTool = new DefaultEditorTool(this);
|
||||
//openSourceFile(filename);
|
||||
refreshWorkspace();
|
||||
updateTreeGraph();
|
||||
ProjectSourceFile file = _wsPanel.findSourceFileItem(filename, false);
|
||||
if (file) {
|
||||
ed.projectSourceFile = file;
|
||||
|
@ -1209,7 +1217,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
buildProject(BuildOperation.Upgrade, cast(Project)a.objectParam);
|
||||
return true;
|
||||
case IDEActions.RefreshProject:
|
||||
refreshWorkspace();
|
||||
updateTreeGraph();
|
||||
return true;
|
||||
case IDEActions.RevealProjectInExplorer:
|
||||
revealProjectInExplorer(cast(Project)a.objectParam);
|
||||
|
@ -1365,7 +1373,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:
|
||||
addDirectory(cast(Object)a.objectParam);
|
||||
return true;
|
||||
case IDEActions.ProjectFolderRemoveItem:
|
||||
removeProjectItem(a.objectParam);
|
||||
|
@ -1433,7 +1444,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
if (cast(Workspace)obj) {
|
||||
Workspace ws = cast(Workspace)obj;
|
||||
ws.refresh();
|
||||
refreshWorkspace();
|
||||
updateTreeGraph();
|
||||
} else if (cast(Project)obj) {
|
||||
project = cast(Project)obj;
|
||||
} else if (cast(ProjectFolder)obj) {
|
||||
|
@ -1452,7 +1463,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
}
|
||||
if (project) {
|
||||
project.refresh();
|
||||
refreshWorkspace();
|
||||
updateTreeGraph();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1479,7 +1490,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
Log.e("Cannot remove file");
|
||||
}
|
||||
project.refresh();
|
||||
refreshWorkspace();
|
||||
updateTreeGraph();
|
||||
}
|
||||
// else ignore
|
||||
return true;
|
||||
|
@ -1487,8 +1498,53 @@ 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();
|
||||
updateTreeGraph();
|
||||
tryOpenSourceFile(res.filename);
|
||||
}
|
||||
}
|
||||
};
|
||||
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) {
|
||||
ProjectFolder newFolder = new ProjectFolder(res.filename);
|
||||
if(folder) {
|
||||
folder.addChild(newFolder);
|
||||
folder.sortItems;
|
||||
newFolder.refresh();
|
||||
if(newFolder.childCount > 0){
|
||||
tryOpenSourceFile(newFolder.child(0).filename);
|
||||
}
|
||||
}
|
||||
updateTreeGraph();
|
||||
_wsPanel.selectItem(newFolder);
|
||||
}
|
||||
}
|
||||
};
|
||||
return dialog;
|
||||
}
|
||||
addProjectItem(&createNewDirectoryDialog, obj);
|
||||
}
|
||||
|
||||
/// add new file to project
|
||||
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) {
|
||||
|
@ -1500,7 +1556,12 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
ProjectFolder folder;
|
||||
if (cast(Project)obj) {
|
||||
project = cast(Project)obj;
|
||||
folder = project.firstSourceFolder;
|
||||
folder = project.items;
|
||||
import std.stdio;
|
||||
writeln("Root filename:", folder.filename);
|
||||
for(int i = 0; i < folder.childCount; i++) {
|
||||
writeln("Child [", i, "]: ", folder.child(i).filename);
|
||||
}
|
||||
} else if (cast(ProjectFolder)obj) {
|
||||
folder = cast(ProjectFolder)obj;
|
||||
project = folder.project;
|
||||
|
@ -1515,21 +1576,8 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
project = srcfile.project;
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -1550,12 +1598,12 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
if (currentWorkspace is null || res.workspace !is currentWorkspace) {
|
||||
// open new workspace
|
||||
setWorkspace(res.workspace);
|
||||
refreshWorkspace();
|
||||
updateTreeGraph();
|
||||
hideHomeScreen();
|
||||
} else {
|
||||
// project added to current workspace
|
||||
loadProject(res.project);
|
||||
refreshWorkspace();
|
||||
updateTreeGraph();
|
||||
hideHomeScreen();
|
||||
}
|
||||
}
|
||||
|
@ -1757,7 +1805,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
currentWorkspace.addProject(project);
|
||||
loadProject(project);
|
||||
currentWorkspace.save();
|
||||
refreshWorkspace();
|
||||
updateTreeGraph();
|
||||
hideHomeScreen();
|
||||
}
|
||||
return true;
|
||||
|
@ -1772,7 +1820,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
}
|
||||
}
|
||||
|
||||
void refreshWorkspace() {
|
||||
void updateTreeGraph() {
|
||||
_logPanel.logLine("Refreshing workspace");
|
||||
_wsPanel.reloadItems();
|
||||
closeRemovedDocuments();
|
||||
|
@ -1838,7 +1886,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
|||
void refreshProject(Project project) {
|
||||
if (currentWorkspace && project.loadSelections()) {
|
||||
currentWorkspace.cleanupUnusedDependencies();
|
||||
refreshWorkspace();
|
||||
updateTreeGraph();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -198,29 +198,6 @@ class NewFileDlg : Dialog {
|
|||
ProjectTemplate _currentTemplate;
|
||||
ProjectTemplate[] _templates;
|
||||
|
||||
static bool isSubdirOf(string path, string basePath) {
|
||||
if (path.equal(basePath))
|
||||
return true;
|
||||
if (path.length > basePath.length + 1 && path.startsWith(basePath)) {
|
||||
char ch = path[basePath.length];
|
||||
return ch == '/' || ch == '\\';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool findSource(string path, ref string sourceFolderPath, ref string relativePath) {
|
||||
foreach(dir; _sourcePaths) {
|
||||
if (isSubdirOf(path, dir)) {
|
||||
sourceFolderPath = dir;
|
||||
relativePath = path[sourceFolderPath.length .. $];
|
||||
if (relativePath.length > 0 && (relativePath[0] == '\\' || relativePath[0] == '/'))
|
||||
relativePath = relativePath[1 .. $];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool setError(dstring msg) {
|
||||
_statusText.text = msg;
|
||||
return msg.empty;
|
||||
|
@ -242,25 +219,12 @@ class NewFileDlg : Dialog {
|
|||
|
||||
if (_currentTemplate.kind == FileKind.MODULE || _currentTemplate.kind == FileKind.PACKAGE) {
|
||||
string sourcePath, relativePath;
|
||||
if (!findSource(_location, sourcePath, relativePath))
|
||||
if (!findSource(_sourcePaths, _location, sourcePath, relativePath))
|
||||
return setError("Location is outside of source path");
|
||||
if (!isValidModuleName(filename))
|
||||
return setError("Invalid file name");
|
||||
_moduleName = filename;
|
||||
char[] buf;
|
||||
foreach(c; relativePath) {
|
||||
char ch = c;
|
||||
if (ch == '/' || ch == '\\')
|
||||
ch = '.';
|
||||
else if (ch == '.')
|
||||
ch = '_';
|
||||
if (ch == '.' && (buf.length == 0 || buf[$-1] == '.'))
|
||||
continue; // skip duplicate .
|
||||
buf ~= ch;
|
||||
}
|
||||
if (buf.length && buf[$-1] == '.')
|
||||
buf.length--;
|
||||
_packageName = buf.dup;
|
||||
_packageName = getPackageName(sourcePath, relativePath);
|
||||
string m;
|
||||
if (_currentTemplate.kind == FileKind.MODULE) {
|
||||
m = !_packageName.empty ? _packageName ~ '.' ~ _moduleName : _moduleName;
|
||||
|
@ -284,20 +248,10 @@ class NewFileDlg : Dialog {
|
|||
|
||||
private FileCreationResult _result;
|
||||
bool createItem() {
|
||||
try {
|
||||
if (_currentTemplate.kind == FileKind.MODULE) {
|
||||
string txt = "module " ~ _packageName ~ ";\n\n" ~ _currentTemplate.srccode;
|
||||
write(_fullPathName, txt);
|
||||
} else if (_currentTemplate.kind == FileKind.PACKAGE) {
|
||||
string txt = "module " ~ _packageName ~ ";\n\n" ~ _currentTemplate.srccode;
|
||||
write(_fullPathName, txt);
|
||||
} else {
|
||||
write(_fullPathName, _currentTemplate.srccode);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("Cannot create file", e);
|
||||
if(!createFile(_fullPathName, _currentTemplate.kind, _packageName, _currentTemplate.srccode)) {
|
||||
return setError("Cannot create file");
|
||||
}
|
||||
|
||||
_result = new FileCreationResult(_project, _fullPathName);
|
||||
return true;
|
||||
}
|
||||
|
@ -377,3 +331,67 @@ class ProjectTemplate {
|
|||
this.kind = kind;
|
||||
}
|
||||
}
|
||||
|
||||
bool createFile(string fullPathName, FileKind fileKind, string packageName, string sourceCode) {
|
||||
try {
|
||||
if (fileKind == FileKind.MODULE) {
|
||||
string txt = "module " ~ packageName ~ ";\n\n" ~ sourceCode;
|
||||
write(fullPathName, txt);
|
||||
} else if (fileKind == FileKind.PACKAGE) {
|
||||
string txt = "module " ~ packageName ~ ";\n\n" ~ sourceCode;
|
||||
write(fullPathName, txt);
|
||||
} else {
|
||||
write(fullPathName, sourceCode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch(Exception e) {
|
||||
Log.e("Cannot create file", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string getPackageName(string path, string[] sourcePaths){
|
||||
string sourcePath, relativePath;
|
||||
if(!findSource(sourcePaths, path, sourcePath, relativePath)) return "";
|
||||
return getPackageName(sourcePath, relativePath);
|
||||
}
|
||||
|
||||
string getPackageName(string sourcePath, string relativePath){
|
||||
|
||||
char[] buf;
|
||||
foreach(c; relativePath) {
|
||||
char ch = c;
|
||||
if (ch == '/' || ch == '\\')
|
||||
ch = '.';
|
||||
else if (ch == '.')
|
||||
ch = '_';
|
||||
if (ch == '.' && (buf.length == 0 || buf[$-1] == '.'))
|
||||
continue; // skip duplicate .
|
||||
buf ~= ch;
|
||||
}
|
||||
if (buf.length && buf[$-1] == '.')
|
||||
buf.length--;
|
||||
return buf.dup;
|
||||
}
|
||||
private bool findSource(string[] sourcePaths, string path, ref string sourceFolderPath, ref string relativePath) {
|
||||
foreach(dir; sourcePaths) {
|
||||
if (isSubdirOf(path, dir)) {
|
||||
sourceFolderPath = dir;
|
||||
relativePath = path[sourceFolderPath.length .. $];
|
||||
if (relativePath.length > 0 && (relativePath[0] == '\\' || relativePath[0] == '/'))
|
||||
relativePath = relativePath[1 .. $];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private bool isSubdirOf(string path, string basePath) {
|
||||
if (path.equal(basePath))
|
||||
return true;
|
||||
if (path.length > basePath.length + 1 && path.startsWith(basePath)) {
|
||||
char ch = path[basePath.length];
|
||||
return ch == '/' || ch == '\\';
|
||||
}
|
||||
return false;
|
||||
}
|
186
src/dlangide/ui/newfolder.d
Normal file
186
src/dlangide/ui/newfolder.d
Normal file
|
@ -0,0 +1,186 @@
|
|||
module dlangide.ui.newfolder;
|
||||
|
||||
import std.array : empty;
|
||||
import std.file : mkdir, exists;
|
||||
import std.path : buildPath, 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.Popup, 800, 0);
|
||||
layoutWidth = FILL_PARENT;
|
||||
_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: wrap
|
||||
TableLayout {
|
||||
margins: 5
|
||||
colCount: 2
|
||||
layoutWidth: fill; layoutHeight: wrap
|
||||
TextWidget { text: NAME }
|
||||
EditLine { id: fileName; text: "newfolder"; layoutWidth: fill }
|
||||
CheckBox { id: makePackage }
|
||||
TextWidget { text: OPTION_MAKE_PACKAGE}
|
||||
}
|
||||
TextWidget { id: statusText; text: ""; layoutWidth: fill; textColor: #FF0000 }
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e("Exceptin while parsing DML", e);
|
||||
throw e;
|
||||
}
|
||||
_edFileName = content.childById!EditLine("fileName");
|
||||
_edMakePackage = content.childById!CheckBox("makePackage");
|
||||
_statusText = content.childById!TextWidget("statusText");
|
||||
|
||||
_edFileName.enterKey.connect(&onEnterKey);
|
||||
|
||||
_edFileName.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);
|
||||
}
|
||||
|
||||
private bool setError(dstring msg) {
|
||||
_statusText.text = msg;
|
||||
return msg.empty;
|
||||
}
|
||||
|
||||
private {
|
||||
EditLine _edFileName;
|
||||
CheckBox _edMakePackage;
|
||||
TextWidget _statusText;
|
||||
|
||||
string _fileName = "newfile";
|
||||
FileCreationResult _result;
|
||||
bool shouldMakePackage() @property {
|
||||
return _edMakePackage.checked;
|
||||
}
|
||||
string fullPathName() @property {
|
||||
return buildNormalizedPath(_location, _fileName);
|
||||
}
|
||||
}
|
||||
|
||||
private bool createItem() {
|
||||
string fullPathName = this.fullPathName;
|
||||
if(exists(fullPathName))
|
||||
return setError("Folder already exists");
|
||||
|
||||
if(!makeDirectory(fullPathName)) return false;
|
||||
if(shouldMakePackage) {
|
||||
if(!makePackageFile(fullPathName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_result = new FileCreationResult(_project, fullPathName);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool makeDirectory(string fullPathName) {
|
||||
try {
|
||||
mkdir(fullPathName);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e("Cannot create folder", e);
|
||||
return setError("Cannot create folder");
|
||||
}
|
||||
}
|
||||
|
||||
private bool makePackageFile(string fullPathName) {
|
||||
string packageName = getPackageName(fullPathName, _project.sourcePaths);
|
||||
if(packageName.empty) {
|
||||
Log.e("Could not determing package name for ", fullPathName);
|
||||
return false;
|
||||
}
|
||||
if(!createFile(fullPathName.buildPath("package.d"), FileKind.PACKAGE, packageName, null)) {
|
||||
Log.e("Could not create package file in folder ", fullPathName);
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -102,7 +102,7 @@ class WorkspacePanel : DockWindow {
|
|||
_projectPopupMenu = new MenuItem();
|
||||
_projectPopupMenu.add(ACTION_PROJECT_SET_STARTUP,
|
||||
ACTION_PROJECT_FOLDER_REFRESH,
|
||||
ACTION_FILE_NEW_SOURCE_FILE,
|
||||
//ACTION_FILE_NEW_DIRECTORY,
|
||||
//ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
||||
ACTION_PROJECT_BUILD,
|
||||
ACTION_PROJECT_REBUILD,
|
||||
|
@ -116,14 +116,17 @@ class WorkspacePanel : DockWindow {
|
|||
);
|
||||
|
||||
_folderPopupMenu = new MenuItem();
|
||||
_folderPopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_PROJECT_FOLDER_REFRESH, ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
||||
_folderPopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE,
|
||||
ACTION_FILE_NEW_DIRECTORY,
|
||||
ACTION_PROJECT_FOLDER_REFRESH, ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
||||
ACTION_PROJECT_FOLDER_EXPAND_ALL, ACTION_PROJECT_FOLDER_COLLAPSE_ALL
|
||||
//ACTION_PROJECT_FOLDER_REMOVE_ITEM,
|
||||
//ACTION_PROJECT_FOLDER_RENAME_ITEM
|
||||
);
|
||||
|
||||
_filePopupMenu = new MenuItem();
|
||||
_filePopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE, ACTION_PROJECT_FOLDER_REFRESH,
|
||||
_filePopupMenu.add(ACTION_FILE_NEW_SOURCE_FILE,
|
||||
ACTION_PROJECT_FOLDER_REFRESH,
|
||||
ACTION_PROJECT_FOLDER_OPEN_ITEM,
|
||||
ACTION_PROJECT_FOLDER_REMOVE_ITEM,
|
||||
//ACTION_PROJECT_FOLDER_RENAME_ITEM
|
||||
|
|
|
@ -422,7 +422,7 @@ class Project : WorkspaceItem {
|
|||
includePath ~= obj.str;
|
||||
}
|
||||
|
||||
_items = new ProjectFolder(fname);
|
||||
_items = new ProjectFolder(fname.dirName);
|
||||
_dependencyVersion = dependencyVersion;
|
||||
_isDependency = _dependencyVersion.length > 0;
|
||||
_projectFile = new SettingsFile(fname);
|
||||
|
@ -607,8 +607,8 @@ class Project : WorkspaceItem {
|
|||
return settings.runInExternalConsole;
|
||||
}
|
||||
|
||||
ProjectFolder findItems(string[] srcPaths) {
|
||||
auto folder = new ProjectFolder(_filename);
|
||||
private ProjectFolder findItems(string[] srcPaths) {
|
||||
auto folder = new ProjectFolder(_filename.dirName);
|
||||
folder.project = this;
|
||||
foreach(customPath; srcPaths) {
|
||||
string path = relativeToAbsolutePath(customPath);
|
||||
|
|
|
@ -34,6 +34,7 @@ NAME=Name
|
|||
MENU_FILE=&File
|
||||
MENU_FILE_NEW=&Create
|
||||
MENU_FILE_NEW_SOURCE_FILE=New file
|
||||
MENU_FILE_NEW_DIRECTORY=New directory
|
||||
MENU_FILE_NEW_PROJECT=New project
|
||||
MENU_FILE_NEW_WORKSPACE=New workspace
|
||||
MENU_FILE_OPEN=&Open file...
|
||||
|
@ -196,6 +197,7 @@ OPTION_GDC_EXECUTABLE=GDC executable
|
|||
OPTION_LANGUAGE=Language
|
||||
OPTION_LDC2_EXECUTABLE=LDC2 executable
|
||||
OPTION_LDMD2_EXECUTABLE=LDMD2 executable
|
||||
OPTION_MAKE_PACKAGE=Create package.d
|
||||
OPTION_MODULE_NAME=Module name
|
||||
OPTION_NEW_PROJECT=New project
|
||||
OPTION_NEW_SOURCE_FILE=New source file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue