mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 06:55:59 +02:00
implemented for delphi unit conversion: auto fixing in filenames
git-svn-id: trunk@6707 -
This commit is contained in:
parent
71f4a8dab7
commit
7f390beb39
@ -1418,7 +1418,7 @@ var UnitSrcSearchPath: string;
|
|||||||
CompiledResult: TCodeBuffer;
|
CompiledResult: TCodeBuffer;
|
||||||
UnitSearchPath: string;
|
UnitSearchPath: string;
|
||||||
SrcPathInitialized: boolean;
|
SrcPathInitialized: boolean;
|
||||||
|
|
||||||
procedure InitSrcPath;
|
procedure InitSrcPath;
|
||||||
begin
|
begin
|
||||||
if SrcPathInitialized then exit;
|
if SrcPathInitialized then exit;
|
||||||
@ -1468,7 +1468,7 @@ begin
|
|||||||
if FilenameIsAbsolute(AnUnitInFilename) then begin
|
if FilenameIsAbsolute(AnUnitInFilename) then begin
|
||||||
Result:=TCodeBuffer(Scanner.OnLoadSource(Self,AnUnitInFilename,true));
|
Result:=TCodeBuffer(Scanner.OnLoadSource(Self,AnUnitInFilename,true));
|
||||||
end else begin
|
end else begin
|
||||||
// file is virtual
|
// file is relative to current unit directory
|
||||||
// -> search file in current directory
|
// -> search file in current directory
|
||||||
CurDir:=AppendPathDelim(CurDir);
|
CurDir:=AppendPathDelim(CurDir);
|
||||||
if not LoadFile(CurDir+AnUnitInFilename,Result) then begin
|
if not LoadFile(CurDir+AnUnitInFilename,Result) then begin
|
||||||
|
@ -61,6 +61,8 @@ type
|
|||||||
const IdentName: string; var IsDefined: boolean) of object;
|
const IdentName: string; var IsDefined: boolean) of object;
|
||||||
|
|
||||||
|
|
||||||
|
{ TStandardCodeTool }
|
||||||
|
|
||||||
TStandardCodeTool = class(TIdentCompletionTool)
|
TStandardCodeTool = class(TIdentCompletionTool)
|
||||||
private
|
private
|
||||||
CachedSourceName: string;
|
CachedSourceName: string;
|
||||||
@ -99,6 +101,10 @@ type
|
|||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
function RemoveUnitFromAllUsesSections(const UpperUnitName: string;
|
function RemoveUnitFromAllUsesSections(const UpperUnitName: string;
|
||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
|
function FixUnitInFilenameCase(
|
||||||
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
|
function FixUnitInFilenameCaseInUsesSection(UsesNode: TCodeTreeNode;
|
||||||
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
function FindUsedUnitNames(var MainUsesSection,
|
function FindUsedUnitNames(var MainUsesSection,
|
||||||
ImplementationUsesSection: TStrings): boolean;
|
ImplementationUsesSection: TStrings): boolean;
|
||||||
function FindUsedUnitFiles(var MainUsesSection,
|
function FindUsedUnitFiles(var MainUsesSection,
|
||||||
@ -597,8 +603,7 @@ begin
|
|||||||
BuildTree(false);
|
BuildTree(false);
|
||||||
SectionNode:=Tree.Root;
|
SectionNode:=Tree.Root;
|
||||||
while (SectionNode<>nil) do begin
|
while (SectionNode<>nil) do begin
|
||||||
if (SectionNode.Desc in [ctnProgram,ctnInterface,ctnImplementation])
|
if (SectionNode.FirstChild<>nil)
|
||||||
and (SectionNode.FirstChild<>nil)
|
|
||||||
and (SectionNode.FirstChild.Desc=ctnUsesSection) then begin
|
and (SectionNode.FirstChild.Desc=ctnUsesSection) then begin
|
||||||
if not RemoveUnitFromUsesSection(SectionNode.FirstChild,UpperUnitName,
|
if not RemoveUnitFromUsesSection(SectionNode.FirstChild,UpperUnitName,
|
||||||
SourceChangeCache)
|
SourceChangeCache)
|
||||||
@ -611,6 +616,109 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TStandardCodeTool.FixUnitInFilenameCase(
|
||||||
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
|
var
|
||||||
|
SectionNode: TCodeTreeNode;
|
||||||
|
begin
|
||||||
|
debugln('TStandardCodeTool.FixUnitInFilenameCase ',MainFilename);
|
||||||
|
Result:=false;
|
||||||
|
BuildTree(false);
|
||||||
|
SectionNode:=Tree.Root;
|
||||||
|
while (SectionNode<>nil) do begin
|
||||||
|
if (SectionNode.FirstChild<>nil)
|
||||||
|
and (SectionNode.FirstChild.Desc=ctnUsesSection) then begin
|
||||||
|
if not FixUnitInFilenameCaseInUsesSection(
|
||||||
|
SectionNode.FirstChild,SourceChangeCache)
|
||||||
|
then begin
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
SectionNode:=SectionNode.NextBrother;
|
||||||
|
end;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TStandardCodeTool.FixUnitInFilenameCaseInUsesSection(
|
||||||
|
UsesNode: TCodeTreeNode; SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
|
|
||||||
|
function FindUnit(const AFilename: string): string;
|
||||||
|
var
|
||||||
|
CurDir: String;
|
||||||
|
MainCodeIsVirtual: Boolean;
|
||||||
|
FileInfo: TSearchRec;
|
||||||
|
CurFilename: String;
|
||||||
|
begin
|
||||||
|
if FilenameIsAbsolute(AFilename) then
|
||||||
|
CurDir:=ExtractFilePath(AFilename)
|
||||||
|
else begin
|
||||||
|
MainCodeIsVirtual:=TCodeBuffer(Scanner.MainCode).IsVirtual;
|
||||||
|
if not MainCodeIsVirtual then begin
|
||||||
|
CurDir:=ExtractFilePath(TCodeBuffer(Scanner.MainCode).Filename);
|
||||||
|
end else begin
|
||||||
|
CurDir:='';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
CurFilename:=ExtractFilename(AFilename);
|
||||||
|
Result:='';
|
||||||
|
if SysUtils.FindFirst(AppendPathDelim(CurDir)+FileMask,
|
||||||
|
faAnyFile,FileInfo)=0 then
|
||||||
|
begin
|
||||||
|
repeat
|
||||||
|
// check if special file
|
||||||
|
if (FileInfo.Name='.') or (FileInfo.Name='..') then continue;
|
||||||
|
if (SysUtils.CompareText(CurFilename,FileInfo.Name)=0)
|
||||||
|
then begin
|
||||||
|
if (Result='') or (FileInfo.Name=CurFilename) then
|
||||||
|
Result:=FileInfo.Name;
|
||||||
|
end;
|
||||||
|
until SysUtils.FindNext(FileInfo)<>0;
|
||||||
|
end;
|
||||||
|
SysUtils.FindClose(FileInfo);
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
UnitInFilename: String;
|
||||||
|
Changed: Boolean;
|
||||||
|
RealUnitInFilename: String;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
if (UsesNode=nil) then exit;
|
||||||
|
MoveCursorToNodeStart(UsesNode);
|
||||||
|
ReadNextAtom; // read 'uses'
|
||||||
|
Changed:=false;
|
||||||
|
repeat
|
||||||
|
ReadNextAtom; // read name
|
||||||
|
if not AtomIsIdentifier(false) then exit;
|
||||||
|
ReadNextAtom;
|
||||||
|
if UpAtomIs('IN') then begin
|
||||||
|
ReadNextAtom;
|
||||||
|
UnitInFilename:=GetAtom;
|
||||||
|
debugln('TStandardCodeTool.FixUnitInFilenameCaseInUsesSection A UnitInFilename="',UnitInFilename,'"');
|
||||||
|
if (UnitInFilename<>'') and (UnitInFilename[1]='''') then begin
|
||||||
|
UnitInFilename:=copy(UnitInFilename,2,length(UnitInFilename)-2);
|
||||||
|
RealUnitInFilename:=FindUnit(UnitInFilename);
|
||||||
|
debugln('TStandardCodeTool.FixUnitInFilenameCaseInUsesSection B RealUnitInFilename="',RealUnitInFilename,'"');
|
||||||
|
if (RealUnitInFilename<>'')
|
||||||
|
and (RealUnitInFilename<>UnitInFilename) then begin
|
||||||
|
if not Changed then begin
|
||||||
|
SourceChangeCache.MainScanner:=Scanner;
|
||||||
|
Changed:=true;
|
||||||
|
end;
|
||||||
|
debugln('TStandardCodeTool.FixUnitInFilenameCaseInUsesSection C Replacing ...');
|
||||||
|
if not SourceChangeCache.Replace(gtNone,gtNone,
|
||||||
|
CurPos.StartPos,CurPos.EndPos,''''+RealUnitInFilename+'''') then exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
ReadNextAtom;
|
||||||
|
end;
|
||||||
|
if AtomIsChar(';') then break;
|
||||||
|
if not AtomIsChar(',') then exit;
|
||||||
|
until (CurPos.StartPos>UsesNode.EndPos) or (CurPos.StartPos>SrcLen);
|
||||||
|
if Changed and (not SourceChangeCache.Apply) then exit;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.FindUsedUnitNames(var MainUsesSection,
|
function TStandardCodeTool.FindUsedUnitNames(var MainUsesSection,
|
||||||
ImplementationUsesSection: TStrings): boolean;
|
ImplementationUsesSection: TStrings): boolean;
|
||||||
var
|
var
|
||||||
@ -701,9 +809,9 @@ begin
|
|||||||
end else
|
end else
|
||||||
AnUnitInFilename:='';
|
AnUnitInFilename:='';
|
||||||
// find unit file
|
// find unit file
|
||||||
NewCode:=FindUnitSource(AnUnitName,AnUnitInFilename,false);
|
|
||||||
if AnUnitInFilename<>'' then begin
|
if AnUnitInFilename<>'' then begin
|
||||||
// An 'in' unit => Delphi project file
|
// An 'in' unit => Delphi project file
|
||||||
|
NewCode:=FindUnitSource(AnUnitName,AnUnitInFilename,false);
|
||||||
if (NewCode=nil) then begin
|
if (NewCode=nil) then begin
|
||||||
// no source found
|
// no source found
|
||||||
MissingInUnits.Add(AnUnitName+' in '+AnUnitInFilename);
|
MissingInUnits.Add(AnUnitName+' in '+AnUnitInFilename);
|
||||||
@ -713,6 +821,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
// the non 'in' units are 'Forms' or units added by the user
|
// the non 'in' units are 'Forms' or units added by the user
|
||||||
|
NewCode:=FindUnitSource(AnUnitName,AnUnitInFilename,false);
|
||||||
NormalUnits.AddObject(AnUnitName,NewCode);
|
NormalUnits.AddObject(AnUnitName,NewCode);
|
||||||
end;
|
end;
|
||||||
// read keyword 'uses' or comma
|
// read keyword 'uses' or comma
|
||||||
@ -2785,6 +2894,7 @@ function TStandardCodeTool.ConvertDelphiToLazarusSource(AddLRSCode: boolean;
|
|||||||
|
|
||||||
function ConvertUsedUnits: boolean;
|
function ConvertUsedUnits: boolean;
|
||||||
// replace unit 'Windows' with 'LCLIntf' and add 'LResources'
|
// replace unit 'Windows' with 'LCLIntf' and add 'LResources'
|
||||||
|
// rename 'in' filenames to case sensitive filename
|
||||||
var
|
var
|
||||||
NamePos, InPos: TAtomPosition;
|
NamePos, InPos: TAtomPosition;
|
||||||
begin
|
begin
|
||||||
@ -2809,6 +2919,11 @@ function TStandardCodeTool.ConvertDelphiToLazarusSource(AddLRSCode: boolean;
|
|||||||
debugln('ConvertUsedUnits Unable to remove Variants from all uses sections');
|
debugln('ConvertUsedUnits Unable to remove Variants from all uses sections');
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
if not FixUnitInFilenameCase(SourceChangeCache) then
|
||||||
|
begin
|
||||||
|
debugln('ConvertUsedUnits Unable to fix unit filename case sensitivity in all uses sections');
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -356,6 +356,7 @@ begin
|
|||||||
[lbfCheckIfText,lbfUpdateFromDisk]);
|
[lbfCheckIfText,lbfUpdateFromDisk]);
|
||||||
if Result<>mrOk then exit;
|
if Result<>mrOk then exit;
|
||||||
CTResult:=CodeToolBoss.ConvertDelphiToLazarusSource(LPRCode,AddLRSCode);
|
CTResult:=CodeToolBoss.ConvertDelphiToLazarusSource(LPRCode,AddLRSCode);
|
||||||
|
debugln('CreateLPRFileForDPRFile: ',LPRCode.Source);
|
||||||
if not CTResult then begin
|
if not CTResult then begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
exit;
|
exit;
|
||||||
|
@ -283,7 +283,8 @@ resourcestring
|
|||||||
lisLazarusProjectInfoLpiLpiAllFiles = 'Lazarus Project Info (*.lpi)|*.lpi|'
|
lisLazarusProjectInfoLpiLpiAllFiles = 'Lazarus Project Info (*.lpi)|*.lpi|'
|
||||||
+'All Files|*.*';
|
+'All Files|*.*';
|
||||||
lisCompilerOptionsForProject = 'Compiler Options for Project: %s';
|
lisCompilerOptionsForProject = 'Compiler Options for Project: %s';
|
||||||
lisChooseDelphiUnit = 'Choose Delphi unit';
|
lisChooseDelphiUnit = 'Choose Delphi unit (*.pas)';
|
||||||
|
lisChooseDelphiProject = 'Choose Delphi project (*.dpr)';
|
||||||
lisUnableToReadFileError = 'Unable to read file %s%s%s%sError: %s';
|
lisUnableToReadFileError = 'Unable to read file %s%s%s%sError: %s';
|
||||||
lisFormatError = 'Format error';
|
lisFormatError = 'Format error';
|
||||||
lisLFMFileCorrupt = 'LFM file corrupt';
|
lisLFMFileCorrupt = 'LFM file corrupt';
|
||||||
|
@ -2918,8 +2918,9 @@ begin
|
|||||||
OpenDialog:=TOpenDialog.Create(nil);
|
OpenDialog:=TOpenDialog.Create(nil);
|
||||||
try
|
try
|
||||||
InputHistories.ApplyFileDialogSettings(OpenDialog);
|
InputHistories.ApplyFileDialogSettings(OpenDialog);
|
||||||
OpenDialog.Title:=lisChooseDelphiUnit;
|
OpenDialog.Title:=lisChooseDelphiProject;
|
||||||
OpenDialog.Options:=OpenDialog.Options;
|
OpenDialog.Options:=OpenDialog.Options;
|
||||||
|
OpenDialog.Filter:='Delphi project (*.dpr)|*.dpr|All files (*.*)|*.*';
|
||||||
if OpenDialog.Execute then begin
|
if OpenDialog.Execute then begin
|
||||||
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
|
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
|
||||||
//debugln('TMainIDE.mnuToolConvertDelphiProjectClicked A ',AFilename);
|
//debugln('TMainIDE.mnuToolConvertDelphiProjectClicked A ',AFilename);
|
||||||
@ -7192,7 +7193,7 @@ begin
|
|||||||
Project1.BeginUpdate(true);
|
Project1.BeginUpdate(true);
|
||||||
try
|
try
|
||||||
if ProjInspector<>nil then ProjInspector.LazProject:=Project1;
|
if ProjInspector<>nil then ProjInspector.LazProject:=Project1;
|
||||||
MainUnitInfo:=TUnitInfo.Create(DPRCode);
|
MainUnitInfo:=TUnitInfo.Create(LPRCode);
|
||||||
MainUnitInfo.SyntaxHighlighter:=
|
MainUnitInfo.SyntaxHighlighter:=
|
||||||
ExtensionToLazSyntaxHighlighter(ExtractFileExt(LPRCode.Filename));
|
ExtensionToLazSyntaxHighlighter(ExtractFileExt(LPRCode.Filename));
|
||||||
MainUnitInfo.IsPartOfProject:=true;
|
MainUnitInfo.IsPartOfProject:=true;
|
||||||
@ -11382,6 +11383,9 @@ end.
|
|||||||
|
|
||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.841 2005/01/28 16:42:30 mattias
|
||||||
|
implemented for delphi unit conversion: auto fixing in filenames
|
||||||
|
|
||||||
Revision 1.840 2005/01/26 15:56:13 mattias
|
Revision 1.840 2005/01/26 15:56:13 mattias
|
||||||
fixed add editor file to project
|
fixed add editor file to project
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user