mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-19 16:00:16 +02:00
Added the ability to use the FIND feature in the editor.
Shane git-svn-id: trunk@157 -
This commit is contained in:
parent
8d90db514d
commit
a5e1df0838
@ -416,6 +416,7 @@ begin
|
||||
ConfFileName:=SecConfFileName;
|
||||
end;
|
||||
end;
|
||||
writeln('EditorOptionsFile=',ConfFilename);
|
||||
XMLConfig:=TXMLConfig.Create(ConfFileName);
|
||||
|
||||
// set defaults
|
||||
@ -462,6 +463,7 @@ procedure TEditorOptions.Load;
|
||||
var SynEditOpt:TSynEditorOption;
|
||||
SynEditOptName:ansistring;
|
||||
begin
|
||||
writeln('AAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
|
||||
// general options
|
||||
for SynEditOpt:=Low(TSynEditorOption) to High(TSynEditorOption) do begin
|
||||
case SynEditOpt of
|
||||
@ -494,6 +496,7 @@ begin
|
||||
|
||||
fUndoAfterSave:=
|
||||
XMLConfig.GetValue('EditorOptions/General/Editor/UndoAfterSave',true);
|
||||
writeln('UndoAfterSave',fUndoAfterSave);
|
||||
fDoubleClickLine:=
|
||||
XMLConfig.GetValue('EditorOptions/General/Editor/DoubleClickLine',false);
|
||||
fFindTextAtCursor:=
|
||||
@ -865,6 +868,7 @@ var a:integer;
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
|
||||
EditorOpts.Load;
|
||||
if LazarusResources.Find(ClassName)=nil then begin
|
||||
Height:=455;
|
||||
Width:=459;
|
||||
@ -897,7 +901,7 @@ begin
|
||||
SetupButtonBar;
|
||||
end;
|
||||
|
||||
EditorOpts.Load;
|
||||
|
||||
for a:=Low(PreviewEdits) to High(PreviewEdits) do
|
||||
PreviewEdits[a]:=nil;
|
||||
EditorOpts.GetHighlighterSettings(PreviewPasSyn);
|
||||
@ -1211,7 +1215,11 @@ begin
|
||||
end;
|
||||
|
||||
procedure TEditorOptionsForm.ComboBoxOnChange(Sender:TObject);
|
||||
var ComboBox:TComboBox;
|
||||
begin
|
||||
ComboBox:=TComboBox(Sender);
|
||||
if ComboBox.Items.IndexOf(ComboBox.Text)>=0 then
|
||||
ComboBoxOnExit(Sender);
|
||||
end;
|
||||
|
||||
procedure TEditorOptionsForm.FindCurHighlightElement;
|
||||
@ -2092,6 +2100,14 @@ begin
|
||||
Top:=EditorFontComboBox.Top+EditorFontComboBox.Height+23;
|
||||
Left:=EditorFontComboBox.Left;
|
||||
Width:=60;
|
||||
Items.BeginUpdate;
|
||||
Items.Add('10');
|
||||
Items.Add('11');
|
||||
Items.Add('12');
|
||||
Items.Add('13');
|
||||
Items.Add('14');
|
||||
Items.Add('15');
|
||||
Items.EndUpdate;
|
||||
SetComboBoxText(EditorFontHeightComboBox
|
||||
,IntToStr(EditorOpts.EditorFontHeight));
|
||||
OnChange:=@ComboBoxOnChange;
|
||||
@ -2118,6 +2134,11 @@ begin
|
||||
Top:=EditorFontHeightComboBox.Top;
|
||||
Left:=EditorFontHeightComboBox.Left+EditorFontHeightComboBox.Width+100;
|
||||
Width:=60;
|
||||
Items.BeginUpdate;
|
||||
Items.Add('0');
|
||||
Items.Add('1');
|
||||
Items.Add('2');
|
||||
Items.EndUpdate;
|
||||
SetComboBoxText(ExtraLineSpacingComboBox
|
||||
,IntToStr(EditorOpts.ExtraLineSpacing));
|
||||
OnChange:=@ComboBoxOnChange;
|
||||
|
@ -59,6 +59,9 @@ public
|
||||
property FIndText : String read FFindText write FFindText;
|
||||
end;
|
||||
|
||||
|
||||
var
|
||||
FindDialog1 : TFindDialog;
|
||||
implementation
|
||||
|
||||
constructor TFindDialog.Create(AOwner: TComponent);
|
||||
|
23
ide/main.pp
23
ide/main.pp
@ -45,7 +45,6 @@ type
|
||||
TMainIDE = class(TFORM)
|
||||
FontDialog1 : TFontDialog;
|
||||
ColorDialog1 : TColorDialog;
|
||||
FindDialog1 : TFindDialog;
|
||||
ToolBar1 : TToolBar;
|
||||
Toolbutton1 : TToolButton;
|
||||
Toolbutton2 : TToolButton;
|
||||
@ -144,8 +143,6 @@ type
|
||||
procedure mnuProjectOptionsClicked(Sender : TObject);
|
||||
procedure mnuViewCodeExplorerClick(Sender : TObject);
|
||||
procedure mnuViewMessagesClick(Sender : TObject);
|
||||
procedure mnuSearchFindClicked(Sender : TObject);
|
||||
procedure mnuSearchFindAgainClicked(Sender : TObject);
|
||||
|
||||
procedure mnuEnvironmentOptionsClicked(Sender : TObject);
|
||||
|
||||
@ -690,10 +687,14 @@ begin
|
||||
itmFileClose.OnClick := @SourceNotebook.CloseClicked;
|
||||
itmFileNew.OnClick := @SourceNotebook.NewClicked;
|
||||
itmFileOpen.OnClick := @SourceNotebook.OpenClicked;
|
||||
itmSearchFind.onClick := @SourceNotebook.FindClicked;
|
||||
itmSearchFindAgain.OnClick := @SourceNotebook.FindAgainClicked;
|
||||
SpeedButton4.OnClick := @SourceNotebook.OpenClicked;
|
||||
SpeedButton5.OnClick := @SourceNotebook.SaveClicked;
|
||||
SpeedButton6.OnClick := @SourceNotebook.SaveAllClicked;
|
||||
|
||||
|
||||
|
||||
end;
|
||||
|
||||
procedure TMainIDE.OIOnAddAvailableComponent(AComponent:TComponent;
|
||||
@ -868,12 +869,10 @@ begin
|
||||
|
||||
itmSearchFind := TMenuItem.Create(nil);
|
||||
itmSearchFind.caption := 'Find';
|
||||
itmSearchFind.OnClick := @mnuSearchFindClicked;
|
||||
mnuSearch.add(itmSearchFind);
|
||||
|
||||
itmSearchFindAgain := TMenuItem.Create(nil);
|
||||
itmSearchFindAgain.caption := 'Find &Again';
|
||||
itmSearchFindAgain.OnClick := @mnuSearchFindAgainClicked;
|
||||
itmSearchFindAgain.Enabled := False;
|
||||
mnuSearch.add(itmSearchFindAgain);
|
||||
|
||||
@ -1455,16 +1454,6 @@ Begin
|
||||
|
||||
end;
|
||||
|
||||
Procedure TMainIDE.mnuSearchFindClicked(Sender : TObject);
|
||||
Begin
|
||||
itmSearchFindAgain.Enabled := True;
|
||||
FindDialog1.ShowModal;
|
||||
End;
|
||||
|
||||
Procedure TMainIDE.mnuSearchFindAgainClicked(Sender : TObject);
|
||||
Begin
|
||||
DoFind(itmSearchFindAgain);
|
||||
End;
|
||||
|
||||
{------------------------------------------------------------}
|
||||
|
||||
@ -1654,6 +1643,10 @@ end.
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.53 2001/01/31 18:57:29 lazarus
|
||||
Added the ability to use the FIND feature in the editor.
|
||||
Shane
|
||||
|
||||
Revision 1.52 2001/01/31 13:03:33 lazarus
|
||||
Commitng source with new editor.
|
||||
Shane
|
||||
|
@ -31,7 +31,7 @@ unit UnitEditor;
|
||||
interface
|
||||
|
||||
uses
|
||||
classes, Controls, forms,buttons,comctrls,sysutils,Dialogs,FormEditor,
|
||||
classes, Controls, forms,buttons,comctrls,sysutils,Dialogs,FormEditor,Find_Dlg,
|
||||
{$ifdef NEW_EDITOR_SYNEDIT}
|
||||
SynEdit, SynEditHighlighter, SynHighlighterPas, SynEditAutoComplete,
|
||||
SynEditKeyCmds,
|
||||
@ -118,6 +118,7 @@ type
|
||||
Function GotoMethod(Value : String) : Integer;
|
||||
Function GotoMethodDeclaration(Value : String) : Integer;
|
||||
|
||||
|
||||
Procedure CreateEditor(AOwner : TComponent; AParent: TWinControl);
|
||||
Procedure CreateFormFromUnit;
|
||||
protected
|
||||
@ -136,15 +137,18 @@ type
|
||||
Procedure BookMarkGoto(Value : Integer);
|
||||
|
||||
|
||||
Procedure EditorKeyDown(Sender : TObject; var Key: Word; Shift : TShiftState);
|
||||
Procedure EditorKeyUp(Sender : TObject; var Key: Word; Shift : TShiftState);
|
||||
Procedure ProcessUserCommand(Sender: TObject; var Command: TSynEditorCommand; var AChar: char; Data: pointer);
|
||||
|
||||
Procedure FocusEditor; //called by TSourceNotebook whne the Notebook page changes so the editor is focused
|
||||
|
||||
Procedure EditorStatusChanged(Sender: TObject; Changes: TSynStatusChanges);
|
||||
|
||||
Function StartFind : Boolean;
|
||||
Function FindAgain(StartX,StartLine : Integer) : Boolean;
|
||||
|
||||
property Editor : TmwCustomEdit read FEditor;
|
||||
property Visible : Boolean read FVisible write FVisible default False;
|
||||
FindText : String;
|
||||
public
|
||||
constructor Create(AOwner : TComponent; AParent : TWinControl);
|
||||
destructor Destroy; override;
|
||||
@ -224,6 +228,9 @@ type
|
||||
procedure SaveAllClicked(Sender : TObject);
|
||||
procedure SaveAsClicked(Sender : TObject);
|
||||
|
||||
procedure FindClicked(Sender : TObject);
|
||||
procedure FindAgainClicked(Sender : TObject);
|
||||
|
||||
Procedure NewFile(UnitName: String; Source : TStrings; aVisible : Boolean);
|
||||
Procedure OpenFile(FileName: String; aVisible : Boolean);
|
||||
|
||||
@ -244,6 +251,12 @@ implementation
|
||||
uses
|
||||
LCLLinux,TypInfo,LResources,Main,LazConf;
|
||||
|
||||
const
|
||||
ecFind = ecUserFirst+1;
|
||||
ecFindAgain = ecUserFirst+2;
|
||||
ecFindProcedureDefinition = ecUserFirst+3;
|
||||
ecFindProcedureMethod = ecUserFirst+4;
|
||||
|
||||
var
|
||||
Editor_Num : Integer;
|
||||
aHighlighter: TSynPasSyn;
|
||||
@ -574,6 +587,76 @@ Begin
|
||||
|
||||
end;
|
||||
|
||||
{--------------------------S T A R T F I N D-----------------------}
|
||||
Function TSourceEditor.StartFind : Boolean;
|
||||
Begin
|
||||
Result := False;
|
||||
if not Assigned(FindDialog1) then
|
||||
FindDialog1 := TFindDialog.Create(nil);
|
||||
|
||||
if (FindDialog1.ShowModal = mrOK) then
|
||||
Begin
|
||||
if not FindDialog1.cbCaseSensitive.Checked then
|
||||
FindText := uppercase(FindDialog1.edtTextToFind.Text);
|
||||
Result := FindAgain(1,0);
|
||||
|
||||
end;
|
||||
|
||||
End;
|
||||
|
||||
{--------------------------F I N D A G A I N -----------------------}
|
||||
Function TSourceEditor.FindAgain(StartX,StartLine : Integer) : Boolean;
|
||||
var
|
||||
I,X : Integer;
|
||||
Texts : String;
|
||||
TempLine : String;
|
||||
P : TPoint;
|
||||
Begin
|
||||
Result := False;
|
||||
|
||||
if FindText = '' then Exit;
|
||||
|
||||
if (StartX < 0) or (StartLine < 0) then
|
||||
Begin
|
||||
StartX := CurrentCursorXLine-1;
|
||||
StartLine := CurrentCursorYLine-1;
|
||||
end;
|
||||
|
||||
for I := StartLine to Source.Count-1 do
|
||||
begin
|
||||
TempLine := Copy(Source.Strings[i],StartX,Length(Source.Strings[i]));
|
||||
if not FindDialog1.cbCaseSensitive.Checked then
|
||||
TempLine := uppercase(TempLine);
|
||||
|
||||
|
||||
X := pos(FindText,Templine);
|
||||
if (X > 0) and (FindDialog1.cbWholeWords.Checked) then
|
||||
begin
|
||||
//check the character prior to X
|
||||
if X > 1 then
|
||||
if (TempLine[X-1] in ['a'..'z', 'A'..'Z', '0'..'9']) then
|
||||
X := 0;
|
||||
if (X < Length(TempLine)) and (X > 0) then
|
||||
if (TempLine[X+1] in ['a'..'z', 'A'..'Z', '0'..'9']) then
|
||||
X := 0;
|
||||
end;
|
||||
if (X > 0) then
|
||||
Begin
|
||||
//re-position cursor and break;
|
||||
P.X := X+Startx-1;
|
||||
P.Y := I+1;
|
||||
FEditor.BlockBegin:= P;
|
||||
P.X := P.X+Length(FindText);
|
||||
FEditor.BlockEND :=P;
|
||||
FEditor.CaretXY := p;
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
StartX := 1;
|
||||
|
||||
end;
|
||||
End;
|
||||
|
||||
|
||||
|
||||
Procedure TSourceEditor.ToggleLineNumbersClicked(Sender : TObject);
|
||||
@ -611,26 +694,34 @@ Begin
|
||||
|
||||
end;
|
||||
|
||||
|
||||
Procedure TSourceEditor.EditorKeyDown(Sender : TObject; var Key: Word; Shift : TShiftState);
|
||||
Procedure TSourceEditor.ProcessUserCommand(Sender: TObject; var Command: TSynEditorCommand; var AChar: char; Data: pointer);
|
||||
var
|
||||
Texts,nmForm : String;
|
||||
Texts2 : String;
|
||||
I,Y : Integer;
|
||||
TheName : String;
|
||||
Y,I : Integer;
|
||||
Texts,Texts2,TheName : String;
|
||||
Begin
|
||||
if (Key = 40) and ( ssCTRL in Shift) then
|
||||
Begin
|
||||
//jump down to the procedure definition
|
||||
Texts := TextUnderCursor; //this should be a procedure name.
|
||||
GotoMethod(Texts);
|
||||
Writeln('[ProcessUserCommand] --------------');
|
||||
case Command of
|
||||
ecFind : Begin
|
||||
FindText := '';
|
||||
StartFind;
|
||||
end;
|
||||
|
||||
end
|
||||
else
|
||||
if (Key = 38) and (ssCTRL in Shift) and (ssShift in Shift)then
|
||||
Begin
|
||||
//jump up to the procedure definition
|
||||
//move up until you find the work PROCEDURE or FUNCTION
|
||||
ecFindAgain : Begin
|
||||
if FindText = '' then
|
||||
StartFind
|
||||
else
|
||||
if not(FindAgain(CurrentCursorXLine-1,CurrentCursorYLine-1)) then
|
||||
if Application.MessageBox('Search String not found. Start from the beginning?','Not Found',mb_YesNo) = mrYEs then
|
||||
FindAgain(1,0);
|
||||
end;
|
||||
|
||||
ecFindProcedureMethod : Begin
|
||||
//jump down to the procedure definition
|
||||
Texts := TextUnderCursor; //this should be a procedure name.
|
||||
GotoMethod(Texts);
|
||||
end;
|
||||
|
||||
ecFindProcedureDefinition : Begin
|
||||
Y := CurrentCursorYLine;
|
||||
Texts2 := Lowercase(Source.Strings[Y-1]);
|
||||
Writeln('The source line = '+Texts2);
|
||||
@ -661,13 +752,10 @@ Begin
|
||||
GotoMethodDeclaration(TheName);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
Procedure TSourceEditor.EditorKeyUp(Sender : TObject; var Key: Word; Shift : TShiftState);
|
||||
Begin
|
||||
end; //case
|
||||
|
||||
end;
|
||||
|
||||
@ -708,9 +796,13 @@ if assigned(FEditor) then
|
||||
Highlighter:=aHighlighter;
|
||||
Gutter.Color:=clBlue;
|
||||
AddKey(ecAutoCompletion, word('J'), [ssCtrl], 0, []);
|
||||
OnKeyDown := @EditorKeyDown;
|
||||
OnKeyUp := @EditorKeyUp;
|
||||
AddKey(ecFind, word('F'), [ssCtrl], 0, []);
|
||||
AddKey(ecFindAgain, VK_F3, [], 0, []);
|
||||
AddKey(ecFindProcedureDefinition, VK_UP, [ssShift,ssCtrl], 0, []);
|
||||
AddKey(ecFindProcedureMethod, VK_Down, [ssShift,ssCtrl], 0, []);
|
||||
|
||||
OnStatusChange := @EditorStatusChanged;
|
||||
OnProcessUserCommand := @ProcessUserCommand;
|
||||
Show;
|
||||
end;
|
||||
FSynAutoComplete.AddEditor(FEditor);
|
||||
@ -962,7 +1054,7 @@ Begin
|
||||
|
||||
|
||||
//figure out what the unit name should be...
|
||||
FUnitName:='Unit1'; //just assigning it to this for now
|
||||
// FUnitName:='Unit1'; //just assigning it to this for now
|
||||
|
||||
with TempSource do
|
||||
try
|
||||
@ -1216,10 +1308,10 @@ var
|
||||
UnitIndex,I:integer;
|
||||
|
||||
Begin
|
||||
UnitIndex := 0;
|
||||
if CreateNotebook then Pagenum := 0;
|
||||
|
||||
if Pagenum = -1 then begin //add a new page
|
||||
UnitIndex:=0;
|
||||
repeat
|
||||
inc(UnitIndex);
|
||||
I:=FSourceEditorList.Count-1;
|
||||
@ -1227,11 +1319,9 @@ Begin
|
||||
and (lowercase(TSourceEditor(FSourceEditorList[I]).UnitName)
|
||||
<>'unit'+IntToStr(UnitIndex)) do dec(I);
|
||||
until I<0;
|
||||
Pagenum := Notebook1.Pages.Add('Unit'+IntToStr(UnitIndex));
|
||||
|
||||
Pagenum := Notebook1.Pages.Add('unit'+IntToStr(UnitIndex));
|
||||
end;
|
||||
|
||||
|
||||
Result := TSourceEditor.Create(Self,Notebook1.Page[PageNum]);
|
||||
Result.FUnitName:=Notebook1.Pages[PageNum];
|
||||
Notebook1.Pageindex := Pagenum;
|
||||
@ -1392,6 +1482,19 @@ Begin
|
||||
UpdateStatusBar;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.FindClicked(Sender : TObject);
|
||||
Begin
|
||||
if GetActiveSe <> nil then
|
||||
GetActiveSE.StartFind;
|
||||
End;
|
||||
|
||||
Procedure TSourceNotebook.FindAgainClicked(Sender : TObject);
|
||||
Begin
|
||||
if GetActiveSe <> nil then
|
||||
GetActiveSE.FindAgain(-1,-1); //-1 uses the currect x and y coords of the cursor in the window
|
||||
End;
|
||||
|
||||
|
||||
|
||||
|
||||
{This is called from outside to toggle a bookmark of the active TSourceEditor}
|
||||
@ -1613,14 +1716,17 @@ End;
|
||||
|
||||
Procedure TSourceNotebook.NoteBookPageChanged(Sender : TObject);
|
||||
Begin
|
||||
GetActiveSE.FocusEditor;
|
||||
|
||||
UpdateStatusBar;
|
||||
if GetActiveSE <> nil then
|
||||
begin
|
||||
GetActiveSE.FocusEditor;
|
||||
UpdateStatusBar;
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
Editor_Num := 0;
|
||||
|
||||
|
||||
{$I designer/bookmark.lrs}
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user