ide: refining new Find&Replace

git-svn-id: svn://ultimatepp.org/upp/trunk@7478 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-07-01 09:00:06 +00:00
parent a161a8a065
commit 5df53f2cd4
9 changed files with 61 additions and 22 deletions

View file

@ -540,6 +540,7 @@ void CodeEditor::LeftDown(Point p, dword keyflags) {
}
LineEdit::LeftDown(p, keyflags);
WhenLeftDown();
CloseFindReplace();
}
void CodeEditor::Tip::Paint(Draw& w)
@ -745,6 +746,10 @@ bool CodeEditor::Key(dword code, int count) {
last_key_time = key_time;
NextUndo();
if(code == replace_key) {
Replace();
return true;
}
switch(code) {
case K_CTRL_DELETE:
DeleteWord();

View file

@ -332,6 +332,10 @@ public:
FrameTop<Button> topsbbutton;
FrameTop<Button> topsbbutton1;
static dword find_next_key;
static dword find_prev_key;
static dword replace_key;
void Clear() { LineEdit::Clear(); found = notfoundfw = notfoundbk = false; }
void Highlight(const String& h);

View file

@ -1,21 +1,21 @@
LAYOUT(IDEFindReplaceLayout, 616, 52)
ITEM(Label, dv___0, SetLabel(t_("&Find")).LeftPosZ(8, 46).TopPosZ(4, 19))
ITEM(WithDropChoice<EditString>, find, LeftPosZ(56, 144).TopPosZ(4, 19))
ITEM(Label, dv___2, SetLabel(t_("&Replace")).LeftPosZ(8, 60).TopPosZ(28, 21))
ITEM(WithDropChoice<EditString>, replace, LeftPosZ(56, 144).TopPosZ(28, 19))
ITEM(Button, prev, LeftPosZ(204, 20).TopPosZ(4, 19))
ITEM(Button, next, LeftPosZ(224, 20).TopPosZ(4, 19))
ITEM(Option, wildcards, SetLabel(t_("Wild&cards")).LeftPosZ(252, 72).TopPosZ(4, 19))
ITEM(Option, wholeword, SetLabel(t_("&Whole word")).LeftPosZ(328, 88).TopPosZ(4, 19))
ITEM(Option, ignorecase, SetLabel(t_("&Ignore case")).LeftPosZ(420, 80).TopPosZ(4, 19))
ITEM(Option, incremental, SetLabel(t_("&Incremental")).LeftPosZ(504, 80).TopPosZ(4, 19))
LAYOUT(IDEFindReplaceLayout, 632, 52)
ITEM(Label, info, SetLabel(t_("&Find")).LeftPosZ(4, 60).TopPosZ(4, 19))
ITEM(WithDropChoice<EditString>, find, LeftPosZ(68, 152).TopPosZ(4, 19))
ITEM(Label, dv___2, SetLabel(t_("&Replace")).LeftPosZ(4, 60).TopPosZ(28, 21))
ITEM(WithDropChoice<EditString>, replace, LeftPosZ(68, 152).TopPosZ(28, 19))
ITEM(Button, prev, LeftPosZ(224, 20).TopPosZ(4, 19))
ITEM(Button, next, LeftPosZ(244, 20).TopPosZ(4, 19))
ITEM(Option, wildcards, SetLabel(t_("Wild&cards")).LeftPosZ(268, 72).TopPosZ(4, 19))
ITEM(Option, wholeword, SetLabel(t_("&Whole word")).LeftPosZ(344, 88).TopPosZ(4, 19))
ITEM(Option, ignorecase, SetLabel(t_("&Ignore case")).LeftPosZ(436, 80).TopPosZ(4, 19))
ITEM(Option, incremental, SetLabel(t_("&Incremental")).LeftPosZ(520, 80).TopPosZ(4, 19))
ITEM(Button, close, RightPosZ(4, 20).TopPosZ(4, 19))
ITEM(Button, amend, LeftPosZ(204, 20).TopPosZ(28, 19))
ITEM(Option, samecase, SetLabel(t_("Mimic case")).LeftPosZ(252, 108).TopPosZ(28, 19))
ITEM(Button, amend, LeftPosZ(224, 20).TopPosZ(28, 19))
ITEM(Option, samecase, SetLabel(t_("Mimic case")).LeftPosZ(268, 108).TopPosZ(28, 19))
END_LAYOUT
LAYOUT(BlockReplaceLayout, 400, 116)
ITEM(Label, dv___0, SetLabel(t_("Find")).LeftPosZ(8, 46).TopPosZ(4, 19))
ITEM(Label, info, SetLabel(t_("Find")).LeftPosZ(8, 46).TopPosZ(4, 19))
ITEM(WithDropChoice<EditString>, find, HSizePosZ(54, 8).TopPosZ(4, 19))
ITEM(Label, dv___2, SetLabel(t_("Replace")).LeftPosZ(8, 46).TopPosZ(28, 19))
ITEM(WithDropChoice<EditString>, replace, HSizePosZ(54, 8).TopPosZ(28, 19))

View file

@ -25,9 +25,7 @@ FindReplaceDlg::FindReplaceDlg()
samecase <<= true;
close.Cancel();
prev.SetImage(CtrlImg::SmallUp());
prev.Tip("Find prev");
amend.SetImage(CodeEditorImg::Replace());
amend.Tip("Replace");
incremental <<= true;
Sync();
}
@ -37,6 +35,10 @@ void FindReplaceDlg::Sync()
samecase.Enable(ignorecase);
}
dword CodeEditor::find_next_key = K_F3;
dword CodeEditor::find_prev_key = K_SHIFT_F3;
dword CodeEditor::replace_key = K_CTRL_R;
bool FindReplaceDlg::Key(dword key, int cnt) {
if(key == K_CTRL_I) {
if(find.HasFocus()) {
@ -74,9 +76,12 @@ void FindReplaceDlg::Setup(bool doreplace)
close.Normal();
close.SetLabel("");
next.SetImage(CtrlImg::SmallDown());
next.Tip("Find next");
next.Tip("Find next (" + GetKeyDesc(CodeEditor::find_next_key) + ")");
next.Normal();
next.SetLabel("");
prev.Tip("Find prev (" + GetKeyDesc(CodeEditor::find_prev_key) + ")");
amend.Tip("Replace (" + GetKeyDesc(CodeEditor::replace_key) + ")");
info.SetLabel("&Find");
replacing = doreplace;
replace.Show(replacing);
amend.Show(replacing);
@ -273,6 +278,7 @@ bool CodeEditor::Find(bool back, bool blockreplace, bool replace)
{
FindReplaceAddHistory();
findreplace.find.Error(false);
findreplace.info.SetLabel("&Find");
if(Find(back, (WString)~findreplace.find, findreplace.wholeword,
findreplace.ignorecase, findreplace.wildcards, blockreplace)) {
if(!blockreplace) {
@ -286,6 +292,7 @@ bool CodeEditor::Find(bool back, bool blockreplace, bool replace)
}
else {
findreplace.find.Error();
findreplace.info.SetLabel("Not &found");
if(!findreplace.incremental)
SetFocus();
return false;
@ -654,7 +661,7 @@ void CodeEditor::DoFindBack()
void CodeEditor::SerializeFind(Stream& s)
{
int version = 0;
int version = 1;
s / version;
s % findreplace.find;
findreplace.find.SerializeList(s);
@ -662,6 +669,8 @@ void CodeEditor::SerializeFind(Stream& s)
if(version >= 0)
s % findreplace.samecase;
s % findreplace.replace;
if(version >= 1)
s % findreplace.incremental;
findreplace.replace.SerializeList(s);
}

View file

@ -1,7 +1,7 @@
#include "ide.h"
void Ide::SerializeFf(Stream& s) {
int version = 0;
void Ide::SerializeFf(Stream& s) { // Used to move data from regular Find dialog, has to be same as FindAndReplace::Serialize
int version = 1;
s / version;
s % ff.find;
ff.find.SerializeList(s);
@ -9,7 +9,10 @@ void Ide::SerializeFf(Stream& s) {
if(version >= 0)
s % ff.samecase;
s % ff.replace;
s % ff.readonly;
if(version >= 1) {
Option dummy;
s % dummy;
}
ff.replace.SerializeList(s);
}

View file

@ -799,6 +799,9 @@ public:
void ToggleReadOnly();
void PosSync();
void DoEditKeys();
void AKEditor();
void PackageMenu(Bar& menu);
void UscFile(const String& file);

View file

@ -25,6 +25,7 @@ KEY(REPLACE, "Replace..", K_CTRL_H)
KEY(FINDSEL, "Find selected text", 0)
KEY(FINDNEXT, "Find Next", K_F3)
KEY(FINDPREV, "Find Previous", K_SHIFT_F3)
KEY(DOREPLACE, "Replace found text", K_CTRL_R)
KEY(GOTO, "Navigate in the file..", K_CTRL_G)
KEY(GOTOGLOBAL, "Navigate..", K_CTRL_J)
KEY(FINDSTRING, "Find string", K_F2)

View file

@ -7,6 +7,19 @@
using namespace IdeKeys;
void Ide::DoEditKeys()
{
EditKeys();
AKEditor();
}
void Ide::AKEditor()
{
CodeEditor::find_next_key = AK_FINDNEXT().key[0];
CodeEditor::find_prev_key = AK_FINDPREV().key[0];
CodeEditor::replace_key = AK_DOREPLACE().key[0];
}
void Ide::PackageMenu(Bar& menu) {
Project(menu);
}
@ -320,7 +333,7 @@ void Ide::Setup(Bar& menu) {
.Help("Fonts, tabs, indentation, status bar");
menu.Add("Abbreviations..", THISBACK(Abbreviations))
.Help("Edit abbreviation keywords and code");
menu.Add("Keyboard shortcuts..", callback(EditKeys))
menu.Add("Keyboard shortcuts..", THISBACK(DoEditKeys))
.Help("Edit key bindings");
menu.Add("Build methods..", THISBACK(SetupBuildMethods))
.Help("Setup build methods");

View file

@ -435,6 +435,7 @@ bool Ide::FileRemove()
}
void Ide::EditFile0(const String& path, byte charset, bool astext, const String& headername) {
AKEditor();
editor.CheckEdited(false);
editor.CloseAssist();
if(path.IsEmpty()) return;