Update results when new matches are found by worker threads

This commit is contained in:
Hans-Albert Maritz 2015-03-23 12:15:32 +11:00
parent 61e54f55f0
commit 50a2ca18f3
1 changed files with 23 additions and 24 deletions

View File

@ -140,11 +140,11 @@ class SearchWidget : TabWidget {
HorizontalLayout _layout; HorizontalLayout _layout;
EditLine _findText; EditLine _findText;
SearchLogWidget _resultLog; SearchLogWidget _resultLog;
int _resultLogMatchIndex;
ComboBox _searchScope; ComboBox _searchScope;
protected IDEFrame _frame; protected IDEFrame _frame;
protected SearchMatchList[] _matchedList; protected synchronized SearchMatchList[] _matchedList;
bool onFindButtonPressed(Widget source) { bool onFindButtonPressed(Widget source) {
@ -209,6 +209,7 @@ class SearchWidget : TabWidget {
if(match.matches.length > 0) { if(match.matches.length > 0) {
synchronized { synchronized {
_matchedList ~= match; _matchedList ~= match;
invalidate(); //Widget must updated with new matches
} }
} }
} }
@ -220,8 +221,9 @@ class SearchWidget : TabWidget {
_resultLog.textToHighlight = ""d; _resultLog.textToHighlight = ""d;
_resultLog.text = ""d; _resultLog.text = ""d;
_matchedList = []; _matchedList = [];
_resultLogMatchIndex = 0;
import std.parallelism; import std.parallelism; //for taskpool.
switch (_searchScope.text) { switch (_searchScope.text) {
case "File": case "File":
@ -249,24 +251,22 @@ class SearchWidget : TabWidget {
default: default:
assert(0); assert(0);
} }
import core.thread;
Thread.sleep( dur!("msecs")(10) );
if (_matchedList.length == 0) {
_resultLog.appendText(to!dstring("No matches found.\n"));
}
else {
_resultLog.textToHighlight = source; _resultLog.textToHighlight = source;
foreach(SearchMatchList fileMatchList; _matchedList) { return true;
_resultLog.appendText("Matches in "d ~ to!dstring(fileMatchList.filename) ~ '\n'); }
foreach(SearchMatch match; fileMatchList.matches) {
override void onDraw(DrawBuf buf) {
//Check if there are new matches to display
if(_resultLogMatchIndex < _matchedList.length) {
for(; _resultLogMatchIndex < _matchedList.length; _resultLogMatchIndex++) {
SearchMatchList matchList = _matchedList[_resultLogMatchIndex];
_resultLog.appendText("Matches in "d ~ to!dstring(matchList.filename) ~ '\n');
foreach(SearchMatch match; matchList.matches) {
_resultLog.appendText(" --> ["d ~ to!dstring(match.line+1) ~ ":"d ~ to!dstring(match.col) ~ "]" ~ match.lineContent ~"\n"d); _resultLog.appendText(" --> ["d ~ to!dstring(match.line+1) ~ ":"d ~ to!dstring(match.col) ~ "]" ~ match.lineContent ~"\n"d);
} }
} }
} }
return true; super.onDraw(buf);
} }
//Find the match/matchList that corrosponds to the line in _resultLog //Find the match/matchList that corrosponds to the line in _resultLog
@ -293,7 +293,7 @@ class SearchWidget : TabWidget {
} }
} }
SearchMatchList findMatches(immutable string filename, immutable dstring searchString) { SearchMatchList findMatches(in string filename, in dstring searchString) {
EditableContent content = new EditableContent(true); EditableContent content = new EditableContent(true);
content.load(filename); content.load(filename);
SearchMatchList match; SearchMatchList match;
@ -303,7 +303,6 @@ SearchMatchList findMatches(immutable string filename, immutable dstring searchS
auto colIndex = line.indexOf(searchString); auto colIndex = line.indexOf(searchString);
if (colIndex != -1) { if (colIndex != -1) {
Log.d("Match at: ", colIndex, " text: ", searchString);
match.matches ~= SearchMatch(lineIndex, colIndex, line); match.matches ~= SearchMatch(lineIndex, colIndex, line);
} }
} }