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

📄 fmain.pas

📁 Delphi编写的一个支持语法高亮显示和很多语言的文本编辑器
💻 PAS
📖 第 1 页 / 共 5 页
字号:
begin
 with Canvas do
 begin

   Pen.Color := clWhite;

   H := CreateRectRgn(R.Left, R.Top, R.Right, R.Bottom);
   SelectClipRgn(Handle, H);
   RoundRect(R.Left, R.Top, R.Right, R.Bottom + 50, D, D);
   SelectClipRgn(Handle, 0);
   DeleteObject(H);

   Pen.Color := clGray;
   OffsetRect(R, 1, 1);

   H := CreateRectRgn(R.Right -D div 2, R.Top, R.Right, R.Bottom);
   SelectClipRgn(Handle, H);
   RoundRect(R.Left, R.Top, R.Right, R.Bottom + 50, D, D);
   SelectClipRgn(Handle, 0);
   DeleteObject(H);

   InflateRect(R, -2, -2);
   TextRect(R, R.Left + 2, R.Top + 1, S);
 end;
end;


function TfrmMain.NewFTP(FileName: String; FTPName: String; FTPDir: String): TfrmDoc;
var
  fNewDoc: TfrmDoc;
  FileExt: String;
  s: String;
  i: integer;
begin
  fNewDoc := TfrmDoc.Create(self);
  if FileExists(FileName) then begin
    FileExt := ExtractFileExt(Filename);
    fNewDoc.cmbLang.items.Assign(dmMain.fHighlighters);
    fNewDoc.sciMain.Highlighter := dmMain.GetHighlighterForFile(FileName);
    s := FileToString(Filename);
//    fNewDoc.SciMain.Lines.LoadFromFile(FileName);
    fNewDoc.fLineBreak := GetLinebreak(s);
    if fNewDoc.fLineBreak <> lbWindows then
      fNewDoc.sciMain.Lines.Text := AdjustLinebreaks(s)
    else
      fNewDoc.sciMain.Lines.Text := s;
//    fNewDoc.SciMain.Lines.LoadFromFile(FileName);
    fNewDoc.Caption := FTPName + '\' + ExtractFileName(Filename);
    fNewDoc.FileName := Filename;
    fNewDoc.DoUpdateCaption;
    fNewDoc.FTPFileName := ExtractFileName(Filename);
  end
  else begin
    fNewDoc.Caption := FTPName + '\' + ExtractFileName(Filename);
    fNewDoc.FileName := '';
//    fNewDoc.synMain.Highlighter := dmMain.synHTML;
  end;
  //if (ActiveMDIChild = nil) or (ActiveMDIChild.WindowState = wsMaximized) then
    //fNewDoc.WindowState := wsMaximized;
  fNewDoc.isFTP := True;
  fNewDoc.FTPName := FTPName;
  fNewDoc.FTPDir := FTPDir;
  tcFiles.Tabs.InsertObject(frmMain.MDIChildCount-1, ExtractFileName(FileName), fNewDoc);
  fNewDoc.FormActivate(nil);
  if fNewdoc.sciMain.Highlighter = nil then
    fnewdoc.cmbLang.ItemIndex := 0
  else
    if fNewDoc.sciMain.Highlighter is TSynMultiSyn then
      fNewDoc.cmbLang.ItemIndex := fNewDoc.cmbLang.Items.IndexOf((fNewDoc.sciMain.Highlighter as TSynMultiSyn).DefaultLanguageName)
    else
      fNewDoc.cmbLang.ItemIndex := fNewDoc.cmbLang.Items.IndexOf(GetLangName(fNewDoc.sciMain.Highlighter));
    Windows.SetFocus(fNewDoc.sciMain.handle);
  
  result := fNewDoc;
//  DeleteFile(Filename);
end;
procedure CustomDrawPageControl(PC: TPageControl);
var
 I,f,s,b,
 Y: Integer;
 R: TRect;
