Packager: Allow overwriting existing unit files in New Component dialog. Error was shown AFTER a file was overwritten. Issue #26928.

git-svn-id: trunk@59240 -
This commit is contained in:
juha 2018-10-03 11:24:35 +00:00
parent baeca2e0d7
commit 8026ce28ae
5 changed files with 118 additions and 88 deletions

View File

@ -15,8 +15,8 @@ object AddToPackageDlg: TAddToPackageDlg
LCLVersion = '2.1.0.0' LCLVersion = '2.1.0.0'
object ButtonPanel1: TButtonPanel object ButtonPanel1: TButtonPanel
Left = 6 Left = 6
Height = 34 Height = 26
Top = 373 Top = 381
Width = 684 Width = 684
OKButton.Name = 'OKButton' OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True OKButton.DefaultCaption = True
@ -50,7 +50,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideRight.Control = AncestorComboBox AnchorSideRight.Control = AncestorComboBox
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 184 Left = 184
Height = 31 Height = 25
Top = 43 Top = 43
Width = 200 Width = 200
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
@ -67,7 +67,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 184 Left = 184
Height = 31 Height = 31
Top = 80 Top = 74
Width = 200 Width = 200
BorderSpacing.Top = 6 BorderSpacing.Top = 6
ItemHeight = 0 ItemHeight = 0
@ -78,11 +78,11 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideLeft.Control = AncestorComboBox AnchorSideLeft.Control = AncestorComboBox
AnchorSideTop.Control = UnitNameEdit AnchorSideTop.Control = UnitNameEdit
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ComponentUnitFileBrowseButton AnchorSideRight.Control = UnitDirectoryBrowseButton
Left = 184 Left = 184
Height = 31 Height = 25
Top = 154 Top = 142
Width = 443 Width = 449
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6 BorderSpacing.Top = 6
OnChange = UnitDirectoryEditChange OnChange = UnitDirectoryEditChange
@ -96,8 +96,8 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideRight.Control = AncestorComboBox AnchorSideRight.Control = AncestorComboBox
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 184 Left = 184
Height = 31 Height = 25
Top = 117 Top = 111
Width = 200 Width = 200
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6 BorderSpacing.Top = 6
@ -111,7 +111,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 184 Left = 184
Height = 32 Height = 32
Top = 213 Top = 195
Width = 32 Width = 32
BorderSpacing.Top = 6 BorderSpacing.Top = 6
Constraints.MinHeight = 32 Constraints.MinHeight = 32
@ -128,7 +128,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 222 Left = 222
Height = 19 Height = 19
Top = 220 Top = 202
Width = 124 Width = 124
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'IconNormInfoLabel' Caption = 'IconNormInfoLabel'
@ -150,38 +150,38 @@ object AddToPackageDlg: TAddToPackageDlg
State = cbChecked State = cbChecked
TabOrder = 1 TabOrder = 1
end end
object ComponentUnitFileBrowseButton: TButton object UnitDirectoryBrowseButton: TButton
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = UnitDirectoryEdit AnchorSideTop.Control = UnitDirectoryEdit
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ComponentUnitFileShortenButton AnchorSideRight.Control = UnitDirectoryShortenButton
Left = 627 Left = 633
Height = 25 Height = 25
Hint = 'Save file dialog' Hint = 'Save file dialog'
Top = 157 Top = 142
Width = 25 Width = 25
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
Caption = '...' Caption = '...'
OnClick = ComponentUnitFileBrowseButtonClick OnClick = UnitDirectoryBrowseButtonClick
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 5 TabOrder = 5
end end
object ComponentUnitFileShortenButton: TButton object UnitDirectoryShortenButton: TButton
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = UnitDirectoryEdit AnchorSideTop.Control = UnitDirectoryEdit
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 652 Left = 658
Height = 33 Height = 25
Hint = 'Shorten or expand filename' Hint = 'Shorten or expand filename'
Top = 153 Top = 142
Width = 28 Width = 22
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Right = 6 BorderSpacing.Right = 6
Caption = '<>' Caption = '<>'
OnClick = ComponentUnitFileShortenButtonClick OnClick = UnitDirectoryShortenButtonClick
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 6 TabOrder = 6
@ -191,7 +191,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 19 Height = 19
Top = 220 Top = 202
Width = 98 Width = 98
Caption = 'IconNormLabel' Caption = 'IconNormLabel'
ParentColor = False ParentColor = False
@ -201,7 +201,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 19 Height = 19
Top = 123 Top = 114
Width = 99 Width = 99
Caption = 'UnitNameLabel' Caption = 'UnitNameLabel'
ParentColor = False ParentColor = False
@ -211,7 +211,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 19 Height = 19
Top = 160 Top = 145
Width = 119 Width = 119
Caption = 'UnitDirectoryLabel' Caption = 'UnitDirectoryLabel'
ParentColor = False ParentColor = False
@ -221,7 +221,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 19 Height = 19
Top = 86 Top = 80
Width = 111 Width = 111
Caption = 'PalettePageLabel' Caption = 'PalettePageLabel'
ParentColor = False ParentColor = False
@ -231,7 +231,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 19 Height = 19
Top = 49 Top = 46
Width = 104 Width = 104
Caption = 'ClassNameLabel' Caption = 'ClassNameLabel'
ParentColor = False ParentColor = False
@ -252,7 +252,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 184 Left = 184
Height = 32 Height = 32
Top = 251 Top = 233
Width = 32 Width = 32
BorderSpacing.Top = 6 BorderSpacing.Top = 6
Constraints.MinHeight = 32 Constraints.MinHeight = 32
@ -267,7 +267,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 184 Left = 184
Height = 32 Height = 32
Top = 289 Top = 271
Width = 32 Width = 32
BorderSpacing.Top = 6 BorderSpacing.Top = 6
Constraints.MinHeight = 32 Constraints.MinHeight = 32
@ -282,7 +282,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 19 Height = 19
Top = 258 Top = 240
Width = 85 Width = 85
Caption = 'Icon150Label' Caption = 'Icon150Label'
ParentColor = False ParentColor = False
@ -293,7 +293,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 5 Left = 5
Height = 19 Height = 19
Top = 296 Top = 278
Width = 85 Width = 85
Caption = 'Icon200Label' Caption = 'Icon200Label'
ParentColor = False ParentColor = False
@ -305,7 +305,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 222 Left = 222
Height = 19 Height = 19
Top = 258 Top = 240
Width = 111 Width = 111
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'Icon150InfoLabel' Caption = 'Icon150InfoLabel'
@ -318,7 +318,7 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 222 Left = 222
Height = 19 Height = 19
Top = 296 Top = 278
Width = 111 Width = 111
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'Icon200InfoLabel' Caption = 'Icon200InfoLabel'
@ -330,11 +330,26 @@ object AddToPackageDlg: TAddToPackageDlg
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 195 Left = 195
Height = 19 Height = 19
Top = 188 Top = 170
Width = 118 Width = 118
BorderSpacing.Left = 11 BorderSpacing.Left = 11
BorderSpacing.Top = 3 BorderSpacing.Top = 3
Caption = 'UnitFilenameLabel' Caption = 'UnitFilenameLabel'
ParentColor = False ParentColor = False
end end
object UnitFilenameExistsLabel: TLabel
AnchorSideLeft.Control = UnitFilenameLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = UnitFilenameLabel
AnchorSideTop.Side = asrCenter
Left = 331
Height = 19
Top = 170
Width = 152
BorderSpacing.Left = 18
Caption = 'UnitFilenameExistsLabel'
Font.Color = clMaroon
ParentColor = False
ParentFont = False
end
end end

