From 8f94ece971fa18bcf6d31df27648dcadfa57a1b2 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Mon, 22 Apr 2019 10:03:03 +0200 Subject: [PATCH] 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. --- source/texteditor.dfm | 6 ++++++ source/texteditor.pas | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/source/texteditor.dfm b/source/texteditor.dfm index 7be3c77c..f6733bbe 100644 --- a/source/texteditor.dfm +++ b/source/texteditor.dfm @@ -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 diff --git a/source/texteditor.pas b/source/texteditor.pas index a4243dc1..0f21cf6b 100644 --- a/source/texteditor.pas +++ b/source/texteditor.pas @@ -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.