IDEIntf: using TIDEOwnedFile as common ancestor of TLazPackageFile and TLazProjectFile

git-svn-id: trunk@45596 -
This commit is contained in:
mattias 2014-06-21 20:57:14 +00:00
parent 4171928dd9
commit 95e940dff4
6 changed files with 189 additions and 53 deletions

View File

@ -74,27 +74,35 @@ type
TIDEPackage = class;
{$M+}
TIDEOwnedFile = class
protected
function GetFilename: string; virtual; abstract;
procedure SetFilename(const AValue: string); virtual; abstract;
public
function GetFullFilename: string; virtual; abstract; // if no path, the file was not saved yet
function GetShortFilename(UseUp: boolean): string; virtual; abstract;
function GetFileOwner: TObject; virtual; abstract;
function GetFileOwnerName: string; virtual; abstract;
property Filename: string read GetFilename write SetFilename;
end;
{$M-}
{ TLazPackageFile }
TLazPackageFile = class
TLazPackageFile = class(TIDEOwnedFile)
private
FDisableI18NForLFM: boolean;
FFilename: string;
FFileType: TPkgFileType;
FRemoved: boolean;
protected
function GetInUses: boolean; virtual; abstract;
procedure SetInUses(AValue: boolean); virtual; abstract;
procedure SetFilename(const AValue: string); virtual;
function GetIDEPackage: TIDEPackage; virtual; abstract;
procedure SetRemoved(const AValue: boolean); virtual;
procedure SetDisableI18NForLFM(AValue: boolean); virtual;
procedure SetFileType(const AValue: TPkgFileType); virtual;
public
function GetFullFilename: string; virtual; abstract;
function GetShortFilename(UseUp: boolean): string; virtual; abstract;
public
property Filename: string read FFilename write SetFilename; // can contain macros
property LazPackage: TIDEPackage read GetIDEPackage;
property Removed: boolean read FRemoved write SetRemoved;
property DisableI18NForLFM: boolean read FDisableI18NForLFM write SetDisableI18NForLFM;
@ -800,11 +808,6 @@ begin
FFileType:=AValue;
end;
procedure TLazPackageFile.SetFilename(const AValue: string);
begin
FFilename:=AValue;
end;
procedure TLazPackageFile.SetRemoved(const AValue: boolean);
begin
FRemoved:=AValue;

View File

@ -17,7 +17,7 @@ interface
uses
Classes, SysUtils, LCLProc, FileUtil, Controls, Forms, AvgLvlTree,
NewItemIntf, ObjInspStrConsts, IDEOptionsIntf, CompOptsIntf;
NewItemIntf, ObjInspStrConsts, IDEOptionsIntf, CompOptsIntf, PackageIntf;
const
FileDescGroupName = 'File';
@ -47,14 +47,12 @@ type
{ TLazProjectFile }
TLazProjectFile = class(TPersistent)
TLazProjectFile = class(TIDEOwnedFile)
private
FCustomData: TStringToStringTree;
FCustomSessionData: TStringToStringTree;
FIsPartOfProject: boolean;
protected
function GetFilename: string; virtual; abstract;
procedure SetFilename(const AValue: string); virtual; abstract;
procedure SetIsPartOfProject(const AValue: boolean); virtual;
public
constructor Create;
@ -65,9 +63,8 @@ type
public
property IsPartOfProject: boolean read FIsPartOfProject
write SetIsPartOfProject;
property Filename: string read GetFilename write SetFilename;
property CustomData: TStringToStringTree read FCustomData;
property CustomSessionData: TStringToStringTree read FCustomSessionData;
property CustomData: TStringToStringTree read FCustomData; // name,value pairs
property CustomSessionData: TStringToStringTree read FCustomSessionData; // name,value pairs
end;
TLazProjectFileClass = class of TLazProjectFile;

View File

