implemented package graph showing open packages

git-svn-id: trunk@4037 -
This commit is contained in:
mattias 2003-04-10 19:42:16 +00:00
parent c6f9b10d5d
commit 7839e19d08
9 changed files with 317 additions and 21 deletions

View File

@ -98,7 +98,7 @@ var
begin
inherited Create(TheOwner);
Name:=DefaultClipbrdHistoryName;
Name:=NonModalIDEWindowNames[nmiwClipbrdHistoryName];
Caption := 'Clipboard History';
ALayout:=EnvironmentOptions.IDEWindowLayoutList.ItemByFormID(Name);
ALayout.Form:=TForm(Self);

View File

@ -1212,14 +1212,14 @@ procedure TEnvironmentOptions.InitLayoutList;
var
i: integer;
l: TNonModalIDEWindow;
begin
fIDEWindowLayoutList:=TIDEWindowLayoutList.Create;
CreateWindowLayout(DefaultMainIDEName);
for l:=Low(TNonModalIDEWindow) to High(TNonModalIDEWindow) do
if l<>nmiwNone then
CreateWindowLayout(NonModalIDEWindowNames[l]);
CreateWindowLayout(DefaultObjectInspectorName);
CreateWindowLayout(DefaultSourceNoteBookName);
CreateWindowLayout(DefaultMessagesViewName);
CreateWindowLayout(DefaultUnitDependenciesName);
for i:=0 to fIDEWindowLayoutList.Count-1 do begin
IDEWindowLayoutList[i].OnApply:=@InternOnApplyWindowLayout;
@ -3641,9 +3641,9 @@ begin
WindowPositionsBox.Save;
WindowPositionsListBox.ItemIndex:=Index;
case Index of
0: WindowPositionsBox.Layout:=FLayouts.ItemByFormID(DefaultMainIDEName);
1: WindowPositionsBox.Layout:=FLayouts.ItemByFormID(DefaultSourceNoteBookName);
2: WindowPositionsBox.Layout:=FLayouts.ItemByFormID(DefaultMessagesViewName);
0: WindowPositionsBox.Layout:=FLayouts.ItemByEnum(nmiwMainIDEName);
1: WindowPositionsBox.Layout:=FLayouts.ItemByEnum(nmiwSourceNoteBookName);
2: WindowPositionsBox.Layout:=FLayouts.ItemByEnum(nmiwMessagesViewName);
3: WindowPositionsBox.Layout:=FLayouts.ItemByFormID(DefaultObjectInspectorName);
end;
if Index>=0 then

View File

@ -36,14 +36,30 @@ uses
Classes, SysUtils, Laz_XMLCfg, Forms, Controls, StdCtrls, Buttons,
LazarusIDEStrConsts;
const
type
TNonModalIDEWindow = (
nmiwNone,
nmiwMainIDEName,
nmiwSourceNoteBookName,
nmiwMessagesViewName,
nmiwUnitDependenciesName,
nmiwCodeExplorerName,
nmiwClipbrdHistoryName,
nmiwPkgGraphExplorer
);
// form names for non modal IDE windows:
DefaultMainIDEName = 'MainIDE';
DefaultSourceNoteBookName = 'SourceNotebook';
DefaultMessagesViewName = 'MessagesView';
DefaultUnitDependenciesName = 'UnitDependencies';
DefaultCodeExplorerName = 'CodeExplorer';
DefaultClipbrdHistoryName = 'ClipBrdHistory';
const
NonModalIDEWindowNames: array[TNonModalIDEWindow] of string = (
'?',
'MainIDE',
'SourceNotebook',
'MessagesView',
'UnitDependencies',
'CodeExplorer',
'ClipBrdHistory',
'PkgGraphExplorer'
);
type
{ TIDEWindowLayout stores information about the position, min/maximized state
@ -159,6 +175,7 @@ type
function IndexOf(const FormID: string): integer;
function ItemByForm(AForm: TForm): TIDEWindowLayout;
function ItemByFormID(const FormID: string): TIDEWindowLayout;
function ItemByEnum(ID: TNonModalIDEWindow): TIDEWindowLayout;
property Items[Index: Integer]: TIDEWindowLayout
read GetItems write SetItems; default;
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
@ -275,6 +292,7 @@ type
end;
function CreateNiceWindowPosition(Width, Height: integer): TRect;
function NonModalIDEFormIDToEnum(const FormID: string): TNonModalIDEWindow;
var
IDEDialogLayoutList: TIDEDialogLayoutList;
@ -354,6 +372,14 @@ begin
Result.Bottom:=y+Height;
end;
function NonModalIDEFormIDToEnum(const FormID: string): TNonModalIDEWindow;
begin
for Result:=Low(TNonModalIDEWindow) to High(TNonModalIDEWindow) do
if NonModalIDEWindowNames[Result]=FormID then
exit;
Result:=nmiwNone;
end;
{ TIDEWindowLayout }
constructor TIDEWindowLayout.Create;
@ -679,6 +705,12 @@ begin
Result:=nil;
end;
function TIDEWindowLayoutList.ItemByEnum(ID: TNonModalIDEWindow
): TIDEWindowLayout;
begin
Result:=ItemByFormID(NonModalIDEWindowNames[ID]);
end;
procedure TIDEWindowLayoutList.ApplyAll;
var i: integer;
begin

View File

@ -97,9 +97,9 @@ Begin
Visible:= true;
end;
end;
Name := DefaultMessagesViewName;
Name := NonModalIDEWindowNames[nmiwMessagesViewName];
ALayout:=EnvironmentOptions.IDEWindowLayoutList.
ItemByFormID(DefaultMessagesViewName);
ItemByEnum(nmiwMessagesViewName);
ALayout.Form:=TForm(Self);
ALayout.Apply;
end;

View File

@ -429,7 +429,7 @@ begin
inherited Create(TheOwner);
if LazarusResources.Find(ClassName)=nil then
begin
Name:=DefaultUnitDependenciesName;
Name:=NonModalIDEWindowNames[nmiwUnitDependenciesName];
Caption := dlgUnitDepCaption;
ALayout:=EnvironmentOptions.IDEWindowLayoutList.ItemByFormID(Name);
ALayout.Form:=TForm(Self);

View File

@ -256,6 +256,9 @@ type
pitDynamic
);
TPkgChangeNameEvent = procedure(Pkg: TLazPackage;
const OldName: string) of object;
TLazPackage = class(TLazPackageID)
private
FAuthor: string;
@ -273,6 +276,7 @@ type
FIconFile: string;
FInstalled: TPackageInstallType;
FModifiedLock: integer;
FOnChangeName: TPkgChangeNameEvent;
FPackageEditor: TBasePackageEditor;
FPackageType: TLazPackageType;
FReadOnly: boolean;
@ -381,6 +385,7 @@ type
property Installed: TPackageInstallType read FInstalled write SetInstalled;
property Registered: boolean read FRegistered write SetRegistered;
property Modified: boolean read GetModified write SetModified;
property OnChangeName: TPkgChangeNameEvent read FOnChangeName write FOnChangeName;
property PackageType: TLazPackageType
read FPackageType write SetPackageType;
property ReadOnly: boolean read FReadOnly write SetReadOnly;
@ -1113,9 +1118,13 @@ begin
end;
procedure TLazPackage.SetName(const AValue: string);
var
OldName: String;
begin
if FName=AValue then exit;
OldName:=FName;
FName:=AValue;
if Assigned(OnChangeName) then OnChangeName(Self,OldName);
Modified:=true;
end;

View File

