IDE: Reduce dependencies in unit PackageDefs.

This commit is contained in:
Juha 2024-03-12 14:48:50 +02:00
parent 2c7e959e62
commit d897c407ed
6 changed files with 105 additions and 70 deletions

View File

@ -44,7 +44,8 @@ uses
FormEditingIntf, IDEImagesIntf, PropEdits, MenuIntf, ComponentReg, LazIDEIntf,
TextTools,
// IDE
LazarusIDEStrConsts, PackageDefs, IDEOptionDefs, EnvGuiOptions, Designer;
LazarusIDEStrConsts, ComponentPalette, PackageDefs, IDEOptionDefs, EnvGuiOptions,
Designer;
const
ComponentListMenuRootName = 'ComponentList';
@ -244,9 +245,9 @@ begin
chbKeepOpen.Caption := lisKeepOpen;
SelectionToolButton.Hint := lisSelectionTool;
ListTree.Images := TPkgComponent.Images;
PalletteTree.Images := TPkgComponent.Images;
InheritanceTree.Images := TPkgComponent.Images;
ListTree.Images := TPaletteComponent.Images;
PalletteTree.Images := TPaletteComponent.Images;
InheritanceTree.Images := TPaletteComponent.Images;
if Assigned(IDEComponentPalette) then
begin
UpdateComponents;
@ -471,8 +472,8 @@ begin
// Add the node
Node := InheritanceTree.Items.AddChildObject(ParentNode, aClassName, CurRegComp);
ClassToNodeTree[aClass]:=Node;
if CurRegComp is TPkgComponent then
II := TPkgComponent(CurRegComp).ImageIndex
if CurRegComp is TPaletteComponent then
II := TPaletteComponent(CurRegComp).ImageIndex
else
II := -1;
if II>=0 then
@ -531,8 +532,8 @@ begin
AListNode := ListTree.Items.AddChildObject(Nil, aClassName, Comp);
// Palette layout item
APaletteNode := PalletteTree.Items.AddChildObject(ParentNode, aClassName, Comp);
if Comp is TPkgComponent then
CurIcon := TPkgComponent(Comp).ImageIndex
if Comp is TPaletteComponent then
CurIcon := TPaletteComponent(Comp).ImageIndex
else
CurIcon := -1;
if CurIcon>=0 then

View File

