2006-01-07 19:56:40 +00:00
|
|
|
{: Connects UnitSwitcher to the IDE.
|
|
|
|
|
|
|
|
Last changed: $Date$
|
|
|
|
Revision: $Rev$
|
|
|
|
Author: $Author$
|
|
|
|
}
|
2006-01-05 06:03:24 +00:00
|
|
|
unit UnSwClient;
|
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
{$I BaseSwDefines.inc}
|
2006-01-06 08:11:17 +00:00
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
interface
|
|
|
|
uses
|
|
|
|
ActnList,
|
|
|
|
Classes,
|
|
|
|
Dialogs,
|
|
|
|
SysUtils,
|
|
|
|
ToolsAPI,
|
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
BaseSwClient,
|
2006-01-05 06:03:24 +00:00
|
|
|
UnSwDialog,
|
|
|
|
UnSwObjects;
|
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
type
|
2007-12-07 15:33:00 +00:00
|
|
|
TUnitSwitcherHook = class(TBaseSwitcherHook)
|
2006-01-05 06:03:24 +00:00
|
|
|
private
|
2007-12-07 15:33:00 +00:00
|
|
|
FViewFormAction: TContainedAction;
|
|
|
|
FViewUnitAction: TContainedAction;
|
2006-01-05 06:03:24 +00:00
|
|
|
protected
|
2006-01-05 21:04:59 +00:00
|
|
|
function ActiveFileName(): String;
|
2006-05-23 19:33:05 +00:00
|
|
|
{$IFDEF DELPHI7ORLOWER}
|
2006-01-06 08:11:17 +00:00
|
|
|
function ActiveGroup(): IOTAProjectGroup;
|
2006-01-06 20:39:08 +00:00
|
|
|
{$ENDIF}
|
2006-01-06 08:11:17 +00:00
|
|
|
function ActiveProject(): IOTAProject;
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
procedure NewExecute(Sender: TObject); virtual;
|
|
|
|
public
|
|
|
|
constructor Create();
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
implementation
|
|
|
|
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
{ TUnitSwitcherHook}
|
|
|
|
constructor TUnitSwitcherHook.Create();
|
|
|
|
begin
|
2007-12-07 15:33:00 +00:00
|
|
|
inherited;
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
try
|
2007-12-07 15:33:00 +00:00
|
|
|
{
|
2006-01-05 06:03:24 +00:00
|
|
|
Assert(Assigned(BorlandIDEServices), 'BorlandIDEServices not available.');
|
2006-01-07 19:56:40 +00:00
|
|
|
Assert(Supports(BorlandIDEServices, INTAServices, ntaServices),
|
2006-01-05 06:03:24 +00:00
|
|
|
'BorlandIDEServices does not support the ' +
|
|
|
|
'INTAServices interface.');
|
|
|
|
Assert(Supports(BorlandIDEServices, IOTAModuleServices),
|
|
|
|
'BorlandIDEServices does not support the ' +
|
|
|
|
'IOTAModuleServices interface.');
|
2006-01-06 08:11:17 +00:00
|
|
|
Assert(Supports(BorlandIDEServices, IOTAActionServices),
|
|
|
|
'BorlandIDEServices does not support the ' +
|
|
|
|
'IOTAActionServices interface.');
|
2007-12-07 15:33:00 +00:00
|
|
|
}
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
FViewFormAction := HookIDEAction('ViewFormCommand', NewExecute);
|
|
|
|
FViewUnitAction := HookIDEAction('ViewUnitCommand', NewExecute);
|
2006-01-05 06:03:24 +00:00
|
|
|
except
|
|
|
|
on E:EAssertionFailed do
|
|
|
|
ShowMessage('Error while loading UnitSwitcher: ' + E.Message);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
function TUnitSwitcherHook.ActiveFileName(): String;
|
|
|
|
var
|
2006-01-07 19:56:40 +00:00
|
|
|
module: IOTAModule;
|
2006-01-05 21:04:59 +00:00
|
|
|
|
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
Result := '';
|
|
|
|
module := (BorlandIDEServices as IOTAModuleServices).CurrentModule;
|
|
|
|
if Assigned(module) then
|
2006-01-05 21:04:59 +00:00
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
if Assigned(module.CurrentEditor) then
|
|
|
|
Result := module.FileName;
|
2006-01-05 21:04:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-05-23 19:33:05 +00:00
|
|
|
{$IFDEF DELPHI7ORLOWER}
|
2006-01-06 08:11:17 +00:00
|
|
|
function TUnitSwitcherHook.ActiveGroup(): IOTAProjectGroup;
|
|
|
|
var
|
2006-01-07 19:56:40 +00:00
|
|
|
module: IOTAModule;
|
|
|
|
moduleServices: IOTAModuleServices;
|
|
|
|
moduleIndex: Integer;
|
2006-01-06 08:11:17 +00:00
|
|
|
|
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
Result := nil;
|
|
|
|
moduleServices := (BorlandIDEServices as IOTAModuleServices);
|
|
|
|
for moduleIndex := 0 to Pred(moduleServices.ModuleCount) do
|
2006-01-06 08:11:17 +00:00
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
module := moduleServices.Modules[moduleIndex];
|
|
|
|
if Supports(module, IOTAProjectGroup, Result) then
|
2006-01-06 08:11:17 +00:00
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
2006-01-06 20:39:08 +00:00
|
|
|
{$ENDIF}
|
2006-01-06 08:11:17 +00:00
|
|
|
|
|
|
|
function TUnitSwitcherHook.ActiveProject(): IOTAProject;
|
2006-05-23 19:33:05 +00:00
|
|
|
{$IFDEF DELPHI7ORLOWER}
|
2006-01-06 08:11:17 +00:00
|
|
|
var
|
2006-01-07 19:56:40 +00:00
|
|
|
projectGroup: IOTAProjectGroup;
|
|
|
|
module: IOTAModule;
|
|
|
|
moduleServices: IOTAModuleServices;
|
|
|
|
moduleIndex: Integer;
|
2006-01-06 08:11:17 +00:00
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
begin
|
2006-05-23 19:33:05 +00:00
|
|
|
{$IFDEF DELPHI7ORLOWER}
|
2006-01-07 19:56:40 +00:00
|
|
|
Result := nil;
|
|
|
|
projectGroup := ActiveGroup();
|
|
|
|
if not Assigned(projectGroup) then
|
2006-01-06 08:11:17 +00:00
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
moduleServices := (BorlandIDEServices as IOTAModuleServices);
|
|
|
|
for moduleIndex := 0 to Pred(moduleServices.ModuleCount) do
|
2006-01-06 08:11:17 +00:00
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
module := moduleServices.Modules[moduleIndex];
|
|
|
|
if Supports(module, IOTAProject, Result) then
|
2006-01-06 08:11:17 +00:00
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end else
|
2006-01-07 19:56:40 +00:00
|
|
|
Result := projectGroup.ActiveProject;
|
2006-01-06 08:11:17 +00:00
|
|
|
{$ELSE}
|
2006-01-07 19:56:40 +00:00
|
|
|
Result := (BorlandIDEServices as IOTAModuleServices).GetActiveProject();
|
2006-01-06 08:11:17 +00:00
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
procedure TUnitSwitcherHook.NewExecute(Sender: TObject);
|
|
|
|
var
|
2006-01-07 19:56:40 +00:00
|
|
|
activeIndex: Integer;
|
|
|
|
activeUnit: TUnSwUnit;
|
2006-01-09 19:24:56 +00:00
|
|
|
itemIndex: Integer;
|
|
|
|
moduleIndex: Integer;
|
|
|
|
project: IOTAProject;
|
|
|
|
selectedUnits: TUnSwUnitList;
|
2006-01-07 19:56:40 +00:00
|
|
|
unitList: TUnSwUnitList;
|
2007-02-16 17:19:22 +00:00
|
|
|
openDFM: Boolean;
|
|
|
|
openType: TUnSwActivateType;
|
|
|
|
fileName: string;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
project := ActiveProject();
|
|
|
|
if not Assigned(project) then
|
2006-01-05 06:03:24 +00:00
|
|
|
exit;
|
|
|
|
|
2006-01-07 19:56:40 +00:00
|
|
|
unitList := TUnSwUnitList.Create();
|
2006-01-05 06:03:24 +00:00
|
|
|
try
|
2006-01-07 19:56:40 +00:00
|
|
|
unitList.Add(TUnSwProjectUnit.Create(project));
|
2006-01-05 21:04:59 +00:00
|
|
|
|
2006-01-07 19:56:40 +00:00
|
|
|
for moduleIndex := 0 to Pred(project.GetModuleCount) do
|
|
|
|
unitList.Add(TUnSwModuleUnit.Create(project.GetModule(moduleIndex)));
|
2006-01-05 21:04:59 +00:00
|
|
|
|
2006-01-07 19:56:40 +00:00
|
|
|
activeUnit := nil;
|
2007-02-16 17:19:22 +00:00
|
|
|
fileName := ActiveFileName();
|
|
|
|
|
|
|
|
if SameText(ExtractFileExt(fileName), '.dfm') then
|
|
|
|
fileName := ChangeFileExt(fileName, '.pas');
|
|
|
|
|
|
|
|
activeIndex := unitList.IndexOfFileName(fileName);
|
2006-01-07 19:56:40 +00:00
|
|
|
if activeIndex > -1 then
|
|
|
|
activeUnit := unitList[activeIndex];
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-09 19:24:56 +00:00
|
|
|
selectedUnits := TfrmUnSwDialog.Execute(unitList, (Sender = FViewFormAction),
|
2007-02-16 17:19:22 +00:00
|
|
|
openDFM, activeUnit);
|
2006-01-09 19:24:56 +00:00
|
|
|
if Assigned(selectedUnits) then
|
|
|
|
try
|
2007-02-16 17:19:22 +00:00
|
|
|
openType := atSource;
|
|
|
|
if openDFM then
|
|
|
|
openType := atDFM
|
|
|
|
else if Sender = FViewFormAction then
|
|
|
|
openType := atForm;
|
|
|
|
|
2006-01-09 19:24:56 +00:00
|
|
|
for itemIndex := 0 to Pred(selectedUnits.Count) do
|
2007-02-16 17:19:22 +00:00
|
|
|
selectedUnits[itemIndex].Activate(openType);
|
2006-01-09 19:24:56 +00:00
|
|
|
finally
|
|
|
|
FreeAndNil(selectedUnits);
|
|
|
|
end;
|
2006-01-05 06:03:24 +00:00
|
|
|
finally
|
2006-01-07 19:56:40 +00:00
|
|
|
FreeAndNil(unitList);
|
2006-01-05 06:03:24 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|