如何在Delphi 7 IDE中将一个方法挂接到Edit事件? [英] How to hook a method to the Edit event in Delphi 7 IDE?

查看:190
本文介绍了如何在Delphi 7 IDE中将一个方法挂接到Edit事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我开始在 Delphi 7 IDE中编辑文件时,我想自动检出文件。

I'd like to automatically checkout a file when I start to edit it in Delphi 7 IDE.

ClearCase是我的版本控制系统,我真的很讨厌在开始编辑之前检出一个文件。它总是打破了我的思想流程:我正在尝试解决一个问题,找到我需要改变的地方,尝试编辑它,失败是因为文件是只读的,打开clearcase,搜索文件,终于checkout,尝试编辑再次出现文件失败,因为IDE仍然认为它是只读的,告诉IDE不是只读的。当我终于回到代码时,我忘记了我在做什么。

ClearCase is my version control system and I really hate the need to checkout a file before starting to edit. It always breaks my thought flow: I'm trying to solve a problem, find where I need to change, try to edit it, fail because the file is read only, open clearcase, search the file, finally checkout, try to edit the file again, fail because the IDE still thinks it is readonly, tell the IDE that isn't readonly. When I finally go back to code, I forgot what I was trying do do.

我发现这个漂亮简单的ClearCase IDE集成代码。它工作,但使用不推荐的ToolIntf单位。我已经添加了几个捷径。这是一个简化版本(没有尝试编译):

I've found this nice and simple ClearCase IDE integration code. It works, but uses the deprecated ToolIntf unit. I've added a couple of shortcuts. Here is a simplified version of it (didn't try to compile):

unit clearcase;

interface
uses ToolsApi, ToolIntf;

implementation
uses
  Windows, Dialogs, Classes, ExptIntf, Menus, ShellApi, SysUtils;

type
  TDelphiClearcase = class
  private
    FClearcaseMenu,
    FDoCheckOutPasDfm,
    FDoCheckInPasDfm : TIMenuItemIntf;

    procedure ExecCommand(const command: string; path: PChar = nil);
  public
    destructor Destroy;override;
    procedure DoClick(Sender: TIMenuItemIntf);
    property ClearcaseMenu: TIMenuItemIntf read FClearcaseMenu write FClearcaseMenu;
    property DoCheckOutPasDfm:TIMenuItemIntf write FDoCheckOutPasDfm;
    property DoCheckInPasDfm: TIMenuItemIntf write FDoCheckInPasDfm;
  end;

var
  dcc: TDelphiClearcase = nil;

{ TDelphiClearcase }

destructor TDelphiClearcase.Destroy;
  procedure Remove(item: TIMenuItemIntf);
  begin
    if( item = nil )then
      Exit;
    item.DestroyMenuItem;
    FreeAndNil(item);
  end;
begin
  Remove(FDoCheckOutPasDfm);
  Remove(FDoCheckInPasDfm);
  inherited;
end;

procedure TDelphiClearcase.DoClick(Sender: TIMenuItemIntf);
  function GetPasDfm(const f: string): string;
  var
    aux: string;
  begin
    aux := Copy(f, 1, Length(f) - 4);
    Result := aux + '.pas' + ' ' + aux + '.dfm'
  end;

var
  command, fileName  : string;
begin
  fileName := ToolServices.GetCurrentFile;

  if( Sender = FDoCheckOutPasDfm )then
    command := 'cleartool co ' + GetPasDfm(fileName)
  else if( Sender = FDoCheckInPasDfm )then
    command := 'cleartool ci ' + GetPasDfm(fileName);

  ExecCommand(command);

  ToolServices.ReloadFile(fileName);

end;

procedure TDelphiClearcase.ExecCommand(const command: string; path: PChar);
var
  pi  : TProcessInformation;
  stinfo : TStartupInfo;
begin
  FillChar(stinfo, SizeOf(stinfo), 0);
  stinfo.cb := SizeOf(stinfo);

  if( CreateProcess(nil, PChar(command), nil, nil, True, CREATE_NEW_CONSOLE,
      nil, path, stinfo, pi) )then begin
    WaitForSingleObject(pi.hProcess, INFINITE);
    CloseHandle(pi.hProcess)
  end
end;

procedure CreateMenus;
var
  services: TIToolServices;
begin
  if( BorlandIDEServices = nil )then
    Exit;
  services := ToolServices;

  if( services = nil )then
    Exit;

  dcc := TDelphiClearcase.Create;

  dcc.ClearcaseMenu := services.GetMainMenu.GetMenuItems.InsertItem(6,
    'C&learcase', 'ClearcaseMenu', 'ClearcaseTools', 0, 0, 0,
    [mfEnabled, mfVisible], nil);


  dcc.DoCheckOutPasDfm := dcc.ClearcaseMenu.InsertItem(2,
    'Check Out pas and dfm', 'DoCheckOutPasDfm', 'Undo the check outs', ShortCut(Ord('>'),
    [ssCtrl]), 0, 2,
    [mfEnabled, mfVisible], dcc.DoClick);
  dcc.DoCheckInPasDfm:= dcc.ClearcaseMenu.InsertItem(4,
    'Check In pas and dfm', 'DoCheckInPasDfm', 'Check in current files', ShortCut(Ord('<'),
    [ssCtrl]), 0, 2,
    [mfEnabled, mfVisible], dcc.DoClick);

end;

procedure DestroyMenus;
begin
  FreeAndNil(dcc);
end;

initialization
  CreateMenus;

finalization
  DestroyMenus
end.

当我第一次开始编辑文件时,我想要检出该文件,它是只读的。我不知道如何将函数挂钩到文件的IDE编辑事件。任何指针都是受欢迎的。

I'd like to checkout the file when I first start editing it and it is read only. I have no idea how to hook a function to the IDE edit event of a file. Any pointers are welcome.

推荐答案

替代API或类似操作是简单地使用快照视图,并使用Highjack 功能,然后只是在后来check'em。

Aternative to writing API or the like is to simply use snapshot views and automatically write files using "Highjack" functionality ...then just check'em in later.

这篇关于如何在Delphi 7 IDE中将一个方法挂接到Edit事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