Merge pull request #273 from shiche/73-openListOfPrevFiles

73 open list of prev files
This commit is contained in:
Vadim Lopatin 2017-09-12 09:45:54 +03:00 committed by GitHub
commit e7d58c9750
3 changed files with 66 additions and 14 deletions

View File

@ -409,7 +409,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
_tabs.renameTab(index, name);
}
}
bool openSourceFile(string filename, ProjectSourceFile file = null, bool activate = true) {
if (!file && !filename)
return false;
@ -1431,9 +1431,20 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
// Write workspace to recent workspaces list
_settings.updateRecentWorkspace(filename);
// All was opened, attempt to restore files
const string[] files = currentWorkspace.files();
for (int i; i < files.length; i++)
openSourceFile(files[i]);
WorkspaceFile[] files = currentWorkspace.files();
for (int i; i < files.length; i++)
with (files[i])
{
// Opening file
if (openSourceFile(filename))
{
auto index = _tabs.tabIndex(filename);
// file is opened in tab
auto source = cast(DSourceEdit)_tabs.tabBody(filename);
// Caret position
source.setCaretPos(column, row);
}
}
});
} else {
window.showMessageBox(UIString.fromId("ERROR_OPEN_WORKSPACE"c).value, UIString.fromId("ERROR_OPENING_WORKSPACE"c).value);
@ -1608,12 +1619,17 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
askForUnsavedEdits(delegate() {
if (currentWorkspace) {
// Remember opened files
string[] files;
WorkspaceFile[] files;
for (auto i = 0; i < _tabs.tabCount(); i++)
{
auto edit = cast(DSourceEdit)_tabs.tabBody(i);
if (edit !is null)
files ~= edit.filename();
if (edit !is null) {
auto file = new WorkspaceFile();
file.filename = edit.filename();
file.row = edit.caretPos.pos;
file.column = edit.caretPos.line;
files ~= file;
}
}
currentWorkspace.files(files);
// saving workspace

View File

@ -98,12 +98,12 @@ class Workspace : WorkspaceItem {
}
/// Last opened files in workspace
@property string[] files() {
@property WorkspaceFile[] files() {
return _settings.files();
}
/// Last opened files in workspace
@property void files(string[] fs) {
@property void files(WorkspaceFile[] fs) {
_settings.files(fs);
}

View File

@ -18,7 +18,7 @@ class WorkspaceSettings : SettingsFile {
private Breakpoint[] _breakpoints;
private EditorBookmark[] _bookmarks;
/// Last opened files in workspace
private string[] _files;
private WorkspaceFile[] _files;
private string _startupProjectName;
@property string startupProjectName() {
@ -33,12 +33,12 @@ class WorkspaceSettings : SettingsFile {
}
/// Last opened files in workspace
@property string[] files() {
@property WorkspaceFile[] files() {
return _files;
}
/// Last opened files in workspace
@property void files(string[] fs) {
@property void files(WorkspaceFile[] fs) {
_files = fs;
// Save to settings file
Setting obj = _setting.settingByPath("files", SettingType.ARRAY);
@ -46,7 +46,9 @@ class WorkspaceSettings : SettingsFile {
int index = 0;
foreach(file; fs) {
Setting single = new Setting();
single.setString("file", file);
single.setString("file", file.filename);
single.setInteger("column", file.column);
single.setInteger("row", file.row);
obj[index++] = single;
}
}
@ -207,7 +209,11 @@ class WorkspaceSettings : SettingsFile {
obj = _setting.settingByPath("files", SettingType.ARRAY);
for (int i = 0; i < obj.length; i++) {
Setting item = obj[i];
_files ~= item.getString("file");
WorkspaceFile file = new WorkspaceFile;
file.filename(item.getString("file"));
file.column(cast(int)item.getInteger("column"));
file.row(cast(int)item.getInteger("row"));
_files ~= file;
}
}
@ -216,3 +222,33 @@ class WorkspaceSettings : SettingsFile {
}
/// Description for workspace file
class WorkspaceFile {
/// File name with full path
private string _filename;
/// Cursor position column
private int _column;
/// Cursor position row
private int _row;
@property string filename() {
return _filename;
}
@property void filename(string _fn) {
this._filename = _fn;
}
@property int column() {
return _column;
}
@property void column(int col) {
_column = col;
}
@property int row() {
return _row;
}
@property void row(int r) {
_row = r;
}
}