@ -72,12 +72,16 @@ const
fpfSearchInPckgsWithEditor,fpfSearchInPkgLinks];
type
TPkgAddedEvent = procedure(Pkg: TLazPackage) of object;
TLazPackageGraph = class
private
FAbortRegistration: boolean;
FErrorMsg: string;
FFCLPackage: TLazPackage;
FLCLPackage: TLazPackage;
FOnAddPackage: TPkgAddedEvent;
FOnChangePackageName: TPkgChangeNameEvent;
FRegistrationFile: TPkgFile;
FRegistrationPackage: TLazPackage;
FRegistrationUnitName: string;
@ -88,6 +92,7 @@ type
procedure SetRegistrationPackage(const AValue: TLazPackage);
function CreateFCLPackage: TLazPackage;
function CreateLCLPackage: TLazPackage;
procedure PackageChangedName(Pkg: TLazPackage; const OldName: string);
public
constructor Create;
destructor Destroy; override;
@ -130,6 +135,8 @@ type
procedure IterateAllComponentClasses(Event: TIterateComponentClassesEvent);
procedure IteratePackages(Flags: TFindPackageFlags;
Event: TIteratePackagesEvent);
procedure IteratePackagesSorted(Flags: TFindPackageFlags;
Event: TIteratePackagesEvent);
public
property Packages[Index: integer]: TLazPackage read GetPackages; default;
property RegistrationPackage: TLazPackage read FRegistrationPackage
@ -141,6 +148,9 @@ type
write SetAbortRegistration;
property FCLPackage: TLazPackage read FFCLPackage;
property LCLPackage: TLazPackage read FLCLPackage;
property OnChangePackageName: TPkgChangeNameEvent read FOnChangePackageName
write FOnChangePackageName;
property OnAddPackage: TPkgAddedEvent read FOnAddPackage write FOnAddPackage;
end;
var
@ -162,6 +172,12 @@ end;
{ TLazPackageGraph }
procedure TLazPackageGraph.PackageChangedName(Pkg: TLazPackage;
const OldName: string);
begin
if Assigned(OnChangePackageName) then OnChangePackageName(Pkg,OldName);
end;
function TLazPackageGraph.GetPackages(Index: integer): TLazPackage;
begin
Result:=TLazPackage(FItems[Index]);
@ -644,6 +660,9 @@ procedure TLazPackageGraph.AddPackage(APackage: TLazPackage);
begin
FTree.Add(APackage);
FItems.Add(APackage);
APackage.OnChangeName:=@PackageChangedName;
writeln('TLazPackageGraph.AddPackage ',Assigned(OnAddPackage));
if Assigned(OnAddPackage) then OnAddPackage(APackage);
end;
procedure TLazPackageGraph.AddStaticBasePackages;
@ -760,6 +779,27 @@ begin
end;
end;
procedure TLazPackageGraph.IteratePackagesSorted(Flags: TFindPackageFlags;
Event: TIteratePackagesEvent);
var
ANode: TAVLTreeNode;
CurPkg: TLazPackage;
begin
ANode:=FTree.FindLowest;
while ANode<>nil do begin
CurPkg:=TLazPackage(ANode.Data);
// check installed packages
if ((fpfSearchInInstalledPckgs in Flags) and (CurPkg.Installed<>pitNope))
// check autoinstall packages
or ((fpfSearchInAutoInstallPckgs in Flags) and (CurPkg.AutoInstall<>pitNope))
// check packages with opened editor
or ((fpfSearchInPckgsWithEditor in Flags) and (CurPkg.Editor<>nil))
then
Event(CurPkg);
ANode:=FTree.FindSuccessor(ANode);
end;
end;
initialization
PackageGraph:=nil;

View File

