Merged revision(s) 50839 #9e35d2c52c from trunk:

Packager: Update search paths after "Add Active File To Package". Issue #27720.
........

git-svn-id: branches/fixes_1_6@50971 -
This commit is contained in:
maxim 2015-12-21 22:44:50 +00:00
parent cf117df75d
commit b30da44735
7 changed files with 151 additions and 342 deletions

View File

@ -4284,9 +4284,6 @@ resourcestring
lisAF2PPackageNotFound = 'Package "%s" not found.';
lisAF2PPackageIsReadOnly = 'Package is read only';
lisAF2PThePackageIsReadOnly = 'The package %s is read only.';
lisAF2PTheFileIsAlreadyInThePackage = 'The file "%s"%sis already in the package %s.';
lisAF2PUnitName = 'Unit name: ';
lisAF2PHasRegisterProcedure = 'Has Register procedure';
lisAF2PFileType = 'File type';
lisPEExpandDirectory = 'Expand directory';
lisPECollapseDirectory = 'Collapse directory';

View File

@ -59,9 +59,13 @@ uses
{$IFDEF IDE_MEM_CHECK}
MemCheck,
{$ENDIF}
Classes, LCLType, LCLIntf, Buttons, Menus, SysUtils,
typinfo, Controls, Graphics, ExtCtrls, Dialogs, FileUtil, Forms,
LazFileUtils, CodeToolManager, CodeCache, AVL_Tree, SynEditKeyCmds,
Classes, SysUtils, typinfo, AVL_Tree,
LCLType, LCLIntf, Buttons, Menus, Controls, Graphics, ExtCtrls, Dialogs, Forms,
SynEditKeyCmds,
// Codetools
CodeToolManager, CodeCache,
// LazUtils
FileUtil, LazFileUtils,
// IDEIntf
PropEdits, ObjectInspector, MenuIntf, SrcEditorIntf, ProjectIntf,
CompOptsIntf, LazIDEIntf, IDEDialogs, IDEWindowIntf,

View File

@ -1,69 +1,31 @@
object AddFileToAPackageDialog: TAddFileToAPackageDialog
Left = 347
Height = 424
Top = 221
Left = 408
Height = 272
Top = 224
Width = 469
ActiveControl = FileNameEdit
Caption = 'AddFileToAPackageDialog'
ClientHeight = 424
ClientHeight = 272
ClientWidth = 469
OnClose = AddFileToAPackageDlgClose
Position = poScreenCenter
ShowHint = True
LCLVersion = '0.9.29'
LCLVersion = '1.7'
object FileGroupBox: TGroupBox
Left = 6
Height = 148
Height = 58
Top = 6
Width = 457
Align = alTop
AutoSize = True
BorderSpacing.Around = 6
Caption = 'FileGroupBox'
ClientHeight = 130
ClientHeight = 39
ClientWidth = 453
TabOrder = 0
object UnitNameLabel: TLabel
AnchorSideTop.Control = FileNameEdit
AnchorSideTop.Side = asrBottom
Left = 6
Height = 14
Top = 33
Width = 439
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 6
BorderSpacing.Top = 6
BorderSpacing.Right = 6
Caption = 'UnitNameLabel'
ParentColor = False
end
object FileTypeRadioGroup: TRadioGroup
AnchorSideTop.Control = HasRegisterProcCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 25
Top = 99
Width = 439
Anchors = [akTop, akLeft, akRight]
AutoFill = True
AutoSize = True
BorderSpacing.Around = 6
Caption = 'FileTypeRadioGroup'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
Constraints.MinHeight = 25
TabOrder = 3
TabStop = True
end
object FileNameEdit: TEdit
Left = 6
Height = 21
Height = 27
Top = 6
Width = 439
Anchors = [akTop, akLeft, akRight]
@ -72,59 +34,35 @@ object AddFileToAPackageDialog: TAddFileToAPackageDialog
TabOrder = 0
Text = 'FileNameEdit'
end
object UnitNameEdit: TEdit
AnchorSideTop.Control = UnitNameLabel
AnchorSideTop.Side = asrBottom
Left = 6
Height = 21
Top = 49
Width = 439
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 2
TabOrder = 1
Text = 'UnitNameEdit'
end
object HasRegisterProcCheckBox: TCheckBox
AnchorSideTop.Control = UnitNameEdit
AnchorSideTop.Side = asrBottom
Left = 6
Height = 17
Top = 76
Width = 439
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6
Caption = 'HasRegisterProcCheckBox'
TabOrder = 2
end
end
object PackagesGroupBox: TGroupBox
Left = 6
Height = 74
Top = 160
Height = 85
Top = 70
Width = 457
Align = alTop
Anchors = [akLeft, akRight]
AutoSize = True
BorderSpacing.Around = 6
Caption = 'PackagesGroupBox'
ClientHeight = 56
ClientHeight = 66
ClientWidth = 453
TabOrder = 1
object PackagesComboBox: TComboBox
Left = 6
Height = 21
Height = 27
Top = 6
Width = 441
Align = alTop
BorderSpacing.Around = 6
ItemHeight = 13
ItemHeight = 0
TabOrder = 0
Text = 'PackagesComboBox'
end
object ShowAllCheckBox: TCheckBox
Left = 6
Height = 17
Top = 33
Height = 21
Top = 39
Width = 441
Align = alTop
BorderSpacing.Around = 6
@ -135,9 +73,17 @@ object AddFileToAPackageDialog: TAddFileToAPackageDialog
end
object BtnPanel: TButtonPanel
Left = 6
Height = 26
Top = 392
Height = 32
Top = 234
Width = 457
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
HelpButton.DefaultCaption = True
CloseButton.Name = 'CloseButton'
CloseButton.DefaultCaption = True
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 2
ShowButtons = [pbOK, pbCancel, pbHelp]
ShowBevel = False

View File

@ -51,13 +51,9 @@ type
TAddFileToAPackageDialog = class(TForm)
BtnPanel: TButtonPanel;
HasRegisterProcCheckBox: TCheckBox;
FileTypeRadioGroup: TRadioGroup;
UnitNameEdit: TEdit;
FileNameEdit: TEdit;
FileGroupBox: TGroupBox;
PackagesGroupBox: TGroupBox;
UnitNameLabel: TLabel;
PackagesComboBox: TComboBox;
ShowAllCheckBox: TCheckBox;
procedure AddFileToAPackageDlgClose(Sender: TObject;
@ -67,47 +63,31 @@ type
procedure PackagesGroupBoxResize(Sender: TObject);
procedure ShowAllCheckBoxClick(Sender: TObject);
private
FOnGetIDEFileInfo: TGetIDEFileStateEvent;
fPackages: TAVLTree;// tree of TLazPackage
function GetFileType: TPkgFileType;
function GetFilename: string;
function GetHasRegisterProc: boolean;
function GetUnitName: string;
procedure SetFileType(const AValue: TPkgFileType);
procedure SetFilename(const AValue: string);
procedure SetHasRegisterProc(const AValue: boolean);
procedure SetUnitName(const AValue: string);
procedure SetupComponents;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure UpdateAvailablePackages;
property Filename: string read GetFilename write SetFilename;
property Unit_Name: string read GetUnitName write SetUnitName;
property FileType: TPkgFileType read GetFileType write SetFileType;
property HasRegisterProc: boolean read GetHasRegisterProc write SetHasRegisterProc;
property OnGetIDEFileInfo: TGetIDEFileStateEvent read FOnGetIDEFileInfo write FOnGetIDEFileInfo;
end;
function ShowAddFileToAPackageDlg(const Filename, AUnitName: string;
HasRegisterProc: boolean; OnGetIDEFileInfo: TGetIDEFileStateEvent): TModalResult;
function ShowAddFileToAPackageDlg(const Filename: string): TModalResult;
implementation
{$R *.lfm}
function ShowAddFileToAPackageDlg(const Filename, AUnitName: string;
HasRegisterProc: boolean; OnGetIDEFileInfo: TGetIDEFileStateEvent): TModalResult;
function ShowAddFileToAPackageDlg(const Filename: string): TModalResult;
var
AddFileToAPackageDialog: TAddFileToAPackageDialog;
begin
AddFileToAPackageDialog:=TAddFileToAPackageDialog.Create(nil);
AddFileToAPackageDialog.Filename:=Filename;
AddFileToAPackageDialog.Unit_Name:=AUnitName;
AddFileToAPackageDialog.HasRegisterProc:=HasRegisterProc;
AddFileToAPackageDialog.OnGetIDEFileInfo:=OnGetIDEFileInfo;
AddFileToAPackageDialog.UpdateAvailablePackages;
Result:=AddFileToAPackageDialog.ShowModal;
AddFileToAPackageDialog.Free;
@ -130,10 +110,8 @@ procedure TAddFileToAPackageDialog.OkButtonClick(Sender: TObject);
var
PkgID: TLazPackageID;
APackage: TLazPackage;
PkgFile: TPkgFile;
FileFlags: TPkgFileFlags;
AddType: TAddToPkgType;
aFilename: String;
NewUnitPaths, NewIncPaths: String;
begin
aFilename:=Filename;
PkgID:=TLazPackageID.Create;
@ -162,31 +140,14 @@ begin
exit;
end;
// check if file is already in the package
PkgFile:=APackage.FindPkgFile(aFilename,true,false);
if PkgFile<>nil then begin
MessageDlg(lisPkgMangFileIsAlreadyInPackage,
Format(lisAF2PTheFileIsAlreadyInThePackage,[aFilename,LineEnding,APackage.IDAsString]),
mtError,[mbCancel],0);
exit;
end;
// check filename
if FilenameIsPascalSource(aFilename) then
AddType:=d2ptUnit
else
AddType:=d2ptFile;
if not CheckAddingUnitFilename(APackage,AddType,
OnGetIDEFileInfo,aFilename) then exit;
// ok -> add file to package
APackage.BeginUpdate;
FileFlags:=[];
if FileType in PkgFileUnitTypes then
Include(FileFlags,pffAddToPkgUsesSection);
if HasRegisterProc then
Include(FileFlags,pffHasRegisterProc);
APackage.AddFile(aFilename,Unit_Name,FileType,FileFlags,cpNormal);
NewUnitPaths:='';
NewIncPaths:='';
APackage.AddFileByName(aFilename, NewUnitPaths, NewIncPaths);
// extend unit and include search path
if not APackage.ExtendUnitSearchPath(NewUnitPaths) then exit;
if not APackage.ExtendIncSearchPath(NewIncPaths) then exit;
if APackage.Editor<>nil then APackage.Editor.UpdateAll(true);
APackage.EndUpdate;
@ -208,67 +169,21 @@ begin
end;
procedure TAddFileToAPackageDialog.SetupComponents;
var
pft: TPkgFileType;
begin
FileGroupBox.Caption:=lisFile;
FileNameEdit.Text:='';
UnitNameLabel.Caption:=lisAF2PUnitName;
UnitNameEdit.Text:='';
HasRegisterProcCheckBox.Caption:=lisAF2PHasRegisterProcedure;
PackagesGroupBox.Caption:=lisAF2PDestinationPackage;
ShowAllCheckBox.Caption:=lisAF2PShowAll;
BtnPanel.OkButton.Caption:=lisMenuOk;
BtnPanel.OkButton.OnClick:=@OkButtonClick;
BtnPanel.OkButton.ModalResult:=mrNone;
BtnPanel.HelpButton.OnClick:=@HelpButtonClick;
with FileTypeRadioGroup do begin
Caption:=lisAF2PFileType;
with Items do begin
BeginUpdate;
for pft:=Low(TPkgFileType) to High(TPkgFileType) do begin
if pft in PkgFileUnitTypes then continue;
Add(GetPkgFileTypeLocalizedName(pft));
end;
EndUpdate;
end;
ItemIndex:=0;
Columns:=2;
end;
end;
procedure TAddFileToAPackageDialog.SetFilename(const AValue: string);
var
NewPFT: TPkgFileType;
begin
if FileNameEdit.Text=AValue then exit;
FileNameEdit.Text:=AValue;
if FilenameIsPascalUnit(AValue) then
NewPFT:=pftUnit
else if CompareFileExt(AValue,'.lfm',true)=0 then
NewPFT:=pftLFM
else if CompareFileExt(AValue,'.lrs',true)=0 then
NewPFT:=pftLRS
else if CompareFileExt(AValue,'.inc',true)=0 then
NewPFT:=pftInclude
else if FileIsText(AValue) then
NewPFT:=pftText
else
NewPFT:=pftBinary;
FileType:=NewPFT;
end;
procedure TAddFileToAPackageDialog.SetHasRegisterProc(const AValue: boolean);
begin
if HasRegisterProc=AValue then exit;
HasRegisterProcCheckBox.Checked:=AValue;
end;
procedure TAddFileToAPackageDialog.SetUnitName(const AValue: string);
begin
if Unit_Name=AValue then exit;
UnitNameEdit.Text:=AValue;
end;
function TAddFileToAPackageDialog.GetFilename: string;
@ -276,62 +191,6 @@ begin
Result:=FileNameEdit.Text;
end;
function TAddFileToAPackageDialog.GetFileType: TPkgFileType;
var
i: Integer;
CurPFT: TPkgFileType;
begin
if FileTypeRadioGroup.Visible then begin
i:=0;
for CurPFT:=Low(TPkgFileType) to High(TPkgFileType) do begin
if CurPFT in PkgFileUnitTypes then continue;
if FileTypeRadioGroup.ItemIndex=i then begin
Result:=CurPFT;
exit;
end;
inc(i);
end;
Result:=pftText;
end else begin
Result:=pftUnit;
end;
end;
function TAddFileToAPackageDialog.GetHasRegisterProc: boolean;
begin
Result:=HasRegisterProcCheckBox.Checked;
end;
function TAddFileToAPackageDialog.GetUnitName: string;
begin
Result:=UnitNameEdit.Text;
end;
procedure TAddFileToAPackageDialog.SetFileType(const AValue: TPkgFileType);
var
ShowUnitProps: Boolean;
i: Integer;
CurPFT: TPkgFileType;
begin
if FileType=AValue then exit;
i:=0;
for CurPFT:=Low(TPkgFileType) to High(TPkgFileType) do begin
if CurPFT in PkgFileUnitTypes then continue;
if CurPFT=AValue then break;
inc(i);
end;
if i<FileTypeRadioGroup.Items.Count then
FileTypeRadioGroup.ItemIndex:=i
else
FileTypeRadioGroup.ItemIndex:=-1;
ShowUnitProps:=(AValue in PkgFileUnitTypes);
UnitNameLabel.Visible:=ShowUnitProps;
UnitNameEdit.Visible:=ShowUnitProps;
HasRegisterProcCheckBox.Visible:=ShowUnitProps;
FileTypeRadioGroup.Visible:=not ShowUnitProps;
end;
constructor TAddFileToAPackageDialog.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);

