📄 jveditorcommon.pas
字号:
FFunctionCall: TJvSymbolColor;
FDeclaration: TJvSymbolColor;
FStatement: TJvSymbolColor;
FPlainText: TJvSymbolColor;
public
constructor Create;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property Comment: TJvSymbolColor read FComment write FComment;
property Number: TJvSymbolColor read FNumber write FNumber;
property Strings: TJvSymbolColor read FString write FString;
property Symbol: TJvSymbolColor read FSymbol write FSymbol;
property Reserved: TJvSymbolColor read FReserved write FReserved;
property Identifier: TJvSymbolColor read FIdentifier write FIdentifier;
property Preproc: TJvSymbolColor read FPreproc write FPreproc;
property FunctionCall: TJvSymbolColor read FFunctionCall write FFunctionCall;
property Declaration: TJvSymbolColor read FDeclaration write FDeclaration;
property Statement: TJvSymbolColor read FStatement write FStatement;
property PlainText: TJvSymbolColor read FPlainText write FPlainText;
end;
IJvHLEditor = interface
['{E165FE73-AE7E-40A8-AC9B-7FD20D55A15E}']
function GetColors: TJvColors;
procedure SetColors(const Value: TJvColors);
function GetSyntaxHighlighting: Boolean;
procedure SetSyntaxHighlighting(Value: Boolean);
function GetHighlighter: TJvHighlighter;
procedure SetHighlighter(const Value: TJvHighlighter);
property Colors: TJvColors read GetColors write SetColors;
property SyntaxHighlighting: Boolean read GetSyntaxHighlighting write SetSyntaxHighlighting;
property Highlighter: TJvHighlighter read GetHighlighter write SetHighlighter;
end;
const
{ Editor commands }
{ When add new commands, please add them into JvInterpreter_JvEditor.pas unit also ! }
ecCharFirst = $00;
ecCharLast = $FF;
ecCommandFirst = $100;
ecIntern = $1000; { use on internal updates }
ecUser = $8000; { use this for descendants }
{Cursor}
ecLeft = ecCommandFirst + 1;
ecUp = ecLeft + 1;
ecRight = ecLeft + 2;
ecDown = ecLeft + 3;
{Cursor with select}
ecSelLeft = ecCommandFirst + 9;
ecSelUp = ecSelLeft + 1;
ecSelRight = ecSelLeft + 2;
ecSelDown = ecSelLeft + 3;
{Cursor with column select}
ecSelColumnLeft = ecIntern + 0;
ecSelColumnUp = ecSelColumnLeft + 1;
ecSelColumnRight = ecSelColumnLeft + 2;
ecSelColumnDown = ecSelColumnLeft + 3;
{Cursor On words [translated] }
ecPrevWord = ecSelDown + 1;
ecNextWord = ecPrevWord + 1;
ecSelPrevWord = ecPrevWord + 2;
ecSelNextWord = ecPrevWord + 3;
ecSelWord = ecPrevWord + 4;
ecWindowTop = ecSelWord + 1;
ecWindowBottom = ecWindowTop + 1;
ecPrevPage = ecWindowTop + 2;
ecNextPage = ecWindowTop + 3;
ecSelPrevPage = ecWindowTop + 4;
ecSelNextPage = ecWindowTop + 5;
ecBeginLine = ecSelNextPage + 1;
ecEndLine = ecBeginLine + 1;
ecBeginDoc = ecBeginLine + 2;
ecEndDoc = ecBeginLine + 3;
ecSelBeginLine = ecBeginLine + 4;
ecSelEndLine = ecBeginLine + 5;
ecSelBeginDoc = ecBeginLine + 6;
ecSelEndDoc = ecBeginLine + 7;
ecSelAll = ecBeginLine + 8;
ecScrollLineUp = ecSelAll + 1;
ecScrollLineDown = ecScrollLineUp + 1;
ecInclusiveBlock = ecCommandFirst + 100;
ecLineBlock = ecCommandFirst + 101;
ecColumnBlock = ecCommandFirst + 102;
ecNonInclusiveBlock = ecCommandFirst + 103;
ecInsertPara = ecCommandFirst + 121;
ecBackspace = ecInsertPara + 1;
ecDelete = ecInsertPara + 2;
ecChangeInsertMode = ecInsertPara + 3;
ecTab = ecInsertPara + 4;
ecBackTab = ecInsertPara + 5;
ecIndent = ecInsertPara + 6;
ecUnindent = ecInsertPara + 7;
ecBackspaceWord = ecIntern + 10;
ecDeleteSelected = ecInsertPara + 10;
ecClipboardCopy = ecInsertPara + 11;
ecClipboardCut = ecClipboardCopy + 1;
ecClipboardPaste = ecClipboardCopy + 2;
ecDeleteLine = ecClipboardPaste + 1;
ecDeleteWord = ecDeleteLine + 1;
ecToUpperCase = ecDeleteLine + 2;
ecToLowerCase = ecToUpperCase + 1;
ecChangeCase = ecToUpperCase + 2;
ecUndo = ecChangeCase + 1;
ecRedo = ecUndo + 1;
ecBeginCompound = ecUndo + 2;
ecEndCompound = ecUndo + 3;
ecBeginUpdate = ecUndo + 4;
ecEndUpdate = ecUndo + 5;
ecSetBookmark0 = ecEndUpdate + 1;
ecSetBookmark1 = ecSetBookmark0 + 1;
ecSetBookmark2 = ecSetBookmark0 + 2;
ecSetBookmark3 = ecSetBookmark0 + 3;
ecSetBookmark4 = ecSetBookmark0 + 4;
ecSetBookmark5 = ecSetBookmark0 + 5;
ecSetBookmark6 = ecSetBookmark0 + 6;
ecSetBookmark7 = ecSetBookmark0 + 7;
ecSetBookmark8 = ecSetBookmark0 + 8;
ecSetBookmark9 = ecSetBookmark0 + 9;
ecGotoBookmark0 = ecSetBookmark9 + 1;
ecGotoBookmark1 = ecGotoBookmark0 + 1;
ecGotoBookmark2 = ecGotoBookmark0 + 2;
ecGotoBookmark3 = ecGotoBookmark0 + 3;
ecGotoBookmark4 = ecGotoBookmark0 + 4;
ecGotoBookmark5 = ecGotoBookmark0 + 5;
ecGotoBookmark6 = ecGotoBookmark0 + 6;
ecGotoBookmark7 = ecGotoBookmark0 + 7;
ecGotoBookmark8 = ecGotoBookmark0 + 8;
ecGotoBookmark9 = ecGotoBookmark0 + 9;
ecCompletionIdentifiers = ecGotoBookmark9 + 1;
ecCompletionTemplates = ecCompletionIdentifiers + 1;
ecRecordMacro = ecCompletionTemplates + 1;
ecPlayMacro = ecRecordMacro + 1;
ecBeginRecord = ecRecordMacro + 2;
ecEndRecord = ecRecordMacro + 3;
twoKeyCommand = High(Word);
function KeyPressed(VK: Integer): Boolean;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvEditorCommon.pas,v $';
Revision: '$Revision: 1.43 $';
Date: '$Date: 2005/02/24 12:26:10 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
Consts,
{$IFDEF HAS_UNIT_RTLCONSTS}
RTLConsts,
{$ENDIF HAS_UNIT_RTLCONSTS}
Math, Clipbrd,
JvJCLUtils, JvThemes, JvConsts, JvResources;
type
TJvEditorCompletionList = class(TListBox)
private
FTimer: TTimer;
YY: Integer;
// HintWindow : THintWindow;
procedure CMHintShow(var Msg: TMessage); message CM_HINTSHOW;
procedure WMCancelMode(var Msg: TMessage); message WM_CancelMode;
procedure OnTimer(Sender: TObject);
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
function KeyPressed(VK: Integer): Boolean;
begin
Result := GetKeyState(VK) and $8000 = $8000;
end;
//=== { TJvUndoBuffer } ======================================================
procedure RedoNotImplemented;
begin
raise EJvEditorError.CreateRes(@RsERedoNotYetImplemented);
end;
procedure TJvUndoBuffer.Add(AUndo: TJvUndo);
begin
if InUndo then
Exit;
ClearRedo;
inherited Add(AUndo);
FPtr := Count - 1;
end;
procedure TJvUndoBuffer.Undo;
function IsIntf(AInstance: TObject; IID: TGUID): Boolean; overload;
begin
Result := (AInstance <> nil) and (AInstance.GetInterfaceEntry(IID) <> nil);
end;
function IsIntf(AClass: TClass; IID: TGUID): Boolean; overload;
begin
Result := (AClass <> nil) and (AClass.GetInterfaceEntry(IID) <> nil);
end;
var
UndoClass: TClass;
Compound: Integer;
IsOnlyCaret: Boolean;
Selection: TJvSelectionRec;
WasModified: Boolean;
begin
if InUndo then
Exit;
Selection := FJvEditor.FSelection;
WasModified := FJvEditor.Modified;
IsOnlyCaret := True;
InUndo := True;
try
if LastUndo <> nil then
begin
Compound := 0;
UndoClass := LastUndo.ClassType;
while (LastUndo <> nil) and
((UndoClass = LastUndo.ClassType) or
{(LastUndo is TJvDeleteTrailUndo) or
(LastUndo is TJvReLineUndo) or}
IsIntf(LastUndo, IJvUndoCompound) or
(Compound > 0)) or
{((UndoClass = TJvBackspaceUndo) and
(LastUndo is TJvBackspaceUnindentUndo)) do}
IsIntf(UndoClass, IJvBackspaceUndo) and
IsIntf(LastUndo, IJvBackspaceUnindentUndo) do
begin
if LastUndo.ClassType = TJvBeginCompoundUndo then
begin
Dec(Compound);
UndoClass := nil;
end
else
if LastUndo.ClassType = TJvEndCompoundUndo then
Inc(Compound);
LastUndo.Undo;
if LastUndo <> nil then
begin
LastUndo.RestoreSelection;
FJvEditor.Modified := LastUndo.FModified;
end;
Dec(FPtr);
{if (UndoClass = TJvDeleteTrailUndo) or
(UndoClass = TJvReLineUndo) then}
if IsIntf(UndoClass, IJvUndoCompound) then
UndoClass := LastUndo.ClassType;
if (UndoClass <> TJvCaretUndo) and
(UndoClass <> TJvSelectUndo) and
(UndoClass <> TJvUnselectUndo) then
IsOnlyCaret := False;
if not FJvEditor.GroupUndo then
Break;
end;
if not FJvEditor.Modified then
IsOnlyCaret := True;
// paint selection
if not CompareMem(@Selection, @FJvEditor.FSelection, SizeOf(TJvSelectionRec)) then
FJvEditor.PaintSelection;
FJvEditor.UpdateEditorView;
if FJvEditor.FUpdateLock = 0 then
if not IsOnlyCaret then
FJvEditor.Changed
else
if WasModified then
FJvEditor.StatusChanged;
end;
finally
InUndo := False;
end;
end;
procedure TJvUndoBuffer.Redo;
begin
if CanRedo then
begin
Inc(FPtr);
LastUndo.Redo;
end;
end;
procedure TJvUndoBuffer.Clear;
begin
while Count > 0 do
begin
TJvUndo(Items[0]).Free;
inherited Delete(0);
end;
end;
procedure TJvUndoBuffer.ClearRedo;
begin
while (Count > 0) and (FPtr < Count - 1) do
begin
TJvUndo(Items[FPtr + 1]).Free;
inherited Delete(FPtr + 1);
end;
end;
procedure TJvUndoBuffer.Delete;
begin
if Count > 0 then
begin
TJvUndo(Items[Count - 1]).Free;
inherited Delete(Count - 1);
end;
end;
function TJvUndoBuffer.LastUndo: TJvUndo;
begin
if (FPtr >= 0) and (Count > 0) then
Result := TJvUndo(Items[FPtr])
else
Result := nil;
end;
function TJvUndoBuffer.IsNewGroup(AUndo: TJvUndo): Boolean;
begin
Result := (LastUndo = nil) or (LastUndo.ClassType <> AUndo.ClassType)
end;
function TJvUndoBuffer.IsCaretGroup: Boolean;
begin
Result := (LastUndo <> nil) and (LastUndo.ClassType = TJvCaretUndo);
end;
function TJvUndoBuffer.CanUndo: Boolean;
begin
Result := (LastUndo <> nil);
end;
function TJvUndoBuffer.CanRedo: Boolean;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -