2006-01-07 19:56:40 +00:00
|
|
|
{: Implements unit handling.
|
|
|
|
|
|
|
|
Last changed: $Date$
|
|
|
|
Revision: $Rev$
|
|
|
|
Author: $Author$
|
|
|
|
}
|
2006-01-05 06:03:24 +00:00
|
|
|
unit UnSwObjects;
|
|
|
|
|
2006-01-06 20:39:08 +00:00
|
|
|
{$I UnSwDefines.inc}
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes,
|
|
|
|
Contnrs,
|
|
|
|
ToolsAPI;
|
|
|
|
|
|
|
|
type
|
|
|
|
// Forward declarations
|
2006-01-05 21:04:59 +00:00
|
|
|
TUnSwUnit = class;
|
|
|
|
TUnSwModuleUnit = class;
|
|
|
|
TUnSwProjectUnit = class;
|
|
|
|
|
|
|
|
|
|
|
|
IUnSwVisitor = interface
|
|
|
|
['{A822C25B-5D0F-462F-94DD-47CD6235D79F}']
|
|
|
|
procedure VisitModule(const AUnit: TUnSwModuleUnit);
|
|
|
|
procedure VisitProject(const AUnit: TUnSwProjectUnit);
|
|
|
|
end;
|
|
|
|
|
|
|
|
IUnSwVisited = interface
|
|
|
|
['{9540671E-184B-4DB6-A015-27B457C74C6C}']
|
|
|
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor);
|
|
|
|
end;
|
|
|
|
|
2006-01-06 08:11:17 +00:00
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
TUnSwNoRefIntfObject = class(TPersistent, IInterface)
|
|
|
|
protected
|
|
|
|
// IInterface
|
|
|
|
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
|
|
|
|
function _AddRef(): Integer; stdcall;
|
|
|
|
function _Release(): Integer; stdcall;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TUnSwUnit = class(TUnSwNoRefIntfObject, IUnSwVisited)
|
|
|
|
protected
|
|
|
|
function GetName(): String; virtual;
|
|
|
|
function GetFileName(): String; virtual;
|
2006-01-06 08:11:17 +00:00
|
|
|
|
2006-01-06 20:39:08 +00:00
|
|
|
procedure OpenModule(const AModule: IOTAModule; const ASource: Boolean); virtual;
|
2006-01-05 21:04:59 +00:00
|
|
|
public
|
|
|
|
// IUnSwVisited
|
|
|
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor); virtual; abstract;
|
|
|
|
|
|
|
|
procedure Activate(const ASource: Boolean); virtual; abstract;
|
|
|
|
|
|
|
|
property Name: String read GetName;
|
|
|
|
property FileName: String read GetFileName;
|
|
|
|
end;
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
TUnSwUnitType = (
|
|
|
|
swutForm = 0,
|
|
|
|
swutDataModule = 1,
|
|
|
|
swutProjUnit = 2,
|
|
|
|
swutUnit = 3,
|
|
|
|
swutRc = 4,
|
|
|
|
swutAsm = 5,
|
|
|
|
swutDef = 6,
|
|
|
|
swutObj = 7,
|
|
|
|
swutRes = 8,
|
|
|
|
swutLib = 9,
|
|
|
|
swutTypeLib = 10,
|
|
|
|
swutPackageImport = 11,
|
|
|
|
swutFormResource = 12,
|
|
|
|
swutCustom = 13,
|
|
|
|
swutIDL = 14
|
|
|
|
);
|
|
|
|
TUnSwUnitTypes = set of TUnSwUnitType;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
|
|
|
|
TUnSwModuleUnit = class(TUnSwUnit)
|
2006-01-05 06:03:24 +00:00
|
|
|
private
|
|
|
|
FModule: IOTAModuleInfo;
|
2006-01-05 21:04:59 +00:00
|
|
|
protected
|
|
|
|
function GetFileName(): String; override;
|
2006-01-06 05:57:45 +00:00
|
|
|
function GetFormName(): String;
|
|
|
|
function GetName(): String; override;
|
2006-01-05 06:03:24 +00:00
|
|
|
function GetUnitType(): TUnSwUnitType;
|
|
|
|
public
|
2006-01-05 21:04:59 +00:00
|
|
|
constructor Create(const AModule: IOTAModuleInfo);
|
|
|
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor); override;
|
|
|
|
|
|
|
|
procedure Activate(const ASource: Boolean); override;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-06 05:57:45 +00:00
|
|
|
property FormName: String read GetFormName;
|
2006-01-05 06:03:24 +00:00
|
|
|
property UnitType: TUnSwUnitType read GetUnitType;
|
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
TUnSwProjectUnit = class(TUnSwUnit)
|
|
|
|
private
|
|
|
|
FProject: IOTAProject;
|
|
|
|
protected
|
|
|
|
function GetName(): String; override;
|
|
|
|
function GetFileName(): String; override;
|
|
|
|
public
|
|
|
|
constructor Create(const AProject: IOTAProject);
|
|
|
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor); override;
|
|
|
|
|
|
|
|
procedure Activate(const ASource: Boolean); override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TUnSwUnitList = class(TUnSwNoRefIntfObject, IUnSwVisited)
|
2006-01-05 06:03:24 +00:00
|
|
|
private
|
|
|
|
FItems: TObjectList;
|
|
|
|
|
2006-01-09 19:24:56 +00:00
|
|
|
function GetOwnsObjects(): Boolean;
|
|
|
|
procedure SetOwnsObjects(const Value: Boolean);
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
function GetCount(): Integer;
|
|
|
|
function GetItem(Index: Integer): TUnSwUnit;
|
|
|
|
procedure SetItem(Index: Integer; Value: TUnSwUnit);
|
|
|
|
public
|
|
|
|
constructor Create();
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
|
|
|
function Add(const AUnit: TUnSwUnit): Integer; virtual;
|
|
|
|
function IndexOf(const AUnit: TUnSwUnit): Integer;
|
2006-01-05 21:04:59 +00:00
|
|
|
function IndexOfFileName(const AFileName: String): Integer;
|
|
|
|
procedure Delete(const AIndex: Integer);
|
|
|
|
function Remove(const AUnit: TUnSwUnit): Integer;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
procedure Sort(Compare: TListSortCompare);
|
2006-01-05 06:03:24 +00:00
|
|
|
procedure Clone(const ASource: TUnSwUnitList); virtual;
|
2006-01-05 21:04:59 +00:00
|
|
|
|
|
|
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor);
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
property Count: Integer read GetCount;
|
|
|
|
property Items[Index: Integer]: TUnSwUnit read GetItem
|
|
|
|
write SetItem; default;
|
2006-01-09 19:24:56 +00:00
|
|
|
property OwnsObjects: Boolean read GetOwnsObjects
|
|
|
|
write SetOwnsObjects;
|
2006-01-05 06:03:24 +00:00
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
implementation
|
|
|
|
uses
|
2006-05-23 19:33:05 +00:00
|
|
|
{$IFDEF DELPHI7ORLOWER}
|
2006-01-07 19:56:40 +00:00
|
|
|
ActnList,
|
|
|
|
{$ENDIF}
|
2006-01-05 21:04:59 +00:00
|
|
|
SysUtils;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
{ TUnSwNoRefIntfObject }
|
|
|
|
function TUnSwNoRefIntfObject.QueryInterface(const IID: TGUID; out Obj): HResult;
|
|
|
|
begin
|
|
|
|
if GetInterface(IID, Obj) then
|
|
|
|
Result := S_OK
|
|
|
|
else
|
|
|
|
Result := E_NOINTERFACE;
|
|
|
|
end;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
function TUnSwNoRefIntfObject._AddRef(): Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
end;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
function TUnSwNoRefIntfObject._Release(): Integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
end;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
{ TUnSwUnit }
|
2006-01-05 21:04:59 +00:00
|
|
|
function TUnSwUnit.GetName(): String;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TUnSwUnit.GetFileName(): String;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-01-06 20:39:08 +00:00
|
|
|
procedure TUnSwUnit.OpenModule(const AModule: IOTAModule; const ASource: Boolean);
|
|
|
|
var
|
2006-01-07 19:56:40 +00:00
|
|
|
editor: IOTAEditor;
|
|
|
|
formEditor: IOTAFormEditor;
|
2006-01-09 19:24:56 +00:00
|
|
|
isForm: Boolean;
|
2006-01-07 19:56:40 +00:00
|
|
|
moduleIndex: Integer;
|
2006-01-06 20:39:08 +00:00
|
|
|
|
2006-01-06 08:11:17 +00:00
|
|
|
begin
|
2006-01-09 19:24:56 +00:00
|
|
|
formEditor := nil;
|
2006-01-07 19:56:40 +00:00
|
|
|
for moduleIndex := 0 to Pred(AModule.ModuleFileCount) do
|
|
|
|
begin
|
|
|
|
editor := AModule.ModuleFileEditors[moduleIndex];
|
2006-01-09 19:24:56 +00:00
|
|
|
isForm := Supports(editor, IOTAFormEditor);
|
2006-01-07 19:56:40 +00:00
|
|
|
|
2006-01-09 19:24:56 +00:00
|
|
|
if (not ASource) and (isForm) and (not Assigned(formEditor)) then
|
|
|
|
formEditor := (editor as IOTAFormEditor);
|
|
|
|
|
|
|
|
if not isForm then
|
2006-01-07 19:56:40 +00:00
|
|
|
editor.Show();
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Assigned(formEditor) then
|
|
|
|
formEditor.Show();
|
2006-01-06 08:11:17 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
{ TUnSwModuleUnit }
|
|
|
|
constructor TUnSwModuleUnit.Create(const AModule: IOTAModuleInfo);
|
2006-01-05 06:03:24 +00:00
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
|
|
|
|
FModule := AModule;
|
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
procedure TUnSwModuleUnit.Activate(const ASource: Boolean);
|
|
|
|
var
|
|
|
|
ifModule: IOTAModule;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
begin
|
|
|
|
ifModule := FModule.OpenModule();
|
|
|
|
if Assigned(ifModule) then
|
2006-01-06 20:39:08 +00:00
|
|
|
OpenModule(ifModule, ASource);
|
2006-01-05 21:04:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TUnSwModuleUnit.AcceptVisitor(const AVisitor: IUnSwVisitor);
|
|
|
|
begin
|
|
|
|
AVisitor.VisitModule(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TUnSwModuleUnit.GetName(): String;
|
2006-01-05 06:03:24 +00:00
|
|
|
begin
|
|
|
|
Result := FModule.Name;
|
|
|
|
end;
|
|
|
|
|
2006-01-06 05:57:45 +00:00
|
|
|
function TUnSwModuleUnit.GetFormName(): String;
|
|
|
|
begin
|
|
|
|
Result := FModule.FormName;
|
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
function TUnSwModuleUnit.GetFileName(): String;
|
2006-01-05 06:03:24 +00:00
|
|
|
begin
|
|
|
|
Result := FModule.FileName;
|
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
function TUnSwModuleUnit.GetUnitType(): TUnSwUnitType;
|
2006-01-05 06:03:24 +00:00
|
|
|
begin
|
|
|
|
Result := TUnSwUnitType(FModule.ModuleType);
|
2006-01-05 21:22:02 +00:00
|
|
|
|
|
|
|
if Result = swutForm then
|
2006-01-06 20:39:08 +00:00
|
|
|
if SameText(FModule.DesignClass, 'TDataModule') then
|
|
|
|
Result := swutDataModule
|
|
|
|
else if Length(FModule.FormName) = 0 then
|
2006-01-05 21:22:02 +00:00
|
|
|
if Length(FModule.FileName) = 0 then
|
|
|
|
Result := swutProjUnit
|
|
|
|
else
|
|
|
|
Result := swutUnit;
|
2006-01-05 06:03:24 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
{ TUnSwProjectUnit }
|
|
|
|
constructor TUnSwProjectUnit.Create(const AProject: IOTAProject);
|
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
|
|
|
|
FProject := AProject;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TUnSwProjectUnit.Activate(const ASource: Boolean);
|
2006-05-23 19:33:05 +00:00
|
|
|
{$IFDEF DELPHI7ORLOWER}
|
2006-01-07 19:56:40 +00:00
|
|
|
var
|
|
|
|
actionIndex: Integer;
|
|
|
|
ntaServices: INTAServices;
|
|
|
|
action: TContainedAction;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
begin
|
2006-05-23 19:33:05 +00:00
|
|
|
{$IFDEF DELPHI7ORLOWER}
|
2006-01-07 19:56:40 +00:00
|
|
|
// Bit of a hack, but opening the file itself will result in Delphi 7
|
|
|
|
// reloading the project...
|
|
|
|
ntaServices := (BorlandIDEServices as INTAServices);
|
|
|
|
for actionIndex := 0 to Pred(ntaServices.ActionList.ActionCount) do
|
|
|
|
begin
|
|
|
|
action := ntaServices.ActionList.Actions[actionIndex];
|
|
|
|
if action.Name = 'ProjectViewSourceCommand' then
|
|
|
|
begin
|
|
|
|
action.Execute();
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{$ELSE}
|
|
|
|
OpenModule(FProject, True);
|
|
|
|
{$ENDIF}
|
2006-01-05 21:04:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TUnSwProjectUnit.AcceptVisitor(const AVisitor: IUnSwVisitor);
|
|
|
|
begin
|
|
|
|
AVisitor.VisitProject(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TUnSwProjectUnit.GetName(): String;
|
|
|
|
begin
|
|
|
|
Result := ChangeFileExt(ExtractFileName(FProject.FileName), '');
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TUnSwProjectUnit.GetFileName(): String;
|
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
Result := FProject.FileName;
|
2006-01-05 21:04:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
{ TUnSwUnitList}
|
|
|
|
constructor TUnSwUnitList.Create();
|
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
|
|
|
|
FItems := TObjectList.Create(True);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TUnSwUnitList.Destroy();
|
|
|
|
begin
|
|
|
|
FreeAndNil(FItems);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
procedure TUnSwUnitList.AcceptVisitor(const AVisitor: IUnSwVisitor);
|
|
|
|
var
|
2006-01-07 19:56:40 +00:00
|
|
|
itemIndex: Integer;
|
2006-01-05 21:04:59 +00:00
|
|
|
|
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
for itemIndex := Pred(Count) downto 0 do
|
|
|
|
Items[itemIndex].AcceptVisitor(AVisitor);
|
2006-01-05 21:04:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
function TUnSwUnitList.Add(const AUnit: TUnSwUnit): Integer;
|
|
|
|
begin
|
|
|
|
Result := FItems.Add(AUnit);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TUnSwUnitList.IndexOf(const AUnit: TUnSwUnit): Integer;
|
|
|
|
begin
|
|
|
|
Result := FItems.IndexOf(AUnit);
|
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
function TUnSwUnitList.IndexOfFileName(const AFileName: String): Integer;
|
|
|
|
var
|
2006-01-07 19:56:40 +00:00
|
|
|
itemIndex: Integer;
|
2006-01-05 21:04:59 +00:00
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
begin
|
2006-01-05 21:04:59 +00:00
|
|
|
Result := -1;
|
|
|
|
if Length(AFileName) = 0 then
|
|
|
|
exit;
|
|
|
|
|
2006-01-07 19:56:40 +00:00
|
|
|
for itemIndex := Pred(Count) downto 0 do
|
|
|
|
if SameText(Items[itemIndex].FileName, AFileName) then
|
2006-01-05 21:04:59 +00:00
|
|
|
begin
|
2006-01-07 19:56:40 +00:00
|
|
|
Result := itemIndex;
|
2006-01-05 21:04:59 +00:00
|
|
|
break;
|
|
|
|
end;
|
2006-01-05 06:03:24 +00:00
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
procedure TUnSwUnitList.Delete(const AIndex: Integer);
|
|
|
|
begin
|
|
|
|
FItems.Delete(AIndex);
|
|
|
|
end;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
function TUnSwUnitList.Remove(const AUnit: TUnSwUnit): Integer;
|
|
|
|
begin
|
|
|
|
Result := FItems.Remove(AUnit);
|
|
|
|
end;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
procedure TUnSwUnitList.Sort(Compare: TListSortCompare);
|
2006-01-05 06:03:24 +00:00
|
|
|
begin
|
2006-01-05 21:04:59 +00:00
|
|
|
FItems.Sort(Compare);
|
2006-01-05 06:03:24 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TUnSwUnitList.Clone(const ASource: TUnSwUnitList);
|
|
|
|
var
|
2006-01-07 19:56:40 +00:00
|
|
|
itemIndex: Integer;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
FItems.Clear();
|
|
|
|
FItems.OwnsObjects := False;
|
|
|
|
|
2006-01-07 19:56:40 +00:00
|
|
|
for itemIndex := 0 to Pred(ASource.Count) do
|
|
|
|
FItems.Add(ASource[itemIndex]);
|
2006-01-05 06:03:24 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TUnSwUnitList.GetCount(): Integer;
|
|
|
|
begin
|
|
|
|
Result := FItems.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TUnSwUnitList.GetItem(Index: Integer): TUnSwUnit;
|
|
|
|
begin
|
|
|
|
Result := TUnSwUnit(FItems[Index]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TUnSwUnitList.SetItem(Index: Integer; Value: TUnSwUnit);
|
|
|
|
begin
|
|
|
|
FItems[Index] := Value;
|
|
|
|
end;
|
|
|
|
|
2006-01-09 19:24:56 +00:00
|
|
|
function TUnSwUnitList.GetOwnsObjects(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := FItems.OwnsObjects;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TUnSwUnitList.SetOwnsObjects(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
FItems.OwnsObjects := Value;
|
|
|
|
end;
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
end.
|