easyeditorbookmarkactions.pas.svn-base

来自「支持自定义语法高亮显示的编辑器控件」· SVN-BASE 代码 · 共 223 行

SVN-BASE
223
字号
unit EasyEditorBookmarkActions;

interface

uses
  ActnList, StdActns, EasyEditor, Classes, EasyStrings, EasyEditorActions;

type
  TEasyEditorBaseBookmarkAction = class(TEasyEditBaseAction)
  private
    fBaseCaption: string;
    fLineColumnFormat: string;
    fBookmarkNr: Integer;
  protected
    procedure AssignTo(Dest: TPersistent); override;
    procedure SetBookmarkNr(Value: Integer);
    procedure SetBaseCaption(Value: string);
  public
    constructor Create(AOwner: TComponent); override;
    procedure UpdateTarget(Target: TObject); override;
    //  published
    property BookmarkNr: Integer read fBookmarkNr write SetBookmarkNr;
    property BaseCaption: string read fBaseCaption write SetBaseCaption;
    property LineColumnFormat: string read fLineColumnFormat write
      fLineColumnFormat;
  end;

  TEasyEditBookmarkClearAllAction = class(TEasyEditorBaseBookmarkAction)
  public
    procedure UpdateTarget(Target: TObject); override;
    procedure ExecuteTarget(Target: TObject); override;
  end;

  TEasyEditBookmarkSetAction = class(TEasyEditorBaseBookmarkAction)
  public
    constructor Create(AOwner: TComponent); override;
    procedure ExecuteTarget(Target: TObject); override;
  published
    property BookmarkNr;
    property BaseCaption;
    property LineColumnFormat;
  end;

  TEasyEditBookmarkGotoAction = class(TEasyEditorBaseBookmarkAction)
  public
    constructor Create(AOwner: TComponent); override;
    procedure ExecuteTarget(Target: TObject); override;
  published
    property BookmarkNr;
    property BaseCaption;
    property LineColumnFormat;
  end;

  TEasyEditBookmarkToggleAction = class(TEasyEditorBaseBookmarkAction)
  public
    constructor Create(AOwner: TComponent); override;
    procedure ExecuteTarget(Target: TObject); override;
  published
    property BookmarkNr;
    property BaseCaption;
    property LineColumnFormat;
  end;

  TEasyEditBookmarkClearAction = class(TEasyEditorBaseBookmarkAction)
  public
    constructor Create(AOwner: TComponent); override;
    procedure ExecuteTarget(Target: TObject); override;
  published
    property BookmarkNr;
    property BaseCaption;
    property LineColumnFormat;
  end;

implementation

uses Windows, SysUtils;



{ TEasyEditorBaseBookmarkAction }

constructor TEasyEditorBaseBookmarkAction.Create(AOwner: TComponent);
begin
  inherited;
  BaseCaption := 'Bookmark &%d';
  BookmarkNr := 1;
  LineColumnFormat := '(L:%d/C:%d)';
end;

procedure TEasyEditorBaseBookmarkAction.SetBookmarkNr(Value: Integer);
begin
  if Value <> fBookmarkNr then
  begin
    if (Caption = Format(BaseCaption, [fBookmarkNr])) or (Caption = '') then
      Caption := Format(BaseCaption, [Value]);
    fBookmarkNr := Value;
  end;
end;

procedure TEasyEditorBaseBookmarkAction.SetBaseCaption(Value: string);
begin
  if Value <> fBaseCaption then
  begin
    if (Caption = Format(fBaseCaption, [fBookmarkNr])) or (Caption = '') then
      Caption := Format(Value, [fBookmarkNr]);
    fBaseCaption := Value;
  end;
end;

procedure TEasyEditorBaseBookmarkAction.AssignTo(Dest: TPersistent);
begin
  if Dest is TEasyEditorBaseBookmarkAction then
    with TEasyEditorBaseBookmarkAction(Dest) do
    begin
      BaseCaption := Self.BaseCaption;
      BookmarkNr := Self.BookmarkNr;
    end;
  inherited AssignTo(Dest);
end;

procedure TEasyEditorBaseBookmarkAction.UpdateTarget(Target: TObject);
var
  b: Boolean;
  p: TPoint;
  s : String;
begin
  if not (Target is TCustomEasyEdit) then
  begin
    Enabled := False;
    Exit;
  end;
  b := CustomEasyEdit.EditSource.FindBookMark(BookmarkNr, p);
  if (Self is TEasyEditBookmarkGotoAction) or (Self is TEasyEditBookmarkClearAction) then
    Enabled := b
  else
    Enabled := true;
  if not (csDesigning in ComponentState) then
    if LineColumnFormat <> '' then
    BEGIN
      if b then
        s := Format(BaseCaption, [fBookmarkNr]) + ' ' +
          Format(LineColumnFormat, [p.Y + 1, p.X + 1])
      else
        s := Format(BaseCaption, [fBookmarkNr]);
      IF s <> Caption THEN
        Caption := s;
    END;
end;


{ TEasyEditBookmarkGotoAction }

constructor TEasyEditBookmarkGotoAction.Create(AOwner: TComponent);
begin
  inherited;
  BaseCaption := 'Goto Bookmark &%d';
end;

procedure TEasyEditBookmarkGotoAction.ExecuteTarget(Target: TObject);
begin
  CustomEasyEdit.EditSource.GotoBookmark(BookmarkNr)
end;

{ TEasyEditBookmarkSetAction }

constructor TEasyEditBookmarkSetAction.Create(AOwner: TComponent);
begin
  inherited;
  BaseCaption := 'Set Bookmark &%d';
end;

procedure TEasyEditBookmarkSetAction.ExecuteTarget(Target: TObject);
begin
  CustomEasyEdit.EditSource.SetBookmark(BookmarkNr, CustomEasyEdit.EditSource.CurrentPosition)
end;

{ TEasyEditBookmarkToggleAction }

constructor TEasyEditBookmarkToggleAction.Create(AOwner: TComponent);
begin
  inherited;
  BaseCaption := 'Toggle Bookmark &%d';
end;

procedure TEasyEditBookmarkToggleAction.ExecuteTarget(Target: TObject);
begin
  CustomEasyEdit.EditSource.ToggleBookmark(BookmarkNr, CustomEasyEdit.EditSource.CurrentPosition)
end;

{ TEasyEditBookmarkClearAction }

constructor TEasyEditBookmarkClearAction.Create(AOwner: TComponent);
begin
  inherited;
  BaseCaption := 'Clear Bookmark &%d';
end;

procedure TEasyEditBookmarkClearAction.ExecuteTarget(Target: TObject);
begin
  CustomEasyEdit.EditSource.ClearBookmark(BookmarkNr)
end;

{ TEasyEditBookmarkClearAction }

procedure TEasyEditBookmarkClearAllAction.ExecuteTarget(Target: TObject);
var
  b: Integer;
  i: Integer;
begin
  b := CustomEasyEdit.EditSource.MaxBookmarkNumber;
  for i := 1 to b do
    CustomEasyEdit.EditSource.ClearBookmark(i);
end;

procedure TEasyEditBookmarkClearAllAction.UpdateTarget(Target: TObject);
begin
  Inherited UpdateTarget (Target);
  Enabled := CustomEasyEdit.EditSource.MaxBookmarkNumber > 1;
end;

end.

⌨️ 快捷键说明

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