@ -39,30 +39,220 @@ interface
uses
Classes, SysUtils, LResources, Forms, Controls, Buttons, ComCtrls, StdCtrls,
ExtCtrls, Menus, LazarusIDEStrConsts, IDEProcs, PackageDefs, PackageSystem;
ExtCtrls, Menus, Dialogs, AVL_Tree, LazarusIDEStrConsts, IDEProcs,
IDEOptionDefs, EnvironmentOpts, PackageDefs, PackageSystem;
type
TPkgGraphExplorer = class(TForm)
ImageList: TImageList;
PkgTreeLabel: TLabel;
PkgTreeView: TTreeView;
PkgListLabel: TLabel;
PkgListBox: TListBox;
InfoMemo: TMemo;
procedure PkgGraphExplorerResize(Sender: TObject);
procedure PkgGraphExplorerShow(Sender: TObject);
private
fSortedPackages: TAVLTree;
procedure SetupComponents;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy;
destructor Destroy; override;
procedure UpdateAll;
procedure UpdateTree;
procedure UpdateList;
procedure UpdateInfo;
procedure UpdatePackageName(Pkg: TLazPackage; const OldName: string);
procedure UpdatePackageID(Pkg: TLazPackage);
procedure UpdatePackageAdded(Pkg: TLazPackage);
end;
var
PackageGraphExplorer: TPkgGraphExplorer;
implementation
uses Math;
{ TPkgGraphExplorer }
procedure TPkgGraphExplorer.PkgGraphExplorerResize(Sender: TObject);
var
x: Integer;
y: Integer;
w: Integer;
begin
x:=1;
y:=1;
w:=((ClientWidth-3*x) div 2);
with PkgTreeLabel do
SetBounds(x,y,w,Height);
inc(x,PkgTreeLabel.Width+PkgTreeLabel.Left);
with PkgListLabel do
SetBounds(x,y,w,Height);
x:=1;
inc(y,PkgTreeLabel.Height+3);
with PkgTreeView do
SetBounds(x,y,w,Max(Parent.ClientHeight-y-80,10));
inc(x,PkgTreeView.Width+PkgTreeView.Left);
with PkgListBox do
SetBounds(x,y,w,PkgTreeView.Height);
x:=1;
inc(y,PkgTreeView.Height+1);
with InfoMemo do
SetBounds(x,y,Parent.ClientWidth-2*x,Max(10,Parent.ClientHeight-y-x));
end;
procedure TPkgGraphExplorer.PkgGraphExplorerShow(Sender: TObject);
begin
UpdateAll;
end;
procedure TPkgGraphExplorer.SetupComponents;
begin
ImageList:=TImageList.Create(Self);
with ImageList do begin
Width:=16;
Height:=16;
Name:='ImageList';
end;
PkgTreeLabel:=TLabel.Create(Self);
with PkgTreeLabel do begin
Name:='PkgTreeLabel';
Parent:=Self;
Caption:='Required Packages Tree:';
end;
PkgTreeView:=TTreeView.Create(Self);
with PkgTreeView do begin
Name:='PkgTreeView';
Parent:=Self;
Options:=Options+[tvoRightClickSelect];
end;
PkgListLabel:=TLabel.Create(Self);
with PkgListLabel do begin
Name:='PkgListLabel';
Parent:=Self;
Caption:='Packages requiring the selected package:';
end;
PkgListBox:=TListBox.Create(Self);
with PkgListBox do begin
Name:='PkgListBox';
Parent:=Self;
end;
InfoMemo:=TMemo.Create(Self);
with InfoMemo do begin
Name:='InfoMemo';
Parent:=Self;
end;
end;
constructor TPkgGraphExplorer.Create(TheOwner: TComponent);
var
ALayout: TIDEWindowLayout;
begin
inherited Create(TheOwner);
fSortedPackages:=TAVLTree.Create(@CompareLazPackageID);
Name:=NonModalIDEWindowNames[nmiwPkgGraphExplorer];
Caption:='Package Graph Explorer';
ALayout:=EnvironmentOptions.IDEWindowLayoutList.ItemByFormID(Name);
ALayout.Form:=TForm(Self);
ALayout.Apply;
SetupComponents;
OnResize:=@PkgGraphExplorerResize;
OnResize(Self);
OnShow:=@PkgGraphExplorerShow;
end;
destructor TPkgGraphExplorer.Destroy;
begin
FreeAndNil(fSortedPackages);
inherited Destroy;
end;
procedure TPkgGraphExplorer.UpdateAll;
begin
UpdateTree;
UpdateList;
UpdateInfo;
end;
procedure TPkgGraphExplorer.UpdateTree;
var
Cnt: Integer;
i: Integer;
CurIndex: Integer;
ViewNode: TTreeNode;
NextViewNode: TTreeNode;
HiddenNode: TAVLTreeNode;
CurPkg: TLazPackage;
begin
// rebuild internal sorted packages
fSortedPackages.Clear;
Cnt:=PackageGraph.Count;
for i:=0 to Cnt-1 do
fSortedPackages.Add(PackageGraph[i]);
// rebuild the TreeView
PkgTreeView.BeginUpdate;
CurIndex:=0;
HiddenNode:=fSortedPackages.FindLowest;
ViewNode:=PkgTreeView.Items.GetFirstNode;
while HiddenNode<>nil do begin
CurPkg:=TLazPackage(HiddenNode.Data);
if ViewNode=nil then
ViewNode:=PkgTreeView.Items.Add(nil,CurPkg.IDAsString)
else
ViewNode.Text:=CurPkg.IDAsString;
ViewNode:=ViewNode.GetNextSibling;
HiddenNode:=fSortedPackages.FindSuccessor(HiddenNode);
inc(CurIndex);
end;
while ViewNode<>nil do begin
NextViewNode:=ViewNode.GetNextSibling;
ViewNode.Free;
ViewNode:=NextViewNode;
end;
PkgTreeView.EndUpdate;
end;
procedure TPkgGraphExplorer.UpdateList;
begin
end;
procedure TPkgGraphExplorer.UpdateInfo;
begin
end;
procedure TPkgGraphExplorer.UpdatePackageName(Pkg: TLazPackage;
const OldName: string);
begin
UpdateAll;
end;
procedure TPkgGraphExplorer.UpdatePackageID(Pkg: TLazPackage);
begin
UpdateAll;
end;
procedure TPkgGraphExplorer.UpdatePackageAdded(Pkg: TLazPackage);
begin
UpdateAll;
end;
initialization
PackageGraphExplorer:=nil;
end.

