MG: added find previous to source editor

git-svn-id: trunk@355 -
This commit is contained in:
lazarus 2001-10-17 13:43:16 +00:00
parent 1ecb6200d7
commit 96a5cb3237
4 changed files with 105 additions and 36 deletions

View File

@ -14,11 +14,11 @@
- mrCancel for Cancel - mrCancel for Cancel
ToDo: ToDo:
-regular expression checkbox
} }
unit findreplacedialog; unit findreplacedialog;
{$mode objfpc} {$mode objfpc}{$H+}
interface interface
@ -52,7 +52,7 @@ type
OkButton:TButton; OkButton:TButton;
ReplaceAllButton:TButton; ReplaceAllButton:TButton;
CancelButton:TButton; CancelButton:TButton;
procedure TextToFindeditKeyDown(Sender: TObject; var Key:Word; procedure TextToFindEditKeyDown(Sender: TObject; var Key:Word;
Shift:TShiftState); Shift:TShiftState);
procedure OkButtonClick(Sender:TObject); procedure OkButtonClick(Sender:TObject);
procedure ReplaceAllButtonClick(Sender:TObject); procedure ReplaceAllButtonClick(Sender:TObject);
@ -117,9 +117,9 @@ begin
Show; Show;
end; end;
ReplaceTextedit:=Tedit.Create(Self); ReplaceTextEdit:=Tedit.Create(Self);
with ReplaceTextedit do begin with ReplaceTextEdit do begin
Name:='ReplaceTextedit'; Name:='ReplaceTextEdit';
Parent:=Self; Parent:=Self;
Left:=90; Left:=90;
Top:=28; Top:=28;
@ -299,6 +299,10 @@ procedure TLazFindReplaceDialog.TextToFindeditKeyDown(
begin begin
if (Key=VK_RETURN) then OkButtonClick(Sender); if (Key=VK_RETURN) then OkButtonClick(Sender);
if (Key=VK_ESCAPE) then CancelButtonClick(Sender); if (Key=VK_ESCAPE) then CancelButtonClick(Sender);
if Key=VK_TAB then begin
if Sender=TextToFindEdit then
ReplaceTextEdit.SetFocus;
end;
end; end;
procedure TLazFindReplaceDialog.OkButtonClick(Sender:TObject); procedure TLazFindReplaceDialog.OkButtonClick(Sender:TObject);
@ -334,7 +338,7 @@ begin
then DirectionRadioGroup.ItemIndex:=0 then DirectionRadioGroup.ItemIndex:=0
else DirectionRadioGroup.ItemIndex:=1; else DirectionRadioGroup.ItemIndex:=1;
ReplaceAllButton.Enabled:=ssoReplace in NewOptions; ReplaceAllButton.Enabled:=ssoReplace in NewOptions;
ReplaceTextedit.Enabled:=ReplaceAllButton.Enabled; ReplaceTextEdit.Enabled:=ReplaceAllButton.Enabled;
ReplaceWithLabel.Enabled:=ReplaceAllButton.Enabled; ReplaceWithLabel.Enabled:=ReplaceAllButton.Enabled;
PromptOnReplaceCheckBox.Enabled:=ReplaceAllButton.Enabled; PromptOnReplaceCheckBox.Enabled:=ReplaceAllButton.Enabled;
if ssoReplace in NewOptions then begin if ssoReplace in NewOptions then begin
@ -372,12 +376,12 @@ end;
function TLazFindReplaceDialog.GetReplaceText:AnsiString; function TLazFindReplaceDialog.GetReplaceText:AnsiString;
begin begin
Result:=ReplaceTextedit.Text; Result:=ReplaceTextEdit.Text;
end; end;
procedure TLazFindReplaceDialog.SetReplaceText(NewReplaceText:AnsiString); procedure TLazFindReplaceDialog.SetReplaceText(NewReplaceText:AnsiString);
begin begin
ReplaceTextedit.Text:=NewReplaceText; ReplaceTextEdit.Text:=NewReplaceText;
end; end;
end. end.

View File

@ -21,8 +21,9 @@ uses
const const
// editor commands constants. see syneditkeycmds.pp for more // editor commands constants. see syneditkeycmds.pp for more
ecFind = ecUserFirst + 1; ecFind = ecUserFirst + 1;
ecFindAgain = ecUserFirst + 2; ecFindAgain = ecUserFirst + 2;
ecFindNext = ecFindAgain;
ecReplace = ecUserFirst + 3; ecReplace = ecUserFirst + 3;
ecFindProcedureDefinition = ecUserFirst + 4; ecFindProcedureDefinition = ecUserFirst + 4;
ecFindProcedureMethod = ecUserFirst + 5; ecFindProcedureMethod = ecUserFirst + 5;
@ -31,7 +32,10 @@ const
ecNextEditor = ecUserFirst + 7; ecNextEditor = ecUserFirst + 7;
ecPrevEditor = ecUserFirst + 8; ecPrevEditor = ecUserFirst + 8;
ecPeriod = ecUserFirst + 9; ecPeriod = ecUserFirst + 9;
ecFindPrevious = ecUserFirst + 10;
ecFindInFiles = ecUserFirst + 11;
ecWordCompletion = ecUserFirst + 100; ecWordCompletion = ecUserFirst + 100;
ecCompleteCode = ecUserFirst + 101; ecCompleteCode = ecUserFirst + 101;
@ -287,7 +291,9 @@ begin
ecSetMarker9: Result:= 'SetMarker9'; ecSetMarker9: Result:= 'SetMarker9';
ecFind: Result:= 'Find text'; ecFind: Result:= 'Find text';
ecFindAgain: Result:= 'Find again'; ecFindNext: Result:= 'Find next';
ecFindPrevious: Result:= 'Find previous';
ecFindInFiles: Result:= 'Find in files';
ecReplace: Result:= 'Replace text'; ecReplace: Result:= 'Replace text';
ecFindProcedureDefinition: Result:= 'find procedure definition'; ecFindProcedureDefinition: Result:= 'find procedure definition';
ecFindProcedureMethod: Result:= 'find procedure method'; ecFindProcedureMethod: Result:= 'find procedure method';
@ -704,10 +710,7 @@ begin
ACaption:='No No No'; ACaption:='No No No';
AText:=' The key "'+KeyAndShiftStateToStr(NewKey2,NewShiftState2)+'"' AText:=' The key "'+KeyAndShiftStateToStr(NewKey2,NewShiftState2)+'"'
+' is already connected to "'+DummyRelation.Name+'".'; +' is already connected to "'+DummyRelation.Name+'".';
// Application.MessageBox(PChar(AText),PChar(ACaption),0);
MessageDlg(ACaption,AText,mterror,[mbok],0); MessageDlg(ACaption,AText,mterror,[mbok],0);
exit; exit;
end; end;
if NewKey1=VK_UNKNOWN then begin if NewKey1=VK_UNKNOWN then begin
@ -877,7 +880,9 @@ begin
Add('Identifier completion',ecIdentCompletion,VK_SPACE,[ssCtrl],VK_UNKNOWN,[]); Add('Identifier completion',ecIdentCompletion,VK_SPACE,[ssCtrl],VK_UNKNOWN,[]);
Add('Find text',ecFind,VK_F,[SSCtrl],VK_UNKNOWN,[]); Add('Find text',ecFind,VK_F,[SSCtrl],VK_UNKNOWN,[]);
Add('Find text again',ecFindAgain,VK_F3,[],VK_UNKNOWN,[]); Add('Find next',ecFindNext,VK_F3,[],VK_UNKNOWN,[]);
Add('Find previous',ecFindPrevious,VK_UNKNOWN,[],VK_UNKNOWN,[]);
Add('Find in files',ecFindInFiles,VK_UNKNOWN,[],VK_UNKNOWN,[]);
Add('Replace text',ecReplace,VK_R,[SSCtrl],VK_UNKNOWN,[]); Add('Replace text',ecReplace,VK_R,[SSCtrl],VK_UNKNOWN,[]);
Add('Find procedure definiton',ecFindProcedureDefinition, Add('Find procedure definiton',ecFindProcedureDefinition,
VK_UP,[ssShift,SSCtrl],VK_UNKNOWN,[]); VK_UP,[ssShift,SSCtrl],VK_UNKNOWN,[]);

View File

@ -109,7 +109,9 @@ type
itmEditPaste: TMenuItem; itmEditPaste: TMenuItem;
itmSearchFind: TMenuItem; itmSearchFind: TMenuItem;
itmSearchFindAgain: TMenuItem; itmSearchFindNext: TMenuItem;
itmSearchFindPrevious: TMenuItem;
itmSearchFindInFiles: TMenuItem;
itmSearchReplace: TMenuItem; itmSearchReplace: TMenuItem;
itmGotoLineNumber: TMenuItem; itmGotoLineNumber: TMenuItem;
@ -527,7 +529,9 @@ begin
// find / replace dialog // find / replace dialog
itmSearchFind.OnClick := @SourceNotebook.FindClicked; itmSearchFind.OnClick := @SourceNotebook.FindClicked;
itmSearchFindAgain.OnClick := @SourceNotebook.FindAgainClicked; itmSearchFindNext.OnClick := @SourceNotebook.FindNextClicked;
itmSearchFindPrevious.OnClick := @SourceNotebook.FindPreviousClicked;
itmSearchFindInFiles.OnClick := @SourceNotebook.FindInFilesClicked;
itmSearchReplace.OnClick := @SourceNotebook.ReplaceClicked; itmSearchReplace.OnClick := @SourceNotebook.ReplaceClicked;
// message view // message view
@ -924,11 +928,23 @@ begin
itmSearchFind.Caption := 'Find'; itmSearchFind.Caption := 'Find';
mnuSearch.add(itmSearchFind); mnuSearch.add(itmSearchFind);
itmSearchFindAgain := TMenuItem.Create(nil); itmSearchFindNext := TMenuItem.Create(nil);
itmSearchFindAgain.Name:='itmSearchFindAgain'; itmSearchFindNext.Name:='itmSearchFindNext';
itmSearchFindAgain.caption := 'Find &Again'; itmSearchFindNext.Caption := 'Find &Next';
itmSearchFindAgain.Enabled := False; itmSearchFindNext.Enabled := False;
mnuSearch.add(itmSearchFindAgain); mnuSearch.add(itmSearchFindNext);
itmSearchFindPrevious := TMenuItem.Create(nil);
itmSearchFindPrevious.Name:='itmSearchFindPrevious';
itmSearchFindPrevious.Caption := 'Find &Previous';
itmSearchFindPrevious.Enabled := False;
mnuSearch.add(itmSearchFindPrevious);
itmSearchFindInFiles := TMenuItem.Create(nil);
itmSearchFindInFiles.Name:='itmSearchFindInFiles';
itmSearchFindInFiles.Caption := 'Find &in files';
itmSearchFindInFiles.Enabled := False;
mnuSearch.add(itmSearchFindInFiles);
itmSearchReplace := TMenuItem.Create(nil); itmSearchReplace := TMenuItem.Create(nil);
itmSearchReplace.Name:='itmSearchReplace'; itmSearchReplace.Name:='itmSearchReplace';
@ -4004,6 +4020,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.123 2001/10/17 13:43:15 lazarus
MG: added find previous to source editor
Revision 1.122 2001/10/16 14:19:10 lazarus Revision 1.122 2001/10/16 14:19:10 lazarus
MG: added nvidia opengl support and a new opengl example from satan MG: added nvidia opengl support and a new opengl example from satan

View File

@ -162,7 +162,8 @@ type
procedure OnReplace(Sender: TObject; const ASearch, AReplace: procedure OnReplace(Sender: TObject; const ASearch, AReplace:
string; Line, Column: integer; var Action: TSynReplaceAction); string; Line, Column: integer; var Action: TSynReplaceAction);
procedure DoFindAndReplace; procedure DoFindAndReplace;
procedure FindAgain; procedure FindNext;
procedure FindPrevious;
procedure GetDialogPosition(Width, Height:integer; var Left,Top:integer); procedure GetDialogPosition(Width, Height:integer; var Left,Top:integer);
property CodeBuffer: TCodeBuffer read FCodeBuffer write SetCodeBuffer; property CodeBuffer: TCodeBuffer read FCodeBuffer write SetCodeBuffer;
@ -299,8 +300,10 @@ type
procedure ToggleFormUnitClicked(Sender: TObject); procedure ToggleFormUnitClicked(Sender: TObject);
procedure FindClicked(Sender : TObject); procedure FindClicked(Sender : TObject);
procedure FindNextClicked(Sender : TObject);
procedure FindPreviousClicked(Sender : TObject);
procedure FindInFilesClicked(Sender : TObject);
procedure ReplaceClicked(Sender : TObject); procedure ReplaceClicked(Sender : TObject);
procedure FindAgainClicked(Sender : TObject);
Procedure NewFile(const NewShortName: String; ASource : TCodeBuffer); Procedure NewFile(const NewShortName: String; ASource : TCodeBuffer);
Procedure CloseFile(PageIndex:integer); Procedure CloseFile(PageIndex:integer);
@ -647,7 +650,7 @@ Begin
End; End;
{------------------------------F I N D A G A I N ----------------------------} {------------------------------F I N D A G A I N ----------------------------}
procedure TSourceEditor.FindAgain; procedure TSourceEditor.FindNext;
var OldOptions: TSynSearchOptions; var OldOptions: TSynSearchOptions;
Begin Begin
OldOptions:=FindReplaceDlg.Options; OldOptions:=FindReplaceDlg.Options;
@ -656,23 +659,40 @@ Begin
FindReplaceDlg.Options:=OldOptions; FindReplaceDlg.Options:=OldOptions;
End; End;
{---------------------------F I N D P R E V I O U S ------------------------}
procedure TSourceEditor.FindPrevious;
var OldOptions: TSynSearchOptions;
Begin
OldOptions:=FindReplaceDlg.Options;
FindReplaceDlg.Options:=FindReplaceDlg.Options-[ssoEntireScope];
if ssoBackwards in FindReplaceDlg.Options then
FindReplaceDlg.Options:=FindReplaceDlg.Options-[ssoBackwards]
else
FindReplaceDlg.Options:=FindReplaceDlg.Options+[ssoBackwards];
DoFindAndReplace;
FindReplaceDlg.Options:=OldOptions;
End;
procedure TSourceEditor.DoFindAndReplace; procedure TSourceEditor.DoFindAndReplace;
var OldCaretXY:TPoint; var OldCaretXY:TPoint;
AText,ACaption:AnsiString; AText,ACaption:AnsiString;
TopLine: integer; TopLine: integer;
begin begin
OldCaretXY:=EditorComponent.CaretXY; OldCaretXY:=EditorComponent.CaretXY;
if EditorComponent.SelAvail then begin
if ssoBackwards in FindReplaceDlg.Options then
EditorComponent.CaretXY:=EditorComponent.BlockBegin
else
EditorComponent.CaretXY:=EditorComponent.BlockEnd
end;
EditorComponent.SearchReplace( EditorComponent.SearchReplace(
FindReplaceDlg.FindText,FindReplaceDlg.ReplaceText,FindReplaceDlg.Options); FindReplaceDlg.FindText,FindReplaceDlg.ReplaceText,FindReplaceDlg.Options);
if (OldCaretXY.X=EditorComponent.CaretX) if (OldCaretXY.X=EditorComponent.CaretX)
and (OldCaretXY.Y=EditorComponent.CaretY) and (OldCaretXY.Y=EditorComponent.CaretY)
and not (ssoReplaceAll in FindReplaceDlg.Options) then begin and not (ssoReplaceAll in FindReplaceDlg.Options) then begin
ACaption:='Message'; ACaption:='Not found';
AText:='Search string '''+FindReplaceDlg.FindText+''' not found!'; AText:='Search string '''+FindReplaceDlg.FindText+''' not found!';
MessageDlg(ACaption,AText,mtInformation,[mbOk],0);
// Application.MessageBox(PChar(AText),PChar(ACaption),MB_OK);
MessageDlg(ACaption,AText,mtinformation,[mbok],0);
end else begin end else begin
TopLine := EditorComponent.CaretY - (EditorComponent.LinesInWindow div 2); TopLine := EditorComponent.CaretY - (EditorComponent.LinesInWindow div 2);
if TopLine < 1 then TopLine:=1; if TopLine < 1 then TopLine:=1;
@ -762,11 +782,18 @@ Begin
aCompletion.Execute(TextS2,P.X,P.Y); aCompletion.Execute(TextS2,P.X,P.Y);
end; end;
ecFind : ecFind:
StartFindAndReplace(false); StartFindAndReplace(false);
ecFindAgain : ecFindNext:
FindAgain; FindNext;
ecFindPrevious:
FindPrevious;
ecFindInFiles:
// ToDo
;
ecReplace: ecReplace:
StartFindAndReplace(true); StartFindAndReplace(true);
@ -2322,11 +2349,25 @@ Begin
if TempEditor <> nil then TempEditor.StartFindAndReplace(true); if TempEditor <> nil then TempEditor.StartFindAndReplace(true);
End; End;
Procedure TSourceNotebook.FindAgainClicked(Sender : TObject); Procedure TSourceNotebook.FindNextClicked(Sender : TObject);
var TempEditor:TSourceEditor; var TempEditor:TSourceEditor;
Begin Begin
TempEditor:=GetActiveSe; TempEditor:=GetActiveSe;
if TempEditor <> nil then TempEditor.FindAgain; if TempEditor <> nil then TempEditor.FindNext;
End;
Procedure TSourceNotebook.FindPreviousClicked(Sender : TObject);
var TempEditor:TSourceEditor;
Begin
TempEditor:=GetActiveSe;
if TempEditor <> nil then TempEditor.FindPrevious;
End;
Procedure TSourceNotebook.FindInFilesClicked(Sender : TObject);
Begin
MessageDlg('Not implemented yet',
'If you can help us to implement this feature, mail to'#13
+'lazarus@miraclec.com', mtInformation,[mbCancel],0);
End; End;
Procedure TSourceNotebook.BookMarkClicked(Sender : TObject); Procedure TSourceNotebook.BookMarkClicked(Sender : TObject);