mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-20 11:39:36 +01:00
ide: package editor: added menu item add new disk files
This commit is contained in:
parent
095aa3167f
commit
09068e7f4e
@ -16,7 +16,7 @@ object PackageEditorForm: TPackageEditorForm
|
|||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
OnDestroy = FormDestroy
|
OnDestroy = FormDestroy
|
||||||
OnDropFiles = FormDropFiles
|
OnDropFiles = FormDropFiles
|
||||||
LCLVersion = '2.3.0.0'
|
LCLVersion = '3.99.0.0'
|
||||||
object ToolBar: TToolBar
|
object ToolBar: TToolBar
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 48
|
Height = 48
|
||||||
@ -32,19 +32,19 @@ object PackageEditorForm: TPackageEditorForm
|
|||||||
object PropsGroupBox: TGroupBox
|
object PropsGroupBox: TGroupBox
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 216
|
Height = 216
|
||||||
Top = 216
|
Top = 222
|
||||||
Width = 464
|
Width = 464
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
Caption = 'PropsGroupBox'
|
Caption = 'PropsGroupBox'
|
||||||
ClientHeight = 186
|
ClientHeight = 200
|
||||||
ClientWidth = 460
|
ClientWidth = 462
|
||||||
ParentFont = False
|
ParentFont = False
|
||||||
TabOrder = 3
|
TabOrder = 3
|
||||||
object PropsPageControl: TPageControl
|
object PropsPageControl: TPageControl
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 186
|
Height = 200
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 460
|
Width = 462
|
||||||
ActivePage = CommonOptionsTabSheet
|
ActivePage = CommonOptionsTabSheet
|
||||||
Align = alClient
|
Align = alClient
|
||||||
ParentFont = False
|
ParentFont = False
|
||||||
@ -59,8 +59,8 @@ object PackageEditorForm: TPackageEditorForm
|
|||||||
end
|
end
|
||||||
object StatusBar: TStatusBar
|
object StatusBar: TStatusBar
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 23
|
Height = 17
|
||||||
Top = 432
|
Top = 438
|
||||||
Width = 464
|
Width = 464
|
||||||
Panels = <>
|
Panels = <>
|
||||||
ParentFont = False
|
ParentFont = False
|
||||||
@ -69,7 +69,7 @@ object PackageEditorForm: TPackageEditorForm
|
|||||||
Cursor = crVSplit
|
Cursor = crVSplit
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 5
|
Height = 5
|
||||||
Top = 211
|
Top = 217
|
||||||
Width = 464
|
Width = 464
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
ResizeAnchor = akBottom
|
ResizeAnchor = akBottom
|
||||||
@ -207,7 +207,7 @@ object PackageEditorForm: TPackageEditorForm
|
|||||||
end
|
end
|
||||||
object ItemsTreeView: TTreeView
|
object ItemsTreeView: TTreeView
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 134
|
Height = 140
|
||||||
Top = 77
|
Top = 77
|
||||||
Width = 464
|
Width = 464
|
||||||
Align = alClient
|
Align = alClient
|
||||||
@ -251,6 +251,10 @@ object PackageEditorForm: TPackageEditorForm
|
|||||||
Default = True
|
Default = True
|
||||||
OnClick = mnuAddDiskFileClick
|
OnClick = mnuAddDiskFileClick
|
||||||
end
|
end
|
||||||
|
object mnuAddNewDiskFiles: TMenuItem
|
||||||
|
Caption = 'Add new disk files...'
|
||||||
|
OnClick = mnuAddNewDiskFilesClick
|
||||||
|
end
|
||||||
object MenuItem1: TMenuItem
|
object MenuItem1: TMenuItem
|
||||||
Caption = '-'
|
Caption = '-'
|
||||||
end
|
end
|
||||||
|
|||||||
@ -40,7 +40,7 @@ uses
|
|||||||
// LazControls
|
// LazControls
|
||||||
TreeFilterEdit,
|
TreeFilterEdit,
|
||||||
// Codetools
|
// Codetools
|
||||||
CodeToolManager, CodeCache,
|
CodeToolManager, CodeCache, DirectoryCacher, FileProcs,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
FileUtil, LazFileUtils, LazFileCache, AvgLvlTree, LazLoggerBase, LazTracer,
|
FileUtil, LazFileUtils, LazFileCache, AvgLvlTree, LazLoggerBase, LazTracer,
|
||||||
// BuildIntf
|
// BuildIntf
|
||||||
@ -65,6 +65,7 @@ var
|
|||||||
// General actions for the Files and Required packages root nodes.
|
// General actions for the Files and Required packages root nodes.
|
||||||
// Duplicates actions found under the "Add" button.
|
// Duplicates actions found under the "Add" button.
|
||||||
PkgEditMenuAddDiskFile: TIDEMenuCommand;
|
PkgEditMenuAddDiskFile: TIDEMenuCommand;
|
||||||
|
PkgEditMenuAddNewDiskFiles: TIDEMenuCommand;
|
||||||
PkgEditMenuAddNewFile: TIDEMenuCommand;
|
PkgEditMenuAddNewFile: TIDEMenuCommand;
|
||||||
PkgEditMenuAddNewComp: TIDEMenuCommand;
|
PkgEditMenuAddNewComp: TIDEMenuCommand;
|
||||||
PkgEditMenuAddNewReqr: TIDEMenuCommand;
|
PkgEditMenuAddNewReqr: TIDEMenuCommand;
|
||||||
@ -145,6 +146,7 @@ type
|
|||||||
|
|
||||||
TPackageEditorForm = class(TBasePackageEditor,IFilesEditorInterface)
|
TPackageEditorForm = class(TBasePackageEditor,IFilesEditorInterface)
|
||||||
MenuItem1: TMenuItem;
|
MenuItem1: TMenuItem;
|
||||||
|
mnuAddNewDiskFiles: TMenuItem;
|
||||||
mnuAddFPMakeReq: TMenuItem;
|
mnuAddFPMakeReq: TMenuItem;
|
||||||
mnuAddDiskFile: TMenuItem;
|
mnuAddDiskFile: TMenuItem;
|
||||||
mnuAddNewFile: TMenuItem;
|
mnuAddNewFile: TMenuItem;
|
||||||
@ -211,6 +213,7 @@ type
|
|||||||
procedure ItemsTreeViewKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
procedure ItemsTreeViewKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||||
procedure mnuAddDiskFileClick(Sender: TObject);
|
procedure mnuAddDiskFileClick(Sender: TObject);
|
||||||
procedure mnuAddFPMakeReqClick(Sender: TObject);
|
procedure mnuAddFPMakeReqClick(Sender: TObject);
|
||||||
|
procedure mnuAddNewDiskFilesClick(Sender: TObject);
|
||||||
procedure mnuAddNewCompClick(Sender: TObject);
|
procedure mnuAddNewCompClick(Sender: TObject);
|
||||||
procedure mnuAddNewReqrClick(Sender: TObject);
|
procedure mnuAddNewReqrClick(Sender: TObject);
|
||||||
procedure mnuAddNewFileClick(Sender: TObject);
|
procedure mnuAddNewFileClick(Sender: TObject);
|
||||||
@ -596,8 +599,10 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
NodeData: TPENodeData;
|
NodeData: TPENodeData;
|
||||||
Item: TObject;
|
Item: TObject;
|
||||||
|
YesToAll: TYesToAllList;
|
||||||
begin
|
begin
|
||||||
BeginUpdate;
|
BeginUpdate;
|
||||||
|
YesToAll:=TYesToAllList.Create;
|
||||||
try
|
try
|
||||||
for i:=ItemsTreeView.SelectionCount-1 downto 0 do
|
for i:=ItemsTreeView.SelectionCount-1 downto 0 do
|
||||||
begin
|
begin
|
||||||
@ -608,7 +613,8 @@ begin
|
|||||||
PkgFile:=TPkgFile(Item);
|
PkgFile:=TPkgFile(Item);
|
||||||
AFilename:=PkgFile.GetFullFilename;
|
AFilename:=PkgFile.GetFullFilename;
|
||||||
if TPkgFileCheck.ReAddingUnit(LazPackage, PkgFile.FileType, AFilename,
|
if TPkgFileCheck.ReAddingUnit(LazPackage, PkgFile.FileType, AFilename,
|
||||||
PackageEditors.OnGetIDEFileInfo)<>mrOk then exit;
|
PackageEditors.OnGetIDEFileInfo,YesToAll)<>mrOk then
|
||||||
|
exit;
|
||||||
//PkgFile.Filename:=AFilename;
|
//PkgFile.Filename:=AFilename;
|
||||||
Assert(PkgFile.Filename=AFilename, 'TPackageEditorForm.ReAddMenuItemClick: Unexpected Filename.');
|
Assert(PkgFile.Filename=AFilename, 'TPackageEditorForm.ReAddMenuItemClick: Unexpected Filename.');
|
||||||
LazPackage.UnremovePkgFile(PkgFile);
|
LazPackage.UnremovePkgFile(PkgFile);
|
||||||
@ -624,6 +630,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
LazPackage.Modified:=True;
|
LazPackage.Modified:=True;
|
||||||
finally
|
finally
|
||||||
|
YesToAll.Free;
|
||||||
EndUpdate;
|
EndUpdate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -748,6 +755,8 @@ begin
|
|||||||
// Files root node
|
// Files root node
|
||||||
SetItem(PkgEditMenuAddDiskFile, @mnuAddDiskFileClick, UserSelection=[pstFilesNode],
|
SetItem(PkgEditMenuAddDiskFile, @mnuAddDiskFileClick, UserSelection=[pstFilesNode],
|
||||||
Writable);
|
Writable);
|
||||||
|
SetItem(PkgEditMenuAddNewDiskFiles, @mnuAddNewDiskFilesClick, UserSelection=[pstFilesNode],
|
||||||
|
Writable);
|
||||||
SetItem(PkgEditMenuAddNewFile, @mnuAddNewFileClick, UserSelection=[pstFilesNode],
|
SetItem(PkgEditMenuAddNewFile, @mnuAddNewFileClick, UserSelection=[pstFilesNode],
|
||||||
Writable);
|
Writable);
|
||||||
SetItem(PkgEditMenuAddNewComp, @mnuAddNewCompClick, UserSelection=[pstFilesNode],
|
SetItem(PkgEditMenuAddNewComp, @mnuAddNewCompClick, UserSelection=[pstFilesNode],
|
||||||
@ -1001,6 +1010,118 @@ begin
|
|||||||
ShowAddFPMakeDepDialog
|
ShowAddFPMakeDepDialog
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPackageEditorForm.mnuAddNewDiskFilesClick(Sender: TObject);
|
||||||
|
var
|
||||||
|
Files: TFilenameToStringTree;
|
||||||
|
|
||||||
|
procedure CollectFile(const aFilename: string; CheckType: TPkgFileType);
|
||||||
|
var
|
||||||
|
Ext: String;
|
||||||
|
IDEFileFlags: TIDEFileStateFlags;
|
||||||
|
begin
|
||||||
|
if CompareFilenames(aFilename,'fpmake.pp')=0 then exit;
|
||||||
|
if CompareFilenames(aFilename,LazPackage.GetSrcFilename)=0 then exit;
|
||||||
|
|
||||||
|
case CheckType of
|
||||||
|
pftUnit:
|
||||||
|
if not FilenameIsPascalUnit(aFilename) then exit;
|
||||||
|
pftInclude:
|
||||||
|
begin
|
||||||
|
Ext:=ExtractFileExt(aFilename);
|
||||||
|
if IsPascalIncExt(PChar(Ext))=pietNone then exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if LazPackage.FindPkgFile(aFilename,true,true)<>nil then
|
||||||
|
exit; // already in package
|
||||||
|
if PackageGraph.FindFileInAllPackages(aFilename,true,false)<>nil then
|
||||||
|
exit; // already in a package
|
||||||
|
PackageEditors.OnGetIDEFileInfo(Self,aFilename,[ifsPartOfProject],IDEFileFlags);
|
||||||
|
if ifsPartOfProject in IDEFileFlags then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
if Files.Contains(aFilename) then exit;
|
||||||
|
Files.Add(aFilename,'');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure CollectFiles(const SearchPath: string; CheckType: TPkgFileType);
|
||||||
|
var
|
||||||
|
p, i: Integer;
|
||||||
|
Dir: String;
|
||||||
|
Cache: TCTDirectoryBaseCache;
|
||||||
|
StarCache: TCTStarDirectoryCache;
|
||||||
|
DirCache: TCTDirectoryCache;
|
||||||
|
begin
|
||||||
|
p:=1;
|
||||||
|
repeat
|
||||||
|
Dir:=GetNextDirectoryInSearchPath(SearchPath,p);
|
||||||
|
if Dir='' then break;
|
||||||
|
Cache:=CodeToolBoss.DirectoryCachePool.GetBaseCache(Dir);
|
||||||
|
if Cache=nil then continue;
|
||||||
|
if Cache is TCTStarDirectoryCache then
|
||||||
|
begin
|
||||||
|
StarCache:=TCTStarDirectoryCache(Cache);
|
||||||
|
for i:=0 to StarCache.Listing.Count-1 do
|
||||||
|
CollectFile(StarCache.Listing.GetSubDirFilename(i),CheckType);
|
||||||
|
end else if Cache is TCTDirectoryCache then begin
|
||||||
|
DirCache:=TCTDirectoryCache(Cache);
|
||||||
|
for i:=0 to DirCache.Listing.Count-1 do
|
||||||
|
CollectFile(DirCache.Directory+DirCache.Listing.GetFilename(i),CheckType);
|
||||||
|
end;
|
||||||
|
until false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
aFilename, NewUnitName, Msg: String;
|
||||||
|
Item: PStringToStringItem;
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
NewFileType: TPkgFileType;
|
||||||
|
NewFlags: TPkgFileFlags;
|
||||||
|
begin
|
||||||
|
if LazPackage.IsVirtual then exit;
|
||||||
|
if TPkgFileCheck.ReadOnlyOk(LazPackage)<>mrOK then exit;
|
||||||
|
|
||||||
|
Files:=TFilenameToStringTree.Create(true);
|
||||||
|
try
|
||||||
|
// collect missing units from unit path
|
||||||
|
CollectFiles(LazPackage.GetUnitPath(false),pftUnit);
|
||||||
|
|
||||||
|
// collect missing include files from include path
|
||||||
|
CollectFiles(LazPackage.GetIncludePath(false),pftInclude);
|
||||||
|
|
||||||
|
if Files.Count=0 then
|
||||||
|
begin
|
||||||
|
IDEMessageDialog('No file missing','All .pas, .pp, .p, .inc in unit/include path are already in a project/package.',mtInformation,[mbOk]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Msg:='Add the following files:';
|
||||||
|
for Item in Files do begin
|
||||||
|
aFilename:=Item^.Name;
|
||||||
|
Msg+=LineEnding+CreateRelativePath(aFilename,LazPackage.Directory,true,false);
|
||||||
|
end;
|
||||||
|
if IDEMessageDialog('Add new disk files?',Msg,mtConfirmation,[mbOk,mbCancel])<>mrOk then exit;
|
||||||
|
|
||||||
|
for Item in Files do begin
|
||||||
|
aFilename:=Item^.Name;
|
||||||
|
NewFlags:=[];
|
||||||
|
Code:=CodeToolBoss.LoadFile(aFilename,true,false);
|
||||||
|
NewUnitName:='';
|
||||||
|
if FilenameIsPascalUnit(aFilename) then
|
||||||
|
NewUnitName:=CodeToolBoss.GetSourceName(Code,false);
|
||||||
|
if NewUnitName<>'' then
|
||||||
|
NewFileType:=pftUnit
|
||||||
|
else
|
||||||
|
NewFileType:=pftInclude;
|
||||||
|
if CodeToolBoss.HasInterfaceRegisterProc(Code) then
|
||||||
|
Include(NewFlags,pffHasRegisterProc);
|
||||||
|
LazPackage.AddFile(aFilename,NewUnitName,NewFileType,NewFlags,cpNormal);
|
||||||
|
end;
|
||||||
|
|
||||||
|
finally
|
||||||
|
Files.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPackageEditorForm.mnuAddNewCompClick(Sender: TObject);
|
procedure TPackageEditorForm.mnuAddNewCompClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
ShowNewCompDialog;
|
ShowNewCompDialog;
|
||||||
@ -1374,11 +1495,14 @@ procedure TPackageEditorForm.FormDropFiles(Sender: TObject;
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
NewFilename, NewUnitPaths, NewIncPaths: String;
|
NewFilename, NewUnitPaths, NewIncPaths: String;
|
||||||
|
YesToAll: TYesToAllList;
|
||||||
|
r: TModalResult;
|
||||||
begin
|
begin
|
||||||
{$IFDEF VerbosePkgEditDrag}
|
{$IFDEF VerbosePkgEditDrag}
|
||||||
debugln(['TPackageEditorForm.FormDropFiles ',length(FileNames)]);
|
debugln(['TPackageEditorForm.FormDropFiles ',length(FileNames)]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if length(FileNames)=0 then exit;
|
if length(FileNames)=0 then exit;
|
||||||
|
YesToAll:=TYesToAllList.Create;
|
||||||
BeginUpdate;
|
BeginUpdate;
|
||||||
try
|
try
|
||||||
NewUnitPaths:='';
|
NewUnitPaths:='';
|
||||||
@ -1386,15 +1510,19 @@ begin
|
|||||||
for i:=0 to high(Filenames) do
|
for i:=0 to high(Filenames) do
|
||||||
begin
|
begin
|
||||||
NewFilename:=FileNames[i];
|
NewFilename:=FileNames[i];
|
||||||
if TPkgFileCheck.AddingUnit(LazPackage, NewFilename,
|
r:=TPkgFileCheck.AddingUnit(LazPackage, NewFilename,
|
||||||
PackageEditors.OnGetIDEFileInfo)=mrOK then
|
PackageEditors.OnGetIDEFileInfo,YesToAll);
|
||||||
LazPackage.AddFileByName(NewFilename, NewUnitPaths, NewIncPaths);
|
if r=mrOK then
|
||||||
|
LazPackage.AddFileByName(NewFilename, NewUnitPaths, NewIncPaths)
|
||||||
|
else if r=mrAbort then
|
||||||
|
break;
|
||||||
end;
|
end;
|
||||||
//UpdateAll(false);
|
//UpdateAll(false);
|
||||||
// extend unit and include search path
|
// extend unit and include search path
|
||||||
if not LazPackage.ExtendUnitSearchPath(NewUnitPaths) then exit;
|
if not LazPackage.ExtendUnitSearchPath(NewUnitPaths) then exit;
|
||||||
if not LazPackage.ExtendIncSearchPath(NewIncPaths) then exit;
|
if not LazPackage.ExtendIncSearchPath(NewIncPaths) then exit;
|
||||||
finally
|
finally
|
||||||
|
YesToAll.Free;
|
||||||
EndUpdate;
|
EndUpdate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1464,9 +1592,12 @@ var
|
|||||||
OpenDialog: TOpenDialog;
|
OpenDialog: TOpenDialog;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
NewFilename, NewUnitPaths, NewIncPaths: String;
|
NewFilename, NewUnitPaths, NewIncPaths: String;
|
||||||
|
r: TModalResult;
|
||||||
|
YesToAll: TYesToAllList;
|
||||||
begin
|
begin
|
||||||
// is readonly
|
// is readonly
|
||||||
if TPkgFileCheck.ReadOnlyOk(LazPackage)<>mrOK then exit;
|
if TPkgFileCheck.ReadOnlyOk(LazPackage)<>mrOK then exit;
|
||||||
|
YesToAll:=nil;
|
||||||
OpenDialog:=TOpenDialog.Create(nil);
|
OpenDialog:=TOpenDialog.Create(nil);
|
||||||
try
|
try
|
||||||
InputHistories.ApplyFileDialogSettings(OpenDialog);
|
InputHistories.ApplyFileDialogSettings(OpenDialog);
|
||||||
@ -1486,12 +1617,16 @@ begin
|
|||||||
InputHistories.StoreFileDialogSettings(OpenDialog);
|
InputHistories.StoreFileDialogSettings(OpenDialog);
|
||||||
NewUnitPaths:='';
|
NewUnitPaths:='';
|
||||||
NewIncPaths:='';
|
NewIncPaths:='';
|
||||||
|
YesToAll:=TYesToAllList.Create;
|
||||||
for i:=0 to OpenDialog.Files.Count-1 do
|
for i:=0 to OpenDialog.Files.Count-1 do
|
||||||
begin
|
begin
|
||||||
NewFilename:=OpenDialog.Files[i];
|
NewFilename:=OpenDialog.Files[i];
|
||||||
if TPkgFileCheck.AddingUnit(LazPackage, NewFilename,
|
r:=TPkgFileCheck.AddingUnit(LazPackage, NewFilename,
|
||||||
PackageEditors.OnGetIDEFileInfo)=mrOK then
|
PackageEditors.OnGetIDEFileInfo,YesToAll);
|
||||||
LazPackage.AddFileByName(NewFilename, NewUnitPaths, NewIncPaths);
|
if r=mrOK then
|
||||||
|
LazPackage.AddFileByName(NewFilename, NewUnitPaths, NewIncPaths)
|
||||||
|
else if r=mrAbort then
|
||||||
|
break;
|
||||||
end;
|
end;
|
||||||
//UpdateAll(false);
|
//UpdateAll(false);
|
||||||
// extend unit and include search path
|
// extend unit and include search path
|
||||||
@ -1499,6 +1634,7 @@ begin
|
|||||||
if not LazPackage.ExtendIncSearchPath(NewIncPaths) then exit;
|
if not LazPackage.ExtendIncSearchPath(NewIncPaths) then exit;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
|
YesToAll.Free;
|
||||||
OpenDialog.Free;
|
OpenDialog.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1785,6 +1921,7 @@ begin
|
|||||||
MoreBitBtn.DropdownMenu := MorePopupMenu;
|
MoreBitBtn.DropdownMenu := MorePopupMenu;
|
||||||
|
|
||||||
mnuAddDiskFile.Caption := lisPckEditAddFilesFromFileSystem;
|
mnuAddDiskFile.Caption := lisPckEditAddFilesFromFileSystem;
|
||||||
|
mnuAddNewDiskFiles.Caption := 'Add Missing Files from File System'; // todo resourcestring
|
||||||
mnuAddNewFile.Caption := lisA2PNewFile;
|
mnuAddNewFile.Caption := lisA2PNewFile;
|
||||||
mnuAddNewComp.Caption := lisMenuNewComponent;
|
mnuAddNewComp.Caption := lisMenuNewComponent;
|
||||||
mnuAddNewReqr.Caption := lisProjAddNewRequirement;
|
mnuAddNewReqr.Caption := lisProjAddNewRequirement;
|
||||||
@ -2175,7 +2312,7 @@ begin
|
|||||||
pftText: Result:=ImageIndexText;
|
pftText: Result:=ImageIndexText;
|
||||||
pftBinary: Result:=ImageIndexBinary;
|
pftBinary: Result:=ImageIndexBinary;
|
||||||
else
|
else
|
||||||
Result:=-1;
|
Result:=-1{%H-};
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else if Item is TPkgDependency then
|
else if Item is TPkgDependency then
|
||||||
|
|||||||
@ -21,6 +21,15 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
{ TYesToAllList }
|
||||||
|
|
||||||
|
TYesToAllList = class(TStringList)
|
||||||
|
public
|
||||||
|
function Inc(Name: string): integer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TProjPackFileCheck }
|
||||||
|
|
||||||
TProjPackFileCheck = class
|
TProjPackFileCheck = class
|
||||||
protected
|
protected
|
||||||
class function UnitNameOk(const AFilename, AUnitFilename: string): TModalResult;
|
class function UnitNameOk(const AFilename, AUnitFilename: string): TModalResult;
|
||||||
@ -32,18 +41,18 @@ type
|
|||||||
TPkgFileCheck = class(TProjPackFileCheck)
|
TPkgFileCheck = class(TProjPackFileCheck)
|
||||||
private
|
private
|
||||||
class function NormalizeFN(LazPackage: TLazPackage; var AFilename: string): TModalResult;
|
class function NormalizeFN(LazPackage: TLazPackage; var AFilename: string): TModalResult;
|
||||||
class function FileExistsOk(LazPackage: TLazPackage; const AFilename: string): TModalResult;
|
class function FileExistsOk(LazPackage: TLazPackage; const AFilename: string; YesToAll: TYesToAllList): TModalResult;
|
||||||
class function PartOfProjectOk(const AFilename: string;
|
class function PartOfProjectOk(const AFilename: string;
|
||||||
OnGetIDEFileInfo: TGetIDEFileStateEvent): TModalResult;
|
OnGetIDEFileInfo: TGetIDEFileStateEvent; YesToAll: TYesToAllList): TModalResult;
|
||||||
class function UniqueUnitOk(LazPackage: TLazPackage;
|
class function UniqueUnitOk(LazPackage: TLazPackage;
|
||||||
const AUnitFilename: string): TModalResult;
|
const AUnitFilename: string; YesToAll: TYesToAllList): TModalResult;
|
||||||
public
|
public
|
||||||
class function ReadOnlyOk(LazPackage: TLazPackage): TModalResult;
|
class function ReadOnlyOk(LazPackage: TLazPackage): TModalResult;
|
||||||
class function AddingUnit(LazPackage: TLazPackage; const AFilename: string;
|
class function AddingUnit(LazPackage: TLazPackage; const AFilename: string;
|
||||||
OnGetIDEFileInfo: TGetIDEFileStateEvent): TModalResult;
|
OnGetIDEFileInfo: TGetIDEFileStateEvent; YesToAll: TYesToAllList): TModalResult; // ok=success, cancel=fail, abort=fail and stop multi add
|
||||||
class function ReAddingUnit(LazPackage: TLazPackage;
|
class function ReAddingUnit(LazPackage: TLazPackage;
|
||||||
FileTyp: TPkgFileType; const AFilename: string;
|
FileTyp: TPkgFileType; const AFilename: string;
|
||||||
OnGetIDEFileInfo: TGetIDEFileStateEvent): TModalResult;
|
OnGetIDEFileInfo: TGetIDEFileStateEvent; YesToAll: TYesToAllList): TModalResult;
|
||||||
class function AddingDependency(LazPackage: TLazPackage;
|
class function AddingDependency(LazPackage: TLazPackage;
|
||||||
NewDependency: TPkgDependency; WarnIfAlreadyThere: boolean): TModalResult;
|
NewDependency: TPkgDependency; WarnIfAlreadyThere: boolean): TModalResult;
|
||||||
end;
|
end;
|
||||||
@ -77,6 +86,14 @@ begin
|
|||||||
Result := TPrjFileCheck.AddingDependency(AProjPack as TProject, ADependency) = mrOK;
|
Result := TPrjFileCheck.AddingDependency(AProjPack as TProject, ADependency) = mrOK;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TYesToAllList }
|
||||||
|
|
||||||
|
function TYesToAllList.Inc(Name: string): integer;
|
||||||
|
begin
|
||||||
|
Result:=StrToIntDef(Values[Name],0)+1;
|
||||||
|
Values[Name]:=IntToStr(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TProjPackFileCheck }
|
{ TProjPackFileCheck }
|
||||||
|
|
||||||
class function TProjPackFileCheck.UnitNameOk(const AFilename, AUnitFilename: string): TModalResult;
|
class function TProjPackFileCheck.UnitNameOk(const AFilename, AUnitFilename: string): TModalResult;
|
||||||
@ -130,7 +147,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
class function TPkgFileCheck.FileExistsOk(LazPackage: TLazPackage;
|
class function TPkgFileCheck.FileExistsOk(LazPackage: TLazPackage;
|
||||||
const AFilename: string): TModalResult;
|
const AFilename: string; YesToAll: TYesToAllList): TModalResult;
|
||||||
var
|
var
|
||||||
PkgFile: TPkgFile;
|
PkgFile: TPkgFile;
|
||||||
Msg: String;
|
Msg: String;
|
||||||
@ -139,7 +156,8 @@ begin
|
|||||||
// check if file exists
|
// check if file exists
|
||||||
if not FileExistsUTF8(AFilename) then
|
if not FileExistsUTF8(AFilename) then
|
||||||
begin
|
begin
|
||||||
IDEMessageDialog(lisFileNotFound, Format(lisPkgMangFileNotFound,[AFilename]),
|
if YesToAll.Inc('FileNotFound')<4 then
|
||||||
|
IDEMessageDialog(lisFileNotFound, Format(lisPkgMangFileNotFound,[AFilename]),
|
||||||
mtError, [mbCancel]);
|
mtError, [mbCancel]);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -147,6 +165,7 @@ begin
|
|||||||
PkgFile:=LazPackage.FindPkgFile(AFilename,true,false);
|
PkgFile:=LazPackage.FindPkgFile(AFilename,true,false);
|
||||||
if PkgFile<>nil then
|
if PkgFile<>nil then
|
||||||
begin
|
begin
|
||||||
|
if YesToAll.Inc('FileAlreadyInPackage')>2 then exit;
|
||||||
Msg:=Format(lisA2PFileAlreadyExistsInThePackage, [AFilename]);
|
Msg:=Format(lisA2PFileAlreadyExistsInThePackage, [AFilename]);
|
||||||
if PkgFile.Filename<>AFilename then
|
if PkgFile.Filename<>AFilename then
|
||||||
Msg:=Msg+LineEnding+Format(lisA2PExistingFile2, [PkgFile.Filename]);
|
Msg:=Msg+LineEnding+Format(lisA2PExistingFile2, [PkgFile.Filename]);
|
||||||
@ -157,7 +176,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
class function TPkgFileCheck.PartOfProjectOk(const AFilename: string;
|
class function TPkgFileCheck.PartOfProjectOk(const AFilename: string;
|
||||||
OnGetIDEFileInfo: TGetIDEFileStateEvent): TModalResult;
|
OnGetIDEFileInfo: TGetIDEFileStateEvent; YesToAll: TYesToAllList
|
||||||
|
): TModalResult;
|
||||||
var
|
var
|
||||||
IDEFileFlags: TIDEFileStateFlags;
|
IDEFileFlags: TIDEFileStateFlags;
|
||||||
begin
|
begin
|
||||||
@ -166,6 +186,7 @@ begin
|
|||||||
OnGetIDEFileInfo(nil,AFilename,[ifsPartOfProject],IDEFileFlags);
|
OnGetIDEFileInfo(nil,AFilename,[ifsPartOfProject],IDEFileFlags);
|
||||||
if ifsPartOfProject in IDEFileFlags then
|
if ifsPartOfProject in IDEFileFlags then
|
||||||
begin
|
begin
|
||||||
|
if YesToAll.Inc('MixingProjectAndPackage')>1 then exit;
|
||||||
IDEMessageDialog(lisA2PFileIsUsed,
|
IDEMessageDialog(lisA2PFileIsUsed,
|
||||||
Format(lisA2PTheFileIsPartOfTheCurrentProjectItIsABadIdea,[AFilename,LineEnding]),
|
Format(lisA2PTheFileIsPartOfTheCurrentProjectItIsABadIdea,[AFilename,LineEnding]),
|
||||||
mtError,[mbCancel]);
|
mtError,[mbCancel]);
|
||||||
@ -175,10 +196,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
class function TPkgFileCheck.UniqueUnitOk(LazPackage: TLazPackage;
|
class function TPkgFileCheck.UniqueUnitOk(LazPackage: TLazPackage;
|
||||||
const AUnitFilename: string): TModalResult;
|
const AUnitFilename: string; YesToAll: TYesToAllList): TModalResult;
|
||||||
// This is called only for Pascal units.
|
// This is called only for Pascal units.
|
||||||
var
|
var
|
||||||
PkgFile: TPkgFile;
|
PkgFile: TPkgFile;
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
// check if unitname already exists in package
|
// check if unitname already exists in package
|
||||||
@ -186,30 +208,64 @@ begin
|
|||||||
if PkgFile<>nil then
|
if PkgFile<>nil then
|
||||||
begin
|
begin
|
||||||
// a unit with this name already exists in this package => warn
|
// a unit with this name already exists in this package => warn
|
||||||
if IDEMessageDialog(lisA2PUnitnameAlreadyExists,
|
i:=YesToAll.Inc('UnitnameExistsInPkg');
|
||||||
|
if i=1 then
|
||||||
|
begin
|
||||||
|
if IDEMessageDialog(lisA2PUnitnameAlreadyExists,
|
||||||
Format(lisA2PTheUnitnameAlreadyExistsInThisPackage,[AUnitFilename]),
|
Format(lisA2PTheUnitnameAlreadyExistsInThisPackage,[AUnitFilename]),
|
||||||
mtError,[mbCancel,mbIgnore]) <> mrIgnore then
|
mtError,[mbCancel,mbIgnore]) <> mrIgnore then
|
||||||
exit;
|
exit;
|
||||||
|
end else if i<100000 then begin
|
||||||
|
if IDEMessageDialog(lisA2PUnitnameAlreadyExists,
|
||||||
|
Format(lisA2PTheUnitnameAlreadyExistsInThisPackage,[AUnitFilename]),
|
||||||
|
mtError,[mbCancel,mbYesToAll]) = mrYesToAll then
|
||||||
|
YesToAll.Values['UnitnameExistsInPkg']:='100000'
|
||||||
|
else
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
PkgFile:=PackageGraph.FindUnit(LazPackage,AUnitFilename,true,true);
|
PkgFile:=PackageGraph.FindUnit(LazPackage,AUnitFilename,true,true);
|
||||||
if (PkgFile<>nil) and (PkgFile.LazPackage<>LazPackage) then
|
if (PkgFile<>nil) and (PkgFile.LazPackage<>LazPackage) then
|
||||||
begin
|
begin
|
||||||
// there is already a unit with this name in another package => warn
|
// there is already a unit with this name in another package => warn
|
||||||
if IDEMessageDialog(lisA2PUnitnameAlreadyExists,
|
i:=YesToAll.Inc('UnitnameExistsInOtherPkg');
|
||||||
|
if i=1 then
|
||||||
|
begin
|
||||||
|
if IDEMessageDialog(lisA2PUnitnameAlreadyExists,
|
||||||
Format(lisA2PTheUnitnameAlreadyExistsInThePackage,
|
Format(lisA2PTheUnitnameAlreadyExistsInThePackage,
|
||||||
[AUnitFilename, LineEnding, PkgFile.LazPackage.IDAsString]),
|
[AUnitFilename, LineEnding, PkgFile.LazPackage.IDAsString]),
|
||||||
mtWarning,[mbCancel,mbIgnore]) <> mrIgnore then
|
mtWarning,[mbCancel,mbIgnore]) <> mrIgnore then
|
||||||
exit;
|
exit;
|
||||||
|
end else if i<100000 then begin
|
||||||
|
if IDEMessageDialog(lisA2PUnitnameAlreadyExists,
|
||||||
|
Format(lisA2PTheUnitnameAlreadyExistsInThePackage,
|
||||||
|
[AUnitFilename, LineEnding, PkgFile.LazPackage.IDAsString]),
|
||||||
|
mtWarning,[mbCancel,mbYesToAll]) = mrYesToAll then
|
||||||
|
YesToAll.Values['UnitnameExistsInOtherPkg']:='100000'
|
||||||
|
else
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
// check if unitname is a componentclass
|
// check if unitname is a componentclass
|
||||||
if IDEComponentPalette.FindRegComponent(AUnitFilename)<>nil then
|
if IDEComponentPalette.FindRegComponent(AUnitFilename)<>nil then
|
||||||
begin
|
begin
|
||||||
if IDEMessageDialog(lisA2PAmbiguousUnitName,
|
i:=YesToAll.Inc('UnitnameIsCompName');
|
||||||
Format(lisA2PTheUnitNameIsTheSameAsAnRegisteredComponent,[AUnitFilename,LineEnding]),
|
if i=1 then
|
||||||
mtWarning,[mbCancel,mbIgnore]) <> mrIgnore then
|
begin
|
||||||
exit;
|
if IDEMessageDialog(lisA2PAmbiguousUnitName,
|
||||||
|
Format(lisA2PTheUnitNameIsTheSameAsAnRegisteredComponent,[AUnitFilename,LineEnding]),
|
||||||
|
mtWarning,[mbCancel,mbIgnore]) <> mrIgnore then
|
||||||
|
exit;
|
||||||
|
end else if i<100000 then begin
|
||||||
|
if IDEMessageDialog(lisA2PAmbiguousUnitName,
|
||||||
|
Format(lisA2PTheUnitNameIsTheSameAsAnRegisteredComponent,[AUnitFilename,LineEnding]),
|
||||||
|
mtWarning,[mbCancel,mbYesToAll]) = mrYesToAll then
|
||||||
|
YesToAll.Values['UnitnameIsCompName']:='100000'
|
||||||
|
else
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
Result:=mrOK;
|
Result:=mrOK;
|
||||||
end;
|
end;
|
||||||
@ -222,23 +278,24 @@ begin
|
|||||||
IDEMessageDialog(lisAF2PPackageIsReadOnly,
|
IDEMessageDialog(lisAF2PPackageIsReadOnly,
|
||||||
Format(lisAF2PThePackageIsReadOnly, [LazPackage.IDAsString]),
|
Format(lisAF2PThePackageIsReadOnly, [LazPackage.IDAsString]),
|
||||||
mtError,[mbCancel]);
|
mtError,[mbCancel]);
|
||||||
exit(mrCancel);
|
exit(mrAbort);
|
||||||
end;
|
end;
|
||||||
Result:=mrOK;
|
Result:=mrOK;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TPkgFileCheck.AddingUnit(LazPackage: TLazPackage;
|
class function TPkgFileCheck.AddingUnit(LazPackage: TLazPackage;
|
||||||
const AFilename: string; OnGetIDEFileInfo: TGetIDEFileStateEvent): TModalResult;
|
const AFilename: string; OnGetIDEFileInfo: TGetIDEFileStateEvent;
|
||||||
|
YesToAll: TYesToAllList): TModalResult;
|
||||||
var
|
var
|
||||||
NewFileType: TPkgFileType;
|
NewFileType: TPkgFileType;
|
||||||
UnitFilename: String;
|
UnitFilename: String;
|
||||||
begin
|
begin
|
||||||
Assert(FilenameIsAbsolute(AFilename), 'TPkgFileCheck.AddingUnit: Not absolute Filename.');
|
Assert(FilenameIsAbsolute(AFilename), 'TPkgFileCheck.AddingUnit: Not absolute Filename.');
|
||||||
// file exists
|
// file exists
|
||||||
Result:=FileExistsOk(LazPackage, AFilename);
|
Result:=FileExistsOk(LazPackage, AFilename, YesToAll);
|
||||||
if Result<>mrOK then exit;
|
if Result<>mrOK then exit;
|
||||||
// file is part of project
|
// file is part of project
|
||||||
Result:=PartOfProjectOk(AFilename, OnGetIDEFileInfo);
|
Result:=PartOfProjectOk(AFilename, OnGetIDEFileInfo, YesToAll);
|
||||||
if Result<>mrOK then exit;
|
if Result<>mrOK then exit;
|
||||||
|
|
||||||
NewFileType:=FileNameToPkgFileType(AFilename);
|
NewFileType:=FileNameToPkgFileType(AFilename);
|
||||||
@ -249,23 +306,24 @@ begin
|
|||||||
Result:=UnitNameOk(AFilename, UnitFilename);
|
Result:=UnitNameOk(AFilename, UnitFilename);
|
||||||
if Result<>mrOK then exit;
|
if Result<>mrOK then exit;
|
||||||
// unit is unique
|
// unit is unique
|
||||||
Result:=UniqueUnitOk(LazPackage, UnitFilename);
|
Result:=UniqueUnitOk(LazPackage, UnitFilename, YesToAll);
|
||||||
if Result<>mrOK then exit;
|
if Result<>mrOK then exit;
|
||||||
Result:=mrOK; // ok
|
Result:=mrOK; // ok
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TPkgFileCheck.ReAddingUnit(LazPackage: TLazPackage;
|
class function TPkgFileCheck.ReAddingUnit(LazPackage: TLazPackage;
|
||||||
FileTyp: TPkgFileType; const AFilename: string;
|
FileTyp: TPkgFileType; const AFilename: string;
|
||||||
OnGetIDEFileInfo: TGetIDEFileStateEvent): TModalResult;
|
OnGetIDEFileInfo: TGetIDEFileStateEvent; YesToAll: TYesToAllList
|
||||||
|
): TModalResult;
|
||||||
var
|
var
|
||||||
UnitFilename: String;
|
UnitFilename: String;
|
||||||
begin
|
begin
|
||||||
Assert(FilenameIsAbsolute(AFilename), 'TPkgFileCheck.ReAddingUnit: Not absolute Filename.');
|
Assert(FilenameIsAbsolute(AFilename), 'TPkgFileCheck.ReAddingUnit: Not absolute Filename.');
|
||||||
// file exists
|
// file exists
|
||||||
Result:=FileExistsOk(LazPackage, AFilename);
|
Result:=FileExistsOk(LazPackage, AFilename, YesToAll);
|
||||||
if Result<>mrOK then exit;
|
if Result<>mrOK then exit;
|
||||||
// file is part of project
|
// file is part of project
|
||||||
Result:=PartOfProjectOk(AFilename, OnGetIDEFileInfo);
|
Result:=PartOfProjectOk(AFilename, OnGetIDEFileInfo, YesToAll);
|
||||||
if Result<>mrOK then exit;
|
if Result<>mrOK then exit;
|
||||||
if not (FileTyp in [pftUnit, pftMainUnit, pftVirtualUnit]) then
|
if not (FileTyp in [pftUnit, pftMainUnit, pftVirtualUnit]) then
|
||||||
exit(mrOK); // Further checks only for Pascal units.
|
exit(mrOK); // Further checks only for Pascal units.
|
||||||
@ -274,7 +332,7 @@ begin
|
|||||||
Result:=UnitNameOk(AFilename, UnitFilename);
|
Result:=UnitNameOk(AFilename, UnitFilename);
|
||||||
if Result<>mrOK then exit;
|
if Result<>mrOK then exit;
|
||||||
// unit is unique
|
// unit is unique
|
||||||
Result:=UniqueUnitOk(LazPackage, UnitFilename);
|
Result:=UniqueUnitOk(LazPackage, UnitFilename, YesToAll);
|
||||||
if Result<>mrOK then exit;
|
if Result<>mrOK then exit;
|
||||||
Result:=mrOK; // ok
|
Result:=mrOK; // ok
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user