View File

@ -49,6 +49,7 @@ uses
KeyMapping, EnvironmentOpts, IDEProcs, ProjectDefs, InputHistory,
IDEDefs, UComponentManMain, PackageEditor, AddToPackageDlg, PackageDefs,
PackageLinks, PackageSystem, ComponentReg, OpenInstalledPkgDlg,
PkgGraphExporer,
BasePkgManager, MainBar;
type
@ -63,6 +64,9 @@ type
function OnPackageEditorOpenPackage(Sender: TObject; APackage: TLazPackage
): TModalResult;
procedure OnPackageEditorSavePackage(Sender: TObject);
procedure PackageGraphChangePackageName(Pkg: TLazPackage;
const OldName: string);
procedure PkgManagerAddPackage(Pkg: TLazPackage);
procedure mnuConfigCustomCompsClicked(Sender: TObject);
procedure mnuPkgEditPackageClicked(Sender: TObject);
procedure mnuOpenRecentPackageClicked(Sender: TObject);
@ -212,6 +216,20 @@ begin
DoSavePackage(TLazPackage(Sender),[]);
end;
procedure TPkgManager.PackageGraphChangePackageName(Pkg: TLazPackage;
const OldName: string);
begin
if PackageGraphExplorer<>nil then
PackageGraphExplorer.UpdatePackageName(Pkg,OldName);
end;
procedure TPkgManager.PkgManagerAddPackage(Pkg: TLazPackage);
begin
writeln('TPkgManager.PkgManagerAddPackage ',PackageGraphExplorer<>nil);
if PackageGraphExplorer<>nil then
PackageGraphExplorer.UpdatePackageAdded(Pkg);
end;
procedure TPkgManager.mnuConfigCustomCompsClicked(Sender: TObject);
begin
ShowConfigureCustomComponents;
@ -414,6 +432,8 @@ begin
PkgLinks:=TPackageLinks.Create;
PackageGraph:=TLazPackageGraph.Create;
PackageGraph.OnChangePackageName:=@PackageGraphChangePackageName;
PackageGraph.OnAddPackage:=@PkgManagerAddPackage;
PackageEditors:=TPackageEditors.Create;
PackageEditors.OnOpenFile:=@MainIDE.DoOpenMacroFile;
@ -426,6 +446,7 @@ end;
destructor TPkgManager.Destroy;
begin
FreeThenNil(PackageGraphExplorer);
FreeThenNil(PackageEditors);
FreeThenNil(PackageGraph);
FreeThenNil(PkgLinks);
@ -671,7 +692,11 @@ end;
function TPkgManager.DoShowPackageGraph: TModalResult;
begin
Result:=mrCancel;
if PackageGraphExplorer=nil then
PackageGraphExplorer:=TPkgGraphExplorer.Create(Application);
PackageGraphExplorer.Show;
PackageGraphExplorer.BringToFront;
Result:=mrOk;
end;
end.