mirror of https://github.com/buggins/dlangide.git
Display whether matches were found or not
This commit is contained in:
parent
7986220a0e
commit
ca2bca72ed
|
@ -3,14 +3,26 @@
|
||||||
import dlangide.ui.frame;
|
import dlangide.ui.frame;
|
||||||
import dlangui;
|
import dlangui;
|
||||||
|
|
||||||
|
import std.string;
|
||||||
|
import std.conv;
|
||||||
|
|
||||||
class SearchWidget : TabWidget {
|
class SearchWidget : TabWidget {
|
||||||
HorizontalLayout _layout;
|
HorizontalLayout _layout;
|
||||||
EditLine _findText;
|
EditLine _findText;
|
||||||
LogWidget _resultLog;
|
LogWidget _resultLog;
|
||||||
|
|
||||||
|
|
||||||
protected IDEFrame _frame;
|
protected IDEFrame _frame;
|
||||||
|
|
||||||
|
struct SearchMatch {
|
||||||
|
int line;
|
||||||
|
long col;
|
||||||
|
string fileName;
|
||||||
|
|
||||||
|
string toString() {
|
||||||
|
return to!string(line) ~ ':' ~ to!string(col) ~ ' ' ~ fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this(string ID, IDEFrame frame) {
|
this(string ID, IDEFrame frame) {
|
||||||
super(ID);
|
super(ID);
|
||||||
_frame = frame;
|
_frame = frame;
|
||||||
|
@ -41,26 +53,23 @@ class SearchWidget : TabWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findText(dstring source) {
|
bool findText(dstring source) {
|
||||||
struct SearchMatch {
|
|
||||||
int line;
|
|
||||||
long col;
|
|
||||||
string fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
import std.string;
|
|
||||||
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) {
|
foreach(int lineIndex, dstring line; _frame.currentEditor.content.lines) {
|
||||||
auto colIndex = line.indexOf(source);
|
auto colIndex = line.indexOf(source);
|
||||||
if( colIndex != -1) {
|
if( colIndex != -1) {
|
||||||
matches ~= SearchMatch(lineIndex+1, colIndex, "");
|
matches ~= SearchMatch(lineIndex+1, colIndex, "");
|
||||||
_resultLog.appendText( " " ~ to!dstring(matches[$-1]) ~ '\n');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// _resultLog.text = "";
|
if(matches.length == 0) {
|
||||||
// if(matches.length > 1){
|
_resultLog.appendText(to!dstring("No matches in current file." ~ '\n'));
|
||||||
// _resultLog.appendText(to!dstring(matches[0].line));
|
}
|
||||||
// }
|
else {
|
||||||
return false;
|
_resultLog.appendText(to!dstring("Matches found in current file: " ~ '\n'));
|
||||||
|
foreach(SearchMatch match; matches) {
|
||||||
|
_resultLog.appendText(to!dstring(" ->" ~ match.toString ~ '\n'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue