mwkeycmds.pas
来自「本人买的<<VC++项目开发实例>>源代码配套光盘.」· PAS 代码 · 共 714 行 · 第 1/2 页
PAS
714 行
I: Integer;
{$ENDIF}
begin
{$IFDEF MWE_COMPILER_2}
Result := FALSE;
for I := Low(EditorCommandStrs) to High(EditorCommandStrs) do
if EditorCommandStrs[I].Value = Cmd then
begin
Result := TRUE;
Ident := EditorCommandStrs[I].Name;
break;
end;
{$ELSE}
Result := IntToIdent(Cmd, Ident, EditorCommandStrs);
{$ENDIF}
end;
function EditorCommandToDescrString(Cmd: TmwEditorCommand): string;
begin
// Doesn't do anything yet.
Result := '';
end;
function EditorCommandToCodeString(Cmd: TmwEditorCommand): string;
begin
if not EditorCommandToIdent(Cmd, Result) then
Result := IntToStr(Cmd);
end;
{ TmwKeyStroke }
procedure TmwKeyStroke.Assign(Source: TPersistent);
begin
if Source is TmwKeyStroke then
begin
Key := TmwKeyStroke(Source).Key;
Shift := TmwKeyStroke(Source).Shift;
Key2 := TmwKeyStroke(Source).Key2;
Shift2 := TmwKeyStroke(Source).Shift2;
Command := TmwKeyStroke(Source).Command;
end else
inherited Assign(Source);
end;
{$IFDEF MWE_COMPILER_3_UP}
function TmwKeyStroke.GetDisplayName: string;
begin
Result := EditorCommandToCodeString(Command) + ' - ' + ShortCutToText(ShortCut);
if ShortCut <> 0 then
Result := Result + ' ' + ShortCutToText(ShortCut2);
if Result = '' then
Result := inherited GetDisplayName;
end;
{$ENDIF}
function TmwKeyStroke.GetShortCut: TShortCut;
begin
Result := Menus.ShortCut(Key, Shift);
end;
procedure TmwKeyStroke.SetCommand(const Value: TmwEditorCommand);
begin
if Value <> FCommand then
FCommand := Value;
end;
procedure TmwKeyStroke.SetKey(const Value: word);
begin
if Value <> FKey then
FKey := Value;
end;
procedure TmwKeyStroke.SetShift(const Value: TShiftState);
begin
if Value <> FShift then
FShift := Value;
end;
procedure TmwKeyStroke.SetShortCut(const Value: TShortCut);
var
NewKey: Word;
NewShift: TShiftState;
Dup: integer;
begin
// Duplicate values of no shortcut are OK.
if Value <> 0 then
begin
// Check for duplicate shortcut in the collection and disallow if there is.
Dup := TmwKeyStrokes(Collection).FindShortcut2(Value, Key2);
if (Dup <> -1) and (Dup <> Self.Index) then
raise EmwKeyError.Create(MWS_EDuplicateShortCut);
end;
Menus.ShortCutToKey(Value, NewKey, NewShift);
if (NewKey <> Key) or (NewShift <> Shift) then
begin
Key := NewKey;
Shift := NewShift;
end;
end;
procedure TmwKeyStroke.SetKey2(const Value: word);
begin
if Value <> FKey2 then
FKey2 := Value;
end;
procedure TmwKeyStroke.SetShift2(const Value: TShiftState);
begin
if Value <> FShift2 then
FShift2 := Value;
end;
procedure TmwKeyStroke.SetShortCut2(const Value: TShortCut);
var
NewKey: Word;
NewShift: TShiftState;
Dup: integer;
begin
// Duplicate values of no shortcut are OK.
if Value <> 0 then
begin
// Check for duplicate shortcut in the collection and disallow if there is.
Dup := TmwKeyStrokes(Collection).FindShortcut2(Key, Value);
if (Dup <> -1) and (Dup <> Self.Index) then
raise EmwKeyError.Create(MWS_EDuplicateShortCut);
end;
Menus.ShortCutToKey(Value, NewKey, NewShift);
if (NewKey <> Key2) or (NewShift <> Shift2) then
begin
Key2 := NewKey;
Shift2 := NewShift;
end;
end;
function TmwKeyStroke.GetShortCut2: TShortCut;
begin
Result := Menus.ShortCut(Key2, Shift2);
end;
{ TmwKeyStrokes }
function TmwKeyStrokes.Add: TmwKeyStroke;
begin
Result := TmwKeyStroke(inherited Add);
end;
procedure TmwKeyStrokes.Assign(Source: TPersistent);
var
x: integer;
begin
if Source is TmwKeyStrokes then
begin
Clear;
for x := 0 to TmwKeyStrokes(Source).Count-1 do
begin
with Add do
Assign(TmwKeyStrokes(Source)[x]);
end;
end else
inherited Assign(Source);
end;
constructor TmwKeyStrokes.Create(AOwner: TPersistent);
begin
inherited Create(TmwKeyStroke);
FOwner := AOwner;
end;
function TmwKeyStrokes.FindCommand(Cmd: TmwEditorCommand): integer;
var
x: integer;
begin
Result := -1;
for x := 0 to Count-1 do
if Items[x].Command = Cmd then
begin
Result := x;
break;
end;
end;
function TmwKeyStrokes.FindKeycode(Code: word; SS: TShiftState): integer;
var
x: integer;
begin
Result := -1;
for x := 0 to Count-1 do
if (Items[x].Key = Code) and (Items[x].Shift = SS) and (Items[x].Key2 = 0)
then begin
Result := x;
break;
end;
end;
function TmwKeyStrokes.FindShortcut(SC: TShortcut): integer;
var
x: integer;
begin
Result := -1;
for x := 0 to Count-1 do
if Items[x].Shortcut = SC then
begin
Result := x;
break;
end;
end;
function TmwKeyStrokes.FindKeycode2(Code1: word; SS1: TShiftState;
Code2: word; SS2: TShiftState): integer;
var
x: integer;
begin
Result := -1;
for x := 0 to Count-1 do
if (Items[x].Key = Code1) and (Items[x].Shift = SS1) and
(Items[x].Key2 = Code2) and (Items[x].Shift2 = SS2) then
begin
Result := x;
break;
end;
end;
function TmwKeyStrokes.FindShortcut2(SC, SC2: TShortcut): integer;
var
x: integer;
begin
Result := -1;
for x := 0 to Count-1 do
if (Items[x].Shortcut = SC) and (Items[x].Shortcut2 = SC2) then
begin
Result := x;
break;
end;
end;
function TmwKeyStrokes.GetItem(Index: Integer): TmwKeyStroke;
begin
Result := TmwKeyStroke(inherited GetItem(Index));
end;
{$IFDEF MWE_COMPILER_3_UP}
function TmwKeyStrokes.GetOwner: TPersistent;
begin
Result := FOwner;
end;
{$ENDIF}
procedure TmwKeyStrokes.ResetDefaults;
procedure AddKey(const ACmd: TmwEditorCommand; const AKey: word;
const AShift: TShiftState);
begin
with Add do
begin
Key := AKey;
Shift := AShift;
Command := ACmd;
end;
end;
begin
Clear;
AddKey(ecUp, VK_UP, []);
AddKey(ecSelUp, VK_UP, [ssShift]);
AddKey(ecScrollUp, VK_UP, [ssCtrl]);
AddKey(ecDown, VK_DOWN, []);
AddKey(ecSelDown, VK_DOWN, [ssShift]);
AddKey(ecScrollDown, VK_DOWN, [ssCtrl]);
AddKey(ecLeft, VK_LEFT, []);
AddKey(ecSelLeft, VK_LEFT, [ssShift]);
AddKey(ecWordLeft, VK_LEFT, [ssCtrl]);
AddKey(ecSelWordLeft, VK_LEFT, [ssShift,ssCtrl]);
AddKey(ecRight, VK_RIGHT, []);
AddKey(ecSelRight, VK_RIGHT, [ssShift]);
AddKey(ecWordRight, VK_RIGHT, [ssCtrl]);
AddKey(ecSelWordRight, VK_RIGHT, [ssShift,ssCtrl]);
AddKey(ecPageDown, VK_NEXT, []);
AddKey(ecSelPageDown, VK_NEXT, [ssShift]);
AddKey(ecPageBottom, VK_NEXT, [ssCtrl]);
AddKey(ecSelPageBottom, VK_NEXT, [ssShift,ssCtrl]);
AddKey(ecPageUp, VK_PRIOR, []);
AddKey(ecSelPageUp, VK_PRIOR, [ssShift]);
AddKey(ecPageTop, VK_PRIOR, [ssCtrl]);
AddKey(ecSelPageTop, VK_PRIOR, [ssShift,ssCtrl]);
AddKey(ecLineStart, VK_HOME, []);
AddKey(ecSelLineStart, VK_HOME, [ssShift]);
AddKey(ecEditorTop, VK_HOME, [ssCtrl]);
AddKey(ecSelEditorTop, VK_HOME, [ssShift,ssCtrl]);
AddKey(ecLineEnd, VK_END, []);
AddKey(ecSelLineEnd, VK_END, [ssShift]);
AddKey(ecEditorBottom, VK_END, [ssCtrl]);
AddKey(ecSelEditorBottom, VK_END, [ssShift,ssCtrl]);
AddKey(ecToggleMode, VK_INSERT, []);
AddKey(ecCopy, VK_INSERT, [ssCtrl]);
AddKey(ecPaste, VK_INSERT, [ssShift]);
AddKey(ecDeleteChar, VK_DELETE, []);
AddKey(ecCut, VK_DELETE, [ssShift]);
AddKey(ecDeleteLastChar, VK_BACK, []);
AddKey(ecDeleteLastWord, VK_BACK, [ssCtrl]);
AddKey(ecUndo, VK_BACK, [ssAlt]);
AddKey(ecRedo, VK_BACK, [ssAlt,ssShift]);
AddKey(ecLineBreak, VK_RETURN, []);
AddKey(ecSelectAll, ord('A'), [ssCtrl]);
AddKey(ecCopy, ord('C'), [ssCtrl]);
AddKey(ecBlockIndent, ord('I'), [ssCtrl,ssShift]);
AddKey(ecLineBreak, ord('M'), [ssCtrl]);
AddKey(ecInsertLine, ord('N'), [ssCtrl]);
AddKey(ecDeleteWord, ord('T'), [ssCtrl]);
AddKey(ecBlockUnindent, ord('U'), [ssCtrl,ssShift]);
AddKey(ecPaste, ord('V'), [ssCtrl]);
AddKey(ecCut, ord('X'), [ssCtrl]);
AddKey(ecDeleteLine, ord('Y'), [ssCtrl]);
AddKey(ecDeleteEOL, ord('Y'), [ssCtrl,ssShift]);
AddKey(ecUndo, ord('Z'), [ssCtrl]);
AddKey(ecRedo, ord('Z'), [ssCtrl,ssShift]);
AddKey(ecGotoMarker0, ord('0'), [ssCtrl]);
AddKey(ecGotoMarker1, ord('1'), [ssCtrl]);
AddKey(ecGotoMarker2, ord('2'), [ssCtrl]);
AddKey(ecGotoMarker3, ord('3'), [ssCtrl]);
AddKey(ecGotoMarker4, ord('4'), [ssCtrl]);
AddKey(ecGotoMarker5, ord('5'), [ssCtrl]);
AddKey(ecGotoMarker6, ord('6'), [ssCtrl]);
AddKey(ecGotoMarker7, ord('7'), [ssCtrl]);
AddKey(ecGotoMarker8, ord('8'), [ssCtrl]);
AddKey(ecGotoMarker9, ord('9'), [ssCtrl]);
AddKey(ecSetMarker0, ord('0'), [ssCtrl,ssShift]);
AddKey(ecSetMarker1, ord('1'), [ssCtrl,ssShift]);
AddKey(ecSetMarker2, ord('2'), [ssCtrl,ssShift]);
AddKey(ecSetMarker3, ord('3'), [ssCtrl,ssShift]);
AddKey(ecSetMarker4, ord('4'), [ssCtrl,ssShift]);
AddKey(ecSetMarker5, ord('5'), [ssCtrl,ssShift]);
AddKey(ecSetMarker6, ord('6'), [ssCtrl,ssShift]);
AddKey(ecSetMarker7, ord('7'), [ssCtrl,ssShift]);
AddKey(ecSetMarker8, ord('8'), [ssCtrl,ssShift]);
AddKey(ecSetMarker9, ord('9'), [ssCtrl,ssShift]);
AddKey(ecNormalSelect, ord('N'), [ssCtrl,ssShift]);
AddKey(ecColumnSelect, ord('C'), [ssCtrl,ssShift]);
AddKey(ecLineSelect, ord('L'), [ssCtrl,ssShift]);
end;
procedure TmwKeyStrokes.SetItem(Index: Integer; Value: TmwKeyStroke);
begin
inherited SetItem(Index, Value);
end;
initialization
RegisterIntegerConsts(TypeInfo(TmwEditorCommand), IdentToEditorCommand,
EditorCommandToIdent);
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?