View File

@ -37,14 +37,20 @@ unit PackageDefs;
interface
uses
Classes, SysUtils, contnrs, typinfo, LCLProc, LCLType, LResources, Graphics,
Forms, FileProcs, FileUtil, AVL_Tree, LazConfigStorage, Laz2_XMLCfg,
LazFileUtils, LazFileCache, LazUTF8, BasicCodeTools, CodeToolsCfgScript,
DefineTemplates, CodeToolManager, CodeCache, CodeToolsStructs, PropEdits,
LazIDEIntf, MacroIntf, MacroDefIntf, PackageIntf, IDEOptionsIntf, ProjPackBase,
// FCL, LCL
Classes, SysUtils, contnrs, typinfo, AVL_Tree,
LCLProc, LCLType, LResources, Graphics, Controls, Forms, Dialogs,
// Codetools
FileProcs, FileUtil, LazConfigStorage, Laz2_XMLCfg, BasicCodeTools,
DefineTemplates, CodeToolManager, CodeCache, CodeToolsCfgScript, CodeToolsStructs,
// LazUtils
LazFileUtils, LazFileCache, LazUTF8,
// IDEIntf
PropEdits, LazIDEIntf, MacroIntf, MacroDefIntf, PackageIntf, IDEOptionsIntf,
ProjPackBase, IDEDialogs, ComponentReg,
// IDE
EditDefineTree, CompilerOptions, CompOptsModes, IDEOptionDefs,
LazarusIDEStrConsts, IDEProcs, ComponentReg, TransferMacros,
FileReferenceList, PublishModule;
LazarusIDEStrConsts, IDEProcs, TransferMacros, FileReferenceList, PublishModule;
type
TLazPackage = class;
@ -639,6 +645,8 @@ type
function IsMakingSense: boolean;
procedure ConsistencyCheck;
// paths, define templates
function ExtendUnitSearchPath(NewUnitPaths: string): boolean;
function ExtendIncSearchPath(NewIncPaths: string): boolean;
function IsVirtual: boolean; override;
function HasDirectory: boolean;
function HasStaticDirectory: boolean;
@ -682,6 +690,8 @@ type
function AddFile(const NewFilename, NewUnitName: string;
NewFileType: TPkgFileType; NewFlags: TPkgFileFlags;
CompPriorityCat: TComponentPriorityCategory): TPkgFile;
function AddFileByName(aFilename: string;
var NewUnitPaths, NewIncPaths: String): Boolean;
function AddRemovedFile(const NewFilename, NewUnitName: string;
NewFileType: TPkgFileType; NewFlags: TPkgFileFlags;
CompPriorityCat: TComponentPriorityCategory): TPkgFile;
@ -3160,6 +3170,50 @@ begin
CheckList(FComponents,true,true,true);
end;
function TLazPackage.ExtendUnitSearchPath(NewUnitPaths: string): boolean;
var
CurUnitPaths: String;
r: TModalResult;
begin
CurUnitPaths:=CompilerOptions.ParsedOpts.GetParsedValue(pcosUnitPath);
NewUnitPaths:=RemoveSearchPaths(NewUnitPaths,CurUnitPaths);
if NewUnitPaths<>'' then begin
NewUnitPaths:=CreateRelativeSearchPath(NewUnitPaths,Directory);
r:=IDEMessageDialog(lisExtendUnitPath,
Format(lisExtendUnitSearchPathOfPackageWith, [Name, #13,
NewUnitPaths]), mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
mrYes: CompilerOptions.OtherUnitFiles:=
MergeSearchPaths(CompilerOptions.OtherUnitFiles,NewUnitPaths);
mrNo: ;
else exit(false);
end;
end;
Result:=true;
end;
function TLazPackage.ExtendIncSearchPath(NewIncPaths: string): boolean;
var
CurIncPaths: String;
r: TModalResult;
begin
CurIncPaths:=CompilerOptions.ParsedOpts.GetParsedValue(pcosIncludePath);
NewIncPaths:=RemoveSearchPaths(NewIncPaths,CurIncPaths);
if NewIncPaths<>'' then begin
NewIncPaths:=CreateRelativeSearchPath(NewIncPaths,Directory);
r:=IDEMessageDialog(lisExtendIncludePath,
Format(lisExtendIncludeFileSearchPathOfPackageWith, [Name, #13,
NewIncPaths]), mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
mrYes: CompilerOptions.IncludePath:=
MergeSearchPaths(CompilerOptions.IncludePath,NewIncPaths);
mrNo: ;
else exit(false);
end;
end;
Result:=true;
end;
function TLazPackage.IndexOfPkgComponent(PkgComponent: TPkgComponent): integer;
begin
Result:=FComponents.IndexOf(PkgComponent);
@ -3358,6 +3412,44 @@ begin
Modified:=true;
end;
function TLazPackage.AddFileByName(aFilename: string;
var NewUnitPaths, NewIncPaths: String): Boolean;
var
NewFileType: TPkgFileType;
NewUnitName: String;
HasRegister: Boolean;
NewFlags: TPkgFileFlags;
Code: TCodeBuffer;
CurDir: String;
begin
Result := True;
aFilename:=CleanAndExpandFilename(aFileName);
if not FileExistsUTF8(aFilename) then Exit(False);
if DirPathExists(aFilename) then Exit(False);
if FindPkgFile(aFilename,true,false)<>nil then Exit(False);
NewFileType:=FileNameToPkgFileType(aFilename);
NewFlags:=[];
HasRegister:=false;
NewUnitName:='';
if (NewFileType=pftUnit) then begin
Code:=CodeToolBoss.LoadFile(aFilename,true,false);
NewUnitName:=CodeToolBoss.GetSourceName(Code,false);
if NewUnitName='' then
NewUnitName:=ExtractFileNameOnly(aFilename);
if FindUsedUnit(NewUnitName)=nil then
Include(NewFlags,pffAddToPkgUsesSection);
CodeToolBoss.HasInterfaceRegisterProc(Code,HasRegister);
if HasRegister then
Include(NewFlags,pffHasRegisterProc);
end;
AddFile(aFilename,NewUnitName,NewFileType,NewFlags,cpNormal);
CurDir:=ChompPathDelim(ExtractFilePath(aFilename));
if NewFileType=pftUnit then
NewUnitPaths:=MergeSearchPaths(NewUnitPaths,CurDir)
else
NewIncPaths:=MergeSearchPaths(NewIncPaths,CurDir);
end;
function TLazPackage.AddRemovedFile(const NewFilename, NewUnitName: string;
NewFileType: TPkgFileType; NewFlags: TPkgFileFlags;
CompPriorityCat: TComponentPriorityCategory): TPkgFile;

View File

@ -320,7 +320,6 @@ type
FFirstNodeData: array[TPENodeType] of TPENodeData;
fUpdateLock: integer;
fForcedFlags: TPEFlags;
function AddOneFile(aFilename: string; var NewUnitPaths, NewIncPaths: String): TModalResult;
procedure DoAddNewFile(NewItem: TNewIDEItemTemplate);
procedure FreeNodeData(Typ: TPENodeType);
function CreateNodeData(Typ: TPENodeType; aName: string; aRemoved: boolean): TPENodeData;
@ -1456,11 +1455,11 @@ begin
NewUnitPaths:='';
NewIncPaths:='';
for i:=0 to high(Filenames) do
if not (AddOneFile(FileNames[i], NewUnitPaths, NewIncPaths) in [mrOk, mrIgnore]) then break;
LazPackage.AddFileByName(FileNames[i], NewUnitPaths, NewIncPaths);
//UpdateAll(false);
// extend unit and include search path
if not ExtendUnitSearchPath(NewUnitPaths) then exit;
if not ExtendIncSearchPath(NewIncPaths) then exit;
if not LazPackage.ExtendUnitSearchPath(NewUnitPaths) then exit;
if not LazPackage.ExtendIncSearchPath(NewIncPaths) then exit;
finally
EndUpdate;
end;
@ -1557,47 +1556,6 @@ begin
DoUseUnitsInDirectory(false);
end;
function TPackageEditorForm.AddOneFile(aFilename: string;
var NewUnitPaths, NewIncPaths: String): TModalResult;
var
NewFileType: TPkgFileType;
NewUnitName: String;
HasRegister: Boolean;
NewFlags: TPkgFileFlags;
Code: TCodeBuffer;
CurDir: String;
begin
Result := mrOK;
aFilename:=CleanAndExpandFilename(aFileName);
if not FileExistsUTF8(aFilename) then Exit(mrIgnore);
if DirPathExists(aFilename) then Exit(mrIgnore);
if LazPackage.FindPkgFile(aFilename,true,false)<>nil then Exit(mrIgnore);
NewFileType:=FileNameToPkgFileType(aFilename);
NewFlags:=[];
HasRegister:=false;
NewUnitName:='';
if (NewFileType=pftUnit) then begin
Code:=CodeToolBoss.LoadFile(aFilename,true,false);
NewUnitName:=CodeToolBoss.GetSourceName(Code,false);
if NewUnitName='' then
NewUnitName:=ExtractFileNameOnly(aFilename);
if LazPackage.FindUsedUnit(NewUnitName)=nil then
Include(NewFlags,pffAddToPkgUsesSection);
CodeToolBoss.HasInterfaceRegisterProc(Code,HasRegister);
if HasRegister then
Include(NewFlags,pffHasRegisterProc);
end;
{$IFDEF VerbosePkgEditDrag}
debugln(['TPackageEditorForm.FormDropFiles Adding files: ',aFilename,' Unit=',NewUnitName,' Type=',PkgFileTypeIdents[NewFileType],' use=',pffAddToPkgUsesSection in NewFlags,' hasregister=',pffHasRegisterProc in NewFlags]);
{$ENDIF}
LazPackage.AddFile(aFilename,NewUnitName,NewFileType,NewFlags,cpNormal);
CurDir:=ChompPathDelim(ExtractFilePath(aFilename));
if NewFileType=pftUnit then
NewUnitPaths:=MergeSearchPaths(NewUnitPaths,CurDir)
else
NewIncPaths:=MergeSearchPaths(NewIncPaths,CurDir);
end;
procedure TPackageEditorForm.mnuAddDiskFileClick(Sender: TObject);
var
OpenDialog: TOpenDialog;
@ -1619,15 +1577,15 @@ begin
+'|'+dlgFilterLazarusPackage+' (*.lpk)|*.lpk'
+'|'+dlgFilterLazarusProjectSource+' (*.lpr)|*.lpr';
if OpenDialog.Execute then begin
InputHistories.StoreFileDialogSettings(OpenDialog);
NewUnitPaths:='';
NewIncPaths:='';
for i:=0 to OpenDialog.Files.Count-1 do
if not (AddOneFile(OpenDialog.Files[i], NewUnitPaths, NewIncPaths) in [mrOk, mrIgnore]) then break;
InputHistories.StoreFileDialogSettings(OpenDialog);
LazPackage.AddFileByName(OpenDialog.Files[i], NewUnitPaths, NewIncPaths);
//UpdateAll(false);
// extend unit and include search path
if not ExtendUnitSearchPath(NewUnitPaths) then exit;
if not ExtendIncSearchPath(NewIncPaths) then exit;
if not LazPackage.ExtendUnitSearchPath(NewUnitPaths) then exit;
if not LazPackage.ExtendIncSearchPath(NewIncPaths) then exit;
end;
finally
OpenDialog.Free;
@ -3065,47 +3023,13 @@ begin
end;
function TPackageEditorForm.ExtendUnitSearchPath(NewUnitPaths: string): boolean;
var
CurUnitPaths: String;
r: TModalResult;
begin
CurUnitPaths:=LazPackage.CompilerOptions.ParsedOpts.GetParsedValue(pcosUnitPath);
NewUnitPaths:=RemoveSearchPaths(NewUnitPaths,CurUnitPaths);
if NewUnitPaths<>'' then begin
NewUnitPaths:=CreateRelativeSearchPath(NewUnitPaths,LazPackage.Directory);
r:=IDEMessageDialog(lisExtendUnitPath,
Format(lisExtendUnitSearchPathOfPackageWith, [LazPackage.Name, #13,
NewUnitPaths]), mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
mrYes: LazPackage.CompilerOptions.OtherUnitFiles:=
MergeSearchPaths(LazPackage.CompilerOptions.OtherUnitFiles,NewUnitPaths);
mrNo: ;
else exit(false);
end;
end;
Result:=true;
Result:=LazPackage.ExtendUnitSearchPath(NewUnitPaths);
end;
function TPackageEditorForm.ExtendIncSearchPath(NewIncPaths: string): boolean;
var
CurIncPaths: String;
r: TModalResult;
begin
CurIncPaths:=LazPackage.CompilerOptions.ParsedOpts.GetParsedValue(pcosIncludePath);
NewIncPaths:=RemoveSearchPaths(NewIncPaths,CurIncPaths);
if NewIncPaths<>'' then begin
NewIncPaths:=CreateRelativeSearchPath(NewIncPaths,LazPackage.Directory);
r:=IDEMessageDialog(lisExtendIncludePath,
Format(lisExtendIncludeFileSearchPathOfPackageWith, [LazPackage.Name, #13,
NewIncPaths]), mtConfirmation, [mbYes, mbNo, mbCancel]);
case r of
mrYes: LazPackage.CompilerOptions.IncludePath:=
MergeSearchPaths(LazPackage.CompilerOptions.IncludePath,NewIncPaths);
mrNo: ;
else exit(false);
end;
end;
Result:=true;
Result:=LazPackage.ExtendIncSearchPath(NewIncPaths);
end;
function TPackageEditorForm.FilesEditTreeView: TTreeView;

View File

@ -5042,8 +5042,6 @@ var
ActiveUnitInfo: TUnitInfo;
PkgFile: TPkgFile;
Filename: String;
TheUnitName: String;
HasRegisterProc: Boolean;
begin
MainIDE.GetCurrentUnitInfo(ActiveSourceEditor,ActiveUnitInfo);
if ActiveSourceEditor=nil then exit(mrAbort);
@ -5074,19 +5072,8 @@ begin
mtWarning,[mbIgnore,mbCancel]);
if Result<>mrIgnore then exit;
end;
TheUnitName:='';
HasRegisterProc:=false;
if FilenameIsPascalUnit(Filename) then begin
Result:=DoGetUnitRegisterInfo(Filename,TheUnitName,HasRegisterProc,false);
if Result<>mrOk then begin
debugln(['Error: (lazarus) [TPkgManager.DoAddActiveUnitToAPackage] DoGetUnitRegisterInfo failed']);
exit;
end;
end;
Result:=ShowAddFileToAPackageDlg(Filename,TheUnitName,HasRegisterProc,
@MainIDE.GetIDEFileState);
Result:=ShowAddFileToAPackageDlg(Filename);
end;
function TPkgManager.DoNewPackageComponent: TModalResult;