new project dialog

This commit is contained in:
Vadim Lopatin 2015-12-07 11:58:51 +03:00
parent 94398cce6a
commit 632ba4a866
2 changed files with 125 additions and 32 deletions

View File

@ -160,7 +160,7 @@ class IDEFrame : AppFrame {
index = _tabs.tabIndex(filename); index = _tabs.tabIndex(filename);
TabItem tab = _tabs.tab(filename); TabItem tab = _tabs.tab(filename);
tab.objectParam = file; tab.objectParam = file;
editor.onModifiedStateChangeListener = &onModifiedStateChange; editor.modifiedStateChange = &onModifiedStateChange;
applySettings(editor, settings); applySettings(editor, settings);
_tabs.selectTab(index, true); _tabs.selectTab(index, true);
if( filename.endsWith(".d") ) if( filename.endsWith(".d") )
@ -637,7 +637,9 @@ class IDEFrame : AppFrame {
} }
void createNewProject(bool newWorkspace) { void createNewProject(bool newWorkspace) {
NewProjectDlg dlg = new NewProjectDlg(window, newWorkspace); if (currentWorkspace is null)
newWorkspace = true;
NewProjectDlg dlg = new NewProjectDlg(window, newWorkspace, currentWorkspace);
dlg.dialogResult = delegate(Dialog dlg, const Action result) { dlg.dialogResult = delegate(Dialog dlg, const Action result) {
if (result.id == ACTION_APPLY.id) { if (result.id == ACTION_APPLY.id) {
//Log.d("settings after edit:\n", s.toJSON(true)); //Log.d("settings after edit:\n", s.toJSON(true));

View File

@ -7,68 +7,83 @@ import dlangui.dialogs.dialog;
import dlangui.widgets.widget; import dlangui.widgets.widget;
import dlangui.widgets.layouts; import dlangui.widgets.layouts;
import dlangui.widgets.editors; import dlangui.widgets.editors;
import dlangui.widgets.controls;
import dlangui.widgets.lists; import dlangui.widgets.lists;
import dlangui.dml.parser; import dlangui.dml.parser;
import dlangui.core.stdaction; import dlangui.core.stdaction;
import dlangide.workspace.project;
import dlangide.workspace.workspace;
class NewProjectDlg : Dialog { class NewProjectDlg : Dialog {
bool _newWorkspace; Workspace currentWorkspace;
this(Window parent, bool newWorkspace, Workspace currentWorkspace) {
StringListWidget _projectTypeList; super(newWorkspace ? UIString("New Workspace"d) : UIString("New Project"d), parent, DialogFlag.Modal | DialogFlag.Resizable, 500, 400);
StringListWidget _projectTemplateList;
EditBox _templateDescription;
this(Window parent, bool newWorkspace) {
super(newWorkspace ? UIString("New Workspace"d) : UIString("New Project"d), parent, DialogFlag.Modal);
_icon = "dlangui-logo1"; _icon = "dlangui-logo1";
this.currentWorkspace = currentWorkspace;
} }
/// override to implement creation of dialog controls /// override to implement creation of dialog controls
override void init() { override void init() {
super.init(); super.init();
initTemplates();
Widget content = parseML(q{ Widget content = parseML(q{
VerticalLayout { VerticalLayout {
id: vlayout id: vlayout
margins: Rect { left: 5; right: 3; top: 2; bottom: 4 } padding: Rect { 5, 5, 5, 5 }
padding: Rect { 5, 4, 3, 2 } // same as Rect { left: 5; top: 4; right: 3; bottom: 2 }
layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT
HorizontalLayout { HorizontalLayout {
layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT
VerticalLayout { VerticalLayout {
layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT margins: 5
layoutWidth: WRAP_CONTENT; layoutHeight: FILL_PARENT
TextWidget { text: "Project template" } TextWidget { text: "Project template" }
StringListWidget { id: projectTemplateList } StringListWidget {
id: projectTemplateList
layoutWidth: WRAP_CONTENT; layoutHeight: FILL_PARENT
}
} }
VerticalLayout { VerticalLayout {
margins: 5
layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT
TextWidget { text: "Template description" } TextWidget { text: "Template description" }
EditBox { id: templateDescription; readOnly: true } EditBox {
id: templateDescription; readOnly: true
layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT
}
} }
} }
HorizontalLayout { HorizontalLayout {
layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT
TableLayout { TableLayout {
margins: 5
colCount: 2 colCount: 2
layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT
TextWidget { text: "" }
CheckBox { id: cbCreateWorkspace; text: "Create new solution" }
TextWidget { text: "Workspace name" }
EditLine {
id: edWorkspaceName; text: "newworkspace"
}
TextWidget { text: "Project name" } TextWidget { text: "Project name" }
EditLine { EditLine {
id: edProjectName id: edProjectName; text: "newproject"
}
TextWidget { text: "Solution name" }
EditLine {
id: edSolutionName
} }
TextWidget { text: "" }
CheckBox { id: cbCreateSubdir; text: "Create subdirectory for project" }
TextWidget { text: "Location" } TextWidget { text: "Location" }
EditLine { EditLine {
id: edLocation id: edLocation
} }
TextWidget { text: "" }
CheckBox { id: cbCreateSubdir; text: "Create subdirectory for project" }
} }
VerticalLayout { VerticalLayout {
layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT
TextWidget { text: "Description" } margins: 5
EditBox { id: directoryLayout } TextWidget { text: "Directory layout" }
EditBox {
id: directoryLayout; readOnly: true
layoutWidth: FILL_PARENT; layoutHeight: FILL_PARENT
}
} }
} }
} }
@ -76,17 +91,93 @@ class NewProjectDlg : Dialog {
_projectTemplateList = content.childById!StringListWidget("projectTemplateList"); _projectTemplateList = content.childById!StringListWidget("projectTemplateList");
_templateDescription = content.childById!EditBox("templateDescription"); _templateDescription = content.childById!EditBox("templateDescription");
_projectTemplateList.items = [ _directoryLayout = content.childById!EditBox("directoryLayout");
"Empty App Project"d, _edProjectName = content.childById!EditLine("edProjectName");
"Empty Library Project"d, _edWorkspaceName = content.childById!EditLine("edWorkspaceName");
"Hello World App"d, _cbCreateSubdir = content.childById!CheckBox("cbCreateSubdir");
"Console Application"d, _cbCreateWorkspace = content.childById!CheckBox("cbCreateWorkspace");
"DlangUI Library"d,
"DlangUI Application"d, _edProjectName.contentChange = delegate (EditableContent source) {
]; _projectName = source.text;
updateDirLayout();
};
_edWorkspaceName.contentChange = delegate (EditableContent source) {
_workspaceName = source.text;
updateDirLayout();
};
// fill templates
dstring[] names;
foreach(t; _templates)
names ~= t.name;
_projectTemplateList.items = names;
_projectTemplateList.selectedItemIndex = 0;
_projectTemplateList.itemSelected = delegate (Widget source, int itemIndex) {
templateSelected(itemIndex);
return true;
};
_projectTemplateList.itemClick = delegate (Widget source, int itemIndex) {
templateSelected(itemIndex);
return true;
};
templateSelected(0);
updateDirLayout();
addChild(content); addChild(content);
addChild(createButtonsPanel([ACTION_OK, ACTION_CANCEL], 0, 0)); addChild(createButtonsPanel([ACTION_OK, ACTION_CANCEL], 0, 0));
}
} }
bool _newWorkspace;
bool _;
StringListWidget _projectTypeList;
StringListWidget _projectTemplateList;
EditBox _templateDescription;
EditBox _directoryLayout;
EditLine _edWorkspaceName;
EditLine _edProjectName;
CheckBox _cbCreateSubdir;
CheckBox _cbCreateWorkspace;
dstring _projectName = "newproject";
dstring _workspaceName = "newworkspace";
void initTemplates() {
_templates ~= new ProjectTemplate("Empty app project"d, "Empty application project.\nNo source files."d);
_templates ~= new ProjectTemplate("Empty library project"d, "Empty library project.\nNo Source files."d);
_templates ~= new ProjectTemplate("Hello world app"d, "Hello world application."d);
_templates ~= new ProjectTemplate("DlangUI: hello world app"d, "Hello world application\nbased on DlangUI library"d);
}
int _currentTemplateIndex = -1;
ProjectTemplate _currentTemplate;
ProjectTemplate[] _templates;
protected void templateSelected(int index) {
if (_currentTemplateIndex == index)
return;
_currentTemplateIndex = index;
_currentTemplate = _templates[index];
_templateDescription.text = _currentTemplate.description;
}
protected void updateDirLayout() {
dchar[] buf;
buf ~= _workspaceName ~ toUTF32(WORKSPACE_EXTENSION) ~ "\n";
dstring level = "";
if (_cbCreateSubdir.checked) {
buf ~= _projectName ~ "/\n";
level = " ";
}
buf ~= level ~ "dub.json" ~ "\n";
_directoryLayout.text = buf.dup;
}
}
class ProjectTemplate {
dstring name;
dstring description;
this(dstring name, dstring description) {
this.name = name;
this.description = description;
}
}