recent workspaces list: close #71

This commit is contained in:
Vadim Lopatin 2015-12-15 14:37:50 +03:00
parent fff1d3e87c
commit c6836aa6c4
3 changed files with 44 additions and 1 deletions

View File

@ -797,6 +797,10 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
});
return true;
case IDEActions.FileOpenWorkspace:
if (!a.stringParam.empty) {
openFileOrWorkspace(a.stringParam);
return true;
}
UIString caption;
caption = "Open Workspace or Project"d;
FileDialog dlg = createFileDialog(caption);
@ -1112,6 +1116,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
askForUnsavedEdits(delegate() {
setWorkspace(ws);
hideHomeScreen();
_settings.updateRecentWorkspace(filename);
});
} else {
window.showMessageBox(UIString("Cannot open workspace"d), UIString("Error occured while opening workspace"d));

View File

@ -7,6 +7,8 @@ import dlangui.widgets.controls;
import dlangide.ui.frame;
import dlangide.ui.commands;
import std.path;
class HomeScreen : ScrollWidget {
protected IDEFrame _frame;
protected HorizontalLayout _content;
@ -38,7 +40,17 @@ class HomeScreen : ScrollWidget {
_column1.addChild(_startItems);
_column1.addChild(new VSpacer());
_column1.addChild((new TextWidget(null, "Recent:"d)).fontSize(20).textColor(linkColor));
_recentItems.addChild((new TextWidget(null, "No recent items"d)));
string[] recentWorkspaces = _frame.settings.recentWorkspaces;
if (recentWorkspaces.length) {
foreach(fn; recentWorkspaces) {
Action a = ACTION_FILE_OPEN_WORKSPACE.clone();
a.label = UIString(toUTF32(stripExtension(baseName(fn))));
a.stringParam = fn;
_column1.addChild(new LinkButton(a));
}
} else {
_recentItems.addChild((new TextWidget(null, "No recent items"d)));
}
_column1.addChild(_recentItems);
_column1.addChild(new VSpacer());
_column2.addChild((new TextWidget(null, "Useful Links:"d)).fontSize(20).textColor(linkColor));

View File

@ -175,5 +175,31 @@ class IDESettings : SettingsFile {
return null;
}
@property string[] recentWorkspaces() {
import std.file;
Setting obj = _setting.objectByPath("history", true);
string[] list = obj.getStringArray("recentWorkspaces");
string[] res;
foreach(fn; list) {
if (exists(fn) && isFile(fn))
res ~= fn;
}
return res;
}
void updateRecentWorkspace(string ws) {
import std.file;
string[] list;
list ~= ws;
string[] existing = recentWorkspaces;
foreach(fn; existing) {
if (exists(fn) && isFile(fn) && !ws.equal(fn))
list ~= fn;
}
Setting obj = _setting.objectByPath("history", true);
obj["recentWorkspaces"] = list;
save();
}
}