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

📄 unit2.pas.svn-base

📁 支持自定义语法高亮显示的编辑器控件
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
  with SaveDialog2 do
  begin
    FilterIndex := 1;
    if Execute then
      EasyEdit9.SaveToFmtFile(FileName, TEasyRtfExporter);
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.btnHtmlClick(Sender: TObject);
begin
  with SaveDialog2 do
  begin
    FilterIndex := 2;
    if Execute then
      EasyEdit9.SaveToFmtFile(FileName, TEasyHTMLExporter);
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.btnPreviewClick(Sender: TObject);
begin
  with PrintPreview(EasyEdit9) do
    SmoothScroll := true;//am
end;

{------------------------------------------------------}

procedure TfrmContainer.btnPrintClick(Sender: TObject);
begin
  PrintWithDialog(EasyEdit9);
end;

{------------------------------------------------------}

procedure TfrmContainer.btnCollapseClick(Sender: TObject);
begin
  FCollapse := not FCollapse;
  if FCollapse then
    btnCollapse.Caption := 'Uncollapse code'
  else
    btnCollapse.Caption := 'Collapse code';
  CollapseChanged;
end;

{------------------------------------------------------}

procedure TfrmContainer.CollapseChanged;
begin
  if FCollapse then
    EasyEdit1.SourceOptions := EasyEdit1.SourceOptions + [srAllowHiddenLines]
  else
    EasyEdit1.SourceOptions := EasyEdit1.SourceOptions - [srAllowHiddenLines];
  UpdateCollapse(true);
  with EasyEdit1, CurrentPosition, TMStrings(Lines) do
  begin
    if not LineVisible[Y] then
      ExpandPrev(Y);
    Navigate(cCenterLine);
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.UpdateCollapse(ACollapse : boolean);
var
  i : integer;
begin
  with EasyEdit1.EditSource, Strings do
  begin
    BeginSourceUpdate(oprOther);
    try
      for i := 0 to Count - 1 do
      begin
         if not FCollapse then
         begin
           Collapsed[i] := false;
           Expanded[i] := false;
           Visible[i] := true;
         end;
         LineVisible[i] := true;
         PEasyStringItem(List[i])^.FHiddenLevel := 0;
      end;
      if FCollapse then
        CollapseCode(ACollapse);
    finally
      EndSourceUpdate;
    end;
  end;
end;

{-----------------------------------------------------------}

procedure TfrmContainer.CollapseCode(ACollapse : boolean);
var
  ACount : integer;
  ALine  : integer;
  FList  : TList;

  {--------------------------------}

  procedure Push(ALine : integer);
  begin
    with EasyEdit1.Lines do
      if not Collapsed[ALine] and not Expanded[ALine] then
        if ACollapse then
          Collapsed[ALine] := true
        else
          Expanded[ALine] := true;
    FList.Add(Pointer(ALine));
  end;

  {--------------------------------}

  procedure Pop(LinePos : integer);
  var
    ALine : integer;
    i     : integer;
  begin
    if FList.Count > 0 then
    begin
      ALine := Integer(FList[FList.Count - 1]);
      with EasyEdit1.Lines do
        for i := ALine + 1 to Min(LinePos, Count - 1) do
        begin
          with PEasyStringItem(List[i])^ do
          begin
            if FHiddenLevel = 0 then
              FHiddenLevel := Max(ACount, 0);
            Visible[i] := false
          end;
        end;
      FList.Delete(FList.Count - 1);
    end;
  end;

  {--------------------------------}

  function CollapseStart(const s : string) : boolean;
  begin
    result := (CompareText(s, 'begin') = 0) or (CompareText(s, 'try') = 0) or
      (CompareText(s, 'case') = 0) or (CompareText(s, 'repeat') = 0) or (CompareText(s, 'class') = 0);
  end;

  {--------------------------------}

  function CollapseEnd(const s : string) : boolean;
  begin
    result := (CompareText(s, 'end') = 0) or (CompareText(s, 'until') = 0);
  end;

  {--------------------------------}

  procedure AssignStrings(Strings : TStrings; Source : TEasyStrings);
  var
    i : integer;
  begin
    with Strings do
    begin
      BeginUpdate;
      try
        Clear;
        for i := 0 to Source.Count - 1 do
          Add(Source[i]);
      finally
        EndUpdate;
      end;
    end;  
  end;

  {--------------------------------}

begin
  if EasyEdit1.Parser = nil then
    Exit;
  FList := TList.Create;
  try
    with TMParser(EasyEdit1.Parser) do
    begin
      {$IFNDEF EASY_UNICODE}
      Strings := EasyEdit1.Lines;
      {$ELSE}
      Strings := TStringList.Create;
      AssignStrings(Strings, EasyEdit1.Lines);
      {$ENDIF}
      try
        Reset;
        ACount := 0;
        while not EndOfSource do
          if NextToken = tresword  then
            if CollapseStart(TokenString) then
            begin
              Inc(ACount);
              if (LineIndex > 0) and (Trim(Copy(Strings[LineIndex], 1, TokenPos - 1)) = '') then
                ALine := LineIndex - 1
              else
                ALine := LineIndex;
              Push(ALine);
            end
            else
            if CollapseEnd(TokenString) then
            begin
              Dec(ACount);
              Pop(LineIndex);
            end;
      finally
      {$IFDEF EASY_UNICODE}
      Strings.Free;
      Strings := nil;
      {$ENDIF}
      end;
    end;
  finally
    FList.Free;
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.EasyEdit1SourceChanged(Sender: TObject;
  State: TEasyEditSourceStates);
