mirror of https://github.com/buggins/dlangide.git
sample project reading
This commit is contained in:
parent
b22c27a5e4
commit
8e211b1adc
|
@ -47,7 +47,7 @@
|
|||
<compiler>0</compiler>
|
||||
<otherDMD>0</otherDMD>
|
||||
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
|
||||
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source</imppath>
|
||||
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png $(SolutionDir)/../dlib</imppath>
|
||||
<fileImppath />
|
||||
<outdir>$(ConfigurationName)</outdir>
|
||||
<objdir>$(OutDir)</objdir>
|
||||
|
@ -190,6 +190,10 @@
|
|||
</Config>
|
||||
<Folder name="dlangide">
|
||||
<Folder name="dlangide">
|
||||
<Folder name="workspace">
|
||||
<File path="src\dlangide\workspace\project.d" />
|
||||
<File path="src\dlangide\workspace\workspace.d" />
|
||||
</Folder>
|
||||
<Folder name="ui">
|
||||
<File path="src/dlangide/ui/commands.d" />
|
||||
<File path="src/dlangide/ui/frame.d" />
|
||||
|
|
|
@ -5,6 +5,7 @@ import std.stdio;
|
|||
import std.conv;
|
||||
import dlangide.ui.frame;
|
||||
import dlangide.ui.commands;
|
||||
import dlangide.workspace.workspace;
|
||||
|
||||
|
||||
mixin APP_ENTRY_POINT;
|
||||
|
@ -40,6 +41,10 @@ extern (C) int UIAppMain(string[] args) {
|
|||
// create some widget to show in window
|
||||
window.mainWidget = new IDEFrame(window);
|
||||
|
||||
// testing workspace loader
|
||||
Workspace ws = new Workspace();
|
||||
ws.load(appendPath(exePath, "../workspaces/sample1/sample1.dlangidews"));
|
||||
|
||||
// show window
|
||||
window.show();
|
||||
|
||||
|
|
|
@ -1,6 +1,79 @@
|
|||
module dlangide.workspace.project;
|
||||
|
||||
/// DLANGIDE D project
|
||||
class Project {
|
||||
import dlangide.workspace.workspace;
|
||||
import dlangui.core.logger;
|
||||
import std.path;
|
||||
import std.file;
|
||||
import std.json;
|
||||
import std.utf;
|
||||
|
||||
class WorkspaceItem {
|
||||
protected string _filename;
|
||||
protected string _dir;
|
||||
protected dstring _name;
|
||||
protected dstring _description;
|
||||
|
||||
this(string fname = null) {
|
||||
filename = fname;
|
||||
}
|
||||
|
||||
/// file name of workspace item
|
||||
@property string filename() {
|
||||
return _filename;
|
||||
}
|
||||
|
||||
/// file name of workspace item
|
||||
@property void filename(string fname) {
|
||||
if (fname.length > 0) {
|
||||
_filename = buildNormalizedPath(fname);
|
||||
_dir = dirName(filename);
|
||||
} else {
|
||||
_filename = null;
|
||||
_dir = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// load
|
||||
bool load(string fname) {
|
||||
// override it
|
||||
return false;
|
||||
}
|
||||
|
||||
bool save() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// DLANGIDE D project
|
||||
class Project : WorkspaceItem {
|
||||
protected Workspace _workspace;
|
||||
protected bool _opened;
|
||||
this(string fname = null) {
|
||||
super(fname);
|
||||
}
|
||||
override bool load(string fname = null) {
|
||||
if (fname.length > 0)
|
||||
filename = fname;
|
||||
if (!exists(filename) || !isFile(filename)) {
|
||||
return false;
|
||||
}
|
||||
Log.d("Reading project from file ", _filename);
|
||||
|
||||
try {
|
||||
string jsonSource = readText!string(_filename);
|
||||
JSONValue json = parseJSON(jsonSource);
|
||||
_name = toUTF32(json["name"].str);
|
||||
_description = toUTF32(json["description"].str);
|
||||
Log.d(" project name: ", _name);
|
||||
Log.d(" project description: ", _description);
|
||||
} catch (JSONException e) {
|
||||
Log.e("Cannot parse json", e);
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
Log.e("Cannot read project file", e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,65 @@
|
|||
module dlangide.workspace.workspace;
|
||||
|
||||
import dlangide.workspace.project;
|
||||
import dlangui.core.logger;
|
||||
import std.path;
|
||||
import std.file;
|
||||
import std.json;
|
||||
import std.utf;
|
||||
|
||||
/**
|
||||
Exception thrown on Workspace errors
|
||||
*/
|
||||
class WorkspaceException : Exception
|
||||
{
|
||||
this(string msg, string file = __FILE__, size_t line = __LINE__)
|
||||
{
|
||||
super(msg, file, line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// DlangIDE workspace
|
||||
class Workspace {
|
||||
protected string _dir;
|
||||
protected dstring _name;
|
||||
protected dstring _description;
|
||||
class Workspace : WorkspaceItem {
|
||||
protected Project[] _projects;
|
||||
|
||||
this(string fname = null) {
|
||||
super(fname);
|
||||
}
|
||||
|
||||
override bool load(string fname = null) {
|
||||
if (fname.length > 0)
|
||||
filename = fname;
|
||||
if (!exists(_filename) || !isFile(_filename)) {
|
||||
return false;
|
||||
}
|
||||
Log.d("Reading workspace from file ", _filename);
|
||||
|
||||
try {
|
||||
string jsonSource = readText!string(_filename);
|
||||
JSONValue json = parseJSON(jsonSource);
|
||||
_name = toUTF32(json["name"].str);
|
||||
_description = toUTF32(json["description"].str);
|
||||
Log.d("workspace name: ", _name);
|
||||
Log.d("workspace description: ", _description);
|
||||
JSONValue projects = json["projects"];
|
||||
foreach(string key, ref JSONValue value; projects) {
|
||||
string path = value.str;
|
||||
Log.d("project: ", key, " path:", path);
|
||||
if (!isAbsolute(path))
|
||||
path = buildNormalizedPath(_dir, path, "dub.json");
|
||||
Project project = new Project(path);
|
||||
_projects ~= project;
|
||||
project.load();
|
||||
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e("Cannot parse json", e);
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
Log.e("Cannot read workspace file", e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
"description": "Sample workspace 1 for testing of DLANG IDE",
|
||||
"projects": {
|
||||
"sampleproject1": "./sampleproject1",
|
||||
"sampleproject2": "./sampleproject2",
|
||||
"sampleproject2": "./sampleproject2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
"targetName": "sample1",
|
||||
"targetPath": "bin",
|
||||
"targetType": "executable",
|
||||
"targetType": "executable"
|
||||
}
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
"targetName": "sample2",
|
||||
"targetPath": "bin",
|
||||
"targetType": "executable",
|
||||
"targetType": "executable"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue