diff --git a/uppsrc/CodeEditor/CodeEditor.h b/uppsrc/CodeEditor/CodeEditor.h index 3ec476135..bfe242579 100644 --- a/uppsrc/CodeEditor/CodeEditor.h +++ b/uppsrc/CodeEditor/CodeEditor.h @@ -160,6 +160,11 @@ struct FindReplaceDlg : WithIDEFindReplaceLayout { Size GetAdjustedSize(); virtual bool Key(dword key, int count); void Setup(bool doreplace); + void Sync(); + + typedef FindReplaceDlg CLASSNAME; + + FindReplaceDlg(); }; class CodeEditor : public LineEdit { @@ -351,7 +356,7 @@ protected: int Match(const wchar *f, const wchar *s, int line, bool we, bool icase, int fi = 0); WString GetWild(int type, int& i); WString GetReplaceText(); - WString GetReplaceText(WString replace, bool wildcards); + WString GetReplaceText(WString replace, bool wildcards, bool samecase); bool InsertRS(int chr, int count = 1); void IndentEnter(int count = 1); @@ -434,7 +439,8 @@ public: bool FindLangString(bool back); void Replace(); void BlockReplace(); - int BlockReplace(WString find, WString replace, bool wholeword, bool ignorecase, bool wildcards); + int BlockReplace(WString find, WString replace, bool wholeword, bool ignorecase, + bool wildcards, bool samecase); void MakeTabsOrSpaces(bool tabs); void MakeLineEnds(); diff --git a/uppsrc/CodeEditor/CodeEditor.lay b/uppsrc/CodeEditor/CodeEditor.lay index a8175fa87..741550d11 100644 --- a/uppsrc/CodeEditor/CodeEditor.lay +++ b/uppsrc/CodeEditor/CodeEditor.lay @@ -3,9 +3,10 @@ LAYOUT(IDEFindReplaceLayout, 376, 118) ITEM(WithDropChoice, find, HSizePosZ(54, 8).TopPosZ(4, 19)) ITEM(Label, replace_lbl, SetLabel(t_("Replace:")).LeftPosZ(8, 46).TopPosZ(28, 19)) ITEM(WithDropChoice, replace, HSizePosZ(54, 8).TopPosZ(28, 19)) - ITEM(Option, wholeword, SetLabel(t_("&Whole word")).LeftPosZ(8, 76).BottomPosZ(40, 18)) - ITEM(Option, ignorecase, SetLabel(t_("&Ignore case")).LeftPosZ(100, 88).BottomPosZ(40, 18)) - ITEM(Option, wildcards, SetLabel(t_("Wild&cards")).LeftPosZ(192, 68).BottomPosZ(40, 18)) + ITEM(Option, wholeword, SetLabel(t_("&Whole word")).LeftPosZ(8, 76).BottomPosZ(38, 20)) + ITEM(Option, wildcards, SetLabel(t_("Wild&cards")).LeftPosZ(92, 68).BottomPosZ(38, 20)) + ITEM(Option, ignorecase, SetLabel(t_("&Ignore case")).LeftPosZ(168, 88).BottomPosZ(38, 20)) + ITEM(Option, samecase, SetLabel(t_("Mimic case")).LeftPosZ(260, 108).TopPosZ(60, 20)) ITEM(Button, amend, SetLabel(t_("R&eplace")).LeftPosZ(8, 68).BottomPosZ(6, 24)) ITEM(Button, findback, SetLabel(t_("Find Previous")).LeftPosZ(136, 80).BottomPosZ(6, 24)) ITEM(Button, ok, SetLabel(t_("Find Next")).RightPosZ(80, 76).BottomPosZ(6, 24)) diff --git a/uppsrc/CodeEditor/FindReplace.cpp b/uppsrc/CodeEditor/FindReplace.cpp index 1f5fed056..8941cd1a1 100644 --- a/uppsrc/CodeEditor/FindReplace.cpp +++ b/uppsrc/CodeEditor/FindReplace.cpp @@ -2,6 +2,18 @@ NAMESPACE_UPP +FindReplaceDlg::FindReplaceDlg() +{ + ignorecase <<= THISBACK(Sync); + samecase <<= true; + Sync(); +} + +void FindReplaceDlg::Sync() +{ + samecase.Enable(ignorecase); +} + bool FindReplaceDlg::Key(dword key, int cnt) { if(key == K_CTRL_I) { if(find.HasFocus()) { @@ -253,10 +265,11 @@ WString CodeEditor::GetWild(int type, int& i) WString CodeEditor::GetReplaceText() { - return GetReplaceText(findreplace.replace.GetText(), findreplace.wildcards); + return GetReplaceText(~findreplace.replace, findreplace.wildcards, + findreplace.wildcards && findreplace.samecase); } -WString CodeEditor::GetReplaceText(WString rs, bool wildcards) +WString CodeEditor::GetReplaceText(WString rs, bool wildcards, bool samecase) { int anyi = 0, onei = 0, spacei = 0, numberi = 0, idi = 0; WString rt; @@ -312,6 +325,23 @@ WString CodeEditor::GetReplaceText(WString rs, bool wildcards) rt.Cat(c); } } + if(samecase) { + WString h = GetSelectionW(); + if(h.GetCount() && rt.GetCount()) { + if(IsUpper(h[0])) + rt.Set(0, ToUpper(rt[0])); + if(IsLower(h[0])) + rt.Set(0, ToLower(rt[0])); + } + if(h.GetCount() > 1) { + if(IsUpper(h[1])) + for(int i = 1; i < rt.GetCount(); i++) + rt.Set(i, ToUpper(rt[i])); + if(IsLower(h[1])) + for(int i = 1; i < rt.GetCount(); i++) + rt.Set(i, ToLower(rt[i])); + } + } return rt; } @@ -328,7 +358,7 @@ void CodeEditor::Replace() } } -int CodeEditor::BlockReplace(WString find, WString replace, bool wholeword, bool ignorecase, bool wildcards) +int CodeEditor::BlockReplace(WString find, WString replace, bool wholeword, bool ignorecase, bool wildcards, bool samecase) { NextUndo(); int l, h; @@ -340,7 +370,7 @@ int CodeEditor::BlockReplace(WString find, WString replace, bool wholeword, bool int hh, ll; GetSelection(ll, hh); CachePos(ll); - h = h - (hh - ll) + Paste(GetReplaceText(replace, wildcards)); + h = h - (hh - ll) + Paste(GetReplaceText(replace, wildcards, ignorecase && samecase)); count++; } SetSelection(l, h); @@ -351,7 +381,7 @@ int CodeEditor::BlockReplace(WString find, WString replace, bool wholeword, bool void CodeEditor::BlockReplace() { BlockReplace(~findreplace.find, ~findreplace.replace, findreplace.wholeword, - findreplace.ignorecase, findreplace.wildcards); + findreplace.ignorecase, findreplace.wildcards, findreplace.samecase); /* NextUndo(); int l, h; @@ -537,9 +567,13 @@ void CodeEditor::DoFindBack() void CodeEditor::SerializeFind(Stream& s) { + int version = 0; + s / version; s % findreplace.find; findreplace.find.SerializeList(s); s % findreplace.wholeword % findreplace.ignorecase % findreplace.wildcards; + if(version >= 0) + s % findreplace.samecase; s % findreplace.replace; findreplace.replace.SerializeList(s); } diff --git a/uppsrc/CtrlCore/Ctrl.cpp b/uppsrc/CtrlCore/Ctrl.cpp index 78d8a247a..b50792ff5 100644 --- a/uppsrc/CtrlCore/Ctrl.cpp +++ b/uppsrc/CtrlCore/Ctrl.cpp @@ -239,7 +239,6 @@ void Ctrl::Jsonize(JsonIO& jio) { GuiLock __; Value x; - bool empty = false; if(jio.IsStoring()) x = GetData(); x.Jsonize(jio); diff --git a/uppsrc/ide/FindInFiles.cpp b/uppsrc/ide/FindInFiles.cpp index 34f7721f9..af6127585 100644 --- a/uppsrc/ide/FindInFiles.cpp +++ b/uppsrc/ide/FindInFiles.cpp @@ -1,9 +1,13 @@ #include "ide.h" void Ide::SerializeFf(Stream& s) { + int version = 0; + s / version; s % ff.find; ff.find.SerializeList(s); s % ff.wholeword % ff.ignorecase % ff.wildcards; + if(version >= 0) + s % ff.samecase; s % ff.replace; s % ff.readonly; ff.replace.SerializeList(s); @@ -21,7 +25,7 @@ FileSel& sSD() } void Ide::SerializeFindInFiles(Stream& s) { - int version = 3; + int version = 4; s / version; s % ff.files; ff.files.SerializeList(s); @@ -37,6 +41,8 @@ void Ide::SerializeFindInFiles(Stream& s) { s % sSD(); if(version >= 3) s % ff.readonly; + if(version >= 4) + s % ff.samecase; } void SearchForFiles(Vector& files, String dir, String mask, int readonly, Progress& pi) { @@ -373,6 +379,11 @@ void Ide::FindFolder() ff.folder <<= ~sSD(); } +void Ide::SyncFindInFiles() +{ + ff.samecase.Enable(ff.ignorecase); +} + void Ide::ConstructFindInFiles() { ff.find.AddButton().SetMonoImage(CtrlImg::smallright()).Tip("Wildcard") <<= THISBACK(FindWildcard); static const char *defs = "*.cpp *.h *.hpp *.c *.m *.C *.M *.cxx *.cc *.mm *.MM *.icpp *.sch *.lay *.rc"; @@ -385,6 +396,9 @@ void Ide::ConstructFindInFiles() { editor.PutI(ff.find); editor.PutI(ff.replace); CtrlLayoutOKCancel(ff, "Find In Files"); + ff.ignorecase <<= THISBACK(SyncFindInFiles); + ff.samecase <<= true; + SyncFindInFiles(); } void FindInFilesDlg::Sync() diff --git a/uppsrc/ide/Macro.cpp b/uppsrc/ide/Macro.cpp index 4eca1b9fa..c48f4ace4 100644 --- a/uppsrc/ide/Macro.cpp +++ b/uppsrc/ide/Macro.cpp @@ -186,13 +186,14 @@ void Ide::MacroReplace(EscEscape& e) { int n = e.GetCount(); if(n < 2 || n > 5) - e.ThrowError("wrong number of arguments in call to Find (2 to 5 expected)"); + e.ThrowError("wrong number of arguments in call to Find (2 to 6 expected)"); WString find = e[0]; WString replace = e[1]; bool whole_word = (n > 2 && e.Int(2) > 0); bool ignore_case = (n > 3 && e.Int(3) > 0); bool wildcards = (n > 4 && e.Int(4) > 0); - e = editor.BlockReplace(find, replace, whole_word, ignore_case, wildcards); + bool samecase = (n > 5 && e.Int(5) > 0); + e = editor.BlockReplace(find, replace, whole_word, ignore_case, wildcards, samecase); } void Ide::MacroFindMatchingBrace(EscEscape& e) diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index be407edd3..06e275e64 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -1009,6 +1009,7 @@ public: void SerializeFf(Stream& s); bool SearchInFile(const String& fn, const String& pattern, bool wholeword, bool ignorecase, int& n); + void SyncFindInFiles(); void ConstructFindInFiles(); void SerializeFindInFiles(Stream& s); diff --git a/uppsrc/ide/ide.lay b/uppsrc/ide/ide.lay index 7a3e2f733..66aefb0c9 100644 --- a/uppsrc/ide/ide.lay +++ b/uppsrc/ide/ide.lay @@ -79,8 +79,9 @@ LAYOUT(FindInFilesLayout, 420, 152) ITEM(Switch, style, SetLabel(t_("&None\nCo&nfirm\n&Auto")).LeftPosZ(52, 164).TopPosZ(78, 15)) ITEM(Label, replace_lbl2, SetLabel(t_("with:")).LeftPosZ(220, 28).TopPosZ(76, 19)) ITEM(Option, wholeword, SetLabel(t_("&Whole word")).LeftPosZ(54, 80).BottomPosZ(34, 18)) - ITEM(Option, ignorecase, SetLabel(t_("&Ignore case")).LeftPosZ(140, 84).BottomPosZ(34, 18)) - ITEM(Option, wildcards, SetLabel(t_("Wild&cards")).LeftPosZ(226, 72).BottomPosZ(34, 18)) + ITEM(Option, wildcards, SetLabel(t_("Wild&cards")).LeftPosZ(140, 72).BottomPosZ(34, 18)) + ITEM(Option, ignorecase, SetLabel(t_("&Ignore case")).LeftPosZ(216, 84).BottomPosZ(34, 18)) + ITEM(Option, samecase, SetLabel(t_("Mimic case")).LeftPosZ(304, 108).TopPosZ(100, 18)) ITEM(Option, readonly, ThreeState(true).SetLabel(t_("Read-only files")).LeftPosZ(54, 142).BottomPosZ(14, 16)) ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(76, 64).BottomPosZ(6, 22)) ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(6, 22))