⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgfileproperties.pas

📁 Delphi编写的一个支持语法高亮显示和很多语言的文本编辑器
💻 PAS
字号:

unit dlgFileProperties;


interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, uOptVars, fDoc, dMain, CorelButton, ComCtrls, ExtCtrls, ImgList, Spin, uTypes;

type
  TFilePropertiesDialog = class(TForm)
    pgFileProperties: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    btnCancel: TCorelButton;
    btnOK: TCorelButton;
    imgIcon: TImage;
    txtFileTitle: TEdit;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Panel2: TPanel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    chkReadOnly: TCheckBox;
    chkModfified: TCheckBox;
    Panel3: TPanel;
    txtMSDOSName: TEdit;
    txtCreated: TEdit;
    txtLastModified: TEdit;
    txtLastAccess: TEdit;
    txtSize: TEdit;
    txtLocation: TEdit;
    txtFileName: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    Panel4: TPanel;
    Label11: TLabel;
    Label12: TLabel;
    cboConnection: TComboBox;
    Label13: TLabel;
    txtDownTime: TEdit;
    txtCharCount: TEdit;
    txtLineCount: TEdit;
    Label14: TLabel;
    Panel5: TPanel;
    Label15: TLabel;
    cboLinebreak: TComboBox;
    cboLanguage: TComboBox;
    Label16: TLabel;
    spnTabWidth: TSpinEdit;
    Label17: TLabel;
    Label19: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure cboConnectionClick(Sender: TObject);
    procedure cboLinebreakClick(Sender: TObject);
  private
    { Private declarations }
    procedure SetEditor(AEditor: TfrmDoc);
    function FileDateToStr(FileDate: TFileTime): string;
  public
    { Public declarations }
    fEditor: TfrmDoc;
    property Editor: TfrmDoc write SetEditor;
  end;

var
  FilePropertiesDialog: TFilePropertiesDialog;

implementation

{$R *.DFM}

uses
  ShellApi, Registry,
  SynEditHighlighter, uHighlighterProcs;

function GetEditorState: string;
resourcestring
  SSearch = 'Search %s: "%s"';
begin
  if dmMain.selDoc <> nil then begin
   if dmMain.selDoc.SciMain.ReadOnly then
      Result := 'ReadOnly'
   else if dmMain.selDoc.SciMain.InsertMode then
      Result := 'Insert'
   else
      Result := 'Overwrite';
  end else
   Result := '';
end;

function FormatByteText(I: Integer): string;
var
  R: Real;
begin
  Result := 'n.a.';
  try
    R := I / 1024;
    if I = 0 then
      Result := '0 Byte'
    else if I < 1048576 then
      Result := FloatToStrF(R, ffNumber, 18, 1) + ' KB'
    else if I < 1073741824 then begin
      R := R / 1024;
      I := Round(R);
      if I < 10 then
        Result := FloatToStrF(R, ffNumber, 18, 1) + ' MB'
      else
        Result := IntToStr(I) + ' MB';
    end
    else begin
      I := Round(R / 1024 / 1024);
      Result := IntToStr(I) + ' GB';
    end;
    if (Result[Length(Result) - 3] = '0') and (Result[Length(Result) - 4] = ',')
      then
      Delete(Result, Length(Result) - 4, 2);
  except
  end;
end;

procedure TFilePropertiesDialog.SetEditor(AEditor: TfrmDoc);
var
  SearchRec: TSearchRec;
resourcestring
  SPropCaption = 'Properties from %s';
  SNotSaved = 'File not locally saved';
