掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
IDEのカスタマイズ (ID:16485)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
unit BEExp; interface uses SysUtils, Classes, ToolsAPI, Menus; resourcestring KeyName = 'BeginEnd'; ModuleName = 'BeginEnd'; BeginShortCut = 'Ctrl+['; EndShortCut = 'Ctrl+]'; BeginText = 'begin'#13#10+' '; EndText = 'end'; {$DEFINE END_WITH_UNINDENT} type TBeginEnd = class(TNotifierObject, IOTAKeyboardBinding) private procedure BeginProc(const Context: IOTAKeyContext; KeyCode: TShortCut; var BindingResult: TKeyBindingResult); procedure EndProc(const Context: IOTAKeyContext; KeyCode: TShortCut; var BindingResult: TKeyBindingResult); public function GetBindingType: TBindingType; function GetDisplayName: string; function GetName: string; procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices); end; procedure Register; implementation procedure TBeginEnd.BeginProc(const Context: IOTAKeyContext; KeyCode: TShortCut; var BindingResult: TKeyBindingResult); var EP: IOTAEditPosition; begin EP := Context.EditBuffer.EditPosition; EP.InsertText(BeginText); BindingResult := krHandled; end; procedure TBeginEnd.EndProc(const Context: IOTAKeyContext; KeyCode: TShortCut; var BindingResult: TKeyBindingResult); var EP: IOTAEditPosition; i, col, row: Integer; s: string; isNewLine: Boolean; begin EP := Context.EditBuffer.EditPosition; {$IFDEF END_WITH_UNINDENT} isNewLine := false; col := EP.Column; row := EP.Row; for i := col - 1 downto 1 do begin EP.Move(row, i); isNewLine := EP.IsWhiteSpace; if not isNewLine then Break; end; EP.Move(row, col); if isNewLine then EP.Tab(-1); {$ENDIF END_WITH_UNINDENT} EP.InsertText(EndText); BindingResult := krHandled; end; function TBeginEnd.GetBindingType: TBindingType; begin Result := btPartial; end; function TBeginEnd.GetDisplayName: string; begin Result := ModuleName; end; function TBeginEnd.GetName: string; begin Result := KeyName; end; procedure TBeginEnd.BindKeyboard(const BindingServices: IOTAKeyBindingServices); var tmp: TShortCut; begin tmp := TextToShortCut(BeginShortCut); if tmp <> 0 then BindingServices.AddKeyBinding([tmp], BeginProc, nil); tmp := TextToShortCut(EndShortCut); if tmp <> 0 then BindingServices.AddKeyBinding([tmp], EndProc, nil); end; //*************** Register ******************************** var BindNo: Integer = -1; procedure Register; begin if BindNo = -1 then BindNo := (BorlandIDEServices as IOTAKeyBoardServices) .AddKeyboardBinding(TBeginEnd.Create); end; procedure UnRegister; begin if BindNo <> -1 then begin (BorlandIDEServices as IOTAKeyBoardServices) .RemoveKeyboardBinding(BindNo); BindNo := -1; end; end; initialization finalization Unregister; {$UNDEF END_WITH_UNINDENT} end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.