Find and replace dialogs in grid popup text editor:

* Cancel dialog when user presses Cancel, regardless of which dialog has focus.
* Show selection when dialog found some text, without having to focus the memo.
This commit is contained in:
Ansgar Becker
2019-04-22 10:03:03 +02:00
parent 4fd77f4fad
commit 8f94ece971
2 changed files with 45 additions and 2 deletions

View File

@ -158,6 +158,9 @@ object frmTextEditor: TfrmTextEditor
object actSearchFind: TSearchFind
Category = 'Search'
Caption = '&Find...'
Dialog.OnClose = actSearchFindFindDialogClose
Dialog.OnShow = actSearchFindFindDialogShow
Dialog.Options = [frDown, frFindNext]
Hint = 'Find|Finds the specified text'
ImageIndex = 30
ShortCut = 16454
@ -172,6 +175,9 @@ object frmTextEditor: TfrmTextEditor
object actSearchReplace: TSearchReplace
Category = 'Search'
Caption = '&Replace'
Dialog.OnClose = actSearchReplaceReplaceDialogClose
Dialog.OnShow = actSearchReplaceReplaceDialogShow
Dialog.Options = [frDown, frFindNext, frReplace, frReplaceAll]
Hint = 'Replace|Replaces specific text with different text'
ImageIndex = 59
end

View File

@ -48,6 +48,10 @@ type
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SelectLinebreaks(Sender: TObject);
procedure TimerMemoChangeTimer(Sender: TObject);
procedure actSearchFindFindDialogShow(Sender: TObject);
procedure actSearchFindFindDialogClose(Sender: TObject);
procedure actSearchReplaceReplaceDialogShow(Sender: TObject);
procedure actSearchReplaceReplaceDialogClose(Sender: TObject);
private
{ Private declarations }
FModified: Boolean;
@ -55,6 +59,7 @@ type
FDetectedLineBreaks,
FSelectedLineBreaks: TLineBreaks;
FmemoText: TLineNormalizingMemo;
FFindDialogActive, FReplaceDialogActive: Boolean;
procedure SetModified(NewVal: Boolean);
public
function GetText: String;
@ -186,6 +191,7 @@ begin
FmemoText.OnChange := memoTextChange;
FmemoText.OnKeyDown := memoTextKeyDown;
FmemoText.OnClick := memoTextClick;
FmemoText.HideSelection := False; // Make found text visible when find dialog has focus
// Use same text properties as in query/find/replace actions
actSearchFind.Caption := MainForm.actQueryFind.Caption;
actSearchFind.Hint := MainForm.actQueryFind.Hint;
@ -238,8 +244,15 @@ begin
TimerMemoChange.Enabled := False;
TimerMemoChange.Enabled := True;
case Key of
// Cancel by Escape
VK_ESCAPE: btnCancelClick(Sender);
// Cancel active dialog by Escape
VK_ESCAPE: begin
if FFindDialogActive then
actSearchFind.Dialog.CloseDialog
else if FReplaceDialogActive then
actSearchReplace.Dialog.CloseDialog
else
btnCancelClick(Sender);
end;
// Apply changes and end editing by Ctrl + Enter
VK_RETURN: if ssCtrl in Shift then btnApplyClick(Sender);
Ord('a'), Ord('A'): if (ssCtrl in Shift) and (not (ssAlt in Shift)) then Mainform.actSelectAllExecute(Sender);
@ -343,4 +356,28 @@ begin
end;
procedure TfrmTextEditor.actSearchFindFindDialogShow(Sender: TObject);
begin
FFindDialogActive := True;
end;
procedure TfrmTextEditor.actSearchFindFindDialogClose(Sender: TObject);
begin
FFindDialogActive := False;
end;
procedure TfrmTextEditor.actSearchReplaceReplaceDialogShow(Sender: TObject);
begin
FReplaceDialogActive := True;
end;
procedure TfrmTextEditor.actSearchReplaceReplaceDialogClose(Sender: TObject);
begin
FReplaceDialogActive := False;
end;
end.