ide: refining find & replace

git-svn-id: svn://ultimatepp.org/upp/trunk@7510 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-07-14 16:27:11 +00:00
parent 8cbe6af7cf
commit 09e6a3633b
6 changed files with 74 additions and 22 deletions

View file

@ -803,7 +803,10 @@ bool CodeEditor::Key(dword code, int count) {
bool sel = code & K_SHIFT;
switch(code & ~K_SHIFT) {
case K_F3:
Find(sel, false);
if(sel)
FindPrev();
else
FindNext();
return true;
// case K_CTRL_F3:
// FindWord(sel);

View file

@ -281,13 +281,16 @@ protected:
void InitFindReplace();
void CancelBracketHighlight(int& pos);
void FindPrevNext(bool prev);
void CheckBrackets();
void OpenNormalFindReplace0(bool replace);
void OpenNormalFindReplace(bool replace);
void FindReplaceAddHistory();
void FindWildcard();
void ReplaceWildcard();
void InsertWildcard(const char *s);
void IncrementalFind();
void NotFound();
void NoFindError();
void CheckSyntaxRefresh(int pos, const WString& text);
@ -355,6 +358,8 @@ public:
bool RegExpFind(int pos, bool block);
bool Find(bool back, bool block);
bool Find(bool back, bool blockreplace, bool replace);
void FindNext();
void FindPrev();
bool GetStringRange(int cursor, int& b, int &e) const;
bool GetStringRange(int& b, int &e) const { return GetStringRange(GetCursor(), b, e); }
bool FindString(bool back);

View file

@ -175,18 +175,16 @@ int CodeEditor::Match(const wchar *f, const wchar *s, int line, bool we, bool ig
bool CodeEditor::Find(bool back, bool block)
{
if(!findreplace.incremental) {
foundsel = true;
if(notfoundfw) MoveTextBegin();
if(notfoundbk) MoveTextEnd();
}
foundsel = false;
int cursor, pos;
if(found)
GetSelection(pos, cursor);
else
GetSelection(cursor, pos);
pos = cursor;
if(findreplace.incremental && !findreplace.incremental_from_cursor)
pos = 0;
return FindFrom(pos, back, block);
}
@ -225,8 +223,16 @@ bool CodeEditor::RegExpFind(int pos, bool block)
bool CodeEditor::FindFrom(int pos, bool back, bool block)
{
if(findreplace.regexp)
return RegExpFind(pos, block);
notfoundbk = notfoundfw = false;
if(findreplace.regexp) {
if(RegExpFind(pos, block))
return true;
if(back)
notfoundbk = true;
else
notfoundfw = true;
return false;
}
WString text = ~findreplace.find;
WString ft;
const wchar *s = text;
@ -328,6 +334,14 @@ void CodeEditor::NoFindError()
findreplace.info.SetLabel("&Find");
}
void CodeEditor::NotFound()
{
findreplace.find.Error();
findreplace.info.SetLabel("Not &found");
if(!findreplace.incremental)
SetFocus();
}
bool CodeEditor::Find(bool back, bool blockreplace, bool replace)
{
NoFindError();
@ -342,10 +356,7 @@ bool CodeEditor::Find(bool back, bool blockreplace, bool replace)
return true;
}
else {
findreplace.find.Error();
findreplace.info.SetLabel("Not &found");
if(!findreplace.incremental)
SetFocus();
NotFound();
return false;
}
}
@ -501,7 +512,7 @@ int CodeEditor::BlockReplace()
return count;
}
void CodeEditor::OpenNormalFindReplace(bool replace)
void CodeEditor::OpenNormalFindReplace0(bool replace)
{
findreplace.Setup(replace);
findreplace.find.SetFocus();
@ -512,6 +523,12 @@ void CodeEditor::OpenNormalFindReplace(bool replace)
if(!findreplace.IsOpen())
InsertFrame(FindFrame(sb), findreplace);
WhenOpenFindReplace();
}
void CodeEditor::OpenNormalFindReplace(bool replace)
{
OpenNormalFindReplace0(replace);
if(!findreplace.incremental_from_cursor)
IncrementalFind();
}
@ -688,7 +705,14 @@ void CodeEditor::IncrementalFind()
findreplace.Sync();
if(!findreplace.incremental || findreplace.GetTopCtrl() == &findreplace) // || we are block replace
return;
Find(false, false);
int pos = 0;
if(findreplace.incremental_from_cursor) {
int l, h;
if(GetSelection(l, h))
pos = l;
}
if(!FindFrom(pos, false, false))
NotFound();
}
void CodeEditor::DoFind()
@ -742,4 +766,24 @@ void CodeEditor::SetFindReplaceData(const FindReplaceData& r)
findreplace.regexp <<= r.regexp;
}
void CodeEditor::FindPrevNext(bool prev)
{
if(!findreplace.IsOpen())
OpenNormalFindReplace0(false);
if(Find(false, false))
NoFindError();
else
NotFound();
}
void CodeEditor::FindNext()
{
FindPrevNext(false);
}
void CodeEditor::FindPrev()
{
FindPrevNext(true);
}
END_UPP_NAMESPACE

