Use comboboxes. Use history. Prettify the dialog. Preselect text on show.

Make the findreplace a dialog. Thus removing resiying code (handled by Anchors now anyway).
Make Anchors work again and publish them for various controls.
SelStart and Co. for TEdit, SelectAll procedure for TComboBox and TEdit.
Clean up and fix some bugs for TComboBox, plus selection stuff.

git-svn-id: trunk@2945 -
This commit is contained in:
lazarus 2002-08-18 08:56:27 +00:00
parent 3e5a17cbe7
commit 5895aa70b7
5 changed files with 191 additions and 168 deletions

View File

@ -45,6 +45,7 @@ type
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Edit1 : TEdit;
mnuMain: TMainMenu;
itmFileQuit: TMenuItem;
@ -63,6 +64,7 @@ type
procedure Button4CLick(Sender : TObject);
procedure Button5CLick(Sender : TObject);
procedure Button6CLick(Sender : TObject);
procedure Button7CLick(Sender : TObject);
procedure ComboOnChange (Sender:TObject);
procedure ComboOnClick (Sender:TObject);
end;
@ -131,6 +133,13 @@ Begin
end;
End;
procedure TForm1.Button7Click(Sender : TObject);
begin
Edit1.SelectAll;
ComboBox1.SelectAll;
end;
procedure TForm1.ComboOnChange (Sender:TObject);
var
s : shortstring;
@ -233,6 +242,16 @@ begin
Button6.Caption := 'Index ?';
Button6.OnClick := @Button6Click;
Button7 := TButton.Create(Self);
Button7.Parent := Self;
Button7.Left := 50;
Button7.Top := 280;
Button7.Width := 120;
Button7.Height := 30;
Button7.Show;
Button7.Caption := 'Select All';
Button7.OnClick := @Button7Click;
{ Create a label for the edit field }
label1 := TLabel.Create(Self);
@ -367,6 +386,13 @@ end.
{
$Log$
Revision 1.5 2002/08/30 06:46:03 lazarus
Use comboboxes. Use history. Prettify the dialog. Preselect text on show.
Make the findreplace a dialog. Thus removing resiying code (handled by Anchors now anyway).
Make Anchors work again and publish them for various controls.
SelStart and Co. for TEdit, SelectAll procedure for TComboBox and TEdit.
Clean up and fix some bugs for TComboBox, plus selection stuff.
Revision 1.4 2002/05/10 06:57:50 lazarus
MG: updated licenses

View File

@ -38,8 +38,6 @@ unit FindReplaceDialog;
{$mode objfpc}{$H+}
{$Define DeleteMeWhenComboBoxFocusIsFixed}
interface
uses
@ -65,16 +63,11 @@ type
function GetReplaceText:AnsiString;
procedure SetReplaceText(NewReplaceText:AnsiString);
procedure SetComboBoxText(AComboBox:TComboBox;const AText:AnsiString);
published
public
TextToFindLabel:TLabel;
ReplaceWithLabel:TLabel;
{$IFDEF DeleteMeWhenComboBoxFocusIsFixed}
TextToFindComboBox:TEdit;
ReplaceTextComboBox:TEdit;
{$ELSE}
TextToFindComboBox:TComboBox;
ReplaceTextComboBox:TComboBox;
{$ENDIF}
OptionsGroupBox:TGroupBox;
CaseSensitiveCheckBox:TCheckBox;
WholeWordsOnlyCheckBox:TCheckBox;
@ -86,20 +79,19 @@ type
OkButton:TButton;
ReplaceAllButton:TButton;
CancelButton:TButton;
constructor Create(TheOwner:TComponent); override;
procedure TextToFindComboboxKeyDown(Sender: TObject; var Key:Word;
Shift:TShiftState);
Shift:TShiftState);
procedure OkButtonClick(Sender:TObject);
procedure ReplaceAllButtonClick(Sender:TObject);
procedure CancelButtonClick(Sender:TObject);
procedure FormResize(Sender: TObject);
property Options:TSynSearchOptions read GetOptions write SetOptions;
property FindText:AnsiString read GetFindText write SetFindText;
property ReplaceText:AnsiString read GetReplaceText write SetReplaceText;
property OnKey: TOnFindDlgKey read FOnKey write SetOnKey;
public
property ComponentText[c: TFindDlgComponent]: string
read GetComponentText write SetComponentText;
constructor Create(TheOwner:TComponent); override;
end;
var FindReplaceDlg:TLazFindReplaceDialog;
@ -116,21 +108,18 @@ begin
if LazarusResources.Find(ClassName)=nil then begin
Caption:='';
Width:=400;
Height:=285;
Height:=266;
BorderStyle:= bsDialog;
Position:=poDesigned;
{$IFDEF DeleteMeWhenComboBoxFocusIsFixed}
TextToFindComboBox:=TEdit.Create(Self);
{$ELSE}
TextToFindComboBox:=TComboBox.Create(Self);
{$ENDIF}
with TextToFindComboBox do begin
Name:='TextToFindComboBox';
Parent:=Self;
Left:=90;
Top:=4;
Width:=220;
Height:=21;
Width:= 306;
Anchors:= [akLeft, akTop, akRight];
Text:='';
OnKeyDown:=@TextToFindComboBoxKeyDown;
Visible:=true;
@ -142,24 +131,19 @@ begin
Parent:=Self;
Left:=8;
Top:=8;
Width:=80;
Height:=15;
Width:= 100;
Caption:='Text to Find';
Visible:=true;
end;
{$IFDEF DeleteMeWhenComboBoxFocusIsFixed}
ReplaceTextComboBox:=TEdit.Create(Self);
{$ELSE}
ReplaceTextComboBox:=TComboBox.Create(Self);
{$ENDIF}
with ReplaceTextComboBox do begin
Name:='ReplaceTextComboBox';
Parent:=Self;
Left:=90;
Top:=28;
Width:=220;
Height:=21;
Width:= 306;
Anchors:= [akLeft, akTop, akRight];
Text:='';
OnKeyDown:=@TextToFindComboBoxKeyDown;
Visible:=true;
@ -171,8 +155,7 @@ begin
Parent:=Self;
Left:=8;
Top:=32;
Width:=80;
Height:=15;
Width:= 100;
Caption:='Replace With';
Visible:=true;
end;
@ -183,7 +166,7 @@ begin
Parent:=Self;
Left:=4;
Top:=58;
Width:=150;
Width:=194;
Height:=105;
Caption:='Options';
Visible:=true;
@ -241,12 +224,12 @@ begin
OriginRadioGroup:=TRadioGroup.Create(Self);
with OriginRadioGroup do begin
Name:='OriginRadioGroup';
Parent:=Self;
Left:=161;
Top:=58;
Width:=150;
Parent:= Self;
Left:= 202;
Top:= 58;
Width:= 194;
Height:=105;
Caption:='Origin';
Caption:= 'Origin';
with Items do begin
BeginUpdate;
Clear;
@ -264,7 +247,7 @@ begin
Parent:=Self;
Left:=4;
Top:=168;
Width:=150;
Width:=194;
Height:=65;
Caption:='Scope';
with Items do begin
@ -282,9 +265,9 @@ begin
with DirectionRadioGroup do begin
Name:='DirectionRadioGroup';
Parent:=Self;
Left:=161;
Left:=202;
Top:=168;
Width:=150;
Width:=194;
Height:=65;
Caption:='Direction';
with Items do begin
@ -301,11 +284,9 @@ begin
OkButton:=TButton.Create(Self);
with OkButton do begin
Name:='OkButton';
Parent:=Self;
Left:=33;
Top:=245;
Width:=75;
Height:=25;
Parent:= Self;
Left:= 163;
Top:= 237;
Caption:='Ok';
OnClick:=@OkButtonClick;
Visible:=true;
@ -314,11 +295,9 @@ begin
ReplaceAllButton:=TButton.Create(Self);
with ReplaceAllButton do begin
Name:='ReplaceAllButton';
Parent:=Self;
Left:=121;
Top:=245;
Width:=75;
Height:=25;
Parent:= Self;
Left:= 242;
Top:= 237;
Caption:='Replace All';
OnClick:=@ReplaceAllButtonClick;
Visible:=true;
@ -327,20 +306,16 @@ begin
CancelButton:=TButton.Create(Self);
with CancelButton do begin
Name:='CancelButton';
Parent:=Self;
Left:=209;
Top:=245;
Width:=75;
Height:=25;
Parent:= Self;
Left:= 321;
Top:= 237;
Caption:='Cancel';
OnClick:=@CancelButtonClick;
Visible:=true;
end;
OnResize:=@FormResize;
end;
fReplaceAllClickedLast:=false;
FormResize(Self);
TextToFindComboBox.SetFocus;
end;
@ -386,109 +361,6 @@ begin
ModalResult:=mrCancel;
end;
procedure TLazFindReplaceDialog.FormResize(Sender: TObject);
var MaxX, TxtLabelWidth, OptionsWidth, ButtonWidth: integer;
begin
TxtLabelWidth:=100;
MaxX:=ClientWidth;
OptionsWidth:=(MaxX-3*4) div 2;
ButtonWidth:=90;
with TextToFindLabel do begin
Left:=8;
Top:=8;
Width:=TxtLabelWidth;
end;
with TextToFindComboBox do begin
Left:=TextToFindLabel.Left+TextToFindLabel.Width+2;
Top:=TextToFindLabel.Top-4;
Width:=MaxX-Left-4;
end;
with ReplaceWithLabel do begin
Left:=TextToFindLabel.Left;
Top:=TextToFindLabel.Top+TextToFindLabel.Height+8;
Width:=TextToFindLabel.Width;
end;
with ReplaceTextComboBox do begin
Left:=TextToFindComboBox.Left;
Top:=ReplaceWithLabel.Top-4;
Width:=MaxX-Left-4;
end;
with OptionsGroupBox do begin
Left:=4;
Top:=ReplaceWithLabel.Top+ReplaceWithLabel.Height+3;
Width:=OptionsWidth;
Height:=110;
end;
with CaseSensitiveCheckBox do begin
Left:=8;
Top:=3;
Width:=Parent.ClientWidth-Left;
end;
with WholeWordsOnlyCheckBox do begin
Left:=8;
Top:=CaseSensitiveCheckBox.Top+CaseSensitiveCheckBox.Height+5;
Width:=Parent.ClientWidth-Left;
end;
with RegularExpressionsCheckBox do begin
Left:=8;
Top:=WholeWordsOnlyCheckBox.Top+WholeWordsOnlyCheckBox.Height+5;
Width:=Parent.ClientWidth-Left;
end;
with PromptOnReplaceCheckBox do begin
Left:=8;
Top:=RegularExpressionsCheckBox.Top+RegularExpressionsCheckBox.Height+5;
Width:=Parent.ClientWidth-Left;
end;
with OriginRadioGroup do begin
Left:=OptionsGroupBox.Left+OptionsGroupBox.Width+4;
Top:=OptionsGroupBox.Top;
Width:=OptionsWidth;
Height:=OptionsGroupBox.Height;
end;
with ScopeRadioGroup do begin
Left:=OptionsGroupBox.Left;
Top:=OptionsGroupBox.Top+OptionsGroupBox.Height+5;
Width:=OptionsWidth;
Height:=65;
end;
with DirectionRadioGroup do begin
Left:=OriginRadioGroup.Left;
Top:=OriginRadioGroup.Top+OriginRadioGroup.Height+5;
Width:=OptionsWidth;
Height:=65;
end;
with OkButton do begin
Left:=MaxX-10-3*(ButtonWidth+7);
Top:=245;
Width:=75;
end;
with ReplaceAllButton do begin
Left:=MaxX-10-2*(ButtonWidth+7);
Top:=245;
Width:=75;
end;
with CancelButton do begin
Left:=MaxX-10-1*(ButtonWidth+7);
Top:=245;
Width:=75;
end;
end;
function TLazFindReplaceDialog.GetComponentText(c: TFindDlgComponent): string;
begin
case c of
@ -562,11 +434,9 @@ end;
procedure TLazFindReplaceDialog.SetFindText(NewFindText:AnsiString);
begin
{$IFDEF DeleteMeWhenComboBoxFocusIsFixed}
TextToFindComboBox.Text:=NewFindText;
{$ELSE}
SetComboBoxText(TextToFindComboBox,NewFindText);
{$ENDIF}
// SetComboBoxText(TextToFindComboBox,NewFindText);
TextToFindComboBox.Text:= NewFindText;
TextToFindComboBox.SelectAll;
end;
function TLazFindReplaceDialog.GetReplaceText:AnsiString;
@ -576,11 +446,7 @@ end;
procedure TLazFindReplaceDialog.SetReplaceText(NewReplaceText:AnsiString);
begin
{$IFDEF DeleteMeWhenComboBoxFocusIsFixed}
ReplaceTextComboBox.Text:=NewReplaceText;
{$ELSE}
SetComboBoxText(ReplaceTextComboBox,NewReplaceText);
{$ENDIF}
end;
procedure TLazFindReplaceDialog.SetComboBoxText(AComboBox:TComboBox;

View File

@ -645,7 +645,7 @@ end;
{------------------------------S T A R T F I N D-----------------------------}
procedure TSourceEditor.StartFindAndReplace(Replace:boolean);
var ALeft,ATop:integer;
Begin
begin
if Owner is TSourceNotebook then
TSourceNotebook(Owner).InitFindDialog;
if Replace then
@ -655,6 +655,10 @@ Begin
FindReplaceDlg.Options :=
FindReplaceDlg.Options - [ssoReplace, ssoReplaceAll, ssoPrompt];
// Fill in history items
FindReplaceDlg.TextToFindComboBox.Items.Assign(InputHistories.FindHistory);
if Replace then FindReplaceDlg.ReplaceTextComboBox.Items.Assign(InputHistories.ReplaceHistory);
with EditorComponent do begin
if EditorOpts.FindTextAtCursor then begin
if SelAvail and (BlockBegin.Y = BlockEnd.Y) then

View File

@ -34,6 +34,105 @@ begin
Height:=23;
end;
{------------------------------------------------------------------------------
Method: TCustomEdit.GetSelText
Params: ---
Returns: selected text
Returns the selected part of text-field.
------------------------------------------------------------------------------}
function TCustomEdit.GetSelText : string;
begin
Result:= Copy(Text, SelStart, SelLength)
end;
{------------------------------------------------------------------------------
Method: TCustomEdit.SetSelText
Params: val - new string for text-field
Returns: nothings
Replace the selected part of text-field with "val".
------------------------------------------------------------------------------}
procedure TCustomEdit.SetSelText(const Val : string);
var
OldText, NewText: string;
begin
OldText:=Text;
NewText:=LeftStr(OldText,SelStart-1)+Val
+RightStr(OldText,length(OldText)-SelStart-SelLength+1);
Text:=NewText;
end;
{------------------------------------------------------------------------------
Method: TCustomEdit.GetSelStart
Params: ---
Returns: starting index of selected text
Returns starting index of selected text
------------------------------------------------------------------------------}
function TCustomEdit.GetSelStart : integer;
begin
if HandleAllocated then
FSelStart:= CNSendMessage(LM_GETSELSTART, Self, nil);
Result:= FSelStart;
end;
{------------------------------------------------------------------------------
Method: TCustomEdit.SetSelStart
Params: val -
Returns: nothing
Sets starting index for selected text.
------------------------------------------------------------------------------}
procedure TCustomEdit.SetSelStart(Val : integer);
begin
FSelStart:= Val;
if HandleAllocated then
CNSendMessage(LM_SETSELSTART, Self, Pointer(Val));
end;
{------------------------------------------------------------------------------
Method: TCustomEdit.GetSelLength
Params: ---
Returns: length of selected text
Returns length of selected text
------------------------------------------------------------------------------}
function TCustomEdit.GetSelLength : integer;
begin
if HandleAllocated then
FSelLength := CNSendMessage(LM_GETSELLEN, Self, nil);
Result:= FSelLength;
end;
{------------------------------------------------------------------------------
Method: TCustomEdit.SetSelLength
Params: val -
Returns: nothing
Sets length of selected text.
------------------------------------------------------------------------------}
procedure TCustomEdit.SetSelLength(Val : integer);
begin
FSelLength:= Val;
if HandleAllocated then
CNSendMessage(LM_SETSELLEN, Self, Pointer(Val));
end;
{------------------------------------------------------------------------------
Method: TCustomEdit.SelectAll
Params: -
Returns: nothing
Select entire text.
------------------------------------------------------------------------------}
procedure TCustomEdit.SelectAll;
begin
if Text <> '' then begin
SetSelStart(0);
SetSelLength(Length(Text));
end;
end;
{------------------------------------------------------------------------------
Method: TCustomEdit.GetModified
@ -126,11 +225,30 @@ Begin
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TCustomEdit.InitializeWnd;
var ASelStart, ASelLength : integer;
begin
inherited InitializeWnd;
if FSelStart <> FSelLength then begin
ASelStart:= FSelStart;
ASelLength:= FSelLength;
SelStart:= ASelStart;
SelLength:= ASelLength;
end;
end;
// included by stdctrls.pp
{ =============================================================================
$Log$
Revision 1.9 2002/08/30 06:46:03 lazarus
Use comboboxes. Use history. Prettify the dialog. Preselect text on show.
Make the findreplace a dialog. Thus removing resiying code (handled by Anchors now anyway).
Make Anchors work again and publish them for various controls.
SelStart and Co. for TEdit, SelectAll procedure for TComboBox and TEdit.
Clean up and fix some bugs for TComboBox, plus selection stuff.
Revision 1.8 2002/05/10 06:05:51 lazarus
MG: changed license to LGPL

View File

@ -22,12 +22,21 @@ begin
inherited Create (AOwner);
fCompStyle := csGroupBox;
ControlStyle := ControlStyle + [csAcceptsControls];
Width:= 185;
Height:= 105;
end;
// included by stdctrls.pp
{
$Log$
Revision 1.8 2002/08/30 06:46:03 lazarus
Use comboboxes. Use history. Prettify the dialog. Preselect text on show.
Make the findreplace a dialog. Thus removing resiying code (handled by Anchors now anyway).
Make Anchors work again and publish them for various controls.
SelStart and Co. for TEdit, SelectAll procedure for TComboBox and TEdit.
Clean up and fix some bugs for TComboBox, plus selection stuff.
Revision 1.7 2002/08/17 15:45:32 lazarus
MG: removed ClientRectBugfix defines