@ -267,7 +267,7 @@ type
FComponentLastLFMStreamSize: TStreamSeekType;
FComponentLastLRSStreamSize: TStreamSeekType;
FDirectives: TStrings;
fFileName: string;
fFileName: string; // with path = saved, without path = not yet saved
fFileReadOnly: Boolean;
FFirstRequiredComponent: TUnitComponentDependency;
FFirstUsedByComponent: TUnitComponentDependency;
@ -341,6 +341,8 @@ type
public
constructor Create(ACodeBuffer: TCodeBuffer);
destructor Destroy; override;
function GetFileOwner: TObject; override;
function GetFileOwnerName: string; override;
function ChangedOnDisk(CompareOnlyLoadSaveTime: boolean): boolean;
function IsAutoRevertLocked: boolean;
@ -348,7 +350,8 @@ type
function IsMainUnit: boolean;
function IsVirtual: boolean;
function GetDirectory: string;
function GetShortFilename(UseUp: boolean): string;
function GetFullFilename: string; override;
function GetShortFilename(UseUp: boolean): string; override;
function NeedsSaveToDisk: boolean;
function ReadOnly: boolean;
function ReadUnitSource(ReadUnitName,Revert:boolean): TModalResult;
@ -1526,6 +1529,19 @@ begin
inherited Destroy;
end;
function TUnitInfo.GetFileOwner: TObject;
begin
Result:=Project;
end;
function TUnitInfo.GetFileOwnerName: string;
begin
if Project<>nil then
Result:=ExtractFilename(Project.ProjectInfoFile)
else
Result:='';
end;
{------------------------------------------------------------------------------
TUnitInfo WriteUnitSource
------------------------------------------------------------------------------}
@ -2021,6 +2037,13 @@ begin
end;
end;
function TUnitInfo.GetFullFilename: string;
begin
Result:=fFilename;
// not saved files have file names without path
// they exist in the Codetools filename space
end;
function TUnitInfo.GetShortFilename(UseUp: boolean): string;
begin
if Project<>nil then

View File

@ -31,11 +31,6 @@
TProjectInspectorForm is the form of the project inspector.
ToDo:
- drop files
- multi select
- popup menu
- delete files
- delete deps
- dnd move
- project groups:
- activate
@ -69,7 +64,7 @@ uses
PackageIntf,
// IDE
LazarusIDEStrConsts, IDEProcs, DialogProcs, IDEOptionDefs, EnvironmentOpts,
PackageDefs, Project, PackageEditor, AddToProjectDlg;
PackageDefs, Project, MainIntf, PackageEditor, AddToProjectDlg;
type
TOnAddUnitToProject =
@ -91,7 +86,7 @@ type
{ TProjectInspectorForm }
TProjectInspectorForm = class(TForm)
TProjectInspectorForm = class(TForm,IFilesEditorInterface)
BtnPanel: TPanel;
DirectoryHierarchyButton: TSpeedButton;
FilterEdit: TTreeFilterEdit;
@ -149,8 +144,8 @@ type
FLazProject: TProject;
FFilesNode: TTreeNode;
FNextSelectedPart: TObject;// select this file/dependency on next update
DependenciesNode: TTreeNode;
RemovedDependenciesNode: TTreeNode;
FDependenciesNode: TTreeNode;
FRemovedDependenciesNode: TTreeNode;
ImageIndexFiles: integer;
ImageIndexRequired: integer;
ImageIndexConflict: integer;
@ -165,10 +160,6 @@ type
FProjectNodeDataList : array [TPENodeType] of TPENodeData;
procedure FreeNodeData(Typ: TPENodeType);
function CreateNodeData(Typ: TPENodeType; aName: string; aRemoved: boolean): TPENodeData;
function GetNodeData(TVNode: TTreeNode): TPENodeData;
function GetNodeItem(NodeData: TPENodeData): TObject;
function GetNodeDataItem(TVNode: TTreeNode; out NodeData: TPENodeData;
out Item: TObject): boolean;
procedure SetDependencyDefaultFilename(AsPreferred: boolean);
procedure SetIdleConnected(AValue: boolean);
procedure SetLazProject(const AValue: TProject);
@ -185,10 +176,7 @@ type
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure BeginUpdate;
procedure EndUpdate;
function IsUpdateLocked: boolean; inline;
procedure UpdateAll(Immediately: boolean = false);
procedure UpdateTitle(Immediately: boolean = false);
procedure UpdateProjectFiles(Immediately: boolean = false);
procedure UpdateRequiredPackages(Immediately: boolean = false);
@ -197,6 +185,28 @@ type
function CanUpdate(Flag: TProjectInspectorFlag): boolean;
function GetSingleSelectedDependency: TPkgDependency;
function TreeViewToInspector(TV: TTreeView): TProjectInspectorForm;
public
// IFilesEditorInterface
procedure BeginUpdate;
procedure EndUpdate;
procedure UpdateAll(Immediately: boolean = false);
function GetNodeData(TVNode: TTreeNode): TPENodeData;
function GetNodeItem(NodeData: TPENodeData): TObject;
function GetNodeDataItem(TVNode: TTreeNode; out NodeData: TPENodeData;
out Item: TObject): boolean;
function ExtendIncSearchPath(NewIncPaths: string): boolean;
function ExtendUnitSearchPath(NewUnitPaths: string): boolean;
function FilesBaseDirectory: string;
function FilesEditForm: TCustomForm;
function FilesEditTreeView: TTreeView;
function FilesOwner: TObject;
function FilesOwnerName: string;
function FilesOwnerReadOnly: boolean;
function FirstRequiredDependency: TPkgDependency;
function GetNodeFilename(Node: TTreeNode): string;
function IsDirectoryNode(Node: TTreeNode): boolean;
function TVNodeFiles: TTreeNode;
function TVNodeRequiredPackages: TTreeNode;
public
property LazProject: TProject read FLazProject write SetLazProject;
property OnShowOptions: TNotifyEvent read FOnShowOptions write FOnShowOptions;
@ -235,6 +245,16 @@ begin
Result:=FUpdateLock>0;
end;
function TProjectInspectorForm.TVNodeFiles: TTreeNode;
begin
Result:=FFilesNode;
end;
function TProjectInspectorForm.TVNodeRequiredPackages: TTreeNode;
begin
Result:=FDependenciesNode;
end;
procedure TProjectInspectorForm.ItemsTreeViewDblClick(Sender: TObject);
begin
OpenButtonClick(Self);
@ -900,9 +920,9 @@ begin
FFilesNode:=Items.Add(nil, dlgEnvFiles);
FFilesNode.ImageIndex:=ImageIndexFiles;
FFilesNode.SelectedIndex:=FFilesNode.ImageIndex;
DependenciesNode:=Items.Add(nil, lisPckEditRequiredPackages);
DependenciesNode.ImageIndex:=ImageIndexRequired;
DependenciesNode.SelectedIndex:=DependenciesNode.ImageIndex;
FDependenciesNode:=Items.Add(nil, lisPckEditRequiredPackages);
FDependenciesNode.ImageIndex:=ImageIndexRequired;
FDependenciesNode.SelectedIndex:=FDependenciesNode.ImageIndex;
end;
end;
@ -982,7 +1002,7 @@ begin
if not CanUpdate(pifNeedUpdateDependencies) then exit;
ItemsTreeView.BeginUpdate;
try
RequiredBranch:=FilterEdit.GetBranch(DependenciesNode);
RequiredBranch:=FilterEdit.GetBranch(FDependenciesNode);
RequiredBranch.Clear;
FreeNodeData(penDependency);
Dependency:=Nil;
@ -1009,13 +1029,13 @@ begin
Dependency:=LazProject.FirstRemovedDependency;
if Dependency<>nil then begin
// Create root node for removed dependencies if not done yet.
if RemovedDependenciesNode=nil then begin
RemovedDependenciesNode:=ItemsTreeView.Items.Add(DependenciesNode,
if FRemovedDependenciesNode=nil then begin
FRemovedDependenciesNode:=ItemsTreeView.Items.Add(FDependenciesNode,
lisProjInspRemovedRequiredPackages);
RemovedDependenciesNode.ImageIndex:=ImageIndexRemovedRequired;
RemovedDependenciesNode.SelectedIndex:=RemovedDependenciesNode.ImageIndex;
FRemovedDependenciesNode.ImageIndex:=ImageIndexRemovedRequired;
FRemovedDependenciesNode.SelectedIndex:=FRemovedDependenciesNode.ImageIndex;
end;
RemovedBranch:=FilterEdit.GetBranch(RemovedDependenciesNode);
RemovedBranch:=FilterEdit.GetBranch(FRemovedDependenciesNode);
// Add all removed dependencies under the branch
while Dependency<>nil do begin
ANodeData := CreateNodeData(penDependency, Dependency.PackageName, True);
@ -1026,10 +1046,10 @@ begin
end;
// Dependency is set to removed required packages if there is active project
if (Dependency=nil) and (RemovedDependenciesNode<>nil) then begin
if (Dependency=nil) and (FRemovedDependenciesNode<>nil) then begin
// No removed dependencies -> delete the root node
FilterEdit.DeleteBranch(RemovedDependenciesNode);
FreeThenNil(RemovedDependenciesNode);
FilterEdit.DeleteBranch(FRemovedDependenciesNode);
FreeThenNil(FRemovedDependenciesNode);
end;
FilterEdit.InvalidateFilter;
finally
@ -1128,6 +1148,77 @@ begin
ProjInspector:=nil;
end;
function TProjectInspectorForm.ExtendIncSearchPath(NewIncPaths: string
): boolean;
begin
Result:=MainIDEInterface.ExtendProjectIncSearchPath(LazProject,NewIncPaths);
end;
function TProjectInspectorForm.ExtendUnitSearchPath(NewUnitPaths: string
): boolean;
begin
Result:=MainIDEInterface.ExtendProjectUnitSearchPath(LazProject,NewUnitPaths);
end;
function TProjectInspectorForm.FilesBaseDirectory: string;
begin
if LazProject<>nil then
Result:=LazProject.ProjectDirectory
else
Result:='';
end;
function TProjectInspectorForm.FilesEditForm: TCustomForm;
begin
Result:=Self;
end;
function TProjectInspectorForm.FilesEditTreeView: TTreeView;
begin
Result:=ItemsTreeView;
end;
function TProjectInspectorForm.FilesOwner: TObject;
begin
Result:=LazProject;
end;
function TProjectInspectorForm.FilesOwnerName: string;
begin
Result:='Project';
end;
function TProjectInspectorForm.FilesOwnerReadOnly: boolean;
begin
Result:=false;
end;
function TProjectInspectorForm.FirstRequiredDependency: TPkgDependency;
begin
if LazProject<>nil then
Result:=LazProject.FirstRequiredDependency
else
Result:=nil;
end;
function TProjectInspectorForm.GetNodeFilename(Node: TTreeNode): string;
var
Item: TFileNameItem;
begin
Result:='';
if Node=nil then exit;
if Node=FFilesNode then
exit(FilesBaseDirectory);
Item:=TFileNameItem(Node.Data);
if not (Item is TFileNameItem) then exit;
Result:=Item.Filename;
end;
function TProjectInspectorForm.IsDirectoryNode(Node: TTreeNode): boolean;
begin
Result:=(Node<>nil) and (Node.Data=nil) and Node.HasAsParent(FFilesNode);
end;
procedure TProjectInspectorForm.BeginUpdate;
begin
inc(FUpdateLock);

View File

@ -136,6 +136,7 @@ type
FComponents: TFPList; // list of TPkgComponent
FDirectory: string;
FFlags: TPkgFileFlags;
fFilename: string;
fFullFilename: string;
fFullFilenameStamp: integer;
FPackage: TLazPackage;
@ -156,6 +157,7 @@ type
function GetInUses: boolean; override;
procedure SetInUses(AValue: boolean); override;
function GetIDEPackage: TIDEPackage; override;
function GetFilename: string; override;
procedure SetFilename(const AValue: string); override;
procedure SetRemoved(const AValue: boolean); override;
procedure SetDisableI18NForLFM(AValue: boolean); override;
@ -178,6 +180,8 @@ type
function GetFullFilename: string; override;
function GetShortFilename(UseUp: boolean): string; override;
function GetResolvedFilename: string; // GetFullFilename + resolve symlinks
function GetFileOwner: TObject; override;
function GetFileOwnerName: string; override;
public
property AddToUsesPkgSection: boolean
read GetAddToUsesPkgSection write SetAddToUsesPkgSection;
@ -1487,7 +1491,7 @@ begin
NewFilename:=AValue;
ForcePathDelims(NewFilename);
if Filename=NewFilename then exit;
inherited SetFilename(NewFilename);
fFilename:=NewFilename;
fFullFilenameStamp:=CTInvalidChangeStamp;
OldDirectory:=FDirectory;
FDirectory:=ExtractFilePath(Filename);
@ -1615,6 +1619,11 @@ begin
Result:=FPackage;
end;
function TPkgFile.GetFilename: string;
begin
Result:=fFilename;
end;
function TPkgFile.HasRegisteredPlugins: boolean;
begin
Result:=ComponentCount>0;
@ -1688,7 +1697,7 @@ begin
AutoReferenceSourceDir:=false;
if (LazPackage=nil) or (not (lpfDestroying in LazPackage.Flags)) then begin
inherited SetRemoved(false);
inherited SetFilename('');
fFilename:='';
FDirectory:='';
FFlags:=[];
inherited SetFileType(pftUnit);
@ -1793,6 +1802,19 @@ begin
Result:=GetPhysicalFilenameCached(GetFullFilename,false);
end;
function TPkgFile.GetFileOwner: TObject;
begin
Result:=LazPackage;
end;
function TPkgFile.GetFileOwnerName: string;
begin
if LazPackage<>nil then
Result:=LazPackage.Name
else
Result:='';
end;
{ TPkgDependency }
procedure TPkgDependency.SetFlags(const AValue: TPkgDependencyFlags);

View File

@ -2757,7 +2757,7 @@ begin
Result:='';
if Node=nil then exit;
if Node=FFilesNode then
exit(LazPackage.DirectoryExpanded);
exit(FilesBaseDirectory);
Item:=TFileNameItem(Node.Data);
if not (Item is TFileNameItem) then exit;
Result:=Item.Filename;
@ -2970,7 +2970,7 @@ end;
function TPackageEditorForm.FilesBaseDirectory: string;
begin
Result:=LazPackage.Directory;
Result:=LazPackage.DirectoryExpanded;
end;
function TPackageEditorForm.FilesOwnerReadOnly: boolean;