View file

@ -218,7 +218,7 @@ public:
void Clear();
void Reset();
void Error(bool error = true) { errorbg = error; }
void Error(bool error = true) { errorbg = error; Refresh(); }
EditField& Password(bool pwd = true) { password = pwd; Finish(); return *this; }
bool IsPassword() const { return password; }

View file

@ -168,7 +168,7 @@ void AssistEditor::ExpressionType(const String& ttype, const Vector<String>& xp,
LLOG("id as: " << id);
}
Index< Tuple2<String, bool> > mtype;
for(int i = 0; i < n.GetCount(); i = FindNext(n, i)) {
for(int i = 0; i < n.GetCount(); i = ::FindNext(n, i)) {
const CppItem& m = n[i];
if(m.name == id) {
LLOG("Member " << m.qtype << "'" << m.name << "'");
@ -273,7 +273,7 @@ void AssistEditor::GatherItems(const String& type, bool only_public, Index<Strin
String n = CodeBase().GetKey(i);
if(n.GetLength() > ntp.GetLength() && memcmp(~ntp, ~n, ntp.GetLength()) == 0) {
Array<CppItem>& n = CodeBase()[i];
for(int i = 0; i < n.GetCount(); i = FindNext(n, i)) {
for(int i = 0; i < n.GetCount(); i = ::FindNext(n, i)) {
const CppItem& m = n[i];
if(m.IsType()) {
CppItemInfo& f = assist_item.Add(m.name);
@ -289,10 +289,10 @@ void AssistEditor::GatherItems(const String& type, bool only_public, Index<Strin
String base;
int typei = assist_type.FindAdd(ntp);
bool op = only_public;
for(int i = 0; i < n.GetCount(); i = FindNext(n, i))
for(int i = 0; i < n.GetCount(); i = ::FindNext(n, i))
if(n[i].kind == FRIENDCLASS)
op = false;
for(int i = 0; i < n.GetCount(); i = FindNext(n, i)) {
for(int i = 0; i < n.GetCount(); i = ::FindNext(n, i)) {
const CppItem& im = n[i];
if(im.kind == STRUCT || im.kind == STRUCTTEMPLATE)
base = im.qptype;

View file

@ -883,8 +883,8 @@ public:
void EditFind() { editor.FindReplace(find_pick_sel, find_pick_text, false); }
void EditReplace() { editor.FindReplace(find_pick_sel, find_pick_text, true); }
void EditFindReplacePickText() { editor.FindReplace(true, true, false); }
void EditFindNext() { editor.Find(false, false); }
void EditFindPrevious() { editor.Find(true, false); }
void EditFindNext() { editor.FindNext(); }
void EditFindPrevious() { editor.FindPrev(); }
void EditPaste() { editor.Paste(); }
bool Next(int tab, ArrayCtrl& ctrl, int d);
void FindNextError();