mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-30 23:11:47 +01:00
Additions for the FIND dialog
Shane git-svn-id: trunk@28 -
This commit is contained in:
parent
1937465711
commit
a60d9daa5e
@ -146,6 +146,7 @@ begin
|
|||||||
Items.Add('Forward');
|
Items.Add('Forward');
|
||||||
Items.Add('Backward');
|
Items.Add('Backward');
|
||||||
visible := True;
|
visible := True;
|
||||||
|
ItemIndex := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
btnOK := TButton.create(self);
|
btnOK := TButton.create(self);
|
||||||
|
|||||||
@ -53,7 +53,7 @@ type
|
|||||||
Function AddPage(title: String; Lines : TStringList) : TmwCustomEdit;
|
Function AddPage(title: String; Lines : TStringList) : TmwCustomEdit;
|
||||||
Procedure DeletePage(Value : Integer);
|
Procedure DeletePage(Value : Integer);
|
||||||
Function GetEditorfromPage(Value : Integer) : TmwCustomEdit;
|
Function GetEditorfromPage(Value : Integer) : TmwCustomEdit;
|
||||||
Procedure SelectText(SelStart,SelEnd : Integer);
|
Procedure SelectText(LineNum,CharStart,LineNum2,CharEnd : Integer);
|
||||||
property CurrentSource : TStrings read GetCurrentSource;
|
property CurrentSource : TStrings read GetCurrentSource;
|
||||||
property CurrentCursorXLine : Integer read GetCurrentCursorXLine write SetCurrentCursorXLine;
|
property CurrentCursorXLine : Integer read GetCurrentCursorXLine write SetCurrentCursorXLine;
|
||||||
property CurrentCursorYLine : Integer read GetCurrentCursorYLine write SetCurrentCursorYLine;
|
property CurrentCursorYLine : Integer read GetCurrentCursorYLine write SetCurrentCursorYLine;
|
||||||
@ -293,18 +293,21 @@ if Temp <> nil then
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure TideEditor.SelectText(SelStart,SelEnd : Integer);
|
Procedure TideEditor.SelectText(LineNum,CharStart,LineNum2,CharEnd : Integer);
|
||||||
var
|
var
|
||||||
temp : TmwCustomEdit;
|
temp : TmwCustomEdit;
|
||||||
|
P : TPoint;
|
||||||
begin
|
begin
|
||||||
Temp := GetEditorFromPage(Notebook1.PageIndex);
|
Temp := GetEditorFromPage(Notebook1.PageIndex);
|
||||||
Writeln('In SelectText');
|
Writeln('In SelectText');
|
||||||
Writeln(Format('SelStart and SelEnd are %d,%d',[SelStart,SelEnd]));
|
|
||||||
if Temp <> nil then
|
if Temp <> nil then
|
||||||
Begin
|
Begin
|
||||||
Temp.SetSelStart(SelStart);
|
P.X := CharStart;
|
||||||
Temp.SetSelEnd(SelEnd);
|
P.Y := LineNum;
|
||||||
|
Temp.BlockBegin := P;
|
||||||
|
P.X := CharEnd;
|
||||||
|
P.Y := LineNum2;
|
||||||
|
Temp.BlockEnd := P;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|||||||
97
ide/main.pp
97
ide/main.pp
@ -95,6 +95,7 @@ type
|
|||||||
itmEditCopy: TMenuItem;
|
itmEditCopy: TMenuItem;
|
||||||
itmEditPaste: TMenuItem;
|
itmEditPaste: TMenuItem;
|
||||||
itmSearchfind: TMenuItem;
|
itmSearchfind: TMenuItem;
|
||||||
|
itmSearchFindAgain: TMenuItem;
|
||||||
itmViewInspector: TMenuItem;
|
itmViewInspector: TMenuItem;
|
||||||
itmViewProject: TMenuItem;
|
itmViewProject: TMenuItem;
|
||||||
itmViewProjectOptions: TMenuItem;
|
itmViewProjectOptions: TMenuItem;
|
||||||
@ -135,6 +136,7 @@ type
|
|||||||
procedure mnuViewCodeExplorerClick(Sender : TObject);
|
procedure mnuViewCodeExplorerClick(Sender : TObject);
|
||||||
procedure mnuViewMessagesClick(Sender : TObject);
|
procedure mnuViewMessagesClick(Sender : TObject);
|
||||||
procedure mnuSearchFindClicked(Sender : TObject);
|
procedure mnuSearchFindClicked(Sender : TObject);
|
||||||
|
procedure mnuSearchFindAgainClicked(Sender : TObject);
|
||||||
|
|
||||||
procedure ControlClick(Sender : TObject);
|
procedure ControlClick(Sender : TObject);
|
||||||
procedure MessageViewDblClick(Sender : TObject);
|
procedure MessageViewDblClick(Sender : TObject);
|
||||||
@ -793,6 +795,11 @@ itmFileNew := TMenuItem.Create(Self);
|
|||||||
itmSearchFind.OnClick := @mnuSearchFindClicked;
|
itmSearchFind.OnClick := @mnuSearchFindClicked;
|
||||||
mnuSearch.add(itmSearchFind);
|
mnuSearch.add(itmSearchFind);
|
||||||
|
|
||||||
|
itmSearchFindAgain := TMenuItem.Create(nil);
|
||||||
|
itmSearchFindAgain.caption := 'Find &Again';
|
||||||
|
itmSearchFindAgain.OnClick := @mnuSearchFindAgainClicked;
|
||||||
|
itmSearchFindAgain.Enabled := False;
|
||||||
|
mnuSearch.add(itmSearchFindAgain);
|
||||||
//--------------
|
//--------------
|
||||||
// View
|
// View
|
||||||
//--------------
|
//--------------
|
||||||
@ -1792,30 +1799,94 @@ I : Integer;
|
|||||||
Findtext : String;
|
Findtext : String;
|
||||||
CharCount : Integer;
|
CharCount : Integer;
|
||||||
Found : Boolean;
|
Found : Boolean;
|
||||||
|
StartLineNUmber : Integer;
|
||||||
|
Searchto : Integer;
|
||||||
|
FoundAt : Integer;
|
||||||
Begin
|
Begin
|
||||||
Found := False;
|
Found := False;
|
||||||
if (IDeEditor1.Visible) then
|
if (IDeEditor1.Visible) then
|
||||||
begin
|
begin
|
||||||
|
if (Sender is TFindDialog) then StartLineNumber := 0
|
||||||
|
else
|
||||||
|
StartLineNumber := IDEEditor1.CurrentCursorYLine-1;
|
||||||
|
|
||||||
IDEEditor1.BringToFront;
|
IDEEditor1.BringToFront;
|
||||||
CaseSensitive := TFindDialog(Sender).cbCaseSensitive.Checked;
|
CaseSensitive := FindDialog1.cbCaseSensitive.Checked;
|
||||||
FindText := TFindDialog(Sender).FindText;
|
FindText := FindDialog1.FindText;
|
||||||
if CaseSensitive then
|
if not CaseSensitive then
|
||||||
FindText := Uppercase(FindText);
|
FindText := Uppercase(FindText);
|
||||||
Source := IDEEditor1.CurrentSource;
|
Source := IDEEditor1.CurrentSource;
|
||||||
if Source <> nil then
|
if Source <> nil then
|
||||||
begin
|
begin
|
||||||
CharCount := 0;
|
CharCount := 0;
|
||||||
for I := 0 to Source.Count -1 do
|
if FindDialog1.rgForwardBack.ItemIndex = 0 then
|
||||||
|
Begin
|
||||||
|
for I := StartLineNumber to Source.Count-1 do
|
||||||
|
Begin
|
||||||
|
Str := Source.Strings[i];
|
||||||
|
Writeln('Str = '+Str);
|
||||||
|
Writeln(Source.Strings[i]);
|
||||||
|
|
||||||
|
//check to see if you should be checking CASE
|
||||||
|
if not CaseSensitive then Str := UpperCase(str);
|
||||||
|
|
||||||
|
if (pos(FindText,Str) <> 0) then
|
||||||
|
begin
|
||||||
|
FoundAt := Pos(FindText,Str);
|
||||||
|
{if the text we are searching for appears more than once on a line,
|
||||||
|
the POS function only finds the first one. Therefore, if we find the text
|
||||||
|
and this function is called by something other than the FindDialog,
|
||||||
|
and we are on the same line as the cursor we need to DELETE what we found and
|
||||||
|
search again. The problem is that effects placing the cursor in the right spot.
|
||||||
|
So, when we delete it, if we find it again we place th cursor to the spot the POS
|
||||||
|
function stated plus the difference between the STRING we are searching and the one
|
||||||
|
in the editor}
|
||||||
|
//first check to see if we are still on the first line
|
||||||
|
Found := True;
|
||||||
|
if (I = StartLineNumber) and not(Sender is TFindDialog) then
|
||||||
|
Begin
|
||||||
|
while (pos(FindText,str) +(Length(Source.Strings[i]) - Length(Str)) <= IDEEDITOR1.CurrentCursorXLine) and (pos(findtext,str) <> 0) do
|
||||||
|
Begin
|
||||||
|
Delete(Str,FoundAt,Length(FindText));
|
||||||
|
end;
|
||||||
|
if (pos(FindText,str) <> 0) then
|
||||||
|
Begin
|
||||||
|
Found := true;
|
||||||
|
FoundAt :=pos(FindText,str);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
FoundAt := pos(FindText,str) + (Length(Source.Strings[i]) - Length(Str));
|
||||||
|
Writeln('***********************************************');
|
||||||
|
Writeln('***********************************************');
|
||||||
|
Writeln('***********************************************');
|
||||||
|
Writeln('***FOUNDAT='+inttostr(foundat)+'********************************************');
|
||||||
|
Writeln('***********************************************');
|
||||||
|
Writeln('***********************************************');
|
||||||
|
if Found then
|
||||||
|
Begin
|
||||||
|
IDEEditor1.CurrentCursorYLine := I+1;
|
||||||
|
IDEEditor1.CurrentCursorXLine := FoundAt;
|
||||||
|
IDEEditor1.SelectText(I+1,FoundAt,I+1,FoundAt+Length(FindText));
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
CharCount := CharCount + Length(Str);
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else {search backwards}
|
||||||
|
Begin
|
||||||
|
if StartLineNumber = 0 then StartLineNUmber := Source.Count-1;
|
||||||
|
for I := StartLineNumber downto 0 do
|
||||||
Begin
|
Begin
|
||||||
Str := Source.Strings[i];
|
Str := Source.Strings[i];
|
||||||
//check to see if you should be checking CASE
|
//check to see if you should be checking CASE
|
||||||
if CaseSensitive then Str := UpperCase(str);
|
if not CaseSensitive then Str := UpperCase(str);
|
||||||
if pos(FindText,Str) <> 0 then
|
if pos(FindText,Str) <> 0 then
|
||||||
begin
|
begin
|
||||||
IDEEditor1.CurrentCursorYLine := I+1;
|
IDEEditor1.CurrentCursorYLine := I+1;
|
||||||
IDEEditor1.CurrentCursorXLine := pos(FindText,Str);
|
IDEEditor1.CurrentCursorXLine := pos(FindText,Str);
|
||||||
|
IDEEditor1.SelectText(I+1,pos(FindText,Str),I+1,pos(FindText,Str)+Length(FindText));
|
||||||
IdeEditor1.SelectText(CharCount+1,CharCount +length(FindText));
|
|
||||||
Found := True;
|
Found := True;
|
||||||
Break;
|
Break;
|
||||||
end;
|
end;
|
||||||
@ -1824,6 +1895,9 @@ if (IDeEditor1.Visible) then
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
if not found then
|
if not found then
|
||||||
Application.Messagebox('Text not found','Error',MB_OK);
|
Application.Messagebox('Text not found','Error',MB_OK);
|
||||||
@ -1832,9 +1906,14 @@ end;
|
|||||||
|
|
||||||
Procedure TForm1.mnuSearchFindClicked(Sender : TObject);
|
Procedure TForm1.mnuSearchFindClicked(Sender : TObject);
|
||||||
Begin
|
Begin
|
||||||
|
itmSearchFindAgain.Enabled := True;
|
||||||
FindDialog1.ShowModal;
|
FindDialog1.ShowModal;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
Procedure TForm1.mnuSearchFindAgainClicked(Sender : TObject);
|
||||||
|
Begin
|
||||||
|
DoFind(itmSearchFindAgain);
|
||||||
|
End;
|
||||||
|
|
||||||
Procedure TForm1.mnuNewProjectClicked(Sender : TObject);
|
Procedure TForm1.mnuNewProjectClicked(Sender : TObject);
|
||||||
var
|
var
|
||||||
@ -2240,6 +2319,10 @@ end.
|
|||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.5 2000/08/10 13:22:51 lazarus
|
||||||
|
Additions for the FIND dialog
|
||||||
|
Shane
|
||||||
|
|
||||||
Revision 1.4 2000/08/09 18:32:10 lazarus
|
Revision 1.4 2000/08/09 18:32:10 lazarus
|
||||||
Added more code for the find function.
|
Added more code for the find function.
|
||||||
Shane
|
Shane
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user