mirror of https://github.com/buggins/dlangide.git
Search in other project items
This commit is contained in:
parent
7d1cda5bad
commit
4178d63229
|
@ -1,7 +1,13 @@
|
||||||
module dlangide.ui.searchPanel;
|
module dlangide.ui.searchPanel;
|
||||||
|
|
||||||
import dlangide.ui.frame;
|
|
||||||
import dlangui;
|
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.string;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
|
@ -19,7 +25,7 @@ class SearchWidget : TabWidget {
|
||||||
string fileName;
|
string fileName;
|
||||||
|
|
||||||
string toString() {
|
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 = new LogWidget("SearchLogWidget");
|
||||||
_resultLog.layoutHeight(FILL_PARENT);
|
_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) {
|
bool findText(dstring source) {
|
||||||
|
Log.d("Finding " ~ source);
|
||||||
SearchMatch[] matches;
|
SearchMatch[] matches;
|
||||||
//TODO Should not crash when in homepage.
|
//TODO Should not crash when in homepage.
|
||||||
foreach(int lineIndex, dstring line; _frame.currentEditor.content.lines) {
|
|
||||||
auto colIndex = line.indexOf(source);
|
searchInProject(_frame.currentEditor.projectSourceFile, matches, source);
|
||||||
if( colIndex != -1) {
|
Log.d("Searching in current file " ~ source);
|
||||||
matches ~= SearchMatch(lineIndex+1, colIndex, "");
|
|
||||||
}
|
if(currentWorkspace) {
|
||||||
}
|
foreach(ProjectItem project ; currentWorkspace.projects[0].items) {
|
||||||
if(matches.length == 0) {
|
searchInProject(project, matches, source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(matches.length == 0) {
|
||||||
_resultLog.appendText(to!dstring("No matches in current file." ~ '\n'));
|
_resultLog.appendText(to!dstring("No matches in current file." ~ '\n'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_resultLog.appendText(to!dstring("Matches found in current file: " ~ '\n'));
|
_resultLog.appendText(to!dstring("Matches found in current file: " ~ '\n'));
|
||||||
foreach(SearchMatch match; matches) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -135,6 +135,21 @@ class ProjectFolder : ProjectItem {
|
||||||
return path;
|
return path;
|
||||||
return buildNormalizedPath(_filename, 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
|
/// Project source file
|
||||||
|
|
Loading…
Reference in New Issue