From a4f0f071120df116d1cc01d89b86fdb5121fddab Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 25 Sep 2017 14:17:18 +0300 Subject: [PATCH] missing source file opening - error handling fixes for #323 --- src/dlangide/ui/dsourceedit.d | 3 ++- src/dlangide/ui/frame.d | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/dlangide/ui/dsourceedit.d b/src/dlangide/ui/dsourceedit.d index 0e3f5b6..bbc7dc4 100644 --- a/src/dlangide/ui/dsourceedit.d +++ b/src/dlangide/ui/dsourceedit.d @@ -140,7 +140,8 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener { override bool load(string fn) { _projectSourceFile = null; bool res = super.load(fn); - setSyntaxSupport(); + if (res) + setSyntaxSupport(); return res; } diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index df33390..f2c0b15 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -413,6 +413,9 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL bool openSourceFile(string filename, ProjectSourceFile file = null, bool activate = true) { if (!file && !filename) return false; + + filename ~= ".invalid"; + if (!file) file = _wsPanel.findSourceFileItem(filename, false); @@ -430,7 +433,9 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL } else { // open new file DSourceEdit editor = new DSourceEdit(filename); + Log.d("trying to open source file ", filename); if (file ? editor.load(file) : editor.load(filename)) { + Log.d("file ", filename, " is opened ok"); _tabs.addTab(editor, toUTF32(baseName(filename)), null, true, filename.toUTF32); index = _tabs.tabIndex(filename); TabItem tab = _tabs.tab(filename); @@ -450,9 +455,10 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL editor.editorTool = new DefaultEditorTool(this); _tabs.layout(_tabs.pos); } else { + Log.d("file ", filename, " cannot be opened"); destroy(editor); if (window) - window.showMessageBox(UIString.fromId("ERROR_OPEN_FILE"c), UIString.fromId("ERROR_OPENING_FILE"c) ~ " " ~ toUTF32(file.filename)); + window.showMessageBox(UIString.fromId("ERROR_OPEN_FILE"c), UIString.fromId("ERROR_OPENING_FILE"c) ~ " " ~ toUTF32(filename)); return false; } } @@ -1534,8 +1540,12 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL if (openSourceFile(filename)) { auto index = _tabs.tabIndex(filename); + if (index < 0) + continue; // file is opened in tab auto source = cast(DSourceEdit)_tabs.tabBody(filename); + if (!source) + continue; // Caret position source.setCaretPos(column, row, true, true); }