?? ufindinfile.pas
字號:
unit UFindInFile;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TFindInFile = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Label1: TLabel;
cbSearch: TComboBox;
GroupBox1: TGroupBox;
chkMatchCase: TCheckBox;
chkWholeWord: TCheckBox;
btnOK: TButton;
btnCancel: TButton;
ListView1: TListView;
Animate1: TAnimate;
procedure FormActivate(Sender: TObject);
procedure cbSearchKeyPress(Sender: TObject; var Key: Char);
procedure btnOKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
private
{ Private declarations }
MatchingPos: Integer;
procedure LoadFindStr;
function SearchingText(SearchStr:string;Options:TSearchTypes):Boolean;
public
{ Public declarations }
end;
var
FindInFile: TFindInFile;
implementation
uses utils,uconst,MAINFORM, Editor, mwCustomEdit;
{$R *.DFM}
procedure TFindInFile.FormActivate(Sender: TObject);
begin
MatchingPos:=0;
cbSearch.SetFocus;
end;
procedure TFindInFile.cbSearchKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then begin
ModalResult:= mrOK;
btnOKClick(self);
Key:= #0;
end;
end;
procedure TFindInFile.btnOKClick(Sender: TObject);
var
Options: TSearchTypes;
begin
SaveFindText(cbSearch.Text);
Height:= 310;
ListView1.Items.Clear;
Animate1.Active:= True;
ListView1.Visible:= True;
if (chkWholeWord.Checked) then Include(Options,stWholeWord);
if (chkMatchCase.Checked) then Include(SearchOption, mwsoMatchCase);
SearchingText(cbSearch.Text,Options);
Animate1.Active:= False;
end;
// 傈俊 八禍茄 鞏磊凱闌 霓焊 冠膠俊 眠啊茄促.
procedure TFindInFile.LoadFindStr;
var
I,Pos1:integer;
TextList: TStringList;
begin
TextList := TStringList.Create;
IniFile.ReadSectionValues('FindText',TextList);
if TextList.Count<1 then Exit;
cbSearch.Items.Clear;
for I:=TextList.Count-1 downto 1 do begin
Pos1:=Pos('=',TextList[I]);
if Pos1>0 then
cbSearch.Items.Add(Copy(TextList[I],Pos1+1,Length(TextList[I])));
end;
TextList.Free;
end;
procedure TFindInFile.FormCreate(Sender: TObject);
begin
Height:= 200;
LoadFindStr;
end;
// 鞏磊凱闌 八禍茄促.
function TFindInFile.SearchingText(SearchStr:string;Options:TSearchTypes):Boolean;
var
FindOption:TSearchTypes;
I,StartPos,LinePos,TempPos:integer;
RichEdit:TRichEdit;
NewItem: TListItem;
Text: array[0..4095] of Char;
L: Integer;
S:String;
begin
Result:= True;
with EditorForm.PageControl1 do begin
for I:=0 to PageCount-1 do begin
RichEdit:= TRichEdit(Pages[I].Controls[0]);
MatchingPos:=0;
while MatchingPos <> -1 do begin
MatchingPos:=RichEdit.FindText(SearchStr,MatchingPos,RichEdit.GetTextlen,Options);
if MatchingPos<>-1 then begin // 鞏磊凱 八禍俊 己傍茄 版快
NewItem:= ListView1.Items.Add;
NewItem.Caption:= Pages[I].Caption;
NewItem.SubItems.Add(IntToStr(MatchingPos));
// 茫籃 鞏磊凱撈 樂綽 青狼 郴儈闌 焊咯霖促.
LinePos:=SendMessage(RichEdit.Handle, EM_LINEFROMCHAR, MatchingPos,0);
L := SendMessage(RichEdit.Handle, EM_GETLINE, LinePos, Longint(@Text));
if (Text[L - 2] = #13) and (Text[L - 1] = #10) then Dec(L, 2);
SetString(S, Text, L);
NewItem.SubItems.Add(S);
Inc(MatchingPos);
end;
end;
end;
end;
end;
procedure TFindInFile.ListView1DblClick(Sender: TObject);
var
I:Integer;
RichEdit: TRichEdit;
begin
with EditorForm.PageControl1 do begin
for I:=0 to PageCount-1 do begin
if Pages[I].Caption = ListView1.Selected.Caption then begin
ActivePage:= Pages[I];
Pages[I].SetFocus;
RichEdit:= TRichEdit(Pages[I].Controls[0]);
RichEdit.SelStart:= StrToInt(ListView1.Selected.SubItems[0]);
RichEdit.SelLength:= Length(cbSearch.Text);
end;
end;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -