diff --git a/converter/convertdelphi.pas b/converter/convertdelphi.pas index e69d6ecdae..438c551ef9 100644 --- a/converter/convertdelphi.pas +++ b/converter/convertdelphi.pas @@ -167,6 +167,7 @@ type function GetCustomDefines: TDefineTemplate; virtual; abstract; procedure CustomDefinesChanged; virtual; abstract; function GetMainName: string; virtual; abstract; + function SaveAndMaybeClose(aFilename: string): TModalResult; virtual; procedure AddPackageDependency(const PackageName: string); virtual; abstract; function FindDependencyByName(const PackageName: string): TPkgDependency; virtual; abstract; procedure RemoveNonExistingFiles(RemoveFromUsesSection: boolean); virtual; abstract; @@ -204,6 +205,7 @@ type function GetCustomDefines: TDefineTemplate; override; procedure CustomDefinesChanged; override; function GetMainName: string; override; + function SaveAndMaybeClose(Filename: string): TModalResult; override; procedure AddPackageDependency(const PackageName: string); override; function FindDependencyByName(const PackageName: string): TPkgDependency; override; procedure RemoveNonExistingFiles(RemoveFromUsesSection: boolean); override; @@ -982,17 +984,12 @@ begin try for i:=0 to ConverterList.Count-1 do begin Converter:=TConvertDelphiUnit(ConverterList[i]); // Converter created in cycle1. - with Converter do begin - Result:=ConvertFormFile; - Result:=CheckFailed(Result); - if Result<>mrOK then exit; - // Load the unit and add it to project. fUnitInfo is set for projects only. - if Assigned(fUnitInfo) then //ofAddToRecent, - LazarusIDE.DoOpenEditorFile(fLazUnitFilename,0,0,[ofAddToProject,ofQuiet]); - // Close unit file after processing. - Result:=LazarusIDE.DoCloseEditorFile(fLazUnitFilename,[cfSaveFirst,cfQuiet]); - if Result<>mrOK then exit; - end; + Result:=Converter.ConvertFormFile; + Result:=Converter.CheckFailed(Result); + if Result<>mrOK then exit; + // Finally save and maybe close the file. + Result:=SaveAndMaybeClose(Converter.fLazUnitFilename); + if Result<>mrOK then exit; end; finally Screen.Cursor:=crDefault; @@ -1281,6 +1278,11 @@ begin Result:=mrOK; // Do nothing. Overridden in project. end; +function TConvertDelphiPBase.SaveAndMaybeClose(aFilename: string): TModalResult; +begin + Result:=mrOK; // Do nothing. Overridden in project. +end; + { TConvertDelphiProject } @@ -1300,8 +1302,7 @@ begin end; function TConvertDelphiProject.CreateInstance: TModalResult; -// If .lpi does not exist, create it -// open new project +// Open or create a project. If .lpi file does not exist, create it. begin LazProject:=Project1; if FileExistsUTF8(fLazPFilename) then begin @@ -1343,6 +1344,8 @@ begin MainUnitInfo.IsPartOfProject:=true; LazProject.AddFile(MainUnitInfo,false); LazProject.MainFileID:=0; + Result:=LazarusIDE.DoOpenEditorFile(MainUnitInfo.Filename,0,0,[ofQuiet]); + if Result<>mrOK then exit; end else begin // replace main unit in project LazProject.MainUnitInfo.Source:=fMainUnitConverter.fPascalBuffer; @@ -1572,6 +1575,27 @@ begin Result:=(fProjPack as TProject).MainUnitInfo.Filename; end; +function TConvertDelphiProject.SaveAndMaybeClose(Filename: string): TModalResult; +var + UnitIndex: Integer; + AnUnitInfo: TUnitInfo; +begin + Result:=mrOk; + if Filename='' then exit; + UnitIndex:=LazProject.IndexOfFilename(Filename, [pfsfOnlyEditorFiles]); + if UnitIndex<0 then exit; + AnUnitInfo:=LazProject.Units[UnitIndex]; + if AnUnitInfo.OpenEditorInfoCount<>1 then + raise Exception.Create('OpenEditorInfoCount='+IntToStr(AnUnitInfo.OpenEditorInfoCount)); +// Assert(AnUnitInfo.OpenEditorInfoCount=1, 'OpenEditorInfoCount='+IntToStr(AnUnitInfo.OpenEditorInfoCount)); + Result:=LazarusIDE.DoSaveEditorFile(AnUnitInfo.OpenEditorInfo[0].EditorComponent, + [sfCheckAmbiguousFiles,sfQuietUnitCheck]); + if not fSettings.KeepFileOpen then + Result:=LazarusIDE.DoCloseEditorFile(AnUnitInfo.OpenEditorInfo[0].EditorComponent, + [cfQuiet]); // Filename + // Result:=LazarusIDE.DoSaveEditorFile(); +end; + procedure TConvertDelphiProject.AddPackageDependency(const PackageName: string); begin (fProjPack as TProject).AddPackageDependency(PackageName); diff --git a/converter/convertsettings.lfm b/converter/convertsettings.lfm index 139fb7b8c3..7de0a4114e 100644 --- a/converter/convertsettings.lfm +++ b/converter/convertsettings.lfm @@ -182,7 +182,7 @@ object ConvertSettingsForm: TConvertSettingsForm Left = 303 Height = 21 Hint = 'Separate form files allow different properties' - Top = 7 + Top = 79 Width = 312 BorderSpacing.Left = 13 BorderSpacing.Around = 7 @@ -192,6 +192,21 @@ object ConvertSettingsForm: TConvertSettingsForm ShowHint = True TabOrder = 1 end + object KeepFileOpenCheckBox: TCheckBox + AnchorSideLeft.Control = TargetRadioGroup + AnchorSideLeft.Side = asrBottom + Left = 303 + Height = 21 + Hint = 'Separate form files allow different properties' + Top = 15 + Width = 234 + BorderSpacing.Left = 13 + BorderSpacing.Around = 7 + Caption = 'Keep converted file open in editor' + ParentShowHint = False + ShowHint = True + TabOrder = 2 + end end object ProjectPathEdit: TLabeledEdit Left = 144 diff --git a/converter/convertsettings.pas b/converter/convertsettings.pas index 5618e6c2fd..19be98e83a 100755 --- a/converter/convertsettings.pas +++ b/converter/convertsettings.pas @@ -56,6 +56,7 @@ type // Actual user settings. fBackupFiles: boolean; fTarget: TConvertTarget; + fKeepFileOpen: boolean; fSameDFMFile: boolean; fAutoRemoveProperties: boolean; fAutoReplaceUnits: boolean; @@ -101,6 +102,7 @@ type property BackupFiles: boolean read fBackupFiles; property Target: TConvertTarget read fTarget; + property KeepFileOpen: boolean read fKeepFileOpen; property SameDFMFile: boolean read fSameDFMFile; property AutoRemoveProperties: boolean read fAutoRemoveProperties; property AutoReplaceUnits: boolean read fAutoReplaceUnits; @@ -117,6 +119,7 @@ type TConvertSettingsForm = class(TForm) PropRemoveAutoCheckBox: TCheckBox; + KeepFileOpenCheckBox: TCheckBox; UnitReplaceAutoCheckBox: TCheckBox; BackupCheckBox: TCheckBox; ButtonPanel1: TButtonPanel; @@ -352,6 +355,7 @@ begin fConfigStorage:=GetIDEConfigStorage('delphiconverter.xml', true); fBackupFiles :=fConfigStorage.GetValue('BackupFiles', true); fTarget:=TConvertTarget(fConfigStorage.GetValue('ConvertTarget', 0)); + fKeepFileOpen :=fConfigStorage.GetValue('KeepFileOpen', false); fSameDFMFile :=fConfigStorage.GetValue('SameDFMFile', false); fAutoReplaceUnits :=fConfigStorage.GetValue('AutoReplaceUnits', true); fAutoRemoveProperties :=fConfigStorage.GetValue('AutoRemoveProperties', true); @@ -457,6 +461,7 @@ begin // Save possibly modified settings to ConfigStorage. fConfigStorage.SetDeleteValue('BackupFiles', fBackupFiles, true); fConfigStorage.SetDeleteValue('ConvertTarget', integer(fTarget), 0); + fConfigStorage.SetDeleteValue('KeepFileOpen', fKeepFileOpen, false); fConfigStorage.SetDeleteValue('SameDFMFile', fSameDFMFile, false); fConfigStorage.SetDeleteValue('AutoReplaceUnits', fAutoReplaceUnits, true); fConfigStorage.SetDeleteValue('AutoRemoveProperties', fAutoRemoveProperties, true); @@ -486,6 +491,7 @@ begin // Settings --> UI. Loaded from ConfigSettings earlier. BackupCheckBox.Checked :=fBackupFiles; TargetRadioGroup.ItemIndex :=integer(fTarget); + KeepFileOpenCheckBox.Checked :=fKeepFileOpen; SameDFMCheckBox.Checked :=fSameDFMFile; PropRemoveAutoCheckBox.Checked :=fAutoRemoveProperties; UnitReplaceAutoCheckBox.Checked :=fAutoReplaceUnits; @@ -497,6 +503,7 @@ begin // UI --> Settings. Will be saved to ConfigSettings later. fBackupFiles :=BackupCheckBox.Checked; fTarget :=TConvertTarget(TargetRadioGroup.ItemIndex); + fKeepFileOpen :=KeepFileOpenCheckBox.Checked; fSameDFMFile :=SameDFMCheckBox.Checked; fAutoRemoveProperties:=PropRemoveAutoCheckBox.Checked; fAutoReplaceUnits :=UnitReplaceAutoCheckBox.Checked; @@ -630,6 +637,9 @@ begin ButtonPanel1.HelpButton.Caption:=lisMenuHelp; ButtonPanel1.CancelButton.Caption:=dlgCancel; + KeepFileOpenCheckBox.Caption:=lisKeepFileOpen; + KeepFileOpenCheckBox.Hint:=lisKeepFileOpenHint; + SameDFMCheckBox.Caption:=lisConvUseSameDFM; SameDFMCheckBox.Hint:=lisConvUseSameDFMHint; diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index 22a145310c..b85dff2cde 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -463,6 +463,8 @@ resourcestring lisConvertTarget2 = 'Lazarus / LCL for Windows only'; lisConvertTarget3 = 'Both Lazarus / LCL and Delphi'; lisConvertTargetHint = 'Converter adds conditional compilation to support different targets'; + lisKeepFileOpen = 'Keep converted file open in editor'; + lisKeepFileOpenHint = 'All project files will be open in editor after conversion'; lisConvUseSameDFM = 'Lazarus uses the same DFM form file as Delphi'; lisConvUseSameDFMHint = 'Separate form files allow different properties'; lisConvAutoReplace = 'Replace automatically';