mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 18:58:04 +02:00
Converter: save the log messages also to a file.
git-svn-id: trunk@41640 -
This commit is contained in:
parent
6cb1308da3
commit
ff691cadc3
@ -262,8 +262,8 @@ 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);
|
||||
fSettings.AddLogLine(Format('Fixed unit name from %s to %s.',
|
||||
[UnitNm, DiskNm]));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -512,13 +512,14 @@ begin
|
||||
NewFunc:=NewFunc+' { ' +Comment+' }';
|
||||
// Old function call with params for IDE message output.
|
||||
s:=copy(fCTLink.CodeTool.Src, FuncInfo.StartPos, FuncInfo.EndPos-FuncInfo.StartPos);
|
||||
s:=StringReplace(s, LineEnding, '', [rfReplaceAll]);
|
||||
s:=StringReplace(s, #10, '', [rfReplaceAll]);
|
||||
s:=StringReplace(s, #13, '', [rfReplaceAll]);
|
||||
// Now replace it.
|
||||
fCTLink.ResetMainScanner;
|
||||
if not fCTLink.SrcCache.Replace(gtNone, gtNone,
|
||||
FuncInfo.StartPos, FuncInfo.EndPos, NewFunc) then exit;
|
||||
IDEMessagesWindow.AddMsg('Replaced call '+s, '', -1);
|
||||
IDEMessagesWindow.AddMsg(' with '+NewFunc, '', -1);
|
||||
fCTLink.fSettings.AddLogLine('Replaced call '+s);
|
||||
fCTLink.fSettings.AddLogLine(' with '+NewFunc);
|
||||
// Add the required unit name to uses section if needed.
|
||||
if Assigned(AddUnitEvent) and (FuncInfo.UnitName<>'') then
|
||||
AddUnitEvent(FuncInfo.UnitName);
|
||||
|
@ -79,7 +79,7 @@ type
|
||||
|
||||
TDelphiUnit = class
|
||||
private
|
||||
// Converter for the project or package this unit belongs to.
|
||||
// Converter for the unit, project or package this unit belongs to.
|
||||
// There is always an owner converter.
|
||||
fOwnerConverter: TConvertDelphiPBase;
|
||||
fOrigUnitFilename: string; // Original unit's file name, .pas
|
||||
@ -115,7 +115,7 @@ type
|
||||
|
||||
{ TConvertDelphiPBase }
|
||||
|
||||
// Takes care of error handling.
|
||||
// Base class for all converters. Takes care of error handling etc.
|
||||
// TConvertDelphiUnit ja TConvertDelphiProjPack inherit from this,
|
||||
// wrapping either one unit or whole project / package conversion.
|
||||
TConvertDelphiPBase = class
|
||||
@ -136,7 +136,8 @@ type
|
||||
fAllCommentedUnits: TStringList;
|
||||
function DoMissingUnits(AUsedUnitsTool: TUsedUnitsTool): integer; virtual;
|
||||
function GetCachedUnitPath(const AUnitName: string): string;
|
||||
procedure ShowEndingMessage(AStatus: TModalResult);
|
||||
protected
|
||||
function EndConvert(AStatus: TModalResult): Boolean;
|
||||
public
|
||||
constructor Create(const AFilename, ADescription: string);
|
||||
destructor Destroy; override;
|
||||
@ -479,7 +480,7 @@ begin
|
||||
fLazFileExt:='';
|
||||
fUnitInfo:=nil;
|
||||
if not LazarusIDE.BeginCodeTools then
|
||||
IDEMessagesWindow.AddMsg(lisConvDelphiBeginCodeToolsFailed, '', -1);
|
||||
fOwnerConverter.fSettings.AddLogLine(lisConvDelphiBeginCodeToolsFailed);
|
||||
fCTLink:=Nil; // Will be created later.
|
||||
fUsedUnitsTool:=Nil;
|
||||
end;
|
||||
@ -506,8 +507,8 @@ end;
|
||||
|
||||
function TDelphiUnit.CopyAndLoadFile: TModalResult;
|
||||
begin
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiConvertingFile,
|
||||
[fOrigUnitFilename]), '', -1);
|
||||
fOwnerConverter.fSettings.AddLogLine(Format(lisConvDelphiConvertingFile,
|
||||
[fOrigUnitFilename]));
|
||||
Application.ProcessMessages;
|
||||
// ConvertUnit in place. File must be writable.
|
||||
Result:=CheckFileIsWritable(fOrigUnitFilename,[mbAbort]);
|
||||
@ -526,8 +527,8 @@ begin
|
||||
if Result<>mrOK then exit;
|
||||
// Change encoding to UTF-8
|
||||
if fPascalBuffer.DiskEncoding<>EncodingUTF8 then begin
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiChangedEncodingToUTF8,
|
||||
[fPascalBuffer.DiskEncoding]), '', -1);
|
||||
fOwnerConverter.fSettings.AddLogLine(Format(lisConvDelphiChangedEncodingToUTF8,
|
||||
[fPascalBuffer.DiskEncoding]));
|
||||
fPascalBuffer.DiskEncoding:=EncodingUTF8; // Takes effect when buffer is saved.
|
||||
end;
|
||||
// Create a shared link for codetools.
|
||||
@ -585,8 +586,9 @@ begin
|
||||
end;
|
||||
// ConvertUnit .dfm file to .lfm file (without context type checking)
|
||||
if FileExistsUTF8(LfmFilename) then begin
|
||||
DFMConverter:=TDFMConverter.Create(IDEMessagesWindow);
|
||||
DFMConverter:=TDFMConverter.Create;
|
||||
try
|
||||
DFMConverter.Settings:=fOwnerConverter.fSettings;
|
||||
Result:=DFMConverter.ConvertDfmToLfm(LfmFilename);
|
||||
if Result<>mrOK then exit;
|
||||
finally
|
||||
@ -596,8 +598,8 @@ begin
|
||||
Result:=LoadCodeBuffer(TempLFMBuffer,LfmFilename,
|
||||
[lbfCheckIfText,lbfUpdateFromDisk],true);
|
||||
if TempLFMBuffer.DiskEncoding<>EncodingUTF8 then begin
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiChangedEncodingToUTF8,
|
||||
[TempLFMBuffer.DiskEncoding]), '', -1);
|
||||
fOwnerConverter.fSettings.AddLogLine(Format(lisConvDelphiChangedEncodingToUTF8,
|
||||
[TempLFMBuffer.DiskEncoding]));
|
||||
TempLFMBuffer.DiskEncoding:=EncodingUTF8;
|
||||
TempLFMBuffer.Save;
|
||||
end;
|
||||
@ -668,10 +670,10 @@ var
|
||||
begin
|
||||
// Fix the LFM file and the pascal unit, updates fPascalBuffer and fLFMBuffer.
|
||||
if fLFMBuffer<>nil then begin
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiRepairingFormFile,
|
||||
[fLFMBuffer.Filename]), '', -1);
|
||||
fOwnerConverter.fSettings.AddLogLine(Format(lisConvDelphiRepairingFormFile,
|
||||
[fLFMBuffer.Filename]));
|
||||
Application.ProcessMessages;
|
||||
LfmFixer:=TLFMFixer.Create(fCTLink,fLFMBuffer,@IDEMessagesWindow.AddMsg);
|
||||
LfmFixer:=TLFMFixer.Create(fCTLink,fLFMBuffer,Nil);
|
||||
try
|
||||
LfmFixer.Settings:=fOwnerConverter.fSettings;
|
||||
LfmFixer.UsedUnitsTool:=fUsedUnitsTool;
|
||||
@ -692,8 +694,8 @@ begin
|
||||
if Result<>mrOK then exit;
|
||||
end;
|
||||
// After other changes: add, remove, fix and comment out units in uses sections.
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiFixingUsedUnits,
|
||||
[fOrigUnitFilename]), '', -1);
|
||||
fOwnerConverter.fSettings.AddLogLine(Format(lisConvDelphiFixingUsedUnits,
|
||||
[fOrigUnitFilename]));
|
||||
Result:=fUsedUnitsTool.ConvertUsed;
|
||||
if Result<>mrOK then exit;
|
||||
Result:=mrOK;
|
||||
@ -760,7 +762,7 @@ var
|
||||
FoundIncludeFiles: TStrings;
|
||||
MissingIncludeFilesCodeXYPos: TFPList;
|
||||
CodePos: PCodeXYPosition;
|
||||
Msg: string;
|
||||
Msg, s: string;
|
||||
i: Integer;
|
||||
OldChange: Boolean;
|
||||
begin
|
||||
@ -775,10 +777,14 @@ begin
|
||||
if CodeTool.FixIncludeFilenames(Code,SrcCache,FoundIncludeFiles,MissingIncludeFilesCodeXYPos)
|
||||
then begin
|
||||
if Assigned(FoundIncludeFiles) then begin
|
||||
FoundIncludeFiles.Delimiter:=';';
|
||||
FoundIncludeFiles.StrictDelimiter:=True;
|
||||
Msg:='Repairing include files : ' + FoundIncludeFiles.DelimitedText;
|
||||
IDEMessagesWindow.AddMsg(Msg, '', -1);
|
||||
Msg:='Repairing include files : ';
|
||||
for i:=0 to FoundIncludeFiles.Count-1 do begin
|
||||
s:=CreateRelativePath(FoundIncludeFiles[i], fOwnerConverter.fSettings.MainPath);
|
||||
if i>0 then
|
||||
Msg:=Msg+'; ';
|
||||
Msg:=Msg+s;
|
||||
end;
|
||||
fOwnerConverter.fSettings.AddLogLine(Msg);
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
@ -787,7 +793,7 @@ begin
|
||||
CodePos:=PCodeXYPosition(MissingIncludeFilesCodeXYPos[i]);
|
||||
Msg:=Format(lisConvDelphiMissingIncludeFile,
|
||||
[CodePos^.Code.Filename,IntToStr(CodePos^.y),IntToStr(CodePos^.x)]);
|
||||
IDEMessagesWindow.AddMsg(Msg, '', -1);
|
||||
fOwnerConverter.fSettings.AddLogLine(Msg);
|
||||
end;
|
||||
end;
|
||||
Application.ProcessMessages;
|
||||
@ -846,17 +852,20 @@ begin
|
||||
Result:=fCachedUnitNames[AUnitName];
|
||||
end;
|
||||
|
||||
procedure TConvertDelphiPBase.ShowEndingMessage(AStatus: TModalResult);
|
||||
function TConvertDelphiPBase.EndConvert(AStatus: TModalResult): Boolean;
|
||||
begin
|
||||
// Show ending message
|
||||
if AStatus=mrOK then
|
||||
IDEMessagesWindow.AddMsg(lisConvDelphiConversionReady, '', -1)
|
||||
fSettings.AddLogLine(lisConvDelphiConversionReady)
|
||||
else begin
|
||||
if fErrorMsg<>'' then
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiError,[fErrorMsg]),'',-1)
|
||||
fSettings.AddLogLine(Format(lisConvDelphiError,[fErrorMsg]))
|
||||
else if CodeToolBoss.ErrorMessage<>'' then
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiError,[CodeToolBoss.ErrorMessage]),'',-1);
|
||||
IDEMessagesWindow.AddMsg(lisConvDelphiConversionAborted, '', -1);
|
||||
fSettings.AddLogLine(Format(lisConvDelphiError,[CodeToolBoss.ErrorMessage]));
|
||||
fSettings.AddLogLine(lisConvDelphiConversionAborted);
|
||||
end;
|
||||
// Save log messages to file.
|
||||
fSettings.SaveLog;
|
||||
end;
|
||||
|
||||
{ TConvertDelphiUnit }
|
||||
@ -875,11 +884,11 @@ function TConvertDelphiUnit.Convert: TModalResult;
|
||||
var
|
||||
DelphiUnit: TDelphiUnit;
|
||||
begin
|
||||
IDEMessagesWindow.Clear;
|
||||
DelphiUnit := TDelphiUnit.Create(Self, fOrigFilename, []);
|
||||
try
|
||||
Result:=fSettings.RunForm(Nil);
|
||||
if Result=mrOK then begin
|
||||
fSettings.ClearLog;
|
||||
with DelphiUnit do
|
||||
try
|
||||
Result:=CopyAndLoadFile;
|
||||
@ -902,7 +911,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
ShowEndingMessage(Result);
|
||||
EndConvert(Result);
|
||||
DelphiUnit.Free;
|
||||
end;
|
||||
end;
|
||||
@ -950,7 +959,6 @@ begin
|
||||
' Please select a .dpr file for projects or .dpk file for packages.';
|
||||
Exit(mrCancel);
|
||||
end;
|
||||
IDEMessagesWindow.Clear;
|
||||
// Start scanning unit files one level above project path. The GUI will appear
|
||||
// without delay but then we must wait for the thread before continuing.
|
||||
CacheUnitsThread:=TCacheUnitsThread.Create(Self,
|
||||
@ -960,6 +968,7 @@ begin
|
||||
Result:=fSettings.RunForm(CacheUnitsThread); // Get settings from user.
|
||||
if Result=mrOK then begin
|
||||
StartTime:=Now;
|
||||
fSettings.ClearLog;
|
||||
// create/open lazarus project or package file
|
||||
fLazPMainFilename:=fSettings.DelphiToLazFilename(fOrigFilename, fLazPMainSuffix, false);
|
||||
|
||||
@ -988,8 +997,8 @@ begin
|
||||
EndTime:=Now;
|
||||
s:=FormatDateTime('hh:nn:ss', EndTime-StartTime);
|
||||
if s<>'00:00:00' then
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiConversionTook, [s]), '', -1);
|
||||
ShowEndingMessage(Result);
|
||||
fSettings.AddLogLine(Format(lisConvDelphiConversionTook, [s]));
|
||||
EndConvert(Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1046,8 +1055,8 @@ var
|
||||
i: Integer;
|
||||
begin
|
||||
if not fSettings.SameDfmFile then begin
|
||||
IDEMessagesWindow.AddMsg('', '', -1);
|
||||
IDEMessagesWindow.AddMsg(lisConvDelphiRepairingFormFiles, '', -1);
|
||||
fSettings.AddLogLine('');
|
||||
fSettings.AddLogLine(lisConvDelphiRepairingFormFiles);
|
||||
end;
|
||||
Application.ProcessMessages;
|
||||
Screen.Cursor:=crHourGlass;
|
||||
@ -1112,8 +1121,7 @@ var
|
||||
if System.Pos(';'+lowercase(DelphiPkgName)+';',
|
||||
';'+lowercase(DelphiPkgNames)+';')>0 then begin
|
||||
AddPackageDependency(LazarusPkgName);
|
||||
IDEMessagesWindow.AddMsg(
|
||||
Format(lisConvDelphiAddedPackageDependency, [LazarusPkgName]), '', -1);
|
||||
fSettings.AddLogLine(Format(lisConvDelphiAddedPackageDependency,[LazarusPkgName]));
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1260,7 +1268,7 @@ begin
|
||||
// They are needed because Jedi.inc undefines "Borland" when "FPC" is defined. Nuts.
|
||||
s:='-dBorland -dVer150 -dDelphi7 -dCompiler6_Up';
|
||||
Options.CustomOptions:=s;
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiAddedCustomOptionDefines, [s]), '', -1);
|
||||
fSettings.AddLogLine(Format(lisConvDelphiAddedCustomOptionDefines, [s]));
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1329,7 +1337,7 @@ begin
|
||||
Dep:=FindDependencyByName(s);
|
||||
if not Assigned(Dep) then begin
|
||||
AddPackageDependency(s);
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiAddedPackageDependency, [s]), '', -1);
|
||||
fSettings.AddLogLine(Format(lisConvDelphiAddedPackageDependency, [s]));
|
||||
Dep:=FindDependencyByName(s);
|
||||
if Assigned(Dep) then
|
||||
PackageGraph.OpenDependency(Dep,false);
|
||||
@ -1348,10 +1356,11 @@ begin
|
||||
if ADefaultPkgName<>'' then begin
|
||||
Dep:=FindDependencyByName(ADefaultPkgName);
|
||||
if not Assigned(Dep) then begin
|
||||
Result:=CheckPackageDep(AUnitName); // Add dependency based on unit name (default is ignored)
|
||||
// Add dependency based on unit name (default is ignored)
|
||||
Result:=CheckPackageDep(AUnitName);
|
||||
if not Result then
|
||||
// Package was not found. Add a message about a package that must be installed.
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiPackageRequired, [ADefaultPkgName]), '', -1);
|
||||
fSettings.AddLogLine(Format(lisConvDelphiPackageRequired, [ADefaultPkgName]));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -1460,7 +1469,7 @@ begin
|
||||
if fSettings.OmitProjUnits.Contains(PureUnitName) then
|
||||
begin
|
||||
fMainUnitConverter.fUsedUnitsTool.Remove(PureUnitName);
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiProjOmittedUnit,[PureUnitName]), '', -1);
|
||||
fSettings.AddLogLine(Format(lisConvDelphiProjOmittedUnit,[PureUnitName]));
|
||||
TryAddPackageDep(PureUnitName, fSettings.OmitProjUnits[PureUnitName]);
|
||||
end
|
||||
else begin
|
||||
@ -1523,8 +1532,8 @@ begin
|
||||
MisUnits:=nil;
|
||||
NormalUnits:=nil;
|
||||
try
|
||||
IDEMessagesWindow.AddMsg('', '', -1);
|
||||
IDEMessagesWindow.AddMsg(lisConvDelphiFindAllUnitFiles, '', -1);
|
||||
fSettings.AddLogLine('');
|
||||
fSettings.AddLogLine(lisConvDelphiFindAllUnitFiles);
|
||||
Application.ProcessMessages;
|
||||
if not CodeToolBoss.FindDelphiProjectUnits(fMainUnitConverter.fPascalBuffer,
|
||||
FoundUnits, MisUnits, NormalUnits) then
|
||||
@ -1601,8 +1610,8 @@ begin
|
||||
try
|
||||
try
|
||||
// convert all units and fix .lfm files
|
||||
IDEMessagesWindow.AddMsg('', '', -1);
|
||||
IDEMessagesWindow.AddMsg(lisConvDelphiConvertingProjPackUnits, '', -1);
|
||||
fSettings.AddLogLine('');
|
||||
fSettings.AddLogLine(lisConvDelphiConvertingProjPackUnits);
|
||||
Application.ProcessMessages;
|
||||
for i:=0 to LazProject.UnitCount-1 do begin
|
||||
CurUnitInfo:=LazProject.Units[i];
|
||||
@ -1614,8 +1623,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
// During conversion there were more units added to be converted.
|
||||
IDEMessagesWindow.AddMsg('', '', -1);
|
||||
IDEMessagesWindow.AddMsg(lisConvDelphiConvertingFoundUnits, '', -1);
|
||||
fSettings.AddLogLine('');
|
||||
fSettings.AddLogLine(lisConvDelphiConvertingFoundUnits);
|
||||
Application.ProcessMessages;
|
||||
for i:=0 to fUnitsToAddToProject.Count-1 do begin
|
||||
Result:=AddUnit(fUnitsToAddToProject[i], CurUnitInfo);
|
||||
@ -1634,8 +1643,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
except
|
||||
IDEMessagesWindow.AddMsg('', '', -1);
|
||||
IDEMessagesWindow.AddMsg('- '+lisConvDelphiExceptionDuringConversion, '', -1);
|
||||
fSettings.AddLogLine('');
|
||||
fSettings.AddLogLine('- '+lisConvDelphiExceptionDuringConversion);
|
||||
DebugLn('- '+lisConvDelphiExceptionDuringConversion);
|
||||
raise;
|
||||
end;
|
||||
@ -1837,8 +1846,8 @@ begin
|
||||
if CodeToolBoss.HasInterfaceRegisterProc(CodeBuffer, HasRegisterProc) then
|
||||
if HasRegisterProc then begin
|
||||
Include(Flags, pffHasRegisterProc);
|
||||
IDEMessagesWindow.AddMsg(Format('Adding flag for "Register" procedure in unit %s.',
|
||||
[UnitN]), '', -1);
|
||||
fSettings.AddLogLine(Format('Adding flag for "Register" procedure in unit %s.',
|
||||
[UnitN]));
|
||||
end;
|
||||
// Add new unit to package
|
||||
LazPackage.AddFile(AFileName, UnitN, pftUnit, Flags, cpNormal);
|
||||
@ -1915,8 +1924,8 @@ begin
|
||||
ConvUnits:=TObjectList.Create;
|
||||
try
|
||||
// Convert all units and fix .lfm files
|
||||
IDEMessagesWindow.AddMsg('', '', -1);
|
||||
IDEMessagesWindow.AddMsg(lisConvDelphiConvertingProjPackUnits, '', -1);
|
||||
fSettings.AddLogLine('');
|
||||
fSettings.AddLogLine(lisConvDelphiConvertingProjPackUnits);
|
||||
Application.ProcessMessages;
|
||||
for i:=0 to LazPackage.FileCount-1 do begin
|
||||
PkgFile:=LazPackage.Files[i];
|
||||
|
@ -32,8 +32,8 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, IDEProcs,
|
||||
StdCtrls, EditBtn, Buttons, ExtCtrls, DialogProcs, ButtonPanel, ComCtrls,
|
||||
LazarusIDEStrConsts, CodeToolsStructs, DividerBevel, AVL_Tree, BaseIDEIntf,
|
||||
LazConfigStorage, ConverterTypes, ReplaceNamesUnit, ReplaceFuncsUnit;
|
||||
LazarusIDEStrConsts, CodeToolsStructs, DividerBevel, BaseIDEIntf, IDEMsgIntf,
|
||||
AVL_Tree, LazConfigStorage, ConverterTypes, ReplaceNamesUnit, ReplaceFuncsUnit;
|
||||
|
||||
type
|
||||
|
||||
@ -49,6 +49,7 @@ type
|
||||
private
|
||||
fEnabled: Boolean;
|
||||
fTitle: String; // Used for form caption.
|
||||
fLog: TStringList;
|
||||
// Unit, Project or Package top file and path.
|
||||
fMainFilename: String;
|
||||
fMainPath: String;
|
||||
@ -100,9 +101,11 @@ type
|
||||
// Create Lazarus file name and copy/rename from Delphi file with new suffix.
|
||||
function RenameDelphiToLazFile(const DelphiFilename, LazExt: string;
|
||||
out LazFilename: string; LowercaseFilename: Boolean): TModalResult; overload;
|
||||
|
||||
function RenameFile(const SrcFilename, DestFilename: string): TModalResult;
|
||||
function BackupFile(const AFilename: string): TModalResult;
|
||||
procedure ClearLog;
|
||||
function AddLogLine(const ALine: string): integer;
|
||||
function SaveLog: Boolean;
|
||||
public
|
||||
property MainFilename: String read fMainFilename write SetMainFilename;
|
||||
property MainPath: String read fMainPath;
|
||||
@ -384,6 +387,7 @@ var
|
||||
|
||||
begin
|
||||
fTitle:=ATitle;
|
||||
fLog:=TStringList.Create;
|
||||
fMainFilename:='';
|
||||
fMainPath:='';
|
||||
fEnabled:=True;
|
||||
@ -647,6 +651,7 @@ begin
|
||||
fReplaceTypes.Free;
|
||||
fReplaceUnits.Free;
|
||||
fOmitProjUnits.Free;
|
||||
fLog.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -769,6 +774,27 @@ begin
|
||||
Result:=CopyFileWithErrorDialogs(AFilename,bp+fn,[mbAbort]);
|
||||
end;
|
||||
|
||||
procedure TConvertSettings.ClearLog;
|
||||
begin
|
||||
IDEMessagesWindow.Clear;
|
||||
fLog.Clear;
|
||||
end;
|
||||
|
||||
function TConvertSettings.AddLogLine(const ALine: string): integer;
|
||||
begin
|
||||
IDEMessagesWindow.AddMsg(ALine, '', -1); // Show in message window
|
||||
Result:=fLog.Add(ALine); // and store for log.
|
||||
end;
|
||||
|
||||
function TConvertSettings.SaveLog: Boolean;
|
||||
var
|
||||
s: String;
|
||||
begin
|
||||
s:=fMainPath+'AutomaticConversion.log';
|
||||
fLog.SaveToFile(s);
|
||||
IDEMessagesWindow.AddMsg('This log was saved to '+s, '', -1);
|
||||
end;
|
||||
|
||||
procedure TConvertSettings.SetMainFilename(const AValue: String);
|
||||
begin
|
||||
fMainFilename:=AValue;
|
||||
|
@ -54,15 +54,17 @@ type
|
||||
// Encapsulates some basic form file conversions.
|
||||
TDFMConverter = class
|
||||
private
|
||||
fSettings: TConvertSettings;
|
||||
fOrigFormat: TLRSStreamOriginalFormat;
|
||||
fIDEMsgWindow: TIDEMessagesWindowInterface;
|
||||
function GetLFMFilename(const DfmFilename: string; KeepCase: boolean): string;
|
||||
|
||||
public
|
||||
constructor Create(aIDEMsgWindow: TIDEMessagesWindowInterface);
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function ConvertDfmToLfm(const aFilename: string): TModalResult;
|
||||
function Convert(const DfmFilename: string): TModalResult;
|
||||
public
|
||||
property Settings: TConvertSettings read fSettings write fSettings;
|
||||
end;
|
||||
|
||||
{ TLfmFixer }
|
||||
@ -145,10 +147,9 @@ end;
|
||||
|
||||
{ TDFMConverter }
|
||||
|
||||
constructor TDFMConverter.Create(aIDEMsgWindow: TIDEMessagesWindowInterface);
|
||||
constructor TDFMConverter.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
fIDEMsgWindow:=aIDEMsgWindow;
|
||||
end;
|
||||
|
||||
destructor TDFMConverter.Destroy;
|
||||
@ -163,14 +164,13 @@ begin
|
||||
Result:=ConvertDfmToLfm(DfmFilename);
|
||||
if Result=mrOK then begin
|
||||
if fOrigFormat=sofBinary then
|
||||
s:=Format('File %s is converted to text format.', [DfmFilename]);
|
||||
if Assigned(fIDEMsgWindow) then
|
||||
IDEMessagesWindow.AddMsg(s, '', -1)
|
||||
else begin
|
||||
if s='' then
|
||||
s:=Format('File %s syntax is correct.', [DfmFilename]);
|
||||
s:=Format('File %s is converted to text format.', [DfmFilename])
|
||||
else
|
||||
s:=Format('File %s syntax is correct.', [DfmFilename]);
|
||||
if Assigned(fSettings) then
|
||||
fSettings.AddLogLine(s)
|
||||
else
|
||||
ShowMessage(s);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -309,8 +309,8 @@ begin
|
||||
if NewIdent<>'' then begin
|
||||
StartPos:=ObjNode.TypeNamePosition;
|
||||
EndPos:=StartPos+Length(OldIdent);
|
||||
IDEMessagesWindow.AddMsg(Format(
|
||||
'Replaced type "%s" with "%s".',[OldIdent, NewIdent]),'',-1);
|
||||
fSettings.AddLogLine(Format('Replaced type "%s" with "%s".',
|
||||
[OldIdent, NewIdent]));
|
||||
AddReplacement(ChgEntryRepl,StartPos,EndPos,NewIdent);
|
||||
Result:=mrRetry;
|
||||
end;
|
||||
@ -324,11 +324,11 @@ begin
|
||||
// Delete the whole property line if no replacement.
|
||||
if NewIdent='' then begin
|
||||
FindNiceNodeBounds(TheNode,StartPos,EndPos);
|
||||
IDEMessagesWindow.AddMsg(Format('Removed property "%s".',[OldIdent]),'',-1);
|
||||
fSettings.AddLogLine(Format('Removed property "%s".',[OldIdent]));
|
||||
end
|
||||
else
|
||||
IDEMessagesWindow.AddMsg(Format(
|
||||
'Replaced property "%s" with "%s".',[OldIdent, NewIdent]),'',-1);
|
||||
fSettings.AddLogLine(Format('Replaced property "%s" with "%s".',
|
||||
[OldIdent, NewIdent]));
|
||||
AddReplacement(ChgEntryRepl,StartPos,EndPos,NewIdent);
|
||||
Result:=mrRetry;
|
||||
end;
|
||||
@ -376,8 +376,8 @@ begin
|
||||
if NewNum<0 then
|
||||
NewNum:=0;
|
||||
fLFMBuffer.Replace(TopOffs.StartPos, Len, IntToStr(NewNum));
|
||||
IDEMessagesWindow.AddMsg(Format('Changed %s coord of %s from "%d" to "%d" inside %s.',
|
||||
[TopOffs.PropName, TopOffs.ChildType, OldNum, NewNum, TopOffs.ParentType]),'',-1);
|
||||
fSettings.AddLogLine(Format('Changed %s coord of %s from "%d" to "%d" inside %s.',
|
||||
[TopOffs.PropName, TopOffs.ChildType, OldNum, NewNum, TopOffs.ParentType]));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -392,8 +392,8 @@ begin
|
||||
for i:=aNewProps.Count-1 downto 0 do begin
|
||||
Entry:=TAddPropEntry(aNewProps[i]);
|
||||
fLFMBuffer.Replace(Entry.StartPos, Entry.EndPos-Entry.StartPos,Entry.NewText);
|
||||
IDEMessagesWindow.AddMsg(Format('Added property "%s" for %s.',
|
||||
[Entry.NewText, Entry.ParentType]),'',-1);
|
||||
fSettings.AddLogLine(Format('Added property "%s" for %s.',
|
||||
[Entry.NewText, Entry.ParentType]));
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -242,8 +242,8 @@ begin
|
||||
if NewUnitName<>OldUnitName then begin
|
||||
// Character case differs, fix it.
|
||||
fUnitsToFixCase[OldUnitName]:=NewUnitName;
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiFixedUnitCase,
|
||||
[OldUnitName, NewUnitName]), '', -1);
|
||||
Settings.AddLogLine(Format(lisConvDelphiFixedUnitCase,
|
||||
[OldUnitName, NewUnitName]));
|
||||
end;
|
||||
// Report Windows specific units as missing if target is CrossPlatform.
|
||||
// Needed if work-platform is Windows.
|
||||
@ -286,8 +286,8 @@ begin
|
||||
fUnitsToRename[AOldName]:=ANewName;
|
||||
fUnitsToRenameKeys.Add(AOldName);
|
||||
fUnitsToRenameVals.Add(ANewName);
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiReplacedUnitInUsesSection,
|
||||
[AOldName, ANewName]), '', -1);
|
||||
fCTLink.Settings.AddLogLine(Format(lisConvDelphiReplacedUnitInUsesSection,
|
||||
[AOldName, ANewName]));
|
||||
// If the unit is not found, open the package containing it.
|
||||
UnitInFileName:='';
|
||||
if fCTLink.CodeTool.DirectoryCache.FindUnitSourceInCompletePath(
|
||||
@ -302,8 +302,8 @@ begin
|
||||
AOldName:=Copy(AOldName, 1, i-1); // Strip the file name part.
|
||||
if fUnitsToRemove.IndexOf(AOldName)=-1 then
|
||||
fUnitsToRemove.Add(AOldName);
|
||||
IDEMessagesWindow.AddMsg(Format(lisConvDelphiRemovedUnitInUsesSection,
|
||||
[AOldName]), '', -1);
|
||||
fCTLink.Settings.AddLogLine(Format(lisConvDelphiRemovedUnitInUsesSection,
|
||||
[AOldName]));
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -724,7 +724,7 @@ begin
|
||||
or RenameValHasUnit(fImplUsedUnits) ) then
|
||||
begin
|
||||
fMainUsedUnits.fUnitsToAdd.Add(aUnitName);
|
||||
IDEMessagesWindow.AddMsg('Added unit '+aUnitName+ ' to uses section', '', -1);
|
||||
fCTLink.Settings.AddLogLine('Added unit '+aUnitName+ ' to uses section');
|
||||
// If the unit is not found, open the package containing it.
|
||||
UnitInFileName:='';
|
||||
if fCTLink.CodeTool.DirectoryCache.FindUnitSourceInCompletePath(
|
||||
|
@ -763,7 +763,7 @@
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="include"/>
|
||||
<OtherUnitFiles Value="frames;../converter;../debugger;../debugger/frames;../packager;../designer;../packager/frames;../ide;frames;frames"/>
|
||||
<OtherUnitFiles Value="frames;../converter;../debugger;../debugger/frames;../packager;../designer;../packager/frames;../ide"/>
|
||||
<UnitOutputDirectory Value="$(LazarusDir)/units/$(TargetCPU)-$(TargetOS)/$(LCLWidgetType)"/>
|
||||
</SearchPaths>
|
||||
<Other>
|
||||
|
@ -5406,7 +5406,7 @@ resourcestring
|
||||
//IDE info dialog
|
||||
lisIDEInfoInformationAboutTheIDE = 'Information about the IDE';
|
||||
|
||||
//Delphi units and projects converter
|
||||
//Delphi converter
|
||||
lisConvDelphiConvertDelphiUnit = 'Convert Delphi unit';
|
||||
lisConvDelphiConvertDelphiProject = 'Convert Delphi project';
|
||||
lisConvDelphiConvertDelphiPackage = 'Convert Delphi package';
|
||||
|
@ -7961,7 +7961,7 @@ begin
|
||||
if OpenDialog.Execute and (OpenDialog.Files.Count>0) then begin
|
||||
For I := 0 to OpenDialog.Files.Count-1 do begin
|
||||
AFilename:=ExpandFileNameUTF8(OpenDialog.Files.Strings[i]);
|
||||
DFMConverter:=TDFMConverter.Create(nil);
|
||||
DFMConverter:=TDFMConverter.Create;
|
||||
try
|
||||
Result:=DFMConverter.Convert(AFilename);
|
||||
finally
|
||||
|
Loading…
Reference in New Issue
Block a user