Asynchronously search for text.

Initial implementation. Still need to update result log.
This commit is contained in:
Hans-Albert Maritz 2015-03-23 10:06:01 +11:00
parent 0c987fa894
commit 61e54f55f0
1 changed files with 50 additions and 32 deletions

View File

@ -124,14 +124,6 @@ class SearchLogWidget : LogWidget {
}
}
class SearchWidget : TabWidget {
HorizontalLayout _layout;
EditLine _findText;
SearchLogWidget _resultLog;
ComboBox _searchScope;
protected IDEFrame _frame;
protected SearchMatchList[] _matchedList;
struct SearchMatch {
int line;
@ -144,6 +136,17 @@ class SearchWidget : TabWidget {
SearchMatch[] matches;
}
class SearchWidget : TabWidget {
HorizontalLayout _layout;
EditLine _findText;
SearchLogWidget _resultLog;
ComboBox _searchScope;
protected IDEFrame _frame;
protected SearchMatchList[] _matchedList;
bool onFindButtonPressed(Widget source) {
dstring txt = _findText.text;
if (txt.length > 0)
@ -195,29 +198,21 @@ class SearchWidget : TabWidget {
void searchInProject(ProjectItem project, dstring text) {
if (project.isFolder == true) {
ProjectFolder projFolder = cast(ProjectFolder) project;
import std.parallelism;
for (int i = 0; i < projFolder.childCount; i++) {
searchInProject(projFolder.child(i), text);
taskPool.put(task(&searchInProject, projFolder.child(i), text));
}
}
else {
Log.d("Searching in: " ~ project.filename);
EditableContent content = new EditableContent(true);
content.load(project.filename);
SearchMatchList match;
match.filename = project.filename;
foreach(int lineIndex, dstring line; content.lines) {
auto colIndex = line.indexOf(text);
if (colIndex != -1) {
match.matches ~= SearchMatch(lineIndex, colIndex, line);
}
}
SearchMatchList match = findMatches(project.filename, text);
if(match.matches.length > 0) {
synchronized {
_matchedList ~= match;
}
}
}
}
bool findText(dstring source) {
Log.d("Finding " ~ source);
@ -226,33 +221,39 @@ class SearchWidget : TabWidget {
_resultLog.text = ""d;
_matchedList = [];
import std.parallelism;
switch (_searchScope.text) {
case "File": //File
case "File":
auto currentFileItem = _frame._wsPanel.workspace.findSourceFileItem(_frame.currentEditor.filename);
if(currentFileItem !is null)
searchInProject(currentFileItem, source);
taskPool.put(task(&searchInProject, currentFileItem, source));
break;
case "Project": //Project
case "Project":
foreach(Project project; _frame._wsPanel.workspace.projects) {
if(!project.isDependency)
searchInProject(project.items, source);
taskPool.put(task(&searchInProject, project.items, source));
}
break;
case "Dependencies": //Dependencies
case "Dependencies":
foreach(Project project; _frame._wsPanel.workspace.projects) {
if(project.isDependency)
searchInProject(project.items, source);
taskPool.put(task(&searchInProject, project.items, source));
}
break;
case "Everywhere": //Everywhere
case "Everywhere":
foreach(Project project; _frame._wsPanel.workspace.projects) {
searchInProject(project.items, source);
taskPool.put(task(&searchInProject, project.items, source));
}
break;
default:
assert(0);
}
import core.thread;
Thread.sleep( dur!("msecs")(10) );
if (_matchedList.length == 0) {
_resultLog.appendText(to!dstring("No matches found.\n"));
}
@ -291,3 +292,20 @@ class SearchWidget : TabWidget {
return false;
}
}
SearchMatchList findMatches(immutable string filename, immutable dstring searchString) {
EditableContent content = new EditableContent(true);
content.load(filename);
SearchMatchList match;
match.filename = filename;
foreach(int lineIndex, dstring line; content.lines) {
auto colIndex = line.indexOf(searchString);
if (colIndex != -1) {
Log.d("Match at: ", colIndex, " text: ", searchString);
match.matches ~= SearchMatch(lineIndex, colIndex, line);
}
}
return match;
}