mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 02:09:14 +02:00
IDE: adding unit to project: add question when unit belongs to other package
git-svn-id: trunk@23759 -
This commit is contained in:
parent
7ff9ae8e45
commit
03419d8ebb
@ -4583,6 +4583,9 @@ resourcestring
|
||||
lisImitateIndentationOfCurrentUnitProjectOrPackage = 'Imitate indentation '
|
||||
+'of current unit, project or package';
|
||||
lisAddPackageRequirement = 'Add package requirement?';
|
||||
lisTheUnitBelongsToPackage = 'The unit belongs to package %s.';
|
||||
lisAddPackageToProject2 = 'Add package to project';
|
||||
lisAddUnitNotRecommended = 'Add unit (not recommended)';
|
||||
lisAddPackageToProject = 'Add package %s to project?';
|
||||
lisOnBreakLineIEReturnOrEnterKey = 'On break line (i.e. return or enter key)';
|
||||
lisOnPasteFromClipboard = 'On paste from clipboard';
|
||||
|
89
ide/main.pp
89
ide/main.pp
@ -9733,6 +9733,10 @@ var
|
||||
ActiveUnitInfo: TUnitInfo;
|
||||
s, ShortUnitName: string;
|
||||
DependencyAdded: boolean;
|
||||
Owners: TFPList;
|
||||
i: Integer;
|
||||
APackage: TLazPackage;
|
||||
MsgResult: TModalResult;
|
||||
begin
|
||||
Result:=mrCancel;
|
||||
if not BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]) then exit;
|
||||
@ -9757,37 +9761,66 @@ begin
|
||||
MessageDlg(Format(
|
||||
lisUnableToAddToProjectBecauseThereIsAlreadyAUnitWith, [s]),
|
||||
mtInformation, [mbOk], 0);
|
||||
end else begin
|
||||
if FilenameIsPascalUnit(ActiveUnitInfo.Filename)
|
||||
and (EnvironmentOptions.CharcaseFileAction<>ccfaIgnore) then
|
||||
begin
|
||||
// ask user to apply naming conventions
|
||||
Result:=DoRenameUnitLowerCase(ActiveUnitInfo,true);
|
||||
if Result=mrIgnore then Result:=mrOk;
|
||||
if Result<>mrOk then begin
|
||||
debugln('TMainIDE.DoAddActiveUnitToProject A DoRenameUnitLowerCase failed ',ActiveUnitInfo.Filename);
|
||||
exit;
|
||||
exit;
|
||||
end;
|
||||
|
||||
Owners:=PkgBoss.GetPossibleOwnersOfUnit(ActiveUnitInfo.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]);
|
||||
MsgResult:=IDEQuestionDialog(lisAddPackageRequirement,
|
||||
Format(lisTheUnitBelongsToPackage, [APackage.IDAsString]),
|
||||
mtConfirmation, [mrYes, lisAddPackageToProject2,
|
||||
mrIgnore, lisAddUnitNotRecommended,
|
||||
mrCancel],'');
|
||||
case MsgResult of
|
||||
mrYes:
|
||||
begin
|
||||
PkgBoss.AddProjectDependency(Project1,APackage);
|
||||
exit;
|
||||
end;
|
||||
mrIgnore: ;
|
||||
else
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
Owners.Free;
|
||||
end;
|
||||
|
||||
if MessageDlg(Format(lisAddToProject, [s]), mtConfirmation, [mbYes,
|
||||
mbCancel], 0) in [mrOk,mrYes]
|
||||
then begin
|
||||
CheckUnitDirIsInSearchPath(ActiveUnitInfo,true,DependencyAdded);
|
||||
if not DependencyAdded then begin
|
||||
ActiveUnitInfo.IsPartOfProject:=true;
|
||||
Project1.Modified:=true;
|
||||
if (FilenameIsPascalUnit(ActiveUnitInfo.Filename))
|
||||
and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags)
|
||||
then begin
|
||||
ActiveUnitInfo.ReadUnitNameFromSource(false);
|
||||
ShortUnitName:=ActiveUnitInfo.CreateUnitName;
|
||||
if (ShortUnitName<>'') then begin
|
||||
if CodeToolBoss.AddUnitToMainUsesSection(
|
||||
Project1.MainUnitInfo.Source,ShortUnitName,'')
|
||||
then
|
||||
Project1.MainUnitInfo.Modified:=true;
|
||||
end;
|
||||
if FilenameIsPascalUnit(ActiveUnitInfo.Filename)
|
||||
and (EnvironmentOptions.CharcaseFileAction<>ccfaIgnore) then
|
||||
begin
|
||||
// ask user to apply naming conventions
|
||||
Result:=DoRenameUnitLowerCase(ActiveUnitInfo,true);
|
||||
if Result=mrIgnore then Result:=mrOk;
|
||||
if Result<>mrOk then begin
|
||||
debugln('TMainIDE.DoAddActiveUnitToProject A DoRenameUnitLowerCase failed ',ActiveUnitInfo.Filename);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
if MessageDlg(Format(lisAddToProject, [s]), mtConfirmation, [mbYes,
|
||||
mbCancel], 0) in [mrOk,mrYes]
|
||||
then begin
|
||||
CheckUnitDirIsInSearchPath(ActiveUnitInfo,false,DependencyAdded);
|
||||
if not DependencyAdded then begin
|
||||
ActiveUnitInfo.IsPartOfProject:=true;
|
||||
Project1.Modified:=true;
|
||||
if (FilenameIsPascalUnit(ActiveUnitInfo.Filename))
|
||||
and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags)
|
||||
then begin
|
||||
ActiveUnitInfo.ReadUnitNameFromSource(false);
|
||||
ShortUnitName:=ActiveUnitInfo.CreateUnitName;
|
||||
if (ShortUnitName<>'') then begin
|
||||
if CodeToolBoss.AddUnitToMainUsesSection(
|
||||
Project1.MainUnitInfo.Source,ShortUnitName,'')
|
||||
then
|
||||
Project1.MainUnitInfo.Modified:=true;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user