mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 12:59:16 +02:00
IDE: DoAddActiveUnitToProject: if unit belongs to a package, ask to add dependency
git-svn-id: trunk@22306 -
This commit is contained in:
parent
aee969033e
commit
a9b7039924
@ -4506,6 +4506,8 @@ resourcestring
|
|||||||
lisContextSensitive = 'Context sensitive';
|
lisContextSensitive = 'Context sensitive';
|
||||||
lisImitateIndentationOfCurrentUnitProjectOrPackage = 'Imitate indentation '
|
lisImitateIndentationOfCurrentUnitProjectOrPackage = 'Imitate indentation '
|
||||||
+'of current unit, project or package';
|
+'of current unit, project or package';
|
||||||
|
lisAddPackageRequirement = 'Add package requirement?';
|
||||||
|
lisAddPackageToProject = 'Add package %s to project?';
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
49
ide/main.pp
49
ide/main.pp
@ -470,8 +470,10 @@ type
|
|||||||
AnUnitInfo: TUnitInfo): TModalresult;
|
AnUnitInfo: TUnitInfo): TModalresult;
|
||||||
|
|
||||||
// Checks if the UnitDirectory is part of the Unit Search Paths,
|
// Checks if the UnitDirectory is part of the Unit Search Paths,
|
||||||
// if not, then ask the user if he wants to include the Unit Search Paths.
|
// if not, then ask the user if he wants to extend dependencies
|
||||||
procedure CheckUnitDirIsInSearchPath(UnitInfo: TUnitInfo);
|
// or the Unit Search Paths.
|
||||||
|
procedure CheckUnitDirIsInSearchPath(UnitInfo: TUnitInfo;
|
||||||
|
AllowAddingDependencies: boolean; out DependencyAdded: boolean);
|
||||||
|
|
||||||
// compiler options dialog events
|
// compiler options dialog events
|
||||||
procedure OnCompilerOptionsDialogTest(Sender: TObject);
|
procedure OnCompilerOptionsDialogTest(Sender: TObject);
|
||||||
@ -9291,6 +9293,7 @@ var
|
|||||||
ActiveSourceEditor: TSourceEditor;
|
ActiveSourceEditor: TSourceEditor;
|
||||||
ActiveUnitInfo: TUnitInfo;
|
ActiveUnitInfo: TUnitInfo;
|
||||||
s, ShortUnitName: string;
|
s, ShortUnitName: string;
|
||||||
|
DependencyAdded: boolean;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
if not BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]) then exit;
|
if not BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]) then exit;
|
||||||
@ -9331,6 +9334,8 @@ begin
|
|||||||
if MessageDlg(Format(lisAddToProject, [s]), mtConfirmation, [mbYes,
|
if MessageDlg(Format(lisAddToProject, [s]), mtConfirmation, [mbYes,
|
||||||
mbCancel], 0) in [mrOk,mrYes]
|
mbCancel], 0) in [mrOk,mrYes]
|
||||||
then begin
|
then begin
|
||||||
|
CheckUnitDirIsInSearchPath(ActiveUnitInfo,true,DependencyAdded);
|
||||||
|
if not DependencyAdded then begin
|
||||||
ActiveUnitInfo.IsPartOfProject:=true;
|
ActiveUnitInfo.IsPartOfProject:=true;
|
||||||
Project1.Modified:=true;
|
Project1.Modified:=true;
|
||||||
if (FilenameIsPascalUnit(ActiveUnitInfo.Filename))
|
if (FilenameIsPascalUnit(ActiveUnitInfo.Filename))
|
||||||
@ -9345,7 +9350,7 @@ begin
|
|||||||
Project1.MainUnitInfo.Modified:=true;
|
Project1.MainUnitInfo.Modified:=true;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
CheckUnitDirIsInSearchPath(ActiveUnitInfo);
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -14622,16 +14627,44 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMainIDE.CheckUnitDirIsInSearchPath(UnitInfo: TUnitInfo);
|
procedure TMainIDE.CheckUnitDirIsInSearchPath(UnitInfo: TUnitInfo;
|
||||||
|
AllowAddingDependencies: boolean; out DependencyAdded: boolean);
|
||||||
var
|
var
|
||||||
CurDirectory: String;
|
CurDirectory: String;
|
||||||
CurUnitPath: String;
|
CurUnitPath: String;
|
||||||
|
Owners: TFPList;
|
||||||
|
i: Integer;
|
||||||
|
APackage: TLazPackage;
|
||||||
begin
|
begin
|
||||||
if not UnitInfo.IsVirtual then begin
|
DependencyAdded:=false;
|
||||||
|
if UnitInfo.IsVirtual then exit;
|
||||||
CurUnitPath:=Project1.CompilerOptions.GetUnitPath(false);
|
CurUnitPath:=Project1.CompilerOptions.GetUnitPath(false);
|
||||||
CurDirectory:=UnitInfo.GetDirectory;
|
CurDirectory:=AppendPathDelim(UnitInfo.GetDirectory);
|
||||||
if SearchDirectoryInSearchPath(CurUnitPath,CurDirectory)<1 then
|
if SearchDirectoryInSearchPath(CurUnitPath,CurDirectory)<1 then
|
||||||
begin
|
begin
|
||||||
|
if AllowAddingDependencies then begin
|
||||||
|
Owners:=PkgBoss.GetPossibleOwnersOfUnit(UnitInfo.Filename,[]);
|
||||||
|
try
|
||||||
|
if (Owners<>nil) then begin
|
||||||
|
for i:=0 to Owners.Count-1 do begin
|
||||||
|
if TObject(Owners[i]) is TLazPackage then begin
|
||||||
|
APackage:=TLazPackage(Owners[i]);
|
||||||
|
if IDEMessageDialog(lisAddPackageRequirement,
|
||||||
|
Format(lisAddPackageToProject, [APackage.IDAsString]),
|
||||||
|
mtConfirmation,[mbYes,mbCancel],'')<>mrYes
|
||||||
|
then
|
||||||
|
exit;
|
||||||
|
PkgBoss.AddProjectDependency(Project1,APackage);
|
||||||
|
DependencyAdded:=true;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
Owners.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
// unit is not in a package => extend unit path
|
||||||
if MessageDlg(lisAddToUnitSearchPath,
|
if MessageDlg(lisAddToUnitSearchPath,
|
||||||
Format(lisTheNewUnitIsNotYetInTheUnitSearchPathAddDirectory, [
|
Format(lisTheNewUnitIsNotYetInTheUnitSearchPathAddDirectory, [
|
||||||
#13, CurDirectory]),
|
#13, CurDirectory]),
|
||||||
@ -14642,7 +14675,6 @@ begin
|
|||||||
CurDirectory);
|
CurDirectory);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMainIDE.ProjInspectorAddUnitToProject(Sender: TObject;
|
function TMainIDE.ProjInspectorAddUnitToProject(Sender: TObject;
|
||||||
@ -14652,11 +14684,12 @@ var
|
|||||||
ActiveUnitInfo: TUnitInfo;
|
ActiveUnitInfo: TUnitInfo;
|
||||||
ShortUnitName: String;
|
ShortUnitName: String;
|
||||||
Dummy: Boolean;
|
Dummy: Boolean;
|
||||||
|
DependencyAdded: boolean;
|
||||||
begin
|
begin
|
||||||
Result:=mrOk;
|
Result:=mrOk;
|
||||||
BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]);
|
BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]);
|
||||||
AnUnitInfo.IsPartOfProject:=true;
|
AnUnitInfo.IsPartOfProject:=true;
|
||||||
CheckUnitDirIsInSearchPath(AnUnitInfo);
|
CheckUnitDirIsInSearchPath(AnUnitInfo,false,DependencyAdded);
|
||||||
if FilenameIsPascalUnit(AnUnitInfo.Filename)
|
if FilenameIsPascalUnit(AnUnitInfo.Filename)
|
||||||
and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags)
|
and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags)
|
||||||
then begin
|
then begin
|
||||||
|
Loading…
Reference in New Issue
Block a user