IDEのカスタマイズ

解決


蕎麦  2005-07-21 20:42:20  No: 16481

begin  や  end  を  ショートカットキーで入力できるようにしたいのですが、ずばりの解説が見つけられません。
どなたかご教授願います。

環境はDelphi6Personalです。

GExperts の Editor Experts には、無い・・ですよね?(汗


それは・・・?  2005-07-21 22:08:00  No: 16482

コードテンプレート・・・?
[Ctrl] + [J]

でも、Delphi6Personalにはないのか?


蕎麦  2005-07-21 22:26:55  No: 16483

返答ありがとうございます。

ctrl+J は Personal にもあります。

今現在、テンプレートに、
begin
end;

というのは入れて使っていますが、もっとスマートに、例えば、ctrl+shift+[  で begin というようにダイレクトに入力したいのですが・・・


RAN  2005-07-22 06:43:35  No: 16484

テスト


Fusa  2005-07-22 09:28:20  No: 16485

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.


Fusa  2005-07-22 19:20:28  No: 16486

元は

Delphi@WCIMH
http://hp.vector.co.jp/authors/VA028375/delphi/setup.html

こちらのOpenToolsの所においてあった
ものだったと記憶してます...

いま、D2005UP3でインストールしてみたところ
Ctrl+[をおすと"begin"と入力されますね。


蕎麦  2005-07-22 20:26:39  No: 16487

出来ました!
ありがとうございます。

Delphi@WCIH  で見て、いいなぁ〜と思っていたんですが、ソースリンクが切れていて出来なかったんです。

パッケージの作成????
初めてで勝手もわからず、でしたがアッサリ動作しました!

OpenToolsAPIって、検索してもなかなかみつからないんですよね・・・


RAN  2005-07-24 03:48:05  No: 16488

どうでしょう?
http://onigiri.s3.xrea.com:8080/delphi/index.php?OpenToolsAPI


蕎麦  2005-07-27 02:50:47  No: 16489

RANさん、情報提供ありがとうございます。
難しそうですがみてみます。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加