mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-23 04:19:47 +02:00
Converter: Let Delphi use missing units instead of commenting them out.
git-svn-id: trunk@24184 -
This commit is contained in:
parent
7b2852cad0
commit
07f218abd9
@ -149,8 +149,8 @@ end;
|
||||
function TConvDelphiCodeTool.AddDelphiAndLCLSections: boolean;
|
||||
// add, remove and rename units for desired target.
|
||||
var
|
||||
WinOnlyUnits: TStringList; // Windows and LCL specific units.
|
||||
LclOnlyUnits: TStringList;
|
||||
DelphiOnlyUnits: TStringList; // Delphi specific units.
|
||||
LclOnlyUnits: TStringList; // LCL specific units.
|
||||
UsesNode: TCodeTreeNode;
|
||||
Junk: TAtomPosition;
|
||||
IsWinUnit, IsVariantUnit: Boolean;
|
||||
@ -158,7 +158,7 @@ var
|
||||
InsPos, i: Integer;
|
||||
begin
|
||||
Result:=false;
|
||||
WinOnlyUnits:=TStringList.Create;
|
||||
DelphiOnlyUnits:=TStringList.Create;
|
||||
LclOnlyUnits:=TStringList.Create;
|
||||
try
|
||||
fCodeTool.BuildTree(true);
|
||||
@ -185,27 +185,39 @@ begin
|
||||
// Don't do anything. Delphi units work for Lazarus under Windows.
|
||||
end;
|
||||
ctLazarusAndDelphi: begin
|
||||
// Make separate sections for LCL and Windows units.
|
||||
// Make separate sections for LCL and Delphi units.
|
||||
if IsWinUnit then begin
|
||||
WinOnlyUnits.Append('Windows');
|
||||
DelphiOnlyUnits.Append('Windows');
|
||||
LclOnlyUnits.Append('LCLIntf');
|
||||
LclOnlyUnits.Append('LCLType');
|
||||
LclOnlyUnits.Append('LMessages');
|
||||
fCodeTool.RemoveUnitFromUsesSection(UsesNode, 'WINDOWS', fSrcCache);
|
||||
end;
|
||||
if IsVariantUnit then begin
|
||||
WinOnlyUnits.Append('Variants');
|
||||
DelphiOnlyUnits.Append('Variants');
|
||||
fCodeTool.BuildTree(true);
|
||||
UsesNode:=fCodeTool.FindMainUsesSection;
|
||||
fCodeTool.MoveCursorToUsesStart(UsesNode);
|
||||
fCodeTool.RemoveUnitFromUsesSection(UsesNode, 'VARIANTS', fSrcCache);
|
||||
end;
|
||||
if (LclOnlyUnits.Count>0) or (WinOnlyUnits.Count>0) then begin
|
||||
// Add Windows and LCL sections for output.
|
||||
// Now the missing units are not commented but used by Delphi instead.
|
||||
for i:=0 to fUnitsToComment.Count-1 do begin
|
||||
s:=UpperCaseStr(fUnitsToComment[i]);
|
||||
fCodeTool.BuildTree(true);
|
||||
UsesNode:=fCodeTool.FindMainUsesSection;
|
||||
fCodeTool.MoveCursorToUsesStart(UsesNode);
|
||||
fCodeTool.RemoveUnitFromUsesSection(UsesNode, s, fSrcCache);
|
||||
end;
|
||||
DelphiOnlyUnits.AddStrings(fUnitsToComment);
|
||||
if (LclOnlyUnits.Count>0) or (DelphiOnlyUnits.Count>0) then begin
|
||||
// Add LCL and Delphi sections for output.
|
||||
nl:=fSrcCache.BeautifyCodeOptions.LineEnd;
|
||||
s:='{$IFDEF LCL}'+nl+' ';
|
||||
for i:=0 to LclOnlyUnits.Count-1 do
|
||||
s:=s+LclOnlyUnits[i]+', ';
|
||||
s:=s+nl+'{$ELSE}'+nl+' ';
|
||||
for i:=0 to WinOnlyUnits.Count-1 do
|
||||
s:=s+WinOnlyUnits[i]+', ';
|
||||
for i:=0 to DelphiOnlyUnits.Count-1 do
|
||||
s:=s+DelphiOnlyUnits[i]+', ';
|
||||
s:=s+nl+'{$ENDIF}';
|
||||
// Now add the lines using codetools.
|
||||
if not fSrcCache.Replace(gtEmptyLine,gtNewLine,InsPos,InsPos,s) then exit;
|
||||
@ -216,7 +228,7 @@ begin
|
||||
Result:=true;
|
||||
finally
|
||||
LclOnlyUnits.Free;
|
||||
WinOnlyUnits.Free;
|
||||
DelphiOnlyUnits.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -303,7 +315,7 @@ var
|
||||
begin
|
||||
Result:=false;
|
||||
if Assigned(fUnitsToRemove) then begin
|
||||
for i := 0 to fUnitsToRemove.Count-1 do
|
||||
for i:=0 to fUnitsToRemove.Count-1 do
|
||||
if not fCodeTool.RemoveUnitFromAllUsesSections(fUnitsToRemove[i], fSrcCache) then
|
||||
exit;
|
||||
end;
|
||||
@ -327,7 +339,7 @@ var
|
||||
begin
|
||||
Result:=false;
|
||||
if Assigned(fUnitsToAdd) then
|
||||
for i := 0 to fUnitsToAdd.Count-1 do
|
||||
for i:=0 to fUnitsToAdd.Count-1 do
|
||||
if not fCodeTool.AddUnitToMainUsesSection(fUnitsToAdd[i],'',fSrcCache) then
|
||||
exit;
|
||||
Result:=true;
|
||||
@ -336,11 +348,14 @@ end;
|
||||
function TConvDelphiCodeTool.CommentOutUnits: boolean;
|
||||
// Comment out missing units
|
||||
begin
|
||||
Result:=false;
|
||||
if Assigned(fUnitsToComment) and (fUnitsToComment.Count>0) then
|
||||
if not fCodeTool.CommentUnitsInUsesSections(fUnitsToComment, fSrcCache) then
|
||||
exit;
|
||||
// If units are used by Delphi (IFDEF block) -> don't comment.
|
||||
if fTarget<>ctLazarusAndDelphi then begin
|
||||
Result:=false;
|
||||
if Assigned(fUnitsToComment) and (fUnitsToComment.Count>0) then
|
||||
if not fCodeTool.CommentUnitsInUsesSections(fUnitsToComment, fSrcCache) then
|
||||
exit;
|
||||
// IDEMessagesWindow.AddMsg('Error="'+CodeToolBoss.ErrorMessage+'"','',-1);
|
||||
end;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
|
@ -41,10 +41,10 @@ uses
|
||||
// IDEIntf
|
||||
ComponentReg, IDEMsgIntf, MainIntf, LazIDEIntf, PackageIntf, ProjectIntf,
|
||||
// IDE
|
||||
IDEProcs, MissingUnits, Project, DialogProcs, //CheckLFMDlg,
|
||||
IDEProcs, Project, DialogProcs,
|
||||
EditorOptions, CompilerOptions, PackageDefs, PackageSystem,
|
||||
PackageEditor, BasePkgManager, LazarusIDEStrConsts,
|
||||
ConvertSettings, ConvCodeTool, MissingPropertiesDlg;
|
||||
ConvertSettings, ConvCodeTool, MissingUnits, MissingPropertiesDlg;
|
||||
|
||||
const
|
||||
SettingDelphiModeTemplName = 'Setting Delphi Mode';
|
||||
@ -639,7 +639,6 @@ begin
|
||||
LfmFixer.Settings:=fSettings;
|
||||
LfmFixer.RootMustBeClassInIntf:=true;
|
||||
LfmFixer.ObjectsMustExists:=true;
|
||||
// was: if RepairLFMBuffer(...,true,true)<>mrOk
|
||||
if LfmFixer.Repair<>mrOk then begin
|
||||
LazarusIDE.DoJumpToCompilerMessage(-1,true);
|
||||
exit(mrAbort);
|
||||
@ -755,7 +754,8 @@ begin
|
||||
// ask user what to do
|
||||
repeat
|
||||
TryAgain:=False;
|
||||
Result:=AskMissingUnits(fMissingUnits, ExtractFileName(fLazUnitFilename));
|
||||
Result:=AskMissingUnits(fMissingUnits, ExtractFileName(fLazUnitFilename),
|
||||
fSettings.Target=ctLazarusAndDelphi);
|
||||
case Result of
|
||||
// mrOK means: comment out.
|
||||
mrOK: begin
|
||||
|
@ -142,6 +142,8 @@ begin
|
||||
fReplaceProps['TCoolBar']:='TPanel';
|
||||
fReplaceProps['TRichEdit']:='TMemo';
|
||||
fReplaceProps['TDBRichEdit']:='TDBMemo';
|
||||
fReplaceProps['TPNGObject']:='TPortableNetworkGraphic';
|
||||
fReplaceProps['TTntForm']:='TForm';
|
||||
end;
|
||||
|
||||
destructor TConvertSettings.Destroy;
|
||||
|
@ -42,19 +42,6 @@ uses
|
||||
CompilerOptions,
|
||||
PackageDefs, Project, DialogProcs, IDEProcs, LazarusIDEStrConsts;
|
||||
|
||||
const
|
||||
// Copied from LazarusIDEStrConsts, remove later...
|
||||
lisMissingUnitsComment = 'Comment Out';
|
||||
lisMissingUnitsSearch = 'Search Unit Path';
|
||||
lisTheseUnitsWereNotFound = 'These units were not found:';
|
||||
lisMissingUnitsChoices = 'Your choices are:';
|
||||
lisMissingUnitsInfo1 = '1) Comment out the missing units (ignore them).';
|
||||
lisMissingUnitsInfo2 = '2) Select a unit path which will be added to project settings.';
|
||||
lisMissingUnitsInfo3 = '3) Abort now, fix the unit path or install packages and try again.';
|
||||
lisUnitNotFound = 'A unit not found in';
|
||||
lisUnitsNotFound2 = 'Units not found in';
|
||||
|
||||
|
||||
type
|
||||
|
||||
{ TMissingUnitsDialog }
|
||||
@ -81,14 +68,16 @@ type
|
||||
var
|
||||
MissingUnitsDialog: TMissingUnitsDialog;
|
||||
|
||||
function AskMissingUnits(AMissingUnits: TStrings; AMainUnitName: string): TModalResult;
|
||||
function AskMissingUnits(AMissingUnits: TStrings; AMainUnitName: string;
|
||||
ATargetDelphi: boolean): TModalResult;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
function AskMissingUnits(AMissingUnits: TStrings; AMainUnitName: string): TModalResult;
|
||||
function AskMissingUnits(AMissingUnits: TStrings; AMainUnitName: string;
|
||||
ATargetDelphi: boolean): TModalResult;
|
||||
var
|
||||
UNFDialog: TMissingUnitsDialog;
|
||||
UnitsTitle, UnitsCommaList: string;
|
||||
@ -113,12 +102,18 @@ begin
|
||||
UNFDialog:=TMissingUnitsDialog.Create(nil);
|
||||
with UNFDialog do begin
|
||||
Caption:=UnitsTitle;
|
||||
CommentButton.Caption:=lisMissingUnitsComment;
|
||||
SearchButton.Caption:=lisMissingUnitsSearch;
|
||||
MissingUnitsInfoLabel.Caption:=lisTheseUnitsWereNotFound;
|
||||
UnitNamesLabel.Caption:=UnitsCommaList;
|
||||
ChoicesLabel.Caption:=lisMissingUnitsChoices;
|
||||
Info1Label.Caption:=lisMissingUnitsInfo1;
|
||||
if ATargetDelphi then begin
|
||||
CommentButton.Caption:=lisMissingUnitsForDelphi;
|
||||
Info1Label.Caption:=lisMissingUnitsInfo1b;
|
||||
end
|
||||
else begin
|
||||
CommentButton.Caption:=lisMissingUnitsComment;
|
||||
Info1Label.Caption:=lisMissingUnitsInfo1;
|
||||
end;
|
||||
Info2Label.Caption:=lisMissingUnitsInfo2;
|
||||
Info3Label.Caption:=lisMissingUnitsInfo3;
|
||||
Result:=ShowModal;
|
||||
|
@ -438,10 +438,12 @@ resourcestring
|
||||
lisUnableToWriteFileError = 'Unable to write file %s%s%s%sError: %s';
|
||||
lisErrorCreatingLrs = 'Error creating lrs';
|
||||
lisMissingUnitsComment = 'Comment Out';
|
||||
lisMissingUnitsForDelphi = 'For Delphi only';
|
||||
lisMissingUnitsSearch = 'Search Unit Path';
|
||||
lisTheseUnitsWereNotFound = 'These units were not found:';
|
||||
lisMissingUnitsChoices = 'Your choices are:';
|
||||
lisMissingUnitsInfo1 = '1) Comment out the missing units (ignore them).';
|
||||
lisMissingUnitsInfo1b = '1) Use the units only for Delphi.';
|
||||
lisMissingUnitsInfo2 = '2) Select a unit path which will be added to project settings.';
|
||||
lisMissingUnitsInfo3 = '3) Abort now, fix the unit path or install packages and try again.';
|
||||
lisUnitNotFound = 'A unit not found in';
|
||||
|
Loading…
Reference in New Issue
Block a user