📄 grepresultsdlg.pas
字号:
Var
Ini: TIniFile;
Begin
// do not localize any of the below strings
Ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + GetDefaultIniName);
Try
Ini.WriteInteger(secGrepResult, 'Left', Left);
Ini.WriteInteger(secGrepResult, 'Top', Top);
Ini.WriteInteger(secGrepResult, 'Width', Width);
Ini.WriteInteger(secGrepResult, 'Height', Height);
Ini.WriteBool(secGrepResult, 'OnTop', OnTop);
SaveFont(Ini, secGrepResult, lbResults.Font);
Finally
Ini.Free;
End;
End;
Procedure TfrmGrepResults.LoadSettings;
Var
Ini: TIniFile;
Begin
// do not localize any of the below strings
Ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + GetDefaultIniName);
Try
Left := Ini.ReadInteger(secGrepResult, 'Left', Left);
Top := Ini.ReadInteger(secGrepResult, 'Top', Top);
Width := Ini.ReadInteger(secGrepResult, 'Width', Width);
Height := Ini.ReadInteger(secGrepResult, 'Height', Height);
OnTop := Ini.ReadBool(secGrepResult, 'OnTop', False);
LoadFont(Ini, secGrepResult, lbResults.Font);
Finally
Ini.Free;
End;
End;
Procedure TfrmGrepResults.FormCreate(Sender: TObject);
Begin
Inherited;
//sbGoto.Enabled := StandAlone;
tran := TvgTranslator.Create(Self);
tran.LanguageFile := CurrentLan;
OnTop := False;
Searching := False;
mnuHelp.Visible := False;
sbHelp.Visible := False;
LoadSettings;
ResizeListBox;
DragSource := TDropFileSource.Create(Nil);
End;
Procedure TfrmGrepResults.lbResultsMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Var
p: Integer;
Begin
If Button = MbLeft Then Begin
p := lbResults.ItemAtPos(Point(X, Y), True);
If p <> -1 Then
If lbResults.Items.Objects[p] Is TSearchResults Then
ExpandContract(p);
End;
End;
Procedure TfrmGrepResults.ExpandContract(n: Integer);
Var
Results: TSearchResults;
i: Integer;
Begin
If (n < 0) Or (n > lbResults.Items.Count - 1) Or Searching Then
Exit;
If lbResults.Items.Objects[n] Is TSearchResults Then Begin
Try
lbResults.Items.BeginUpdate;
Results := TSearchResults(lbResults.Items.Objects[n]);
If Results.Expanded Then Begin
While (n + 1 <= lbResults.Items.Count - 1) And
(Not (lbResults.Items.Objects[n + 1] Is TSearchResults)) Do Begin
lbResults.Items.Delete(n + 1);
End;
Results.Expanded := False;
End
Else Begin
For i := Results.Count - 1 Downto 0 Do
lbResults.Items.InsertObject(n + 1, Results.Items[i].Line, Results.Items[i]);
Results.Expanded := True;
End
Finally
lbResults.Items.EndUpdate;
End;
End;
End;
Procedure TfrmGrepResults.lbResultsKeyPress(Sender: TObject; Var Key: Char);
Begin
Case Key Of
'+',
'=',
'-': ExpandContract(lbResults.ItemIndex);
#13: sbGotoClick(sbGoto);
End;
End;
Procedure TfrmGrepResults.FormKeyPress(Sender: TObject; Var Key: Char);
Begin
If Key = #27 Then Begin
If Searching Then
SAbort := True
Else
Hide;
End;
End;
Procedure TfrmGrepResults.sbFontClick(Sender: TObject);
Begin
dlgGrepFont.Font.Assign(lbResults.Font);
If dlgGrepFont.Execute Then Begin
lbResults.Font.Assign(dlgGrepFont.Font);
ResizeListBox;
End;
End;
Procedure TfrmGrepResults.ResizeListBox;
Begin
With lbResults Do Begin
Canvas.Font.Assign(Font);
ItemHeight := Canvas.TextHeight('W') + 3; // "W" is any character
Refresh;
End;
End;
Procedure TfrmGrepResults.lbResultsDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
Var
TopColor: TColor;
BottomColor: TColor;
ResultsCanvas: TCanvas;
c: Integer;
p: Integer;
i: Integer;
st: String;
Result: TSearchResult;
sb: TColor;
sf: TColor;
nb: TColor;
nf: TColor;
Begin
ResultsCanvas := lbResults.Canvas;
TopColor := clBtnHighlight;
BottomColor := clBtnShadow;
If lbResults.Items.Objects[Index] Is TSearchResults Then Begin
ResultsCanvas.Brush.Color := clBtnFace;
ResultsCanvas.Font.Color := clBtnText;
ResultsCanvas.FillRect(Rect);
Rect.Right := Rect.Right + 2;
If OdSelected In State Then
Frame3D(ResultsCanvas, Rect, BottomColor, TopColor, 1)
Else
Frame3D(ResultsCanvas, Rect, TopColor, BottomColor, 1);
i := ResultsCanvas.TextWidth('+');
ResultsCanvas.TextOut(Rect.Left + i + 8, Rect.Top, lbResults.Items[Index]);
//c:=Rect.Top+((Rect.Bottom-Rect.Top) div 2);
If TSearchResults(lbResults.Items.Objects[Index]).Expanded Then
ResultsCanvas.TextOut(Rect.Left + 3, Rect.Top, '-')
Else
ResultsCanvas.TextOut(Rect.Left + 3, Rect.Top, '+');
st := tran.TMsg(SItemMatches) + IntToStr(TSearchResults(lbResults.Items.Objects[Index]).Count);
p := ResultsCanvas.TextWidth(SItemMatches + '00000') + 10; // do not localize
If (ResultsCanvas.TextWidth(lbResults.Items[Index]) + i + 7) <= Rect.Right - p Then
ResultsCanvas.TextOut(lbResults.ClientWidth - p, Rect.Top, st);
End
Else Begin
Result := TSearchResult(lbResults.Items.Objects[Index]);
If OdSelected In State Then Begin
nb := clHighlight;
nf := clHighlightText;
sb := clWindow;
sf := clWindowText;
End
Else Begin
sb := clHighlight;
sf := clHighlightText;
nb := clWindow;
nf := clWindowText;
End;
ResultsCanvas.Brush.Color := nb;
ResultsCanvas.Font.Color := nf;
ResultsCanvas.FillRect(Rect);
ResultsCanvas.TextOut(Rect.Left + 10, Rect.Top + 1, IntToStr(Result.LineNo));
p := 60;
st := lbResults.Items[Index];
c := MyTrim(st);
i := 1;
While i <= Length(st) Do Begin
If (i >= Result.SPos - c) And (i <= Result.EPos - c) Then Begin
ResultsCanvas.Font.Color := sf;
ResultsCanvas.Brush.Color := sb;
End
Else Begin
ResultsCanvas.Font.Color := nf;
ResultsCanvas.Brush.Color := nb;
End;
If ByteType(st, i) <> MbSingleByte Then Begin
// It's a MBCS
ResultsCanvas.TextOut(Rect.Left + p, Rect.Top + 1, Copy(st, i, 2));
p := p + ResultsCanvas.TextWidth(Copy(st, i, 2));
Inc(i);
End
Else Begin
ResultsCanvas.TextOut(Rect.Left + p, Rect.Top + 1, Copy(st, i, 1));
p := p + ResultsCanvas.TextWidth(Copy(st, i, 1));
End;
Inc(i);
End;
End;
End;
Procedure TfrmGrepResults.WMExitSizeMove(Var Message: TMessage);
Begin
lbResults.Repaint;
End;
Procedure TfrmGrepResults.sbPrintClick(Sender: TObject);
Var
RichEdit: TRichEdit;
Results: TSearchResults;
Line: String;
i, j, c: Integer;
LinePos: Integer;
Begin
If lbResults.Items.Count = 0 Then
Exit;
RichEdit := TRichEdit.Create(Self);
Try
RichEdit.Visible := False;
RichEdit.Parent := Self;
RichEdit.Font.Name := 'Arial';
RichEdit.Font.Size := 10;
RichEdit.Clear;
For i := 0 To lbResults.Items.Count - 1 Do
If lbResults.Items.Objects[i] Is TSearchResults Then Begin
RichEdit.Lines.Add(''); // space between fileresults
Results := TSearchResults(lbResults.Items.Objects[i]);
RichEdit.SelAttributes.Style := [FsBOld];
RichEdit.Lines.Add(Results.FileName);
RichEdit.SelAttributes.Style := [];
For j := 0 To Results.Count - 1 Do Begin
LinePos := RichEdit.GetTextLen;
Line := Results.Items[j].Line;
c := MyTrim(Line);
With RichEdit Do Begin
Lines.Add(Format(' %5d'#9, [Results.Items[j].LineNo]) + Line);
// Now make the found Text bold
SelStart := LinePos + 7 - c + Results.Items[j].SPos;
SelLength := Results.Items[j].EPos - Results.Items[j].SPos + 1;
SelAttributes.Style := [FsBOld];
SelLength := 0;
SelAttributes.Style := [];
End;
End;
End;
RichEdit.Print('Grep Search Results');
Finally
RichEdit.Free;
End;
End;
Procedure TfrmGrepResults.mnuRefreshClick(Sender: TObject);
Begin
Execute(True);
End;
Procedure TfrmGrepResults.mnuOnTopClick(Sender: TObject);
Begin
Inherited;
OnTop := Not OnTop;
End;
Procedure TfrmGrepResults.SetOnTop(Value: Boolean);
Begin
mnuOnTop.Checked := Value;
sbOnTopUp.Visible := Not Value;
sbOnTopDown.Visible := Value;
If Value Then
SetWindowPos(Self.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
Else
SetWindowPos(Self.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
End;
Function TfrmGrepResults.GetOnTop: Boolean;
Begin
Result := mnuOnTop.Checked;
End;
Procedure TfrmGrepResults.sbOnTopClick(Sender: TObject);
Begin
OnTop := Not OnTop;
End;
Procedure TfrmGrepResults.sbRefreshClick(Sender: TObject);
Begin
Execute(True);
End;
Procedure TfrmGrepResults.FormShow(Sender: TObject);
Begin
tran.LanguageFile := CurrentLan;
tran.Translate;
End;
Procedure TfrmGrepResults.sbReplaceClick(Sender: TObject);
Var
dlgResult: Integer;
SearchOptions: TSynSearchOptions;
Begin
If lbResults.Items.Count < 1 Then Exit;
dlgReplace := TdlgReplace.Create(Nil);
Try
dlgReplace.cbFindText.Text := GrepSettings.Pattern;
dlgReplace.cbFindText.Enabled := False;
dlgResult := dlgReplace.ShowModal;
With dlgReplace Do If (dlgResult = MrOk) Or (dlgResult = MrYesToAll) Then Begin
SearchOptions := [ssoReplace];
If cbMatchCase.Checked Then Include(SearchOptions, ssoMatchCase);
If cbWholeWord.Checked Then Include(SearchOptions, ssoWholeWord);
If rbBackward.Checked Then Include(SearchOptions, ssoBackwards);
If rbSelectedOnly.Checked Then Include(SearchOptions, ssoSelectedOnly);
If rbEntireScope.Checked Then Include(SearchOptions, ssoEntireScope);
If cbPrompt.Checked Then Include(SearchOptions, ssoPrompt);
Include(SearchOptions, ssoReplaceAll);
dlgResult := 0;
While dlgResult < lbResults.Items.Count Do
If lbResults.Items.Objects[dlgResult] Is TSearchResults Then Begin
frmJediEdit.OpenFile((lbResults.Items.Objects[dlgResult] As TSearchResults).FileName);
frmJediEdit.CurrentEditor.SearchReplace(cbFindText.Text, cbReplaceText.Text, SearchOptions);
Inc(dlgResult);
End Else Inc(dlgResult);
End;
Finally
dlgReplace.Free;
End;
End;
Procedure TfrmGrepResults.FormClose(Sender: TObject;
Var Action: TCloseAction);
Begin
frmJediEdit.pnlBottomDockSite.Height := 3;
frmJediEdit.sptBottom.Visible := False;
End;
Initialization
End.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -