Run Project improvements

This commit is contained in:
Vadim Lopatin 2015-12-09 13:33:44 +03:00
parent 02d7d13379
commit f2db9a74fc
3 changed files with 59 additions and 9 deletions

View File

@ -11,6 +11,8 @@ import core.thread;
import std.string;
import std.conv;
alias BuildResultListener = void delegate(int);
class Builder : BackgroundOperationWatcher {
protected Project _project;
protected ExternalProcess _extprocess;
@ -20,12 +22,15 @@ class Builder : BackgroundOperationWatcher {
protected BuildConfiguration _buildConfig;
protected BuildOperation _buildOp;
protected bool _verbose;
protected BuildResultListener _listener;
protected int _exitCode = int.min;
@property Project project() { return _project; }
@property void project(Project p) { _project = p; }
this(AppFrame frame, Project project, OutputPanel log, ProjectConfiguration projectConfig, BuildConfiguration buildConfig, BuildOperation buildOp, bool verbose) {
this(AppFrame frame, Project project, OutputPanel log, ProjectConfiguration projectConfig, BuildConfiguration buildConfig, BuildOperation buildOp, bool verbose, BuildResultListener listener = null) {
super(frame);
_listener = listener;
_projectConfig = projectConfig;
_buildConfig = buildConfig;
_buildOp = buildOp;
@ -35,6 +40,7 @@ class Builder : BackgroundOperationWatcher {
_extprocess = new ExternalProcess();
_box = new ProtectedTextStorage();
}
/// log lines
void pollText() {
dstring text = _box.readText();
@ -107,6 +113,7 @@ class Builder : BackgroundOperationWatcher {
}
state = _extprocess.poll();
if (state == ExternalProcessState.Stopped) {
_exitCode = _extprocess.result;
_box.writeText("Builder finished with result "d ~ to!dstring(_extprocess.result) ~ "\n"d);
_finished = true;
return;
@ -119,4 +126,9 @@ class Builder : BackgroundOperationWatcher {
}
super.update();
}
override void removing() {
super.removing();
if (_exitCode != int.min && _listener)
_listener(_exitCode);
}
}

View File

@ -117,6 +117,22 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener {
_logPanel.logLine("Program " ~ process.executableFile ~ " is finished");
break;
}
_statusLine.setBackgroundOperationStatus(null, null);
});
}
protected void buildAndRunProject() {
if (!currentWorkspace)
return;
Project project = currentWorkspace.startupProject;
if (!project) {
window.showMessageBox(UIString("Cannot run project"d), UIString("Startup project is not specified"d));
return;
}
buildProject(BuildOperation.Build, delegate(int result) {
if (!result) {
runProject();
}
});
}
@ -127,7 +143,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener {
return;
Project project = currentWorkspace.startupProject;
if (!project) {
window.showMessageBox(UIString("Cannot run project"d), UIString("Startup project is not specified"d));
window.showMessageBox(UIString("Cannot run project"d), UIString("Startup project is not specified"d));
return;
}
// build project
@ -138,13 +154,19 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener {
return;
}
string[] args;
string externalConsoleExecutable = null; // TODO
string workingDirectory = null; // TODO
string externalConsoleExecutable = null;
string workingDirectory = project.workingDirectory;
if (project.runInExternalConsole) {
version(Windows) {
} else {
externalConsoleExecutable = "xterm";
}
}
// TODO: provide thread safe listener
_logPanel.logLine("Starting " ~ executableFileName);
_statusLine.setBackgroundOperationStatus("debug-run", "running..."d);
_execution = new ProgramExecutionNoDebug(executableFileName, args, workingDirectory, externalConsoleExecutable, this);
_execution.run();
// TODO: update status
}
override protected void init() {
@ -649,8 +671,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener {
case IDEActions.DebugStart:
case IDEActions.DebugStartNoDebug:
case IDEActions.DebugContinue:
runProject();
//buildProject(BuildOperation.Run);
buildAndRunProject();
return true;
case IDEActions.UpdateProjectDependencies:
buildProject(BuildOperation.Upgrade);
@ -1010,12 +1031,12 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener {
}
}
void buildProject(BuildOperation buildOp) {
void buildProject(BuildOperation buildOp, BuildResultListener listener = null) {
if (!currentWorkspace || !currentWorkspace.startupProject) {
_logPanel.logLine("No project is opened");
return;
}
Builder op = new Builder(this, currentWorkspace.startupProject, _logPanel, currentWorkspace.projectConfiguration, currentWorkspace.buildConfiguration, buildOp, false);
Builder op = new Builder(this, currentWorkspace.startupProject, _logPanel, currentWorkspace.projectConfiguration, currentWorkspace.buildConfiguration, buildOp, false, listener);
setBackgroundOperation(op);
}

View File

@ -457,6 +457,23 @@ class Project : WorkspaceItem {
return exePath;
}
/// working directory for running and debugging project
@property string workingDirectory() {
// TODO: get from settings
return _filename.dirName;
}
/// commandline parameters for running and debugging project
@property string runArgs() {
// TODO: get from settings
return null;
}
@property bool runInExternalConsole() {
// TODO
return true;
}
ProjectFolder findItems(string[] srcPaths) {
ProjectFolder folder = new ProjectFolder(_filename);
folder.project = this;