From aa5f6fd0f7a95f3f33c50bb403ef5cc01e6a1cae Mon Sep 17 00:00:00 2001 From: juha Date: Sat, 8 Jun 2013 16:32:39 +0000 Subject: [PATCH] Converter: Change unit name to match disk name unless the disk name is all lowercase. git-svn-id: trunk@41593 - --- converter/convcodetool.pas | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/converter/convcodetool.pas b/converter/convcodetool.pas index 8f0c2a44b2..c777d07001 100644 --- a/converter/convcodetool.pas +++ b/converter/convcodetool.pas @@ -95,6 +95,7 @@ type destructor Destroy; override; function Convert: TModalResult; function FindApptypeConsole: boolean; + function RenameUnitIfNeeded: boolean; function RenameResourceDirectives: boolean; function FixMainClassAncestor(const AClassName: string; AReplaceTypes: TStringToStringTree): boolean; @@ -215,6 +216,7 @@ begin fCTLink.SrcCache.BeginUpdate; try // these changes can be applied together without rescan + if not RenameUnitIfNeeded then exit; if not AddModeDelphiDirective then exit; if not RenameResourceDirectives then exit; if fCTLink.Settings.FuncReplaceMode=rsEnabled then @@ -243,6 +245,31 @@ begin end; end; +function TConvDelphiCodeTool.RenameUnitIfNeeded: boolean; +// Change the unit name to match the disk name unless the disk name is all lowercase. +var + NamePos: TAtomPosition; + DiskNm, UnitNm: String; +begin + Result:=false; + //BuildTree(lsrSourceName); + with fCTLink do begin + DiskNm := ExtractFileNameOnly(Code.Filename); + if LowerCase(DiskNm)<>DiskNm then begin // Lowercase name is found always. + if not CodeTool.GetSourceNamePos(NamePos) then exit; + UnitNm:=copy(CodeTool.Src, NamePos.StartPos, NamePos.EndPos-NamePos.StartPos); + if DiskNm<>UnitNm then begin + SrcCache.MainScanner:=CodeTool.Scanner; + SrcCache.Replace(gtNone, gtNone, NamePos.StartPos, NamePos.EndPos, DiskNm); + if not SrcCache.Apply then exit; + IDEMessagesWindow.AddMsg(Format('Fixed unit name from %s to %s.', + [UnitNm, DiskNm]), '', -1); + end; + end; + end; + Result:=true; +end; + function TConvDelphiCodeTool.AddModeDelphiDirective: boolean; var ModeDirectivePos: integer;