begin
  Screen.Cursor := crHourGlass;
  try
    fEditor := AEditor;
    txtFileTitle.Text := fEditor.FileName;
    Caption := Format(SPropCaption, [AEditor.Filename]);
    dmMain.imlShellLarge.GetIcon(GetIconIndexFromFile(aEditor.FileName, False),
      imgIcon.Picture.Icon);
    if FileExists(AEditor.FileName) then begin
      txtFileName.Text := AEditor.FileName;
      txtLocation.Text := ExtractFileDir(AEditor.FileName);

      txtMSDOSName.Text := ExtractShortPathName(AEditor.FileName);
      if FindFirst(AEditor.FileName, faAnyFile, SearchRec) = 0 then begin
        txtSize.Text := FormatByteText(SearchRec.Size) +
          ' (' + IntToStr(SearchRec.Size) + ' Byte)';
        txtCreated.Text := FileDateToStr(SearchRec.FindData.ftCreationTime);
        txtLastModified.Text := FileDateToStr(SearchRec.FindData.ftLastWriteTime);
        txtLastAccess.Text := FileDateToStr(SearchRec.FindData.ftLastAccessTime);

        FindClose(SearchRec);
      end;
      cboLinebreak.ItemIndex := Integer(AEditor.fLineBreak) - 1;
    end else begin
      if AEditor.FileName <> '' then
        txtFileName.Text := AEditor.FileName
      else
        txtFileName.Text := SNotSaved;
      txtLocation.Text := SNotSaved;
      txtMSDOSName.Text := SNotSaved;
      txtSize.Text := FormatByteText(Length(AEditor.sciMain.Text)) +
        ' (' + IntToStr(Length(AEditor.sciMain.Text)) + ' Byte)';
      txtCreated.Text := SNotSaved;
      txtLastModified.Text := SNotSaved;
      txtLastAccess.Text := SNotSaved;
      cboLinebreak.ItemIndex := Ord(lbWindows) - 1;
    end;
    txtLineCount.Text := IntToStr(AEditor.sciMain.Lines.Count);
    txtCharCount.Text := IntToStr(Length(AEditor.sciMain.Text));

    if AEditor.sciMain.Highlighter = nil then
      cboLanguage.ItemIndex := 0
    else
      cboLanguage.ItemIndex := cboLanguage.Items.IndexOf(GetLangName(AEditor.sciMain.Highlighter));
    spnTabWidth.Value := AEditor.sciMain.TabWidth;
    chkReadOnly.Checked := (AEditor.sciMain.ReadOnly);
    chkModfified.Checked := AEditor.sciMain.Modified;
    if fEditor.isFtp then begin
      label19.Font.Color := clRed;
      label19.caption := 'Document is an FTP file!';
    end
    else begin
      label19.Font.Color := clBlue;
      label19.caption := 'Document is not an FTP file!';
    end;
    cboConnectionClick(Self);
  finally
    Screen.Cursor := crDefault;
  end;
end;

function TFilePropertiesDialog.FileDateToStr(FileDate: TFileTime): string;
var
  ft: TSystemTime;
begin
  FileTimeToSystemTime(FileDate, ft);
  //Sonntag, 15. Juli 2001 15:29:57
  DateTimeToString(Result, 'dddd, dd. mmmm, yyyy hh:nn:ss',
    EncodeDate(ft.wYear, ft.wMonth, ft.wDay) +
    EncodeTime(ft.wHour, ft.wMinute, ft.wSecond, ft.wMilliseconds));
end;

procedure TFilePropertiesDialog.FormCreate(Sender: TObject);
var
  i: integer;
begin
  with dmMain do begin
    for i := 0 to ComponentCount - 1 do
      if Components[i] is TSynCustomHighlighter then
        cboLanguage.Items.AddObject(GetLangName(Components[i] as TSynCustomHighlighter),
        TObject((Components[i] as TSynCustomHighlighter)));
  end;
end;

procedure TFilePropertiesDialog.cboConnectionClick(Sender: TObject);
resourcestring
  SSecond = '%d Second(s)';
var
  iSpeed, iTime: integer;
begin
  iSpeed := StrToInt(cboConnection.Text) div 8;
  iTime := Length(fEditor.sciMain.Text) div iSpeed;
  txtDownTime.Text := Format(SSecond, [iTime]);
end;

procedure TFilePropertiesDialog.cboLinebreakClick(Sender: TObject);
begin
//  if TLineBreak(cboLinebreak.ItemIndex + 1) <> fEditor.GetLinebr then
//    chkModfified.Checked := true;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -