Unit uKeyBindings2;
Interface
Uses Classes,
Windows,
ToolsAPI,
Menus;
Type
TKeyBindings =
Class(TNotifierObject, IUnknown, IOTANotifier, IOTAKeyboardBinding)
//IOTAKeyboardBinding
Procedure BindKeyboard(
Const BindingServices: IOTAKeyBindingServices);
Function GetBindingType: TBindingType;
Function GetDisplayName:
String;
Function GetName:
String;
//Testroutine für Taste F2
Procedure Do_F2(
Const Context: IOTAKeyContext; KeyCode: TShortCut;
Var BindingResult: TKeyBindingResult);
public
Procedure Destroyed;
End;
Procedure Register;
Implementation
Const
InvalidIndex = -1;
Var
BindingIndex: Integer;
Procedure Register;
Begin
BindingIndex := (BorlandIDEServices
As IOTAKeyBoardServices).AddKeyboardBinding(TKeyBindings.Create);
End;
//--------------------------------------------------------------------------------------------------------------------
{ TKeyBindings }
Procedure TKeyBindings.Do_F2(
Const Context: IOTAKeyContext; KeyCode: TShortCut;
Var BindingResult: TKeyBindingResult);
//Fügt Trennlinie in aktuelle Zeile ein
Var
oEditorServices: IOTAEditorServices;
oEditView: IOTAEditView;
Begin
BindingResult := krHandled;
oEditorServices := BorlandIDEServices
As IOTAEditorServices;
oEditView := oEditorServices.TopView;
//Aktueller Buffer
If Assigned(oEditView)
Then Begin
//An den Anfang springen, einen Zeilenumbruch einfügen, und wieder zurück an den Anfang springen
oEditView.Buffer.EditPosition.Move(-1, 1);
oEditView.Buffer.EditPosition.InsertText('
//-------------------------------------------');
End;
End;
//--------------------------------------------------------------------------------------------------------------------
Procedure TKeyBindings.BindKeyboard(
Const BindingServices: IOTAKeyBindingServices);
//Registriert alles KeyBindings
Begin
BindingServices.AddKeyBinding([ShortCut(Ord(VK_F2), [])], Do_F2,
Nil);
End;
//--------------------------------------------------------------------------------------------------------------------
Function TKeyBindings.GetBindingType: TBindingType;
Begin
Result := btPartial;
End;
//--------------------------------------------------------------------------------------------------------------------
Function TKeyBindings.GetDisplayName:
String;
Begin
Result := '
SOFF_KeyBindings';
End;
//--------------------------------------------------------------------------------------------------------------------
Function TKeyBindings.GetName:
String;
Begin
Result := '
SOFF_KeyBindings';
End;
//--------------------------------------------------------------------------------------------------------------------
Procedure TKeyBindings.Destroyed;
Begin
If BindingIndex > InvalidIndex
Then
(BorlandIDEServices
As IOTAKeyBoardServices).RemoveKeyboardBinding(BindingIndex);
BindingIndex := InvalidIndex;
End;
//--------------------------------------------------------------------------------------------------------------------
Initialization
BindingIndex := InvalidIndex;
End.