begin
 with PC, Canvas do
 begin
   DoubleBuffered := True;
   Canvas.Font := PC.Font;
   Canvas.Brush.Color := TForm(PC).Color;

   // clear control
   R := ClientRect;
   FillRect(R);

   // draw frame around control
   R := THackPageControl(PC).DisplayRect;
   InflateRect(R, 4, 4);
   Frame3D(Canvas, R, clWhite, clGray, 1);
   Y := R.Top;
   // draw inactive tabs
   Font.Color := clGray;
   b:=0;
   s:=0;
   for I := 0 to PageCount - 1  do
    // if (Pages[activepageindex].TabVisible = true) then begin
       if I <> ActivePageIndex then
       begin
         b := 0;
         for s := 0 to i do begin
           if pages[s].TabVisible = false then
             inc(b);
         end;
         s := i-b; //b+i-1;
         if s < 0 then s := 0;
         if s > PageCount - 1 then s := PageCount - 1;
         R := TabRect(s);
         R.Left := R.Left - 2;
         if Pages[i].TabVisible = false then begin
           f := i - 1;
           if f < 0 then f := 0;
           DrawEclTab(Canvas, R, Pages[f].Caption);
         end
         else
           DrawEclTab(Canvas, R, Pages[i].Caption);         
       // draw bottom line
         Pen.Color := clWhite;
         MoveTo(R.Left, Y - 1);
         LineTo(R.Right + 1, Y - 1);
       end;
    // end;
   // draw active tab
   if (ActivePageIndex >= 0) then
   begin
     b := 0;
     for s := 0 to ActivePageIndex do begin
       if Pages[s].TabVisible = false then
         inc(b);
     end;
     b := activepageindex-b;//+b;// - b;
     if b < 0 then b := 0;
     if b > PageCount -1 then b := pagecount - 1;
//     if b =0 then messageBox(0, 'test', 'test', 0);
     Font.Color := clBlack;
     R := TabRect(b);
     R.Top := R.Top - 2;
     R.Left := R.Left - 2;
     R.Bottom := R.Bottom + 1;
     DrawEclTab(Canvas, R, Pages[ActivePageIndex].Caption);
   end;
 end;
end;


procedure TfrmMain.FormCreate(Sender: TObject);
var
  i: integer;
  m_sIniFileName: String;
