From 09e6a3633b6d4a740c2fea985759dc9bc8b60bb6 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 14 Jul 2014 16:27:11 +0000 Subject: [PATCH] ide: refining find & replace git-svn-id: svn://ultimatepp.org/upp/trunk@7510 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CodeEditor/CodeEditor.cpp | 5 ++- uppsrc/CodeEditor/CodeEditor.h | 5 +++ uppsrc/CodeEditor/FindReplace.cpp | 72 +++++++++++++++++++++++++------ uppsrc/CtrlLib/EditCtrl.h | 2 +- uppsrc/ide/Cpp.cpp | 8 ++-- uppsrc/ide/ide.h | 4 +- 6 files changed, 74 insertions(+), 22 deletions(-) diff --git a/uppsrc/CodeEditor/CodeEditor.cpp b/uppsrc/CodeEditor/CodeEditor.cpp index 4acf2084d..8800951b3 100644 --- a/uppsrc/CodeEditor/CodeEditor.cpp +++ b/uppsrc/CodeEditor/CodeEditor.cpp @@ -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); diff --git a/uppsrc/CodeEditor/CodeEditor.h b/uppsrc/CodeEditor/CodeEditor.h index 80c6940db..66881e829 100644 --- a/uppsrc/CodeEditor/CodeEditor.h +++ b/uppsrc/CodeEditor/CodeEditor.h @@ -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); diff --git a/uppsrc/CodeEditor/FindReplace.cpp b/uppsrc/CodeEditor/FindReplace.cpp index eb522069f..8ca4df2cd 100644 --- a/uppsrc/CodeEditor/FindReplace.cpp +++ b/uppsrc/CodeEditor/FindReplace.cpp @@ -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) { - if(notfoundfw) MoveTextBegin(); - if(notfoundbk) MoveTextEnd(); - } + 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 diff --git a/uppsrc/CtrlLib/EditCtrl.h b/uppsrc/CtrlLib/EditCtrl.h index 72824ddbc..189875baa 100644 --- a/uppsrc/CtrlLib/EditCtrl.h +++ b/uppsrc/CtrlLib/EditCtrl.h @@ -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; } diff --git a/uppsrc/ide/Cpp.cpp b/uppsrc/ide/Cpp.cpp index 0703de73a..9571483d1 100644 --- a/uppsrc/ide/Cpp.cpp +++ b/uppsrc/ide/Cpp.cpp @@ -168,7 +168,7 @@ void AssistEditor::ExpressionType(const String& ttype, const Vector& xp, LLOG("id as: " << id); } Index< Tuple2 > 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 ntp.GetLength() && memcmp(~ntp, ~n, ntp.GetLength()) == 0) { Array& 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