diff --git a/src/dlangide/ui/searchPanel.d b/src/dlangide/ui/searchPanel.d index dc4072e..f8c9d28 100644 --- a/src/dlangide/ui/searchPanel.d +++ b/src/dlangide/ui/searchPanel.d @@ -1,7 +1,13 @@ module dlangide.ui.searchPanel; -import dlangide.ui.frame; + import dlangui; +import dlangui.core.editable; + +import dlangide.ui.frame; +import dlangide.ui.wspanel; +import dlangide.workspace.workspace; +import dlangide.workspace.project; import std.string; import std.conv; @@ -19,7 +25,7 @@ class SearchWidget : TabWidget { string fileName; string toString() { - return to!string(line) ~ ':' ~ to!string(col) ~ ' ' ~ fileName; + return '[' ~ to!string(line) ~ ':' ~ to!string(col) ~ "] " ~ fileName; } } @@ -48,28 +54,59 @@ class SearchWidget : TabWidget { _resultLog = new LogWidget("SearchLogWidget"); _resultLog.layoutHeight(FILL_PARENT); - addChild(_resultLog); + addChild(_resultLog); + } + + void searchInProject(ProjectItem project, ref SearchMatch[] matches, dstring text) { + if(project.isFolder) { + foreach(ProjectItem child; cast(ProjectFolder) project) { + searchInProject(child, matches, text); + } + } + else { + EditableContent content = new EditableContent(true); + content.load(project.filename); + foreach(int lineIndex, dstring line; content.lines) { + auto colIndex = line.indexOf(text); + if( colIndex != -1) { + matches ~= SearchMatch(lineIndex+1, colIndex, project.filename); + } + } + } + } bool findText(dstring source) { + Log.d("Finding " ~ source); SearchMatch[] matches; //TODO Should not crash when in homepage. - foreach(int lineIndex, dstring line; _frame.currentEditor.content.lines) { - auto colIndex = line.indexOf(source); - if( colIndex != -1) { - matches ~= SearchMatch(lineIndex+1, colIndex, ""); - } - } - if(matches.length == 0) { + + searchInProject(_frame.currentEditor.projectSourceFile, matches, source); + Log.d("Searching in current file " ~ source); + + if(currentWorkspace) { + foreach(ProjectItem project ; currentWorkspace.projects[0].items) { + searchInProject(project, matches, source); + } + } + + if(matches.length == 0) { _resultLog.appendText(to!dstring("No matches in current file." ~ '\n')); } else { _resultLog.appendText(to!dstring("Matches found in current file: " ~ '\n')); foreach(SearchMatch match; matches) { - _resultLog.appendText(to!dstring(" ->" ~ match.toString ~ '\n')); + if(match.fileName == _frame.currentEditor.content.filename) + _resultLog.appendText(to!dstring(" --> [" ~ to!string(match.line) ~ ':' ~ to!string(match.col) ~ "] in current file\n")); + else + _resultLog.appendText(to!dstring(" --> " ~ match.toString" ~ '\n')); } } + + + + return true; } -} \ No newline at end of file +} diff --git a/src/dlangide/workspace/project.d b/src/dlangide/workspace/project.d index 5dc712f..825ae76 100644 --- a/src/dlangide/workspace/project.d +++ b/src/dlangide/workspace/project.d @@ -135,6 +135,21 @@ class ProjectFolder : ProjectItem { return path; return buildNormalizedPath(_filename, path); } + + int begin; + int end; + bool empty() const { + return begin == _children.count; + } + + void popFront() + { + ++begin; + } + + ProjectItem front() { + return _children[begin]; + } } /// Project source file