fix #256 - crash on FindInFiles when there is no opened editor

This commit is contained in:
Vadim Lopatin 2017-09-08 15:56:09 +03:00
parent 5c72e879c1
commit 52c0818b49
3 changed files with 48 additions and 11 deletions

View File

@ -1108,8 +1108,11 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
_logPanel.getTabs.selectTab("search");
if(searchPanel !is null) {
searchPanel.focus();
dstring selectedText = currentEditor.getSelectedText();
dstring selectedText;
if (currentEditor)
selectedText = currentEditor.getSelectedText();
searchPanel.setSearchText(selectedText);
searchPanel.checkSearchMode();
}
return true;
case IDEActions.FileNewWorkspace:

View File

@ -152,6 +152,8 @@ class SearchWidget : TabWidget {
SearchLogWidget _resultLog;
int _resultLogMatchIndex;
ComboBox _searchScope;
ImageCheckButton _cbCaseSensitive;
ImageCheckButton _cbWholeWords;
protected IDEFrame _frame;
protected SearchMatchList[] _matchedList;
@ -206,6 +208,18 @@ class SearchWidget : TabWidget {
_searchScope = new ComboBox("searchScope", ["File"d, "Project"d, "Dependencies"d, "Everywhere"d]);
_searchScope.selectedItemIndex = 0;
_layout.addChild(_searchScope);
_cbCaseSensitive = new ImageCheckButton("cbCaseSensitive", "find_case_sensitive");
_cbCaseSensitive.tooltipText = "EDIT_FIND_CASE_SENSITIVE";
_cbCaseSensitive.styleId = "TOOLBAR_BUTTON";
_cbCaseSensitive.checked = true;
_layout.addChild(_cbCaseSensitive);
_cbWholeWords = new ImageCheckButton("cbWholeWords", "find_whole_words");
_cbWholeWords.tooltipText = "EDIT_FIND_WHOLE_WORDS";
_cbWholeWords.styleId = "TOOLBAR_BUTTON";
_layout.addChild(_cbWholeWords);
addChild(_layout);
_resultLog = new SearchLogWidget("SearchLogWidget");
@ -250,9 +264,11 @@ class SearchWidget : TabWidget {
switch (_searchScope.text) {
case "File":
if (_frame.currentEditor) {
SearchMatchList match = findMatches(_frame.currentEditor.filename, source);
if(match.matches.length > 0)
_matchedList ~= match;
}
break;
case "Project":
foreach(Project project; _frame._wsPanel.workspace.projects) {
@ -303,22 +319,40 @@ class SearchWidget : TabWidget {
super.onDraw(buf);
}
void checkSearchMode() {
if (!_frame.currentEditor && _searchScope.selectedItemIndex == 0)
_searchScope.selectedItemIndex = 1;
}
uint makeSearchFlags() {
uint res = 0;
if (_cbCaseSensitive.checked)
res |= TextSearchFlag.CaseSensitive;
if (_cbWholeWords.checked)
res |= TextSearchFlag.WholeWords;
return res;
}
//Find the match/matchList that corrosponds to the line in _resultLog
bool onMatchClick(int line) {
line++;
foreach(matchList; _matchedList){
line--;
if (line == 0) {
_frame.openSourceFile(matchList.filename);
if (_frame.openSourceFile(matchList.filename)) {
_frame.currentEditor.setTextToHighlight(_findText.text, makeSearchFlags);
_frame.currentEditor.setFocus();
}
return true;
}
foreach(match; matchList.matches) {
line--;
if (line == 0) {
_frame.openSourceFile(matchList.filename);
if (_frame.openSourceFile(matchList.filename)) {
_frame.currentEditor.setCaretPos(match.line, to!int(match.col));
_frame.currentEditor.setTextToHighlight(_findText.text, makeSearchFlags);
_frame.currentEditor.setFocus();
}
return true;
}
}

View File

@ -1 +1 @@
v0.7.70
v0.7.71