easyeditoractions.pas.svn-base
来自「支持自定义语法高亮显示的编辑器控件」· SVN-BASE 代码 · 共 1,309 行 · 第 1/3 页
SVN-BASE
1,309 行
if Target is TCustomEdit then
CustomEdit.CutToClipboard
else
inherited ExecuteTarget(Target);
end;
procedure TEasyEditCutAction.UpdateTarget(Target: TObject);
var
b : Boolean;
begin
if (Target is TCustomEdit) then
begin
b := CustomEdit.SelLength > 0;
Enabled := b and (not TCustomEditCrack(Target).ReadOnly)
end
else
if Target is TCustomEasyEdit then
begin
b := CustomEasyEdit.SelType <> slNone;
Enabled := b and (not CustomEasyEdit.ReadOnly);
end;
end;
{ TEasyEditCopyAction }
procedure TEasyEditCopyAction.ExecuteTarget(Target: TObject);
begin
if Target is TCustomEasyEdit then
CustomEasyEdit.CopyBlock
else
if Target is TCustomEdit then
CustomEdit.CopyToClipboard
else
inherited ExecuteTarget(Target);
end;
procedure TEasyEditCopyAction.UpdateTarget(Target: TObject);
begin
if (Target is TCustomEdit) then
Enabled := CustomEdit.SelLength > 0
else
if Target is TCustomEasyEdit then
Enabled := CustomEasyEdit.SelType <> slNone;
end;
{ TEasyEditPasteAction }
procedure TEasyEditPasteAction.ExecuteTarget(Target: TObject);
begin
if Target is TCustomEasyEdit then
CustomEasyEdit.PasteBlock
else
if Target is TCustomEdit then
CustomEdit.PasteFromClipboard
else
inherited ExecuteTarget(Target);
end;
procedure TEasyEditPasteAction.UpdateTarget(Target: TObject);
var
B: Boolean;
begin
B := Clipboard.HasFormat(CF_TEXT);
if Target is TCustomEdit then
Enabled := B and not TCustomEditCrack(Target).ReadOnly
else
if Target is TCustomEasyEdit then
Enabled := CustomEasyEdit.CanPaste;
end;
{ TEasyEditClearAction }
procedure TEasyEditClearAction.ExecuteTarget(Target: TObject);
begin
if Target is TCustomEasyEdit then
CustomEasyEdit.Clear
else
if Target is TCustomEdit then
CustomEdit.ClearSelection
else
inherited ExecuteTarget(Target);
end;
procedure TEasyEditClearAction.UpdateTarget(Target: TObject);
begin
if Target is TCustomEdit then
Enabled := CustomEdit.GetTextLen <> 0
else
if Target is TCustomEasyEdit then
Enabled := CustomEasyEdit.Lines.Count > 0;
end;
{ TEasyEditSelectAllAction }
procedure TEasyEditSelectAllAction.ExecuteTarget(Target: TObject);
begin
if Target is TCustomEasyEdit then
CustomEasyEdit.SelectAll
else
if Target is TCustomEdit then
CustomEdit.SelectAll
else
inherited ExecuteTarget(Target);
end;
procedure TEasyEditSelectAllAction.UpdateTarget(Target: TObject);
begin
if Target is TCustomEdit then
Enabled := CustomEdit.SelLength <>
CustomEdit.GetTextLen
else
if Target is TCustomEasyEdit then
Enabled := CustomEasyEdit.Lines.Count > 0;
end;
{ TEasyEditUndoAction }
procedure TEasyEditUndoAction.ExecuteTarget(Target: TObject);
begin
if Target is TCustomEasyEdit then
CustomEasyEdit.Undo
else
if Target is TCustomEdit then
CustomEdit.Undo
else
inherited ExecuteTarget(Target);
end;
procedure TEasyEditUndoAction.UpdateTarget(Target: TObject);
begin
if Target is TCustomEdit then
Enabled := CustomEdit.CanUndo
else
if Target is TCustomEasyEdit then
Enabled := CustomEasyEdit.CanUndo;
end;
{ TEasyEditRedoAction }
procedure TEasyEditRedoAction.ExecuteTarget(Target: TObject);
begin
if Target is TCustomEasyEdit then
CustomEasyEdit.Redo
else
inherited ExecuteTarget(Target);
end;
procedure TEasyEditRedoAction.UpdateTarget(Target: TObject);
begin
if Target is TCustomEasyEdit then
begin
if Self is TEasyEditRedoAction then
Enabled := CustomEasyEdit.CanRedo;
end;
end;
{ TEasyEditAutoCorrectionAction }
constructor TEasyEditAutoCorrectionAction.create (AOwner : TComponent);
begin
Inherited create (AOwner);
end;
type
TMEdit = class(TCustomEasyEdit);
TMSource = class(TCustomEasyEditSource);
procedure TEasyEditAutoCorrectionAction.DoAutoCorrection ;
var
Word : TEasyString;
CorrectWord : TEasyString;
ALeft : integer;
ARight : integer;
Delta : integer;
OldDelims : TEasyCharSet;
OldPosition : TPoint;
Begin
OldPosition := CustomEasyEdit.CurrentPosition;
with TMEdit(CustomEasyEdit), TMSource(EditSource) do
begin
CurrentPosition := Point(0, 0);
OldDelims := Delimiters;
Delimiters := Delimiters + WordDelimSet;
BeginSourceUpdate(oprOther);
try
while CurrentPosition.Y < Strings.Count do
begin
GetWord(CurrentPosition, ALeft, ARight, wsWord);
if (ARight > ALeft) or ((ARight = ALeft) and (ARight > 0)) then
begin
Delta := CurrentPosition.X - ARight;
Word := Copy(Strings[CurrentPosition.Y], ALeft, ARight - ALeft + 1);
if (Word <> '') and not (Assigned(OnWordSpell) and CheckWordSpelling(Word)) then
begin
CorrectWord := Word;
if HasAutoCorrection(Word, CorrectWord) then
begin
JumpTo(ALeft - 1, CurrentPosition.Y);
DeleteString(ARight - ALeft + 1);
InsertString(CorrectWord);
Navigate(Length(CorrectWord) + Delta + 1, 0);
end;
end;
end;
CustomEasyEdit.Navigate(cWordRight);
if (CurrentPosition.Y = Strings.Count - 1) and (CurrentPosition.X >= Length(Strings[Strings.Count - 1]) - 1) then
Break;
end;
finally
Delimiters := OldDelims;
EndSourceUpdate;
end;
end;
CustomEasyEdit.CurrentPosition := OldPosition;
End;
procedure TEasyEditAutoCorrectionAction.UpdateTarget(Target: TObject);
VAR b : Boolean;
begin
IF (Target is TCustomEasyEdit) THEN
Enabled := b
ELSE
IF Enabled THEN
Enabled := False;
end;
procedure TEasyEditAutoCorrectionAction.ExecuteTarget(Target: TObject);
begin
DoAutoCorrection;
end;
//*****************************************************************************
{ TEasyEditBaseBlockAction }
//*****************************************************************************
procedure TEasyEditBaseBlockAction.UpdateTarget(Target: TObject);
var
B: Boolean;
begin
IF (Target is TCustomEasyEdit) THEN
BEGIN
B := (CustomEasyEdit.SelType <> slNone) and (not CustomEasyEdit.ReadOnly);
IF b <> Enabled THEN
Enabled := b
ELSE
END
ELSE
IF Enabled THEN
Enabled := False;
end;
{ TEasyEditIndentAction }
procedure TEasyEditIndentAction.ExecuteTarget(Target: TObject);
begin
CustomEasyEdit.ProcessBlock (cIndentBlock)
end;
{ TEasyEditUnindentAction }
procedure TEasyEditUnindentAction.ExecuteTarget(Target: TObject);
begin
CustomEasyEdit.ProcessBlock (cOutdentBlock)
end;
{ TEasyEditUppercaseAction }
procedure TEasyEditUppercaseAction.ExecuteTarget(Target: TObject);
begin
CustomEasyEdit.ProcessBlock (cUppercaseBlock)
end;
{ TEasyEditLowercaseAction }
procedure TEasyEditLowercaseAction.ExecuteTarget(Target: TObject);
begin
CustomEasyEdit.ProcessBlock (cLowercaseBlock)
end;
{ TEasyEditCollapsableAction }
procedure TEasyEditCollapsableAction.ExecuteTarget(Target: TObject);
var
Rect: TRect;
i: Integer;
begin
if Target is TCustomEasyEdit then
begin
if not (srAllowHiddenLines in CustomEasyEdit.SourceOptions) then
CustomEasyEdit.SourceOptions := CustomEasyEdit.SourceOptions +
[srAllowHiddenLines];
Rect := CustomEasyEdit.SelRect;
CustomEasyEdit.Lines.Collapsed[Rect.Top] := true;
CustomEasyEdit.Lines.Visible[Rect.Top] := true;
for i := Rect.Top + 1 to Rect.Bottom do
CustomEasyEdit.Lines.Visible[i] := false;
end
else
inherited ExecuteTarget(Target);
end;
{ TEasyEditUncollapsableAction }
procedure TEasyEditUncollapsableAction.ExecuteTarget(Target: TObject);
var
i: Integer;
begin
if Target is TCustomEasyEdit then
begin
with CustomEasyEdit, Lines do
begin
i := CurrentPosition.Y;
while (i >= 0) and (not Visible[i]) do
Dec(i);
if (i < 0) or not (Collapsed[i] or Expanded[i]) then
exit;
Collapsed[i] := false;
Expanded[i] := false;
Inc(i);
while not Visible[i] do
begin
Visible[i] := true;
Inc(i);
end;
// CustomEasyEdit.Options := CustomEasyEdit.Options -
// [moHideInvisibleLines];
end;
end
else
inherited ExecuteTarget(Target);
end;
{ TEasyEditCommentAction }
constructor TEasyEditCommentAction.create (AOwner : TComponent);
begin
Inherited create (AOwner);
LineCommentStart := '--';
end;
procedure TEasyEditCommentAction.ExecuteTarget(Target: TObject);
var
Rect: TRect;
st : TEasySelType;
pt : tPoint;
i: Integer;
L, R: Integer;
begin
if LineCommentStart = '' then
Exit;
st := CustomEasyEdit.SelType;
pt := CustomEasyEdit.CurrentPosition;
if st = slNone then
exit;
try
CustomEasyEdit.EditSource.BeginSourceUpdate(oprOther);
CustomEasyEdit.EditSource.LockUndo;
Rect := CustomEasyEdit.SelRect;
for i := Rect.Top to Rect.Bottom do
begin
tHackCustomEasyEdit(CustomEasyEdit).GetSelBounds (i, L, R);
if L < R then
BEGIN
CustomEasyEdit.EditSource.CurrentPosition := Point(l,i);
CustomEasyEdit.EditSource.InsertString(LineCOmmentStart);
END;
end;
finally
CustomEasyEdit.EditSource.UnlockUndo;
CustomEasyEdit.EditSource.EndSourceUpdate;
CustomEasyEdit.CurrentPosition := pt;
CustomEasyEdit.SetSelection (Rect, st);
end;
end;
constructor TEasyEditUnCommentAction.create (AOwner : TComponent);
begin
Inherited create (AOwner);
LineCommentStart := '--';
end;
procedure TEasyEditUnCommentAction.ExecuteTarget(Target: TObject);
var
Rect: TRect;
st : TEasySelType;
pt : tPoint;
i: Integer;
L, R: Integer;
begin
if LineCommentStart = '' then
Exit;
pt := CustomEasyEdit.CurrentPosition;
st := CustomEasyEdit.SelType;
if st = slNone then
exit;
try
CustomEasyEdit.EditSource.BeginSourceUpdate(oprOther);
CustomEasyEdit.EditSource.LockUndo;
Rect := CustomEasyEdit.SelRect;
for i := Rect.Top to Rect.Bottom do
begin
tHackCustomEasyEdit(CustomEasyEdit).GetSelBounds (i, L, R);
if L < R then
if Copy(CustomEasyEdit.EditSource.Strings[i], L + 1,
Length(LineCommentStart)) = LineCommentStart then
BEGIN
CustomEasyEdit.EditSource.CurrentPosition := Point(l,i);
CustomEasyEdit.EditSource.DeleteString(Length(LineCOmmentStart));
END;
end;
finally
CustomEasyEdit.EditSource.UnlockUndo;
CustomEasyEdit.EditSource.EndSourceUpdate;
CustomEasyEdit.CurrentPosition := pt;
CustomEasyEdit.SetSelection (Rect, st);
end;
end;
procedure TEasyEditSortUpAction.ExecuteTarget(Target: TObject);
var
SortList: TStringList;
Rect: TRect;
st : TEasySelType;
pt : tPoint;
i, j: Integer;
L, R: Integer;
s: string;
begin
st := CustomEasyEdit.SelType;
pt := CustomEasyEdit.CurrentPosition;
if st = slNone then
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?