Skip to content
Permalink
Browse files

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.
  • Loading branch information...
ansgarbecker committed Apr 22, 2019
1 parent 4fd77f4 commit 8f94ece971fa18bcf6d31df27648dcadfa57a1b2
Showing with 45 additions and 2 deletions.
  1. +6 −0 source/texteditor.dfm
  2. +39 −2 source/texteditor.pas
@@ -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
@@ -48,13 +48,18 @@ TfrmTextEditor = class(TFormWithSizeGrip)
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;
FStopping: Boolean;
FDetectedLineBreaks,
FSelectedLineBreaks: TLineBreaks;
FmemoText: TLineNormalizingMemo;
FFindDialogActive, FReplaceDialogActive: Boolean;
procedure SetModified(NewVal: Boolean);
public
function GetText: String;
@@ -186,6 +191,7 @@ procedure TfrmTextEditor.FormCreate(Sender: TObject);
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 @@ procedure TfrmTextEditor.memoTextKeyDown(Sender: TObject; var Key: Word; Shift:
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 @@ procedure TfrmTextEditor.SetModified(NewVal: Boolean);
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.

0 comments on commit 8f94ece

Please sign in to comment.
You can’t perform that action at this time.