@ -46,13 +46,25 @@ uses
// IdeIntf
FormEditingIntf, LazIDEIntf, IDEImagesIntf, PropEdits, ComponentReg,
// IDE
ComponentPalette_Options,
MainBase, LazarusIDEStrConsts, DesignerProcs, PackageDefs, EnvGuiOptions;
const
CompPalSelectionToolBtnPrefix = 'PaletteSelectBtn';
CompPaletteCompBtnPrefix = 'PaletteBtn';
type
{ TPaletteComponent }
TPaletteComponent = class(TPkgComponent)
protected
function InheritsFromControl: boolean; override;
public
function HasIcon: boolean;
function ImageIndex: TImageIndex;
class function Images: TCustomImageList;
end;
{ TComponentPage }
TComponentPage = class(TBaseComponentPage)
@ -66,8 +78,8 @@ type
procedure RemoveSheet;
procedure InsertVisiblePage(aCompNames: TRegisteredCompList);
procedure CreateSelectionButton(aButtonUniqueName: string; aScrollBox: TScrollBox);
procedure CreateOrDelButton(aComp: TPkgComponent; aButtonUniqueName: string;
aScrollBox: TScrollBox);
procedure CreateOrDelButton(aComp: TpaletteComponent;
aButtonUniqueName: string; aScrollBox: TScrollBox);
procedure CreateButtons;
protected
public
@ -151,8 +163,14 @@ type
property OnChangeActivePage: TNotifyEvent read FOnChangeActivePage write FOnChangeActivePage;
end;
TOptionsClickEvent = Procedure();
var
OnOptionsClick: TOptionsClickEvent;
function CompareControlsWithTag(Control1, Control2: Pointer): integer;
implementation
{$R ../images/components_images.res}
@ -174,6 +192,32 @@ begin
Result:=0;
end;
{ TPaletteComponent }
function TPaletteComponent.InheritsFromControl: boolean;
begin
Result:=ComponentClass.InheritsFrom(TControl);
end;
function TPaletteComponent.HasIcon: boolean;
begin
Result:=RealPage.PageName<>'';
end;
function TPaletteComponent.ImageIndex: TImageIndex;
begin
Result := IDEImages.GetImageIndex(ComponentClass.UnitName+'.'+ComponentClass.ClassName, 24);
if Result<0 then
Result := IDEImages.GetImageIndex(ComponentClass.ClassName, 24);
if Result=-1 then
Result := IDEImages.GetImageIndex('default', 24);
end;
class function TPaletteComponent.Images: TCustomImageList;
begin
Result := IDEImages.Images_24;
end;
{ TComponentPage }
constructor TComponentPage.Create(const ThePageName: string);
@ -426,7 +470,7 @@ begin
end;
end;
procedure TComponentPage.CreateOrDelButton(aComp: TPkgComponent; aButtonUniqueName: string;
procedure TComponentPage.CreateOrDelButton(aComp: TpaletteComponent; aButtonUniqueName: string;
aScrollBox: TScrollBox);
var
Pal: TComponentPalette;
@ -490,7 +534,7 @@ procedure TComponentPage.CreateButtons;
// Create speedbuttons for every visible component
var
ScrollBox: TScrollBox;
Comp: TPkgComponent;
Comp: TPaletteComponent;
i: Integer;
begin
if not Visible then Exit;
@ -508,7 +552,7 @@ begin
fBtnIndex := 0;
Assert(Assigned(fRegComps), 'TComponentPage.CreateButtons: fCompNames is not assigned.');
for i := 0 to fRegComps.Count-1 do begin
Comp := TPkgComponent(fRegComps[i]);
Comp := TPaletteComponent(fRegComps[i]);
if Assigned(Comp) then
CreateOrDelButton(Comp, Format('%d_%d_',[FIndex,i]), ScrollBox);
end;
@ -572,7 +616,8 @@ end;
procedure TComponentPalette.OptionsClicked(Sender: TObject);
begin
MainIDE.DoOpenIDEOptions(TCompPaletteOptionsFrame, '', [], []);
if Assigned(OnOptionsClick) then
OnOptionsClick();
end;
procedure TComponentPalette.PalettePopupMenuPopup(Sender: TObject);
@ -1066,8 +1111,8 @@ begin
ARegComp:=nil;
if ARegComp<>nil then
begin
ImageList := TPkgComponent(ARegComp).Images;
ImageIndex := TPkgComponent(ARegComp).ImageIndex;
ImageList := TPaletteComponent(ARegComp).Images;
ImageIndex := TPaletteComponent(ARegComp).ImageIndex;
end else
begin
GetUnregisteredIcon(ImageList, ImageIndex);
@ -1100,5 +1145,8 @@ begin
Result := TPkgComponent(FindCompByButton(TSpeedButton(Button)));
end;
initialization
PkgComponentClass := TPaletteComponent;
end.

View File

@ -40,7 +40,7 @@ uses
// IdeConfig
EnvironmentOpts, IDEOptionDefs,
// IDE
LazarusIDEStrConsts, PackageDefs, EnvGuiOptions;
LazarusIDEStrConsts, MainBase, PackageDefs, ComponentPalette, EnvGuiOptions;
type
@ -126,12 +126,20 @@ type
property ConfigChanged: Boolean read fConfigChanged;
end;
procedure OptionsClickHandler;
implementation
uses MainBar;
{$R *.lfm}
procedure OptionsClickHandler;
begin
MainIDE.DoOpenIDEOptions(TCompPaletteOptionsFrame, '', [], []);
end;
{ TCompPaletteOptionsFrame }
function TCompPaletteOptionsFrame.GetTitle: String;
@ -144,6 +152,7 @@ begin
inherited Create(AOwner);
fLocalOptions:=TCompPaletteOptions.Create;
fLocalUserOrder:=TCompPaletteUserOrder.Create(IDEComponentPalette);
Assert(IDEComponentPalette is TComponentPalette, 'IDEComponentPalette is not TComponentPalette');
end;
destructor TCompPaletteOptionsFrame.Destroy;
@ -650,9 +659,9 @@ var
begin
Comp := TRegisteredComponent(Item.Data);
ARect := Item.DisplayRect(drIcon);
if Comp is TPkgComponent then begin
IL := TPkgComponent(Comp).Images;
II := TPkgComponent(Comp).ImageIndex;
if Comp is TPaletteComponent then begin
IL := TPaletteComponent(Comp).Images;
II := TPaletteComponent(Comp).ImageIndex;
if (IL<>nil) and (II>=0) then
begin
Res := IL.ResolutionForControl[0, Sender];
@ -871,6 +880,7 @@ end;
initialization
RegisterIDEOptionsEditor(GroupEnvironment, TCompPaletteOptionsFrame, EnvOptionsCompPalette);
ComponentPalette.OnOptionsClick := @OptionsClickHandler;
end.

View File

@ -40,7 +40,7 @@ uses
// FCL
Classes, SysUtils, Contnrs, TypInfo, AVL_Tree, System.UITypes,
// LCL
Forms, Controls, ImgList,
Forms,
// Codetools
LazConfigStorage, DefineTemplates, CodeToolManager,
CodeCache, CodeToolsCfgScript, CodeToolsStructs, BasicCodeTools,
@ -49,9 +49,9 @@ uses
LazTracer, LazLoggerBase, Laz2_XMLCfg, AvgLvlTree,
// BuildIntf
MacroIntf, MacroDefIntf, IDEOptionsIntf, PublishModuleIntf,
PackageDependencyIntf, PackageIntf, FppkgIntf,
PackageDependencyIntf, PackageIntf, FppkgIntf, LazMsgWorker,
// IDEIntf
LazIDEIntf, IDEOptEditorIntf, IDEDialogs, ComponentReg, IDEImagesIntf,
LazIDEIntf, ComponentReg,
// IdeConfig
TransferMacros, IDEProcs, IDEOptionDefs, CompOptsModes, SearchPathProcs, IdeXmlConfigProcs,
// IDE
@ -94,19 +94,17 @@ type
function CanBeCreatedInDesigner: boolean; override;
procedure ConsistencyCheck; override;
function GetPriority: TComponentPriority; override;
function InheritsFromControl: boolean; override;
public
constructor Create(ThePkgFile: TPkgFile; TheComponentClass: TComponentClass;
const ThePageName: string);
destructor Destroy; override;
function GetUnitName: string; override;
function HasIcon: boolean;
function ImageIndex: TImageIndex;
class function Images: TCustomImageList;
public
property PkgFile: TPkgFile read FPkgFile write SetPkgFile;
end;
TPkgComponentClass = class of TPkgComponent;
{ TPkgFile }
type
@ -804,12 +802,12 @@ type
property LazPackage: TLazPackage read GetLazPackage write SetLazPackage;
end;
const
LazPkgXMLFileVersion = 5;
AutoUpdateNames: array[TPackageUpdatePolicy] of string = (
'Manually', 'OnRebuildingAll', 'AsNeeded');
var
// All TPkgDependency are added to this AVL tree (sorted for names, not version!)
PackageDependencies: TAVLTree = nil; // tree of TPkgDependency
@ -818,6 +816,9 @@ var
OnGetDependencyOwnerDescription: TGetDependencyOwnerDescription = nil;
OnGetDependencyOwnerDirectory: TGetDependencyOwnerDirectory = nil;
OnPackageFileLoaded: TNotifyEvent = nil;
PkgComponentClass: TPkgComponentClass;
Package1: TLazPackage; // don't use it - only for options dialog
function CompareLazPackageID(Data1, Data2: Pointer): integer;
function CompareNameWithPackageID(Key, Data: Pointer): integer;
@ -879,9 +880,6 @@ procedure PkgVersionSaveToXMLConfig(Version: TPkgVersion; XMLConfig: TXMLConfig;
procedure PkgVersionLoadFromXMLConfig(Version: TPkgVersion;
XMLConfig: TXMLConfig);
var
Package1: TLazPackage; // don't use it - only for options dialog
function dbgs(p: TPackageUpdatePolicy): string; overload;
function dbgs(p: TLazPackageType): string; overload;
function PackagePathToStr(PathList: TFPList): string;
@ -3187,7 +3185,7 @@ begin
if NewUnitPaths='' then Exit;
NewUnitPaths:=CreateRelativeSearchPath(NewUnitPaths,Directory);
if NewUnitPaths='.' then Exit;
r:=IDEMessageDialog(lisExtendUnitPath,
r:=LazMessageWorker(lisExtendUnitPath,
Format(lisExtendUnitSearchPathOfPackageWith, [Name, #13, NewUnitPaths]),
mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
@ -3208,7 +3206,7 @@ begin
if NewIncPaths='' then Exit;
NewIncPaths:=CreateRelativeSearchPath(NewIncPaths,Directory);
if NewIncPaths='.' then Exit;
r:=IDEMessageDialog(lisExtendIncludePath,
r:=LazMessageWorker(lisExtendIncludePath,
Format(lisExtendIncludeFileSearchPathOfPackageWith, [Name, #13, NewIncPaths]),
mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
@ -3745,7 +3743,10 @@ end;
function TLazPackage.AddComponent(PkgFile: TPkgFile; const Page: string;
TheComponentClass: TComponentClass): TPkgComponent;
begin
Result:=TPkgComponent.Create(PkgFile,TheComponentClass,Page);
// IDE sets this to TPaletteComponent. Outside the IDE use TPkgComponent.
if PkgComponentClass = Nil then
PkgComponentClass := TPkgComponent;
Result:=PkgComponentClass.Create(PkgFile,TheComponentClass,Page);
end;
procedure TLazPackage.AddPkgComponent(APkgComponent: TPkgComponent);
@ -4054,11 +4055,6 @@ begin
if (FPkgFile<>nil) then PkgFile.AddPkgComponent(Self);
end;
function TPkgComponent.InheritsFromControl: boolean;
begin
Result:=ComponentClass.InheritsFrom(TControl);
end;
constructor TPkgComponent.Create(ThePkgFile: TPkgFile;
TheComponentClass: TComponentClass; const ThePageName: string);
begin
@ -4105,25 +4101,6 @@ begin
RaiseGDBException('TIDEComponent.ConsistencyCheck PkgFile.FComponents.IndexOf(Self)<0');
end;
class function TPkgComponent.Images: TCustomImageList;
begin
Result := IDEImages.Images_24;
end;
function TPkgComponent.HasIcon: boolean;
begin
Result:=RealPage.PageName<>'';
end;
function TPkgComponent.ImageIndex: TImageIndex;
begin
Result := IDEImages.GetImageIndex(ComponentClass.UnitName+'.'+ComponentClass.ClassName, 24);
if Result<0 then
Result := IDEImages.GetImageIndex(ComponentClass.ClassName, 24);
if Result=-1 then
Result := IDEImages.GetImageIndex('default', 24);
end;
function TPkgComponent.CanBeCreatedInDesigner: boolean;
begin
Result:=(not PkgFile.Removed);
@ -4777,8 +4754,6 @@ begin
end;
initialization
RegisterIDEOptionsGroup(GroupPackage, TPackageIDEOptions);
RegisterIDEOptionsGroup(GroupPkgCompiler, TPkgCompilerOptions);
PackageDependencies:=TAVLTree.Create(@ComparePkgDependencyNames);
finalization

View File

@ -53,7 +53,7 @@ uses
EnvironmentOpts, SearchPathProcs,
// IDE
MainBase, DialogProcs, LazarusIDEStrConsts, IDEDefs, CompilerOptions,
PackageSystem, PackageDefs, AddToPackageDlg, AddPkgDependencyDlg,
PackageSystem, PackageDefs, AddToPackageDlg, AddPkgDependencyDlg, ComponentPalette,
AddFPMakeDependencyDlg, ProjPackChecks, PkgVirtualUnitEditor, CleanPkgDeps,
MissingPkgFilesDlg, ProjPackFilePropGui, ProjPackEditing, BasePkgManager;
@ -1274,7 +1274,7 @@ end;
procedure TPackageEditorForm.RegisteredListBoxDrawItem(Control: TWinControl;
Index: Integer; ARect: TRect; State: TOwnerDrawState);
var
CurComponent: TPkgComponent;
CurComponent: TPaletteComponent;
CurStr: string;
CurObject: TObject;
TxtH: Integer;
@ -1289,9 +1289,9 @@ begin
if LazPackage=nil then exit;
if (Index<0) or (Index>=FPlugins.Count) then exit;
CurObject:=FPlugins.Objects[Index];
if CurObject is TPkgComponent then begin
if CurObject is TPaletteComponent then begin
// draw registered component
CurComponent:=TPkgComponent(CurObject);
CurComponent:=TPaletteComponent(CurObject);
with FPropGui.RegisteredListBox do begin
if Assigned(CurComponent.RealPage) then
CurStr:=Format(lisPckEditPage,[CurComponent.ComponentClass.ClassName,

View File

@ -54,10 +54,10 @@ uses
FileProcs, DefineTemplates, CodeToolManager, CodeCache, DirectoryCacher,
BasicCodeTools, NonPascalCodeTools, SourceChanger,
// BuildIntf
IDEExternToolIntf, MacroDefIntf, ProjectIntf, CompOptsIntf, FppkgIntf,
PackageDependencyIntf, PackageLinkIntf, PackageIntf,
IDEExternToolIntf, IDEOptionsIntf, MacroDefIntf, ProjectIntf, CompOptsIntf,
FppkgIntf, PackageDependencyIntf, PackageLinkIntf, PackageIntf,
// IDEIntf
IDEDialogs, IDEMsgIntf, LazIDEIntf, ComponentReg,
IDEDialogs, IDEMsgIntf, LazIDEIntf, IDEOptEditorIntf, ComponentReg,
// Package registration
LazarusPackageIntf,
// IdeConfig
@ -6695,7 +6695,8 @@ begin
end;
initialization
PackageGraph:=nil;
RegisterIDEOptionsGroup(GroupPackage, TPackageIDEOptions);
RegisterIDEOptionsGroup(GroupPkgCompiler, TPkgCompilerOptions);
end.