mirror of https://github.com/buggins/dlangide.git
commit
950c7f69a9
|
@ -124,25 +124,28 @@ class SearchLogWidget : LogWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct SearchMatch {
|
||||||
|
int line;
|
||||||
|
long col;
|
||||||
|
dstring lineContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SearchMatchList {
|
||||||
|
string filename;
|
||||||
|
SearchMatch[] matches;
|
||||||
|
}
|
||||||
|
|
||||||
class SearchWidget : TabWidget {
|
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;
|
||||||
|
|
||||||
struct SearchMatch {
|
|
||||||
int line;
|
|
||||||
long col;
|
|
||||||
dstring lineContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SearchMatchList {
|
|
||||||
string filename;
|
|
||||||
SearchMatch[] matches;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool onFindButtonPressed(Widget source) {
|
bool onFindButtonPressed(Widget source) {
|
||||||
dstring txt = _findText.text;
|
dstring txt = _findText.text;
|
||||||
|
@ -195,26 +198,19 @@ class SearchWidget : TabWidget {
|
||||||
void searchInProject(ProjectItem project, dstring text) {
|
void searchInProject(ProjectItem project, dstring text) {
|
||||||
if (project.isFolder == true) {
|
if (project.isFolder == true) {
|
||||||
ProjectFolder projFolder = cast(ProjectFolder) project;
|
ProjectFolder projFolder = cast(ProjectFolder) project;
|
||||||
|
import std.parallelism;
|
||||||
for (int i = 0; i < projFolder.childCount; i++) {
|
for (int i = 0; i < projFolder.childCount; i++) {
|
||||||
searchInProject(projFolder.child(i), text);
|
taskPool.put(task(&searchInProject, projFolder.child(i), text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.d("Searching in: " ~ project.filename);
|
Log.d("Searching in: " ~ project.filename);
|
||||||
EditableContent content = new EditableContent(true);
|
SearchMatchList match = findMatches(project.filename, text);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(match.matches.length > 0) {
|
if(match.matches.length > 0) {
|
||||||
_matchedList ~= match;
|
synchronized {
|
||||||
|
_matchedList ~= match;
|
||||||
|
invalidate(); //Widget must updated with new matches
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,49 +221,54 @@ class SearchWidget : TabWidget {
|
||||||
_resultLog.textToHighlight = ""d;
|
_resultLog.textToHighlight = ""d;
|
||||||
_resultLog.text = ""d;
|
_resultLog.text = ""d;
|
||||||
_matchedList = [];
|
_matchedList = [];
|
||||||
|
_resultLogMatchIndex = 0;
|
||||||
|
|
||||||
|
import std.parallelism; //for taskpool.
|
||||||
|
|
||||||
switch (_searchScope.text) {
|
switch (_searchScope.text) {
|
||||||
case "File": //File
|
case "File":
|
||||||
auto currentFileItem = _frame._wsPanel.workspace.findSourceFileItem(_frame.currentEditor.filename);
|
auto currentFileItem = _frame._wsPanel.workspace.findSourceFileItem(_frame.currentEditor.filename);
|
||||||
if(currentFileItem !is null)
|
if(currentFileItem !is null)
|
||||||
searchInProject(currentFileItem, source);
|
taskPool.put(task(&searchInProject, currentFileItem, source));
|
||||||
break;
|
break;
|
||||||
case "Project": //Project
|
case "Project":
|
||||||
foreach(Project project; _frame._wsPanel.workspace.projects) {
|
foreach(Project project; _frame._wsPanel.workspace.projects) {
|
||||||
if(!project.isDependency)
|
if(!project.isDependency)
|
||||||
searchInProject(project.items, source);
|
taskPool.put(task(&searchInProject, project.items, source));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Dependencies": //Dependencies
|
case "Dependencies":
|
||||||
foreach(Project project; _frame._wsPanel.workspace.projects) {
|
foreach(Project project; _frame._wsPanel.workspace.projects) {
|
||||||
if(project.isDependency)
|
if(project.isDependency)
|
||||||
searchInProject(project.items, source);
|
taskPool.put(task(&searchInProject, project.items, source));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Everywhere": //Everywhere
|
case "Everywhere":
|
||||||
foreach(Project project; _frame._wsPanel.workspace.projects) {
|
foreach(Project project; _frame._wsPanel.workspace.projects) {
|
||||||
searchInProject(project.items, source);
|
taskPool.put(task(&searchInProject, project.items, source));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
_resultLog.textToHighlight = source;
|
||||||
if (_matchedList.length == 0) {
|
|
||||||
_resultLog.appendText(to!dstring("No matches found.\n"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_resultLog.textToHighlight = source;
|
|
||||||
foreach(SearchMatchList fileMatchList; _matchedList) {
|
|
||||||
_resultLog.appendText("Matches in "d ~ to!dstring(fileMatchList.filename) ~ '\n');
|
|
||||||
foreach(SearchMatch match; fileMatchList.matches) {
|
|
||||||
_resultLog.appendText(" --> ["d ~ to!dstring(match.line+1) ~ ":"d ~ to!dstring(match.col) ~ "]" ~ match.lineContent ~"\n"d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
bool onMatchClick(int line) {
|
bool onMatchClick(int line) {
|
||||||
line++;
|
line++;
|
||||||
|
@ -291,3 +292,19 @@ class SearchWidget : TabWidget {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SearchMatchList findMatches(in string filename, in 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) {
|
||||||
|
match.matches ~= SearchMatch(lineIndex, colIndex, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue