IDE: DoAddActiveUnitToProject: if unit belongs to a package, ask to add dependency

git-svn-id: trunk@22306 -
This commit is contained in:
mattias 2009-10-27 12:04:57 +00:00
parent aee969033e
commit a9b7039924
2 changed files with 65 additions and 30 deletions

View File

@ -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

View File

@ -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,21 +9334,23 @@ 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
ActiveUnitInfo.IsPartOfProject:=true; CheckUnitDirIsInSearchPath(ActiveUnitInfo,true,DependencyAdded);
Project1.Modified:=true; if not DependencyAdded then begin
if (FilenameIsPascalUnit(ActiveUnitInfo.Filename)) ActiveUnitInfo.IsPartOfProject:=true;
and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags) Project1.Modified:=true;
then begin if (FilenameIsPascalUnit(ActiveUnitInfo.Filename))
ActiveUnitInfo.ReadUnitNameFromSource(false); and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags)
ShortUnitName:=ActiveUnitInfo.CreateUnitName; then begin
if (ShortUnitName<>'') then begin ActiveUnitInfo.ReadUnitNameFromSource(false);
if CodeToolBoss.AddUnitToMainUsesSection( ShortUnitName:=ActiveUnitInfo.CreateUnitName;
Project1.MainUnitInfo.Source,ShortUnitName,'') if (ShortUnitName<>'') then begin
then if CodeToolBoss.AddUnitToMainUsesSection(
Project1.MainUnitInfo.Modified:=true; Project1.MainUnitInfo.Source,ShortUnitName,'')
then
Project1.MainUnitInfo.Modified:=true;
end;
end; end;
end; end;
CheckUnitDirIsInSearchPath(ActiveUnitInfo);
end; end;
end; end;
end; end;
@ -14622,26 +14627,53 @@ 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;
CurUnitPath:=Project1.CompilerOptions.GetUnitPath(false); if UnitInfo.IsVirtual then exit;
CurDirectory:=UnitInfo.GetDirectory; CurUnitPath:=Project1.CompilerOptions.GetUnitPath(false);
if SearchDirectoryInSearchPath(CurUnitPath,CurDirectory)<1 then CurDirectory:=AppendPathDelim(UnitInfo.GetDirectory);
begin if SearchDirectoryInSearchPath(CurUnitPath,CurDirectory)<1 then
if MessageDlg(lisAddToUnitSearchPath, begin
Format(lisTheNewUnitIsNotYetInTheUnitSearchPathAddDirectory, [ if AllowAddingDependencies then begin
#13, CurDirectory]), Owners:=PkgBoss.GetPossibleOwnersOfUnit(UnitInfo.Filename,[]);
mtConfirmation,[mbYes,mbNo],0)=mrYes try
then begin if (Owners<>nil) then begin
Project1.CompilerOptions.OtherUnitFiles:= for i:=0 to Owners.Count-1 do begin
MergeSearchPaths(Project1.CompilerOptions.OtherUnitFiles, if TObject(Owners[i]) is TLazPackage then begin
CurDirectory); 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;
end; end;
// unit is not in a package => extend unit path
if MessageDlg(lisAddToUnitSearchPath,
Format(lisTheNewUnitIsNotYetInTheUnitSearchPathAddDirectory, [
#13, CurDirectory]),
mtConfirmation,[mbYes,mbNo],0)=mrYes
then begin
Project1.CompilerOptions.OtherUnitFiles:=
MergeSearchPaths(Project1.CompilerOptions.OtherUnitFiles,
CurDirectory);
end;
end; end;
end; end;
@ -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