begin
  if (csEdit in State) and not (csVisibleChanged in State) and FCollapse and not FDisableFlag
  and not (csDestroying in ComponentState) then
    Timer1.Enabled := true;
end;

{------------------------------------------------------}

procedure TfrmContainer.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := false;
  if FCollapse then
  begin
    FDisableFlag := true;
    try
      UpdateCollapse(false);
    finally
      FDisableFlag := false;
    end;
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.sbPaintFormattingMarksClick(Sender: TObject);
begin
  with EasyEdit1 do
  begin
    if eoPaintFormattingMarks in Options then
      Options := Options - [eoPaintFormattingMarks]
    else
      Options := Options + [eoPaintFormattingMarks];
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.cbRulerUnitsChange(Sender: TObject);
begin
  case cbRulerUnits.ItemIndex of
    0: EasyEdit1.Ruler.Units := erCharacters;
    1: EasyEdit1.Ruler.Units := erInches;
    2: EasyEdit1.Ruler.Units := erMilimeters;
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.cbBlockSelModeChange(Sender: TObject);
begin
  EasyEdit4.BlockSelMode := TEasyBlockSelMode(cbBlockSelMode.ItemIndex);
end;

{------------------------------------------------------}

procedure TfrmContainer.cbLineBreakChange(Sender: TObject);
begin
  EasyEdit5.LineBreak := TEasyLineBreak(cbLineBreak.ItemIndex);
end;

{------------------------------------------------------}

procedure TfrmContainer.cbBlockSelectionClick(Sender: TObject);
begin
  with EasyEdit4 do
  begin
    if cbBlockSelection.Checked then
      Options := Options + [eoReduceBlockSel]
    else
      Options := Options - [eoReduceBlockSel];
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.chbHighlightBracketsClick(Sender: TObject);
begin
  with EasyEdit2 do
  begin
    if chbHighlightBrackets.Checked then
      Options := Options + [eoHighlightBrackets]
    else
      Options := Options - [eoHighlightBrackets];
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.EasyEdit3KeyPress(Sender: TObject; var Key: Char);
var
  Sl : TStrings;
begin
  if (Key = ' ') and ((GetAsyncKeyState(VK_CONTROL) and $80000000) <> 0) then
  begin
    Key := #0;
    Sl := TStringList.Create;
    try
      FillCodeCompletion(EasyEdit3, Sl);
      EasyEdit3.ShowPopupListBox(Sl, true);
    finally
      Sl.Free;
    end;
  end;
end;

{------------------------------------------------------}

procedure TfrmContainer.btnPrintSettingsClick(Sender: TObject);
begin
  EditPrintSettings(EasyEdit9);
end;

{------------------------------------------------------}
//am
procedure TfrmContainer.chbDrawLineBookmarksClick(Sender: TObject);
begin
  EasyEdit1.DrawLineBookmarks := chbDrawLineBookmarks.Checked;
end;

{------------------------------------------------------}

procedure TfrmContainer.EasyEdit2SelectionChanged(Sender: TObject);
var
  i : integer;
begin
  FLoading := true;
  i := EasyEdit2.CurrentPosition.y;
  if (i >= 0) and (i < EasyEdit2.Lines.Count) then
    chbLineReadOnly.Checked := EasyEdit2.Lines.LineReadOnly[i]
  else
    chbLineReadOnly.Checked := false;
  FLoading := false;
end;

{------------------------------------------------------}

procedure TfrmContainer.chbLineReadOnlyClick(Sender: TObject);
var
  i : integer;
begin
  if FLoading then
    exit;
  i := EasyEdit2.CurrentPosition.y;
  if (i >= 0) and (i < EasyEdit2.Lines.Count) then
    EasyEdit2.Lines.LineReadOnly[i] := not EasyEdit2.Lines.LineReadOnly[i];
end;

{------------------------------------------------------}

procedure TfrmContainer.chbTripleClickLineClick(Sender: TObject);
begin
  with EasyEdit2 do
    if chbTripleClickLine.Checked then
      Options := Options + [eoTripleClickLine]
    else
      Options := Options - [eoTripleClickLine];
end;

{------------------------------------------------------}

procedure TfrmContainer.sbtUndoClick(Sender: TObject);
begin
  EasyEdit5.Undo;
end;

{------------------------------------------------------}

procedure TfrmContainer.sbtRedoClick(Sender: TObject);
begin
  EasyEdit5.Redo;
end;

{------------------------------------------------------}

procedure TfrmContainer.chbUndoAfterSaveClick(Sender: TObject);
begin
  with EasyEdit5 do
    if chbUndoAfterSave.Checked then
      SourceOptions := SourceOptions + [srUndoAfterSave]
    else
      SourceOptions := SourceOptions - [srUndoAfterSave];
end;

{------------------------------------------------------}

procedure TfrmContainer.UpdateModified;
begin
  sbtUndo.Enabled := EasyEdit5.CanUndo;
  sbtRedo.Enabled := EasyEdit5.CanRedo;
  if EasyEdit5.Modified then
    laModified.Caption := 'Modified: true'
  else
    laModified.Caption := 'Modified: false';
end;

{------------------------------------------------------}

procedure TfrmContainer.EasyEdit5SelectionChanged(Sender: TObject);
begin
  UpdateModified;
end;

{------------------------------------------------------}

procedure TfrmContainer.chbLeaveTabsClick(Sender: TObject);
begin
  with EasyEdit2 do
    if chbLeaveTabs.Checked then
      SourceOptions := SourceOptions + [srLeaveTabs]
    else
      SourceOptions := SourceOptions - [srLeaveTabs];
end;

{------------------------------------------------------}
//endam
end.

⌨️ 快捷键说明

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