mirror of https://github.com/buggins/dlangide.git
Loading project configs from projects
This commit is contained in:
parent
6de6b99afe
commit
fa94e9bbf9
|
|
@ -16,7 +16,7 @@ class Builder : BackgroundOperationWatcher {
|
||||||
protected ExternalProcess _extprocess;
|
protected ExternalProcess _extprocess;
|
||||||
protected OutputPanel _log;
|
protected OutputPanel _log;
|
||||||
protected ProtectedTextStorage _box;
|
protected ProtectedTextStorage _box;
|
||||||
protected dstring _projectConfig;
|
protected ProjectConfiguration _projectConfig;
|
||||||
protected BuildConfiguration _buildConfig;
|
protected BuildConfiguration _buildConfig;
|
||||||
protected BuildOperation _buildOp;
|
protected BuildOperation _buildOp;
|
||||||
protected bool _verbose;
|
protected bool _verbose;
|
||||||
|
|
@ -24,7 +24,7 @@ class Builder : BackgroundOperationWatcher {
|
||||||
@property Project project() { return _project; }
|
@property Project project() { return _project; }
|
||||||
@property void project(Project p) { _project = p; }
|
@property void project(Project p) { _project = p; }
|
||||||
|
|
||||||
this(AppFrame frame, Project project, OutputPanel log, dstring projectConfig, BuildConfiguration buildConfig, BuildOperation buildOp, bool verbose) {
|
this(AppFrame frame, Project project, OutputPanel log, ProjectConfiguration projectConfig, BuildConfiguration buildConfig, BuildOperation buildOp, bool verbose) {
|
||||||
super(frame);
|
super(frame);
|
||||||
_projectConfig = projectConfig;
|
_projectConfig = projectConfig;
|
||||||
_buildConfig = buildConfig;
|
_buildConfig = buildConfig;
|
||||||
|
|
@ -85,8 +85,8 @@ class Builder : BackgroundOperationWatcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_projectConfig != DEFAULT_PROJECT_CONFIGURATION) {
|
if(_projectConfig.name != ProjectConfiguration.DEFAULT_NAME) {
|
||||||
params ~= "--config=".dup ~ cast(string)(_projectConfig);
|
params ~= "--config=".dup ~ _projectConfig.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_verbose)
|
if (_verbose)
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,33 @@ class BackgroundOperationWatcherTest : BackgroundOperationWatcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Subclass of toolbars that can update their items
|
||||||
|
class UpdateableToolBarComboBox : ToolBarComboBox {
|
||||||
|
this(string id, dstring[] items) {
|
||||||
|
super(id, items);
|
||||||
|
}
|
||||||
|
|
||||||
|
@property items(dstring[] newItems) {
|
||||||
|
_adapter.items = newItems;
|
||||||
|
if(newItems.length > 0) {
|
||||||
|
selectedItemIndex = 0;
|
||||||
|
}
|
||||||
|
requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
@property dstring selectedItem() {
|
||||||
|
size_t index = _selectedItemIndex;
|
||||||
|
if(index < 0 || index >= _adapter.itemCount) return "";
|
||||||
|
|
||||||
|
return _adapter.items.get(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// DIDE app frame
|
/// DIDE app frame
|
||||||
class IDEFrame : AppFrame {
|
class IDEFrame : AppFrame {
|
||||||
|
|
||||||
|
private UpdateableToolBarComboBox projectConfigurationCombo;
|
||||||
|
|
||||||
MenuItem mainMenuItems;
|
MenuItem mainMenuItems;
|
||||||
WorkspacePanel _wsPanel;
|
WorkspacePanel _wsPanel;
|
||||||
OutputPanel _logPanel;
|
OutputPanel _logPanel;
|
||||||
|
|
@ -435,15 +459,15 @@ class IDEFrame : AppFrame {
|
||||||
|
|
||||||
tb.addButtons(ACTION_DEBUG_START);
|
tb.addButtons(ACTION_DEBUG_START);
|
||||||
|
|
||||||
ToolBarComboBox cbProjectConfiguration = new ToolBarComboBox("projectConfig", [DEFAULT_PROJECT_CONFIGURATION]);
|
projectConfigurationCombo = new UpdateableToolBarComboBox("projectConfig", [ProjectConfiguration.DEFAULT_NAME.to!dstring]);
|
||||||
cbProjectConfiguration.onItemClickListener = delegate(Widget source, int index) {
|
projectConfigurationCombo.onItemClickListener = delegate(Widget source, int index) {
|
||||||
if (currentWorkspace) {
|
if (currentWorkspace) {
|
||||||
currentWorkspace.projectConfiguration = cbProjectConfiguration.text;
|
currentWorkspace.setStartupProjectConfiguration(projectConfigurationCombo.selectedItem.to!string);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
cbProjectConfiguration.action = ACTION_PROJECT_CONFIGURATIONS;
|
projectConfigurationCombo.action = ACTION_PROJECT_CONFIGURATIONS;
|
||||||
tb.addControl(cbProjectConfiguration);
|
tb.addControl(projectConfigurationCombo);
|
||||||
|
|
||||||
ToolBarComboBox cbBuildConfiguration = new ToolBarComboBox("buildConfig", ["Debug"d, "Release"d, "Unittest"d]);
|
ToolBarComboBox cbBuildConfiguration = new ToolBarComboBox("buildConfig", ["Debug"d, "Release"d, "Unittest"d]);
|
||||||
cbBuildConfiguration.onItemClickListener = delegate(Widget source, int index) {
|
cbBuildConfiguration.onItemClickListener = delegate(Widget source, int index) {
|
||||||
|
|
@ -604,7 +628,7 @@ class IDEFrame : AppFrame {
|
||||||
|
|
||||||
void openFileOrWorkspace(string filename) {
|
void openFileOrWorkspace(string filename) {
|
||||||
if (filename.isWorkspaceFile) {
|
if (filename.isWorkspaceFile) {
|
||||||
Workspace ws = new Workspace();
|
Workspace ws = new Workspace(this);
|
||||||
if (ws.load(filename)) {
|
if (ws.load(filename)) {
|
||||||
askForUnsavedEdits(delegate() {
|
askForUnsavedEdits(delegate() {
|
||||||
setWorkspace(ws);
|
setWorkspace(ws);
|
||||||
|
|
@ -663,7 +687,7 @@ class IDEFrame : AppFrame {
|
||||||
string defWsFile = project.defWorkspaceFile;
|
string defWsFile = project.defWorkspaceFile;
|
||||||
_logPanel.logLine("Creating new workspace " ~ defWsFile);
|
_logPanel.logLine("Creating new workspace " ~ defWsFile);
|
||||||
// new ws
|
// new ws
|
||||||
Workspace ws = new Workspace();
|
Workspace ws = new Workspace(this);
|
||||||
ws.name = project.name;
|
ws.name = project.name;
|
||||||
ws.description = project.description;
|
ws.description = project.description;
|
||||||
ws.addProject(project);
|
ws.addProject(project);
|
||||||
|
|
@ -700,7 +724,12 @@ class IDEFrame : AppFrame {
|
||||||
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);
|
||||||
setBackgroundOperation(op);
|
setBackgroundOperation(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// updates list of available configurations
|
||||||
|
void setProjectConfigurations(dstring[] items) {
|
||||||
|
projectConfigurationCombo.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
/// handle files dropped to application window
|
/// handle files dropped to application window
|
||||||
void onFilesDropped(string[] filenames) {
|
void onFilesDropped(string[] filenames) {
|
||||||
//Log.d("onFilesDropped(", filenames, ")");
|
//Log.d("onFilesDropped(", filenames, ")");
|
||||||
|
|
|
||||||
|
|
@ -223,6 +223,59 @@ string[] dmdSourcePaths() {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Stores info about project configuration
|
||||||
|
struct ProjectConfiguration {
|
||||||
|
/// name used to build the project
|
||||||
|
string name;
|
||||||
|
/// type, for libraries one can run tests, for apps - execute them
|
||||||
|
Type type;
|
||||||
|
|
||||||
|
/// How to display default configuration in ui
|
||||||
|
immutable static string DEFAULT_NAME = "default";
|
||||||
|
/// Default project configuration
|
||||||
|
immutable static ProjectConfiguration DEFAULT = ProjectConfiguration(DEFAULT_NAME, Type.Default);
|
||||||
|
|
||||||
|
/// Type of configuration
|
||||||
|
enum Type {
|
||||||
|
Default,
|
||||||
|
Executable,
|
||||||
|
Library
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type parseType(string s)
|
||||||
|
{
|
||||||
|
switch(s)
|
||||||
|
{
|
||||||
|
case "executable": return Type.Executable;
|
||||||
|
case "library": return Type.Library;
|
||||||
|
case "dynamicLibrary": return Type.Library;
|
||||||
|
case "staticLibrary": return Type.Library;
|
||||||
|
default: return Type.Default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// parsing from setting file
|
||||||
|
static ProjectConfiguration[string] load(Setting s)
|
||||||
|
{
|
||||||
|
ProjectConfiguration[string] res = [DEFAULT_NAME: DEFAULT];
|
||||||
|
if(s.map is null || "configurations" !in s.map || s.map["configurations"].array is null)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
foreach(conf; s.map["configurations"].array)
|
||||||
|
{
|
||||||
|
if(conf.map is null || "name" !in conf.map) continue;
|
||||||
|
Type t = Type.Default;
|
||||||
|
if("targetType" in conf.map) {
|
||||||
|
t = parseType(conf.map["targetType"].str);
|
||||||
|
}
|
||||||
|
string confName = conf.map["name"].str;
|
||||||
|
res[confName] = ProjectConfiguration(confName, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// DLANGIDE D project
|
/// DLANGIDE D project
|
||||||
class Project : WorkspaceItem {
|
class Project : WorkspaceItem {
|
||||||
protected Workspace _workspace;
|
protected Workspace _workspace;
|
||||||
|
|
@ -233,13 +286,19 @@ class Project : WorkspaceItem {
|
||||||
|
|
||||||
protected string[] _sourcePaths;
|
protected string[] _sourcePaths;
|
||||||
protected string[] _builderSourcePaths;
|
protected string[] _builderSourcePaths;
|
||||||
|
protected ProjectConfiguration[string] _configurations;
|
||||||
|
|
||||||
this(string fname = null) {
|
this(string fname = null) {
|
||||||
super(fname);
|
super(fname);
|
||||||
_items = new ProjectFolder(fname);
|
_items = new ProjectFolder(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// returns project configurations
|
||||||
|
@property const(ProjectConfiguration[string]) configurations() const
|
||||||
|
{
|
||||||
|
return _configurations;
|
||||||
|
}
|
||||||
|
|
||||||
/// returns project's own source paths
|
/// returns project's own source paths
|
||||||
@property string[] sourcePaths() { return _sourcePaths; }
|
@property string[] sourcePaths() { return _sourcePaths; }
|
||||||
/// returns project's own source paths
|
/// returns project's own source paths
|
||||||
|
|
@ -356,6 +415,9 @@ class Project : WorkspaceItem {
|
||||||
Log.i("Project source paths: ", sourcePaths);
|
Log.i("Project source paths: ", sourcePaths);
|
||||||
Log.i("Builder source paths: ", builderSourcePaths);
|
Log.i("Builder source paths: ", builderSourcePaths);
|
||||||
|
|
||||||
|
_configurations = ProjectConfiguration.load(_projectFile);
|
||||||
|
Log.i("Project configurations: ", _configurations);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e("Cannot parse json", e);
|
Log.e("Cannot parse json", e);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
module dlangide.workspace.workspace;
|
module dlangide.workspace.workspace;
|
||||||
|
|
||||||
import dlangide.workspace.project;
|
import dlangide.workspace.project;
|
||||||
|
import dlangide.ui.frame;
|
||||||
import dlangui.core.logger;
|
import dlangui.core.logger;
|
||||||
|
import std.conv;
|
||||||
import std.path;
|
import std.path;
|
||||||
import std.file;
|
import std.file;
|
||||||
import std.json;
|
import std.json;
|
||||||
|
import std.range;
|
||||||
import std.utf;
|
import std.utf;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
|
|
||||||
|
|
@ -35,7 +38,6 @@ class WorkspaceException : Exception
|
||||||
}
|
}
|
||||||
|
|
||||||
immutable string WORKSPACE_EXTENSION = ".dlangidews";
|
immutable string WORKSPACE_EXTENSION = ".dlangidews";
|
||||||
immutable dstring DEFAULT_PROJECT_CONFIGURATION = "default"d;
|
|
||||||
|
|
||||||
/// return true if filename matches rules for workspace file names
|
/// return true if filename matches rules for workspace file names
|
||||||
bool isWorkspaceFile(string filename) {
|
bool isWorkspaceFile(string filename) {
|
||||||
|
|
@ -45,12 +47,14 @@ bool isWorkspaceFile(string filename) {
|
||||||
/// DlangIDE workspace
|
/// DlangIDE workspace
|
||||||
class Workspace : WorkspaceItem {
|
class Workspace : WorkspaceItem {
|
||||||
protected Project[] _projects;
|
protected Project[] _projects;
|
||||||
|
|
||||||
protected BuildConfiguration _buildConfiguration;
|
|
||||||
protected dstring _projectConfiguration = DEFAULT_PROJECT_CONFIGURATION;
|
|
||||||
|
|
||||||
this(string fname = null) {
|
protected IDEFrame _frame;
|
||||||
|
protected BuildConfiguration _buildConfiguration;
|
||||||
|
protected ProjectConfiguration _projectConfiguration = ProjectConfiguration.DEFAULT;
|
||||||
|
|
||||||
|
this(IDEFrame frame, string fname = null) {
|
||||||
super(fname);
|
super(fname);
|
||||||
|
_frame = frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property Project[] projects() {
|
@property Project[] projects() {
|
||||||
|
|
@ -60,17 +64,28 @@ class Workspace : WorkspaceItem {
|
||||||
@property BuildConfiguration buildConfiguration() { return _buildConfiguration; }
|
@property BuildConfiguration buildConfiguration() { return _buildConfiguration; }
|
||||||
@property void buildConfiguration(BuildConfiguration config) { _buildConfiguration = config; }
|
@property void buildConfiguration(BuildConfiguration config) { _buildConfiguration = config; }
|
||||||
|
|
||||||
@property dstring projectConfiguration() { return _projectConfiguration; }
|
@property ProjectConfiguration projectConfiguration() { return _projectConfiguration; }
|
||||||
@property void projectConfiguration(dstring config) { _projectConfiguration = config; }
|
@property void projectConfiguration(ProjectConfiguration config) { _projectConfiguration = config; }
|
||||||
|
|
||||||
protected Project _startupProject;
|
protected Project _startupProject;
|
||||||
|
|
||||||
@property Project startupProject() { return _startupProject; }
|
@property Project startupProject() { return _startupProject; }
|
||||||
@property void startupProject(Project project) { _startupProject = project; }
|
@property void startupProject(Project project) {
|
||||||
|
_startupProject = project;
|
||||||
|
_frame.setProjectConfigurations(project.configurations.keys.map!(k => k.to!dstring).array);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// setups currrent project configuration by name
|
||||||
|
void setStartupProjectConfiguration(string conf)
|
||||||
|
{
|
||||||
|
if(_startupProject && conf in _startupProject.configurations) {
|
||||||
|
_projectConfiguration = _startupProject.configurations[conf];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void fillStartupProject() {
|
protected void fillStartupProject() {
|
||||||
if (!_startupProject && _projects.length)
|
if (!_startupProject && _projects.length)
|
||||||
_startupProject = _projects[0];
|
startupProject = _projects[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// tries to find source file in one of projects, returns found project source file item, or null if not found
|
/// tries to find source file in one of projects, returns found project source file item, or null if not found
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue