From 848d1492d9bee55f30ea3f9f6cf058defd4f1a32 Mon Sep 17 00:00:00 2001 From: Juha Date: Tue, 2 Jul 2024 09:55:28 +0300 Subject: [PATCH] IDE: Improve renaming project unit filenames to lowercase. Still not perfect. Issue #10370. --- ide/lazarusidestrconsts.pas | 2 -- ide/sourcefilemanager.pas | 29 +++++++---------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index 8e452e3e52..74b217c364 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -718,7 +718,6 @@ resourcestring +'%sRename it to lowercase?'; lisRenameToLowercase = 'Rename to lowercase'; lisKeepName = 'Keep name'; - lisAmbiguousFilesFound = 'Ambiguous files found'; lisThereAreOtherFilesInTheDirectoryWithTheSameName = 'There are other files in ' +'the directory with the same name,' +'%swhich only differ in case:' @@ -5306,7 +5305,6 @@ resourcestring lisShort = 'Short:'; lisInsertUrlTag = 'Insert url tag'; lisInsertPrintshortTag2 = 'Insert printshort tag'; - lisDeleteOldFile2 = 'Delete old file?'; lisTheUnitSearchPathOfContainsTheSourceDirectoryOfPac = 'The unit search ' +'path of "%s" contains the source directory "%s" of package %s'; lisFPCVersionEG222 = 'FPC Version (e.g. 2.2.2)'; diff --git a/ide/sourcefilemanager.pas b/ide/sourcefilemanager.pas index 73834cb1db..db2e8ddea8 100644 --- a/ide/sourcefilemanager.pas +++ b/ide/sourcefilemanager.pas @@ -1834,7 +1834,6 @@ begin try Result:=ActionForFiles; finally - // all changes were handled automatically by events, just clear the logs CodeToolBoss.SourceCache.ClearAllSourceLogEntries; Project1.EndUpdate; end; @@ -1931,33 +1930,19 @@ function TRenameFilesSelector.ActionForFiles: TModalResult; var i: Integer; AnUnitInfo: TUnitInfo; - UnitPath, ShortUnitN, FileN, LowerFileN, FullFileName: String; begin Assert(fUnitInfos.Count > 0, 'TRemoveFilesSelector.ActionForFiles: No files'); + Result:=mrOK; for i:=0 to fUnitInfos.Count-1 do begin AnUnitInfo:=TUnitInfo(fUnitInfos[i]); Assert(AnUnitInfo.IsPartOfProject, 'TRenameFilesSelector.ActionForFiles: ' + AnUnitInfo.Unit_Name + ' is not part of project'); - UnitPath:=ExtractFilePath(AnUnitInfo.Filename); - FileN:=ExtractFileName(AnUnitInfo.Filename); - ShortUnitN:=ExtractFileNameOnly(FileN); - LowerFileN:=LowerCase(FileN); - DebugLn(['TRenameFilesSelector.ActionForFiles: UnitPath=', UnitPath, - ', FileN=', FileN, ', LowerFileN=', LowerFileN]); - if LowerFileN<>FileN then begin - FullFileName:=UnitPath+LowerFileN; - Result:=RenameFileWithErrorDialogs(AnUnitInfo.Filename, FullFileName, [mbAbort]); - if Result<>mrOK then begin - //MainIDE.DoJumpToCodeToolBossError; // ToDo - exit(mrCancel); - end; - AnUnitInfo.Unit_Name:=ShortUnitN; - AnUnitInfo.Modified:=true; - //AnUnitInfo.ReadUnitSource(false,false); - Project1.Modified:=true; - end; + Result:=RenameUnitLowerCase(AnUnitInfo, false); + if Result<>mrOK then exit; end; + if Result=mrOK then + Result:=SaveProject([sfDoNotSaveVirtualFiles,sfCanAbort]); end; // --- @@ -5900,7 +5885,7 @@ begin else S:=Format(lisThereAreOtherFilesInTheDirectoryWithTheSameName, [LineEnding, LineEnding, AmbiguousFiles.Text, LineEnding]); - Result:=IDEMessageDialog(lisAmbiguousFilesFound, S, + Result:=IDEMessageDialog(lisAmbiguousFileFound, S, mtWarning,[mbYes,mbNo,mbAbort]); if Result=mrAbort then exit; if Result=mrYes then begin @@ -5942,7 +5927,7 @@ begin // delete old pas, .pp, .ppu if (CompareFilenames(NewFilename,OldFilename)<>0) and OldFileExisted then begin - if IDEMessageDialog(lisDeleteOldFile2, Format(lisDeleteOldFile,[OldFilename]), + if IDEMessageDialog(lisDelete2, Format(lisDeleteOldFile,[OldFilename]), mtConfirmation,[mbYes,mbNo])=mrYes then begin Result:=DeleteFileInteractive(OldFilename,[mbAbort]);