📄 syneditkeycmds.pas
字号:
{-------------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: SynEditKeyCmds.pas, released 2000-04-07.
The Original Code is based on the mwKeyCmds.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Brad Stowers.
All Rights Reserved.
Contributors to the SynEdit and mwEdit projects are listed in the
Contributors.txt file.
Alternatively, the contents of this file may be used under the terms of the
GNU General Public License Version 2 or later (the "GPL"), in which case
the provisions of the GPL are applicable instead of those above.
If you wish to allow use of your version of this file only under the terms
of the GPL and not to allow others to use your version of this file
under the MPL, indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by the GPL.
If you do not delete the provisions above, a recipient may use your version
of this file under either the MPL or the GPL.
$Id: SynEditKeyCmds.pas,v 1.6 2005/01/08 17:04:28 specu Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
Known Issues:
-------------------------------------------------------------------------------}
{$IFNDEF QSYNEDITKEYCMDS}
unit SynEditKeyCmds;
{$ENDIF}
{$I SynEdit.inc}
interface
uses
{$IFDEF SYN_CLX}
QMenus,
{$ELSE}
Menus,
{$ENDIF}
Classes,
SysUtils;
const
//****************************************************************************
// NOTE! If you add an editor command, you must also update the
// EditorCommandStrs constant array in implementation section below, or the
// command will not show up in the IDE.
//****************************************************************************
// "Editor Commands". Key strokes are translated from a table into these
// I used constants instead of a set so that additional commands could be
// added in descendants (you can't extend a set)
// There are two ranges of editor commands: the ecViewXXX commands are always
// valid, while the ecEditXXX commands are ignored when the editor is in
// read-only mode
ecNone = 0; // Nothing. Useful for user event to handle command
ecViewCommandFirst = 0;
ecViewCommandLast = 500;
ecEditCommandFirst = 501;
ecEditCommandLast = 1000;
ecLeft = 1; // Move cursor left one char
ecRight = 2; // Move cursor right one char
ecUp = 3; // Move cursor up one line
ecDown = 4; // Move cursor down one line
ecWordLeft = 5; // Move cursor left one word
ecWordRight = 6; // Move cursor right one word
ecLineStart = 7; // Move cursor to beginning of line
ecLineEnd = 8; // Move cursor to end of line
ecPageUp = 9; // Move cursor up one page
ecPageDown = 10; // Move cursor down one page
ecPageLeft = 11; // Move cursor right one page
ecPageRight = 12; // Move cursor left one page
ecPageTop = 13; // Move cursor to top of page
ecPageBottom = 14; // Move cursor to bottom of page
ecEditorTop = 15; // Move cursor to absolute beginning
ecEditorBottom = 16; // Move cursor to absolute end
ecGotoXY = 17; // Move cursor to specific coordinates, Data = PPoint
//******************************************************************************
// Maybe the command processor should just take a boolean that signifies if
// selection is affected or not?
//******************************************************************************
ecSelection = 100; // Add this to ecXXX command to get equivalent
// command, but with selection enabled. This is not
// a command itself.
// Same as commands above, except they affect selection, too
ecSelLeft = ecLeft + ecSelection;
ecSelRight = ecRight + ecSelection;
ecSelUp = ecUp + ecSelection;
ecSelDown = ecDown + ecSelection;
ecSelWordLeft = ecWordLeft + ecSelection;
ecSelWordRight = ecWordRight + ecSelection;
ecSelLineStart = ecLineStart + ecSelection;
ecSelLineEnd = ecLineEnd + ecSelection;
ecSelPageUp = ecPageUp + ecSelection;
ecSelPageDown = ecPageDown + ecSelection;
ecSelPageLeft = ecPageLeft + ecSelection;
ecSelPageRight = ecPageRight + ecSelection;
ecSelPageTop = ecPageTop + ecSelection;
ecSelPageBottom = ecPageBottom + ecSelection;
ecSelEditorTop = ecEditorTop + ecSelection;
ecSelEditorBottom = ecEditorBottom + ecSelection;
ecSelGotoXY = ecGotoXY + ecSelection; // Data = PPoint
ecSelectAll = 199; // Select entire contents of editor, cursor to end
ecCopy = 201; // Copy selection to clipboard
ecScrollUp = 211; // Scroll up one line leaving cursor position unchanged.
ecScrollDown = 212; // Scroll down one line leaving cursor position unchanged.
ecScrollLeft = 213; // Scroll left one char leaving cursor position unchanged.
ecScrollRight = 214; // Scroll right one char leaving cursor position unchanged.
ecInsertMode = 221; // Set insert mode
ecOverwriteMode = 222; // Set overwrite mode
ecToggleMode = 223; // Toggle ins/ovr mode
ecNormalSelect = 231; // Normal selection mode
ecColumnSelect = 232; // Column selection mode
ecLineSelect = 233; // Line selection mode
ecMatchBracket = 250; // Go to matching bracket
ecCommentBlock = 251; // Comment Block
ecGotoMarker0 = 301; // Goto marker
ecGotoMarker1 = 302; // Goto marker
ecGotoMarker2 = 303; // Goto marker
ecGotoMarker3 = 304; // Goto marker
ecGotoMarker4 = 305; // Goto marker
ecGotoMarker5 = 306; // Goto marker
ecGotoMarker6 = 307; // Goto marker
ecGotoMarker7 = 308; // Goto marker
ecGotoMarker8 = 309; // Goto marker
ecGotoMarker9 = 310; // Goto marker
ecSetMarker0 = 351; // Set marker, Data = PPoint - X, Y Pos
ecSetMarker1 = 352; // Set marker, Data = PPoint - X, Y Pos
ecSetMarker2 = 353; // Set marker, Data = PPoint - X, Y Pos
ecSetMarker3 = 354; // Set marker, Data = PPoint - X, Y Pos
ecSetMarker4 = 355; // Set marker, Data = PPoint - X, Y Pos
ecSetMarker5 = 356; // Set marker, Data = PPoint - X, Y Pos
ecSetMarker6 = 357; // Set marker, Data = PPoint - X, Y Pos
ecSetMarker7 = 358; // Set marker, Data = PPoint - X, Y Pos
ecSetMarker8 = 359; // Set marker, Data = PPoint - X, Y Pos
ecSetMarker9 = 360; // Set marker, Data = PPoint - X, Y Pos
ecGotFocus = 480;
ecLostFocus = 481;
ecContextHelp = 490; // Help on Word, Data = Word
ecDeleteLastChar = 501; // Delete last char (i.e. backspace key)
ecDeleteChar = 502; // Delete char at cursor (i.e. delete key)
ecDeleteWord = 503; // Delete from cursor to end of word
ecDeleteLastWord = 504; // Delete from cursor to start of word
ecDeleteBOL = 505; // Delete from cursor to beginning of line
ecDeleteEOL = 506; // Delete from cursor to end of line
ecDeleteLine = 507; // Delete current line
ecClearAll = 508; // Delete everything
ecLineBreak = 509; // Break line at current position, move caret to new line
ecInsertLine = 510; // Break line at current position, leave caret
ecChar = 511; // Insert a character at current position
ecImeStr = 550; // Insert character(s) from IME
ecUndo = 601; // Perform undo if available
ecRedo = 602; // Perform redo if available
ecCut = 603; // Cut selection to clipboard
ecPaste = 604; // Paste clipboard to current position
ecBlockIndent = 610; // Indent selection
ecBlockUnindent = 611; // Unindent selection
ecTab = 612; // Tab key
ecShiftTab = 613; // Shift+Tab key
ecAutoCompletion = 650;
ecUpperCase = 620; // apply to the current or previous word
ecLowerCase = 621;
ecToggleCase = 622;
ecTitleCase = 623;
ecUpperCaseBlock = 625; // apply to current selection, or current char if no selection
ecLowerCaseBlock = 626;
ecToggleCaseBlock = 627;
ecString = 630; //Insert a whole string
ecUserFirst = 1001; // Start of user-defined commands
type
ESynKeyError = class(Exception);
TSynEditorCommand = type word;
TSynEditKeyStroke = class(TCollectionItem)
private
FKey: word; // Virtual keycode, i.e. VK_xxx
FShift: TShiftState;
FKey2: word;
FShift2: TShiftState;
FCommand: TSynEditorCommand;
function GetShortCut: TShortCut;
function GetShortCut2: TShortCut;
procedure SetCommand(const Value: TSynEditorCommand);
procedure SetKey(const Value: word);
procedure SetKey2(const Value: word);
procedure SetShift(const Value: TShiftState);
procedure SetShift2(const Value: TShiftState);
procedure SetShortCut(const Value: TShortCut);
procedure SetShortCut2(const Value: TShortCut);
protected
{$IFDEF SYN_COMPILER_3_UP}
function GetDisplayName: string; override;
{$ENDIF}
public
procedure Assign(Source: TPersistent); override;
{begin} //ac 2000-07-05
procedure LoadFromStream(AStream: TStream);
procedure SaveToStream(AStream: TStream);
{end} //ac 2000-07-05
// No duplicate checking is done if assignment made via these properties!
property Key: word read FKey write SetKey;
property Key2: word read FKey2 write SetKey2;
property Shift: TShiftState read FShift write SetShift;
property Shift2: TShiftState read FShift2 write SetShift2;
published
property Command: TSynEditorCommand read FCommand write SetCommand;
property ShortCut: TShortCut read GetShortCut write SetShortCut
default 0; //mh 2000-11-07
property ShortCut2: TShortCut read GetShortCut2 write SetShortCut2
default 0; //mh 2000-11-07
end;
TSynEditKeyStrokes = class(TCollection)
private
FOwner: TPersistent;
function GetItem(Index: Integer): TSynEditKeyStroke;
procedure SetItem(Index: Integer; Value: TSynEditKeyStroke);
protected
{$IFDEF SYN_COMPILER_3_UP}
function GetOwner: TPersistent; override;
{$ENDIF}
public
constructor Create(AOwner: TPersistent);
function Add: TSynEditKeyStroke;
procedure AddKey(const ACmd: TSynEditorCommand; const AKey: word;
const AShift: TShiftState);
procedure Assign(Source: TPersistent); override;
function FindCommand(Cmd: TSynEditorCommand): integer;
function FindKeycode(Code: word; SS: TShiftState): integer;
function FindKeycode2(Code1: word; SS1: TShiftState;
Code2: word; SS2: TShiftState): integer;
function FindShortcut(SC: TShortcut): integer;
function FindShortcut2(SC, SC2: TShortcut): integer;
procedure LoadFromStream(AStream: TStream); //ac 2000-07-05
procedure ResetDefaults;
procedure SaveToStream(AStream: TStream); //ac 2000-07-05
public
property Items[Index: Integer]: TSynEditKeyStroke read GetItem
write SetItem; default;
end;
// These are mainly for the TSynEditorCommand property editor, but could be
// useful elsewhere.
function EditorCommandToDescrString(Cmd: TSynEditorCommand): string;
function EditorCommandToCodeString(Cmd: TSynEditorCommand): string;
procedure GetEditorCommandValues(Proc: TGetStrProc);
procedure GetEditorCommandExtended(Proc: TGetStrProc);
function IdentToEditorCommand(const Ident: string; var Cmd: longint): boolean;
function EditorCommandToIdent(Cmd: longint; var Ident: string): boolean;
function ConvertCodeStringToExtended(AString : String) : String;
function ConvertExtendedToCodeString(AString : String) : String;
function ConvertExtendedToCommand(AString : String) : TSynEditorCommand;
function ConvertCodeStringToCommand(AString : String) : TSynEditorCommand;
function IndexToEditorCommand(const AIndex: Integer) : Integer;
implementation
uses
{$IFDEF SYN_CLX}
kTextDrawer,
Types,
Qt,
QSynEditKeyConst,
QSynEditStrConst;
{$ELSE}
Windows,
SynEditKeyConst,
SynEditStrConst;
{$ENDIF}
{ Command mapping routines }
{$IFDEF SYN_COMPILER_2}
// This is defined in D3/C3 and up.
type
TIdentMapEntry = record
Value: TSynEditorCommand;
Name: string;
end;
{$ENDIF}
const
EditorCommandStrs: array[0..99] of TIdentMapEntry = (
(Value: ecNone; Name: 'ecNone'),
(Value: ecLeft; Name: 'ecLeft'),
(Value: ecRight; Name: 'ecRight'),
(Value: ecUp; Name: 'ecUp'),
(Value: ecDown; Name: 'ecDown'),
(Value: ecWordLeft; Name: 'ecWordLeft'),
(Value: ecWordRight; Name: 'ecWordRight'),
(Value: ecLineStart; Name: 'ecLineStart'),
(Value: ecLineEnd; Name: 'ecLineEnd'),
(Value: ecPageUp; Name: 'ecPageUp'),
(Value: ecPageDown; Name: 'ecPageDown'),
(Value: ecPageLeft; Name: 'ecPageLeft'),
(Value: ecPageRight; Name: 'ecPageRight'),
(Value: ecPageTop; Name: 'ecPageTop'),
(Value: ecPageBottom; Name: 'ecPageBottom'),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -