我想自动检出一个文件,当我开始编辑它在Delphi 7 IDE。
ClearCase是我的版本控制系统,我真的讨厌需要检出一个文件,然后开始编辑。它总是打破我的思想流程:我试图解决一个问题,找到我需要改变,尝试编辑它,失败,因为文件是只读,打开清除,搜索文件,最后签出,尝试编辑文件,失败,因为IDE仍然认为它是readonly,告诉IDE不是readonly。当我终于回到代码,我忘了我在做什么。
我发现this nice and simple ClearCase IDE integration code.它的工作,但使用已弃用的ToolIntf单位。我添加了几个快捷方式。这里是它的简化版本(没有尝试编译):
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,True,CREATE_NEW_CONSOLE,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',[mfEnabled,mfVisible],nil); dcc.DoCheckOutPasDfm := dcc.ClearcaseMenu.InsertItem(2,'Check Out pas and dfm','DoCheckOutPasDfm','Undo the check outs',ShortCut(Ord('>'),[ssCtrl]),2,dcc.DoClick); dcc.DoCheckInPasDfm:= dcc.ClearcaseMenu.InsertItem(4,'Check In pas and dfm','DoCheckInPasDfm','Check in current files',ShortCut(Ord('<'),dcc.DoClick); end; procedure DestroyMenus; begin FreeAndNil(dcc); end; initialization CreateMenus; finalization DestroyMenus end.