begin
  Application.OnHelp := HH;
   {It's an example of Native package.
   {Note: Native packages can't be removed}
   {Note1: Don't add items at runtime to ActionList1 or ImageList1 after created
   MenuService}
   {native package}
//   frmInstallPackage.AddPackage(nil);

  //mru.GetAllMenuItems;
  pManager.PluginFolder := ExtractFilePath(Application.ExeName) + 'plugins\';

  pManager.LoadPlugins;
  dmMain := tDMMain.Create(self);
  tbrMain.FloatingDockSiteClass := TgbToolDockForm;
  tbStandard.FloatingDockSiteClass := TgbToolDockForm;
  tbMacros.FloatingDockSiteClass := TgbToolDockForm;
  tbSearch.FloatingDockSiteClass := TgbToolDockForm;
  tbrProg.FloatingDockSiteClass := TgbToolDockForm;
  tbWeb.FloatingDockSiteClass := TgbToolDockForm;
  tbtools.FloatingDockSiteClass := TgbToolDockForm;
  Loading := True;
  Application.OnIdle := AppIdle;
  DockHandler.TabType := ttIcon;
  DockHandler.ShowGrabberBars := True;
  ReadSettings;
  dmMain := TdmMain.Create(self);
  OpenToolbar;
  LoadSettings;
  LoadOptions;
  if pgTop.PageCount > 0 then pgTop.ActivePage := pgTop.Pages[0];
  DockHandler.OnRefresh := DoRefresh;
  triggerProc := ActivationFromOtherInstance;
  m_sIniFileName := ExtractFilePath(Application.ExeName) + 'cEdit.ini';

  ctrlTab.Visible := bMDITabs;
  stbMain.Visible := bStatusBar;
  dmMain.imgMain.BkColor := tbrMain.Color;
  dmMain.imgMain.BlendColor := tbrMain.Color;
  OW := pgTop.WindowProc;
  pgTop.WindowProc := NW;
  tbTools.Images := dmMain.imlShellIcon;
  //CheckPlugins;
end;
procedure TfrmMain.OpenToolbar;
var
  ini: TiniFile;
  x, y: Integer;

  pStore: String;
begin
  ini := TiniFile.Create(extractFilePath(Application.ExeName) + 'data\toolbars.dat');
  ReadToolbarState(ini, tbrMain, 'MainToolbar', [cntrlTop], false);
  ReadToolbarState(ini, tbrProg, 'ProgToolbar', [cntrlTop], false);
  ReadToolbarState(ini, tbStandard, 'StandardToolbar', [cntrlTop], false);
  ReadToolbarState(ini, tbSearch, 'SearchToolbar', [cntrlTop], false);
  ReadToolbarState(ini, tbWeb, 'WebToolbar', [cntrlTop], false);
  ReadToolbarState(ini, tbMacros, 'MacrosToolbar', [cntrlTop], false);
  ReadToolbarState(ini, tbTools, 'ToolToolbar', [cntrlTop], false);
  ReadToolbarState(ini, pnlPage, 'PagePanel', [cntrlTop], false);
{  pStore := ini.ReadString('MainToolbar', 'ToolbarOwner', 'none');
  x := ini.ReadInteger('MainToolbar', 'ToolbarX', 0);
  y:= ini.ReadInteger('MainToolbar', 'ToolbarY', 0);

  if pStore <> 'none' then begin
    if pStore = 'cntrlTop' then
      tbrMain.ManualDock(cntrlTop);
      tbrMain.Left := x;
      tbrMain.Top := y;
  end;}
end;
function NewColor(ACanvas: TCanvas; clr: TColor; Value: integer): TColor;
var
  r, g, b: integer;

begin
  if Value > 100 then Value := 100;
  clr := ColorToRGB(clr);
  r := Clr and $000000FF;
  g := (Clr and $0000FF00) shr 8;
  b := (Clr and $00FF0000) shr 16;


  r := r + Round((255 - r) * (value / 100));
  g := g + Round((255 - g) * (value / 100));
  b := b + Round((255 - b) * (value / 100));

  //Result := Windows.GetNearestColor(ACanvas.Handle, RGB(r, g, b));
  Result := RGB(r, g, b);

end;

procedure TfrmMain.SaveToolbar;
var
  ini: TiniFile;
begin
  ini := TiniFile.Create(extractFilePath(Application.ExeName) + 'data\toolbars.dat');
  WriteToolbarState(ini, tbrMain, 'MainToolbar');
  WriteToolbarState(ini, tbrProg, 'ProgToolbar');
  WriteToolbarState(ini, tbtools, 'ToolToolbar');
  WriteToolbarState(ini, tbweb, 'WebToolbar');
  WriteToolbarState(ini, tbstandard, 'StandardToolbar');
  WriteToolbarState(ini, tbsearch, 'SearchToolbar');
  WriteToolbarState(ini, tbMacros, 'MacrosToolbar');
  WriteToolbarState(ini, pnlPage, 'PagePanel');
  {if (tbrMain.Floating = False) then
    ini.WriteString('MainToolbar', 'ToolbarOwner', tbrMain.Owner.Name)
  else
    ini.WriteString('MainToolbar', 'ToolbarOwner', 'none');
  ini.WriteInteger('MainToolbar', 'ToolbarX', tbrMain.Left);
  ini.WriteInteger('MainToolbar', 'ToolbarY', tbrMain.top);
  ini.free;}
end;

procedure TfrmMain.CheckMenuBar;
begin
{  if MenuBar.Floating then begin
    MDIBorderIcons.Parent := IconPnl;
    IconPnl.Left := tbHelp.Width+tbHelp.Left;
    IconPnl.Visible := MDIBorderIcons.Visible;
  end else begin
    MDIBorderIcons.Parent := Self;
    IconPnl.Visible := False;
  end;
  MenuBar.Width := MenuBar.Width+1;}
end;

procedure TfrmMain.AppIdle(Sender: TObject; var Done: Boolean);

var
  i: integer;
  sParam: String;
begin
  //Application.OnIdle := nil;
  if Done = False then exit;
  if Loading = True then begin
    if ParamCount > 0 then begin
      for i := 1 to ParamCount do begin
        sParam := ParamStr(i);
        if FileExists(sParam) then begin
          dmMain.NewDoc(sParam);
        end;
      end;
    end else begin
      dmMain.ActFileNewExecute(nil);
    end;
//    WindowList1.Items[0].Visible := False;
    Loading := false;
    // We load in the plugins here to make sure it's all properly loaded
    // so no errors due to the form not existing :)
//    mxPlugin.LoadFromFolder(ExtractFilePath(Application.ExeName) + 'plugins\', False);

//    FormFocus(Sender);
  end;
end;

procedure TfrmMain.PopNewClick(Sender: TObject);
begin
  dmMain.NewDoc('Untitled' + INtToStr(frmMain.MDIChildCount), dmMain.SetHighlighter(AnsiReplaceText((Sender as TMenuItem).Caption, '&', '')) );
end;

procedure TfrmMain.LoadTools;
var
  Reg: TMyReg;
  tbButton: TToolButton;
  ToolCount,i,x,b: Integer;
  tmButton: TMEnuItem;
  strExec: String;
begin
  Reg := TMyReg.Create;

  with Reg do begin
  OpenKey('software\cedit\tools', true);
  ToolCount := ReadReg('Count', 0);
  For i:=tbTools.ButtonCount - 1 downto 0 do
    tbTools.Buttons[i].Destroy;
  for i:=Tools1.Count-1 downto 2 do
    Tools1.Items[i].Destroy;
    if ToolCount > 0 then begin
      for i := 1 to ToolCount do begin
        tbButton := TToolButton.Create(tbTools);
        tmButton := TMenuItem.Create(Tools1);
        strExec := ReadReg('ECmd_' + IntToStr(ToolCount+1-i), '');
        strExec := AnsiReplaceStr(StrExec, SVarWinDirShort, WindowsDirectory);
        strExec := AnsiReplaceStr(StrExec, SVarSysDirShort, SystemDirectory);
        strExec := AnsiReplaceStr(strExec, SVarTempDirShort, TempDir);
        with tbButton do begin
          Caption := ReadReg('Name_' + IntToStr(ToolCount+1-i), '');
          Hint := ReadReg('Name_' + IntToStr(ToolCount+1-i), '');
          Tag := ToolCount+1-i;
          OnClick := Tools1Click;
          x := GetIconIndexFromFile(StrExec, True);
          if x > dmMain.imlShellIcon.Count - 1 then x := 4;
          ImageIndex := x;
          Parent := tbTools;
        end;
        with tmButton do begin
          Caption := ReadReg('Name_' + IntToStr(i), '');
          Hint := ReadReg('Name_' + IntToStr(i), '');
          Tag := i;
          OnClick := Tools1Click;
          //x := GetIconIndexFromFile(ReadReg('ECmd_' + IntToStr(i), ''), True);
          ImageIndex := GetNormalIcon(StrExec);
        end;
        Tools1.Add(tmButton);

{          tbTools.Buttons[i].InsertComponent(tbButton);
          tbTools.InsertControl(tbButton);}
      end;

    end;
  end;

  if tools1.count > 2 then
        for i := 2 to (((tools1.Count-3) div 2)+2) do begin
          x := tools1.items[i].ImageIndex;
          b := tools1.items[tools1.count-1-(i-2)].ImageIndex;
          tools1.items[i].ImageIndex := b;
          tools1.items[tools1.count-1-(i-2)].ImageIndex := x;
        end;
        xp.ActivateMenuItem(tools1, true);
  reg.Destroy
end;

procedure TfrmMain.LoadOptions;
var
  Reg: TMyReg;
  Styled: TFontStyles;
  AutoCorrOp: TAsSynAutoCorrectOptions;
begin
  { Editor - General Options }
  Reg := TMyReg.Create;
  Reg.OpenKey('software\cedit\settings', False);
  { Editor - General Options }
  bAutoIndent := Reg.ReadReg('bAutoIndent', True);
  bMaximize := reg.ReadReg('bMaximize', True);
  bDragDropEditing := reg.ReadReg('bDragDropEditing', True);
  bDragDropFiles := reg.ReadReg('bDragDropFiles', False);
  bAltSetsColumnMode := reg.ReadReg('bAltSetscolumnMode', False);
  bMaintainCaretColumn := reg.ReadReg('bMaintainCaretColumn', False);
  bWantTabs := reg.ReadReg('bWantTabs', True);
  bMDITabs := reg.ReadReg('bMDITabs', True);
  bStatusBar := reg.ReadReg('bStatusBar', True);
  bSmartTabs := reg.ReadReg('bSmartTabs', True);
  bSmartTabDelete := reg.ReadReg('bSmartTabDelete', True);
  bRightMouseMovesCursor := reg.ReadReg('bRightMouseMovesCursor', False);
  bEnhanceHomeKey := reg.ReadReg('bEnhanceHomeKey', False);

⌨️ 快捷键说明

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