View File

@ -101,10 +101,11 @@ type
Icon150InfoLabel: TLabel; Icon150InfoLabel: TLabel;
Icon200InfoLabel: TLabel; Icon200InfoLabel: TLabel;
IconNormLabel: TLabel; IconNormLabel: TLabel;
ComponentUnitFileBrowseButton: TButton; UnitFilenameExistsLabel: TLabel;
UnitDirectoryBrowseButton: TButton;
UnitDirectoryEdit: TEdit; UnitDirectoryEdit: TEdit;
UnitDirectoryLabel: TLabel; UnitDirectoryLabel: TLabel;
ComponentUnitFileShortenButton: TButton; UnitDirectoryShortenButton: TButton;
UnitNameEdit: TEdit; UnitNameEdit: TEdit;
UnitNameLabel: TLabel; UnitNameLabel: TLabel;
Icon200BitBtn: TBitBtn; Icon200BitBtn: TBitBtn;
@ -119,8 +120,8 @@ type
procedure AncestorShowAllCheckBoxClick(Sender: TObject); procedure AncestorShowAllCheckBoxClick(Sender: TObject);
procedure ClassNameEditChange(Sender: TObject); procedure ClassNameEditChange(Sender: TObject);
procedure IconBitBtnClick(Sender: TObject); procedure IconBitBtnClick(Sender: TObject);
procedure ComponentUnitFileBrowseButtonClick(Sender: TObject); procedure UnitDirectoryBrowseButtonClick(Sender: TObject);
procedure ComponentUnitFileShortenButtonClick(Sender: TObject); procedure UnitDirectoryShortenButtonClick(Sender: TObject);
procedure UnitDirectoryEditChange(Sender: TObject); procedure UnitDirectoryEditChange(Sender: TObject);
procedure UnitNameEditChange(Sender: TObject); procedure UnitNameEditChange(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
@ -130,8 +131,6 @@ type
fLastNewAncestorType: string; fLastNewAncestorType: string;
fLastNewClassName: string; fLastNewClassName: string;
FLazPackage: TLazPackage; FLazPackage: TLazPackage;
FOnGetIDEFileInfo: TGetIDEFileStateEvent;
FOnGetUnitRegisterInfo: TOnGetUnitRegisterInfo;
fPkgComponents: TAVLTree;// tree of TPkgComponent fPkgComponents: TAVLTree;// tree of TPkgComponent
fPackages: TAVLTree;// tree of TLazPackage or TPackageLink fPackages: TAVLTree;// tree of TLazPackage or TPackageLink
fParams: TAddToPkgResult; fParams: TAddToPkgResult;
@ -146,37 +145,28 @@ type
function CheckNewCompOk: Boolean; function CheckNewCompOk: Boolean;
procedure AutoCompleteNewComponent; procedure AutoCompleteNewComponent;
procedure AutoCompleteUnitName; procedure AutoCompleteUnitName;
procedure UpdateUnitFilename;
public public
procedure UpdateAvailableAncestorTypes; procedure UpdateAvailableAncestorTypes;
procedure UpdateAvailablePageNames; procedure UpdateAvailablePageNames;
public public
property LazPackage: TLazPackage read FLazPackage write SetLazPackage; property LazPackage: TLazPackage read FLazPackage write SetLazPackage;
property OnGetIDEFileInfo: TGetIDEFileStateEvent read FOnGetIDEFileInfo
write FOnGetIDEFileInfo;
property OnGetUnitRegisterInfo: TOnGetUnitRegisterInfo
read FOnGetUnitRegisterInfo write FOnGetUnitRegisterInfo;
end; end;
function ShowAddToPackageDlg(Pkg: TLazPackage; out Params: TAddToPkgResult; function ShowAddToPackageDlg(Pkg: TLazPackage; out Params: TAddToPkgResult): TModalResult;
OnGetIDEFileInfo: TGetIDEFileStateEvent;
OnGetUnitRegisterInfo: TOnGetUnitRegisterInfo): TModalResult;
implementation implementation
{$R *.lfm} {$R *.lfm}
function ShowAddToPackageDlg(Pkg: TLazPackage; out Params: TAddToPkgResult; function ShowAddToPackageDlg(Pkg: TLazPackage; out Params: TAddToPkgResult): TModalResult;
OnGetIDEFileInfo: TGetIDEFileStateEvent;
OnGetUnitRegisterInfo: TOnGetUnitRegisterInfo): TModalResult;
var var
AddDlg: TAddToPackageDlg; AddDlg: TAddToPackageDlg;
begin begin
Params:=nil; Params:=nil;
AddDlg:=TAddToPackageDlg.Create(nil); AddDlg:=TAddToPackageDlg.Create(nil);
try try
AddDlg.OnGetIDEFileInfo:=OnGetIDEFileInfo;
AddDlg.OnGetUnitRegisterInfo:=OnGetUnitRegisterInfo;
AddDlg.LazPackage:=Pkg; AddDlg.LazPackage:=Pkg;
Result:=AddDlg.ShowModal; Result:=AddDlg.ShowModal;
if Result=mrOk then begin if Result=mrOk then begin
@ -257,12 +247,13 @@ begin
UnitDirectoryLabel.Caption:=lisA2PDirectoryForUnitFile; UnitDirectoryLabel.Caption:=lisA2PDirectoryForUnitFile;
UnitDirectoryEdit.Text:=''; UnitDirectoryEdit.Text:='';
UnitFilenameLabel.Caption:=''; UnitFilenameLabel.Caption:='';
with ComponentUnitFileBrowseButton do begin UnitFilenameExistsLabel.Caption:='';
with UnitDirectoryBrowseButton do begin
Caption:='...'; Caption:='...';
ShowHint:=true; ShowHint:=true;
Hint:=lisA2PSaveFileDialog; Hint:=lisChooseDirectory; // Remove lisA2PSaveFileDialog later.
end; end;
with ComponentUnitFileShortenButton do begin with UnitDirectoryShortenButton do begin
Caption:='<>'; Caption:='<>';
ShowHint:=true; ShowHint:=true;
Hint:=lisA2PShortenOrExpandFilename; Hint:=lisA2PShortenOrExpandFilename;
@ -365,7 +356,7 @@ begin
end; end;
end; end;
procedure TAddToPackageDlg.ComponentUnitFileBrowseButtonClick(Sender: TObject); procedure TAddToPackageDlg.UnitDirectoryBrowseButtonClick(Sender: TObject);
var var
DirDialog: TSelectDirectoryDialog; DirDialog: TSelectDirectoryDialog;
begin begin
@ -378,7 +369,7 @@ begin
//DirDialog.Filter:=Format('%s|*.pas;*.pp', [dlgFilterPascalFile]); //DirDialog.Filter:=Format('%s|*.pas;*.pp', [dlgFilterPascalFile]);
if DirDialog.Execute then begin if DirDialog.Execute then begin
UnitDirectoryEdit.Text:=DirDialog.Filename; UnitDirectoryEdit.Text:=DirDialog.Filename;
UnitFilenameLabel.Caption:=AppendPathDelim(UnitDirectoryEdit.Text)+GenerateUnitFileName; UpdateUnitFilename;
end; end;
InputHistories.StoreFileDialogSettings(DirDialog); InputHistories.StoreFileDialogSettings(DirDialog);
finally finally
@ -386,7 +377,7 @@ begin
end; end;
end; end;
procedure TAddToPackageDlg.ComponentUnitFileShortenButtonClick(Sender: TObject); procedure TAddToPackageDlg.UnitDirectoryShortenButtonClick(Sender: TObject);
var var
S: string; S: string;
begin begin
@ -400,12 +391,12 @@ begin
UnitDirectoryEdit.Text:=CreateRelativePath(S,LazPackage.Directory,True) UnitDirectoryEdit.Text:=CreateRelativePath(S,LazPackage.Directory,True)
else else
UnitDirectoryEdit.Text:=CreateAbsolutePath(S,LazPackage.Directory); UnitDirectoryEdit.Text:=CreateAbsolutePath(S,LazPackage.Directory);
UnitFilenameLabel.Caption:=AppendPathDelim(UnitDirectoryEdit.Text)+GenerateUnitFileName; UpdateUnitFilename;
end; end;
procedure TAddToPackageDlg.UnitDirectoryEditChange(Sender: TObject); procedure TAddToPackageDlg.UnitDirectoryEditChange(Sender: TObject);
begin begin
UnitFilenameLabel.Caption:=AppendPathDelim(UnitDirectoryEdit.Text)+GenerateUnitFileName; UpdateUnitFilename;
if UnitDirectoryEdit.Text<>'' then if UnitDirectoryEdit.Text<>'' then
fIconDlg.InitialDir:=UnitDirectoryEdit.Text; fIconDlg.InitialDir:=UnitDirectoryEdit.Text;
end; end;
@ -413,7 +404,7 @@ end;
procedure TAddToPackageDlg.UnitNameEditChange(Sender: TObject); procedure TAddToPackageDlg.UnitNameEditChange(Sender: TObject);
begin begin
CheckNewCompOk; CheckNewCompOk;
UnitFilenameLabel.Caption:=AppendPathDelim(UnitDirectoryEdit.Text)+GenerateUnitFileName; UpdateUnitFilename;
end; end;
procedure TAddToPackageDlg.NewComponentButtonClick(Sender: TObject); procedure TAddToPackageDlg.NewComponentButtonClick(Sender: TObject);
@ -445,6 +436,13 @@ begin
raise Exception.Create('NewComponentButtonClick: Cannot create directory '+ThePath); raise Exception.Create('NewComponentButtonClick: Cannot create directory '+ThePath);
fParams.UnitFilename:=AppendPathDelim(ThePath)+GenerateUnitFileName; fParams.UnitFilename:=AppendPathDelim(ThePath)+GenerateUnitFileName;
// check if package is readonly
if LazPackage.ReadOnly then begin
IDEMessageDialog(lisAF2PPackageIsReadOnly,
Format(lisAF2PThePackageIsReadOnly, [LazPackage.IDAsString]),
mtError,[mbCancel]);
exit;
end;
// check Ancestor Type // check Ancestor Type
if not IsValidIdent(fParams.AncestorType) then begin if not IsValidIdent(fParams.AncestorType) then begin
IDEMessageDialog(lisA2PInvalidAncestorType, IDEMessageDialog(lisA2PInvalidAncestorType,
@ -503,9 +501,14 @@ begin
then then
exit; exit;
end; end;
// check filename // check if unitname is a componentclass
if not CheckAddingPackageUnit(LazPackage, d2ptNewComponent, if IDEComponentPalette.FindComponent(fParams.Unit_Name)<>nil then begin
OnGetIDEFileInfo, fParams.UnitFilename) then exit; if IDEMessageDialog(lisA2PAmbiguousUnitName,
Format(lisA2PTheUnitNameIsTheSameAsAnRegisteredComponent,[fParams.Unit_Name,LineEnding]),
mtWarning,[mbCancel,mbIgnore])<>mrIgnore
then
exit;
end;
// create dependency if needed // create dependency if needed
PkgComponent:=TPkgComponent(IDEComponentPalette.FindComponent(fParams.AncestorType)); PkgComponent:=TPkgComponent(IDEComponentPalette.FindComponent(fParams.AncestorType));
@ -590,6 +593,15 @@ begin
UnitDirectoryEdit.Text:=LazPackage.Directory; UnitDirectoryEdit.Text:=LazPackage.Directory;
end; end;
procedure TAddToPackageDlg.UpdateUnitFilename;
begin
UnitFilenameLabel.Caption:=AppendPathDelim(UnitDirectoryEdit.Text)+GenerateUnitFileName;
if FileExists(UnitFilenameLabel.Caption) then
UnitFilenameExistsLabel.Caption:=lisA2PFileAlreadyExists
else
UnitFilenameExistsLabel.Caption:='';
end;
procedure TAddToPackageDlg.UpdateAvailableAncestorTypes; procedure TAddToPackageDlg.UpdateAvailableAncestorTypes;
var var
ANode: TAVLTreeNode; ANode: TAVLTreeNode;

View File

@ -373,7 +373,7 @@ type
procedure DoSave(SaveAs: boolean); procedure DoSave(SaveAs: boolean);
procedure DoSortFiles; procedure DoSortFiles;
function DoOpenPkgFile(PkgFile: TPkgFile): TModalResult; function DoOpenPkgFile(PkgFile: TPkgFile): TModalResult;
function ShowAddDialog: TModalResult; function ShowNewCompDialog: TModalResult;
function ShowAddDepDialog: TModalResult; function ShowAddDepDialog: TModalResult;
function ShowAddFPMakeDepDialog: TModalResult; function ShowAddFPMakeDepDialog: TModalResult;
function PkgNameToFormName(const PkgName: string): string; function PkgNameToFormName(const PkgName: string): string;
@ -1074,7 +1074,7 @@ end;
procedure TPackageEditorForm.mnuAddNewCompClick(Sender: TObject); procedure TPackageEditorForm.mnuAddNewCompClick(Sender: TObject);
begin begin
ShowAddDialog; ShowNewCompDialog;
end; end;
procedure TPackageEditorForm.mnuAddNewReqrClick(Sender: TObject); procedure TPackageEditorForm.mnuAddNewReqrClick(Sender: TObject);
@ -2128,7 +2128,7 @@ begin
end; end;
end; end;
function TPackageEditorForm.ShowAddDialog: TModalResult; function TPackageEditorForm.ShowNewCompDialog: TModalResult;
var var
IgnoreUnitPaths: TFilenameToStringTree; IgnoreUnitPaths: TFilenameToStringTree;
@ -2140,19 +2140,25 @@ var
procedure AddNewComponent(AddParams: TAddToPkgResult); procedure AddNewComponent(AddParams: TAddToPkgResult);
begin begin
ExtendUnitIncPathForNewUnit(AddParams.UnitFilename,'',IgnoreUnitPaths); ExtendUnitIncPathForNewUnit(AddParams.UnitFilename, '', IgnoreUnitPaths);
// add file // add file
with AddParams do with AddParams do
LazPackage.AddFile(UnitFilename,Unit_Name,FileType,PkgFileFlags,cpNormal); begin
FreeAndNil(FNextSelectedPart); Assert(FilenameIsAbsolute(UnitFilename), 'AddNewComponent: Filename is relative.');
FNextSelectedPart:=TPENodeData.Create(penFile,AddParams.UnitFilename,false); // This file can also replace an existing file.
// add dependency if LazPackage.FindPkgFile(UnitFilename,true,false)=nil then
if (AddParams.Dependency<>nil) LazPackage.AddFile(UnitFilename, Unit_Name, FileType, PkgFileFlags, cpNormal)
and (not PkgDependsOn(AddParams.Dependency.PackageName)) then else
PackageGraph.AddDependencyToPackage(LazPackage,AddParams.Dependency); LazPackage.Modified:=True;
if (AddParams.IconNormFile<>'') and (not PkgDependsOn('LCL')) then FreeAndNil(FNextSelectedPart);
PackageGraph.AddDependencyToPackage(LazPackage,PackageGraph.LCLPackage); FNextSelectedPart:=TPENodeData.Create(penFile, UnitFilename, false);
PackageEditors.DeleteAmbiguousFiles(LazPackage,AddParams.UnitFilename); // add dependency
if (Dependency<>nil) and not PkgDependsOn(Dependency.PackageName) then
PackageGraph.AddDependencyToPackage(LazPackage, Dependency);
if (IconNormFile<>'') and not PkgDependsOn('LCL') then
PackageGraph.AddDependencyToPackage(LazPackage, PackageGraph.LCLPackage);
PackageEditors.DeleteAmbiguousFiles(LazPackage, UnitFilename);
end;
// open file in editor // open file in editor
PackageEditors.CreateNewFile(Self,AddParams); PackageEditors.CreateNewFile(Self,AddParams);
end; end;
@ -2165,9 +2171,7 @@ begin
exit(mrCancel); exit(mrCancel);
end; end;
Result:=ShowAddToPackageDlg(LazPackage, AddParams, Result:=ShowAddToPackageDlg(LazPackage, AddParams);
PackageEditors.OnGetIDEFileInfo,
PackageEditors.OnGetUnitRegisterInfo);
if Result<>mrOk then exit; if Result<>mrOk then exit;
PackageGraph.BeginUpdate(false); PackageGraph.BeginUpdate(false);

View File

@ -1920,16 +1920,15 @@ begin
end; end;
{$ENDIF} {$ENDIF}
if (IDEComponentPalette<>nil) if (IDEComponentPalette<>nil)
and (IDEComponentPalette.FindComponent(CurClassname)<>nil) then begin and (IDEComponentPalette.FindComponent(CurClassname)<>nil) then
RegistrationError( RegistrationError(Format(lisPkgSysComponentClassAlreadyDefined,[CurClassname]));
Format(lisPkgSysComponentClassAlreadyDefined, [CurComponent.ClassName]));
end;
if AbortRegistration then exit; if AbortRegistration then exit;
// add the component to the package owning the file // add the component to the package owning the file
// (e.g. a designtime package can register units of a runtime packages) // (e.g. a designtime package can register units of a runtime packages)
NewPkgComponent:= NewPkgComponent:=
FRegistrationFile.LazPackage.AddComponent(FRegistrationFile,Page,CurComponent); FRegistrationFile.LazPackage.AddComponent(FRegistrationFile,Page,CurComponent);
//debugln('TLazPackageGraph.RegisterComponentsHandler Page="',Page,'" CurComponent=',CurComponent.ClassName,' FRegistrationFile=',FRegistrationFile.Filename); //DebugLn('TLazPackageGraph.RegisterComponentsHandler Page="',Page,
// '" CurComponent=',CurClassname,' FRegistrationFile=',FRegistrationFile.Filename);
if IDEComponentPalette<>nil then if IDEComponentPalette<>nil then
IDEComponentPalette.AddComponent(NewPkgComponent); IDEComponentPalette.AddComponent(NewPkgComponent);
end; end;

View File

@ -5244,7 +5244,7 @@ begin
// save // save
Result:=DoSavePackage(APackage,SaveFlags); Result:=DoSavePackage(APackage,SaveFlags);
if Result<>mrOk then exit; if Result<>mrOk then exit;
Result:=CurEditor.ShowAddDialog; // show new component dialog Result:=CurEditor.ShowNewCompDialog; // show new component dialog
end; end;
function TPkgManager.SavePackageFiles(APackage: TLazPackage): TModalResult; function TPkgManager.SavePackageFiles(APackage: TLazPackage): TModalResult;