From 0fb64e33bc9faf30d2f41f6537c5d7dfde39753b Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 8 Dec 2015 10:19:43 +0300 Subject: [PATCH] new project - working --- src/dlangide/ui/frame.d | 13 +++- src/dlangide/ui/newproject.d | 121 +++++++++++++++++++++++++------ src/dlangide/workspace/project.d | 32 +++++++- 3 files changed, 143 insertions(+), 23 deletions(-) diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index e478aa4..ea4d382 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -193,6 +193,10 @@ class IDEFrame : AppFrame { } } + void hideHomeScreen() { + _tabs.removeTab(HOME_SCREEN_ID); + } + void onTabChanged(string newActiveTabId, string previousTabId) { int index = _tabs.tabIndex(newActiveTabId); if (index >= 0) { @@ -649,9 +653,13 @@ class IDEFrame : AppFrame { if (currentWorkspace is null || res.workspace !is currentWorkspace) { // open new workspace setWorkspace(res.workspace); + refreshWorkspace(); + hideHomeScreen(); } else { // project added to current workspace loadProject(res.project); + refreshWorkspace(); + hideHomeScreen(); } } } @@ -708,8 +716,9 @@ class IDEFrame : AppFrame { if (filename.isWorkspaceFile) { Workspace ws = new Workspace(this); if (ws.load(filename)) { - askForUnsavedEdits(delegate() { + askForUnsavedEdits(delegate() { setWorkspace(ws); + hideHomeScreen(); }); } else { window.showMessageBox(UIString("Cannot open workspace"d), UIString("Error occured while opening workspace"d)); @@ -732,12 +741,14 @@ class IDEFrame : AppFrame { if (result.id == IDEActions.CreateNewWorkspace) { // new ws createNewWorkspaceForExistingProject(project); + hideHomeScreen(); } else if (result.id == IDEActions.AddToCurrentWorkspace) { // add to current currentWorkspace.addProject(project); loadProject(project); currentWorkspace.save(); refreshWorkspace(); + hideHomeScreen(); } return true; }); diff --git a/src/dlangide/ui/newproject.d b/src/dlangide/ui/newproject.d index 51e43c9..82ebc2b 100644 --- a/src/dlangide/ui/newproject.d +++ b/src/dlangide/ui/newproject.d @@ -195,25 +195,6 @@ class NewProjectDlg : Dialog { string _workspaceName = "newworkspace"; string _location; - void initTemplates() { - _templates ~= new ProjectTemplate("Empty app project"d, "Empty application project.\nNo source files."d, null, null, false); - _templates ~= new ProjectTemplate("Empty library project"d, "Empty library project.\nNo Source files."d, null, null, true); - _templates ~= new ProjectTemplate("Hello world app"d, "Hello world application."d, "app.d", - q{ - import std.stdio; - void main(string[] args) { - writeln("Hello World!"); - } - }, false); - _templates ~= new ProjectTemplate("DlangUI: hello world app"d, "Hello world application\nbased on DlangUI library"d, "app.d", - q{ - import std.stdio; - void main(string[] args) { - writeln("Hello World!"); - } - }, false); - } - int _currentTemplateIndex = -1; ProjectTemplate _currentTemplate; ProjectTemplate[] _templates; @@ -313,12 +294,14 @@ class NewProjectDlg : Dialog { project.content.setString("targetType", "executable"); project.content.setString("targetPath", "bin"); } + if (_currentTemplate.json) + project.content.merge(_currentTemplate.json); project.save(); ws.addProject(project); if (ws.startupProject is null) ws.startupProject = project; if (!_currentTemplate.srcfile.empty && !_currentTemplate.srccode.empty) { - string srcdir = buildNormalizedPath(pdir, "dub.json"); + string srcdir = buildNormalizedPath(pdir, "source"); if (!exists(srcdir)) mkdir(srcdir); string srcfile = buildNormalizedPath(srcdir, _currentTemplate.srcfile); @@ -328,22 +311,118 @@ class NewProjectDlg : Dialog { return setError("Cannot save project file"); if (!ws.save()) return setError("Cannot save workspace file"); + project.load(); _result = new ProjectCreationResult(ws, project); return true; } + + void initTemplates() { + _templates ~= new ProjectTemplate("Empty app project"d, "Empty application project.\nNo source files."d, null, null, false); + _templates ~= new ProjectTemplate("Empty library project"d, "Empty library project.\nNo Source files."d, null, null, true); + _templates ~= new ProjectTemplate("Hello world app"d, "Hello world application."d, "app.d", + SOURCE_CODE_HELLOWORLD, false); + _templates ~= new ProjectTemplate("DlangUI: hello world app"d, "Hello world application\nbased on DlangUI library"d, "app.d", + SOURCE_CODE_DLANGUI_HELLOWORLD, false, DUB_JSON_DLANGUI_HELLOWORLD); + } } +immutable string SOURCE_CODE_HELLOWORLD = q{ +import std.stdio; +void main(string[] args) { + writeln("Hello World!"); +} +}; + +immutable string SOURCE_CODE_DLANGUI_HELLOWORLD = q{ +import dlangui; + +mixin APP_ENTRY_POINT; + +/// entry point for dlangui based application +extern (C) int UIAppMain(string[] args) { + // create window + Window window = Platform.instance.createWindow("DlangUI HelloWorld", null); + + // create some widget to show in window + //window.mainWidget = (new Button()).text("Hello, world!"d).margins(Rect(20,20,20,20)); + window.mainWidget = parseML(q{ + VerticalLayout { + margins: 10 + padding: 10 + backgroundColor: "#C0E0E070" // semitransparent yellow background + // red bold text with size = 150% of base style size and font face Arial + TextWidget { text: "Hello World example for DlangUI"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" } + // arrange controls as form - table with two columns + TableLayout { + colCount: 2 + TextWidget { text: "param 1" } + EditLine { id: edit1; text: "some text" } + TextWidget { text: "param 2" } + EditLine { id: edit2; text: "some text for param2" } + TextWidget { text: "some radio buttons" } + // arrange some radio buttons vertically + VerticalLayout { + RadioButton { id: rb1; text: "Item 1" } + RadioButton { id: rb2; text: "Item 2" } + RadioButton { id: rb3; text: "Item 3" } + } + TextWidget { text: "and checkboxes" } + // arrange some checkboxes horizontally + HorizontalLayout { + CheckBox { id: cb1; text: "checkbox 1" } + CheckBox { id: cb2; text: "checkbox 2" } + } + } + HorizontalLayout { + Button { id: btnOk; text: "Ok" } + Button { id: btnCancel; text: "Cancel" } + } + } + }); + // you can access loaded items by id - e.g. to assign signal listeners + auto edit1 = window.mainWidget.childById!EditLine("edit1"); + auto edit2 = window.mainWidget.childById!EditLine("edit2"); + // close window on Cancel button click + window.mainWidget.childById!Button("btnCancel").click = delegate(Widget w) { + window.close(); + return true; + }; + // show message box with content of editors + window.mainWidget.childById!Button("btnOk").click = delegate(Widget w) { + window.showMessageBox(UIString("Ok button pressed"d), + UIString("Editors content\nEdit1: "d ~ edit1.text ~ "\nEdit2: "d ~ edit2.text)); + return true; + }; + + // show window + window.show(); + + // run message loop + return Platform.instance.enterMessageLoop(); +} +}; + +immutable string DUB_JSON_DLANGUI_HELLOWORLD = q{ +{ + "dependencies": { + "dlangui": "~master" + } +} +}; + class ProjectTemplate { dstring name; dstring description; string srcfile; string srccode; bool isLibrary; - this(dstring name, dstring description, string srcfile, string srccode, bool isLibrary) { + string json; + this(dstring name, dstring description, string srcfile, string srccode, bool isLibrary, string json = null) { this.name = name; this.description = description; this.srcfile = srcfile; this.srccode = srccode; this.isLibrary = isLibrary; + this.json = json; } } diff --git a/src/dlangide/workspace/project.d b/src/dlangide/workspace/project.d index 51681b6..de101f5 100644 --- a/src/dlangide/workspace/project.d +++ b/src/dlangide/workspace/project.d @@ -295,6 +295,7 @@ class Project : WorkspaceItem { _items = new ProjectFolder(fname); _dependencyVersion = dependencyVersion; _isDependency = _dependencyVersion.length > 0; + _projectFile = new SettingsFile(fname); } @property bool isDependency() { return _isDependency; } @@ -308,7 +309,29 @@ class Project : WorkspaceItem { /// direct access to project file (json) @property SettingsFile content() { return _projectFile; } - + + /// name + override @property dstring name() { + return super.name(); + } + + /// name + override @property void name(dstring s) { + super.name(s); + _projectFile.setString("name", toUTF8(s)); + } + + /// name + override @property dstring description() { + return super.description(); + } + + /// name + override @property void description(dstring s) { + super.description(s); + _projectFile.setString("description", toUTF8(s)); + } + /// returns project's own source paths @property string[] sourcePaths() { return _sourcePaths; } /// returns project's own source paths @@ -467,6 +490,13 @@ class Project : WorkspaceItem { return true; } + override bool save(string fname = null) { + if (fname !is null) + filename = fname; + assert(filename !is null); + return _projectFile.save(filename, true); + } + protected Project[] _dependencies; @property Project[] dependencies() { return _dependencies; } protected bool addDependency(Project dep) {