使用Delphi Open Tools API将自己的项添加到Delphi IDE Insight(F6)

时间:2012-04-13 20:25:29

标签: delphi delphi-xe toolsapi

我想使用INTAIDEINsightService或许AddItemAddActionList向Delphi中的IDE洞察功能添加条目。

根据Delphi OTA wiki,INTAIDEINsightService允许您注册自己的操作。我能找到的唯一参考是here,它提到了API的名称,并且它完全存在。 Delphi中没有任何关于它的帮助。 Delphi XE中的ToolsAPI.pas单元在此界面中显示了两种方法,可用于注册操作:

function AddActionList(  Actions: TCustomActionList; ... ): Integer;
procedure RemoveActionList(const Index: Integer);

评论说“项目将显示为[描述|]类别| TCustomAction.Caption。不会显示未指定类别的包含操作。”。

我无法使用操作找到任何其他文档或示例。一个简单的“hello world”示例,其中一个动作,或者只是一个项目,在描述或类别“helloworld”中注册,然后可以搜索并在您点击F6时显示,这将是完美的,但是动作是首选。

看起来这样的向导必须实现INTAIDEInsightItem以便在IDE洞察中呈现自己,但我不确定这是否是“必需”的hello-world样本。我不确定你是否必须使用动作,或者常规的“项目”添加是否足够。

(我的最终目标是创建一个新的gExperts风格的专家“通过使用IDE洞察力按名称搜索我的库路径中的任何单元”但我会首先将单元名称添加到ide insight中一次。)

1 个答案:

答案 0 :(得分:9)

以下显示“命令”下的“Hello”类别:

IDE Insight screenshot

unit Unit1;

interface

uses
  SysUtils, Classes, ActnList, ImgList, Controls;

type
  TDataModule1 = class(TDataModule)
    ActionList1: TActionList;
    ImageList1: TImageList;
    ActionHello: TAction;
    procedure ActionHelloExecute(Sender: TObject);
  private
  public
  end;

var
  DataModule1: TDataModule1;

implementation

{$R *.dfm}

uses
  ToolsAPI, Dialogs;

procedure TDataModule1.ActionHelloExecute(Sender: TObject);
begin
  ShowMessage('Hello, world!');
end;

var
  Index: Integer = -1;

initialization
  DataModule1 := TDataModule1.Create(nil);
  Index := (BorlandIDEServices as INTAIDEInsightService).AddActionList(DataModule1.ActionList1);

finalization
  if Index <> -1 then
    (BorlandIDEServices as INTAIDEInsightService).RemoveActionList(Index);
  FreeAndNil(DataModule1);

end.

dfm只是一个带有动作列表,图像列表和动作的数据模块:

object DataModule1: TDataModule1
  OldCreateOrder = False
  Left = 218
  Top = 134
  Height = 215
  Width = 306
  object ActionList1: TActionList
    Images = ImageList1
    Left = 24
    Top = 16
    object ActionHello: TAction
      Category = 'Hello'
      Caption = 'Hello, World!'
      ImageIndex = 0
      OnExecute = ActionHelloExecute
    end
  end
  object ImageList1: TImageList
    Left = 88
    Top = 16
    Bitmap = {
      494C010101000C000C0010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
      0000000000003600000028000000400000001000000001002000000000000010
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000800080008000800086868600000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000008000800080008000FFFFFF00FFFFFF00C0C0C000868686000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000008000
      800080008000FFFFFF00FFFFFF000000000000000000C0C0C000C0C0C0008686
      8600000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000868686008000800080008000FFFF
      FF00FFFFFF000000000000000000800080008000800000000000C0C0C000C0C0
      C000868686000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000008686860080008000FFFFFF000000
      000000000000800080008000800080008000800080008000800000000000C0C0
      C000C0C0C0008686860000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000008686860000000000000000008000
      800080008000800080000080800000FFFF008000800080008000800080000000
      0000C0C0C000C0C0C00086868600000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000008686860080008000800080008000
      8000800080008000800080008000008080008000800080008000800080008000
      800000000000C0C0C00000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000080008000FFFFFF008000
      80008000800080008000800080008000800000FFFF0000FFFF00800080008000
      8000800080000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000000000000080008000FFFF
      FF0080008000800080008000800080008000800080000080800000FFFF0000FF
      FF00800080008000800000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000008000
      8000FFFFFF00800080008000800080008000008080008000800000FFFF0000FF
      FF00800080008000800080008000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000080008000FFFFFF00800080008000800000FFFF0000FFFF0000FFFF008000
      8000800080008000800000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000080008000FFFFFF00800080008000800080008000800080008000
      8000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000080008000FFFFFF008000800080008000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000800080008000800000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000424D3E000000000000003E000000
      2800000040000000100000000100010000000000800000000000000000000000
      000000000000000000000000FFFFFF00FFFF000000000000FE3F000000000000
      F81F000000000000E00F00000000000080070000000000000003000000000000
      0001000000000000000000000000000000010000000000008001000000000000
      C001000000000000E000000000000000F000000000000000F803000000000000
      FC0F000000000000FE3F00000000000000000000000000000000000000000000
      000000000000}
  end
end

此处,我将Description方法的可选参数CategoryAddActionList保留为默认的空字符串,最后为“命令”,并且值为来自操作列表的Category,但您可以指定自己的值,这些值将覆盖这些默认值。