mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 02:09:21 +02:00
Converter: open main source file in editor, added option to keep all project files open.
git-svn-id: trunk@27427 -
This commit is contained in:
parent
53f9372ad7
commit
2c86da69b2
@ -167,6 +167,7 @@ type
|
|||||||
function GetCustomDefines: TDefineTemplate; virtual; abstract;
|
function GetCustomDefines: TDefineTemplate; virtual; abstract;
|
||||||
procedure CustomDefinesChanged; virtual; abstract;
|
procedure CustomDefinesChanged; virtual; abstract;
|
||||||
function GetMainName: string; virtual; abstract;
|
function GetMainName: string; virtual; abstract;
|
||||||
|
function SaveAndMaybeClose(aFilename: string): TModalResult; virtual;
|
||||||
procedure AddPackageDependency(const PackageName: string); virtual; abstract;
|
procedure AddPackageDependency(const PackageName: string); virtual; abstract;
|
||||||
function FindDependencyByName(const PackageName: string): TPkgDependency; virtual; abstract;
|
function FindDependencyByName(const PackageName: string): TPkgDependency; virtual; abstract;
|
||||||
procedure RemoveNonExistingFiles(RemoveFromUsesSection: boolean); virtual; abstract;
|
procedure RemoveNonExistingFiles(RemoveFromUsesSection: boolean); virtual; abstract;
|
||||||
@ -204,6 +205,7 @@ type
|
|||||||
function GetCustomDefines: TDefineTemplate; override;
|
function GetCustomDefines: TDefineTemplate; override;
|
||||||
procedure CustomDefinesChanged; override;
|
procedure CustomDefinesChanged; override;
|
||||||
function GetMainName: string; override;
|
function GetMainName: string; override;
|
||||||
|
function SaveAndMaybeClose(Filename: string): TModalResult; override;
|
||||||
procedure AddPackageDependency(const PackageName: string); override;
|
procedure AddPackageDependency(const PackageName: string); override;
|
||||||
function FindDependencyByName(const PackageName: string): TPkgDependency; override;
|
function FindDependencyByName(const PackageName: string): TPkgDependency; override;
|
||||||
procedure RemoveNonExistingFiles(RemoveFromUsesSection: boolean); override;
|
procedure RemoveNonExistingFiles(RemoveFromUsesSection: boolean); override;
|
||||||
@ -982,17 +984,12 @@ begin
|
|||||||
try
|
try
|
||||||
for i:=0 to ConverterList.Count-1 do begin
|
for i:=0 to ConverterList.Count-1 do begin
|
||||||
Converter:=TConvertDelphiUnit(ConverterList[i]); // Converter created in cycle1.
|
Converter:=TConvertDelphiUnit(ConverterList[i]); // Converter created in cycle1.
|
||||||
with Converter do begin
|
Result:=Converter.ConvertFormFile;
|
||||||
Result:=ConvertFormFile;
|
Result:=Converter.CheckFailed(Result);
|
||||||
Result:=CheckFailed(Result);
|
if Result<>mrOK then exit;
|
||||||
if Result<>mrOK then exit;
|
// Finally save and maybe close the file.
|
||||||
// Load the unit and add it to project. fUnitInfo is set for projects only.
|
Result:=SaveAndMaybeClose(Converter.fLazUnitFilename);
|
||||||
if Assigned(fUnitInfo) then //ofAddToRecent,
|
if Result<>mrOK then exit;
|
||||||
LazarusIDE.DoOpenEditorFile(fLazUnitFilename,0,0,[ofAddToProject,ofQuiet]);
|
|
||||||
// Close unit file after processing.
|
|
||||||
Result:=LazarusIDE.DoCloseEditorFile(fLazUnitFilename,[cfSaveFirst,cfQuiet]);
|
|
||||||
if Result<>mrOK then exit;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
Screen.Cursor:=crDefault;
|
Screen.Cursor:=crDefault;
|
||||||
@ -1281,6 +1278,11 @@ begin
|
|||||||
Result:=mrOK; // Do nothing. Overridden in project.
|
Result:=mrOK; // Do nothing. Overridden in project.
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TConvertDelphiPBase.SaveAndMaybeClose(aFilename: string): TModalResult;
|
||||||
|
begin
|
||||||
|
Result:=mrOK; // Do nothing. Overridden in project.
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TConvertDelphiProject }
|
{ TConvertDelphiProject }
|
||||||
|
|
||||||
@ -1300,8 +1302,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TConvertDelphiProject.CreateInstance: TModalResult;
|
function TConvertDelphiProject.CreateInstance: TModalResult;
|
||||||
// If .lpi does not exist, create it
|
// Open or create a project. If .lpi file does not exist, create it.
|
||||||
// open new project
|
|
||||||
begin
|
begin
|
||||||
LazProject:=Project1;
|
LazProject:=Project1;
|
||||||
if FileExistsUTF8(fLazPFilename) then begin
|
if FileExistsUTF8(fLazPFilename) then begin
|
||||||
@ -1343,6 +1344,8 @@ begin
|
|||||||
MainUnitInfo.IsPartOfProject:=true;
|
MainUnitInfo.IsPartOfProject:=true;
|
||||||
LazProject.AddFile(MainUnitInfo,false);
|
LazProject.AddFile(MainUnitInfo,false);
|
||||||
LazProject.MainFileID:=0;
|
LazProject.MainFileID:=0;
|
||||||
|
Result:=LazarusIDE.DoOpenEditorFile(MainUnitInfo.Filename,0,0,[ofQuiet]);
|
||||||
|
if Result<>mrOK then exit;
|
||||||
end else begin
|
end else begin
|
||||||
// replace main unit in project
|
// replace main unit in project
|
||||||
LazProject.MainUnitInfo.Source:=fMainUnitConverter.fPascalBuffer;
|
LazProject.MainUnitInfo.Source:=fMainUnitConverter.fPascalBuffer;
|
||||||
@ -1572,6 +1575,27 @@ begin
|
|||||||
Result:=(fProjPack as TProject).MainUnitInfo.Filename;
|
Result:=(fProjPack as TProject).MainUnitInfo.Filename;
|
||||||
end;
|
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);
|
procedure TConvertDelphiProject.AddPackageDependency(const PackageName: string);
|
||||||
begin
|
begin
|
||||||
(fProjPack as TProject).AddPackageDependency(PackageName);
|
(fProjPack as TProject).AddPackageDependency(PackageName);
|
||||||
|
@ -182,7 +182,7 @@ object ConvertSettingsForm: TConvertSettingsForm
|
|||||||
Left = 303
|
Left = 303
|
||||||
Height = 21
|
Height = 21
|
||||||
Hint = 'Separate form files allow different properties'
|
Hint = 'Separate form files allow different properties'
|
||||||
Top = 7
|
Top = 79
|
||||||
Width = 312
|
Width = 312
|
||||||
BorderSpacing.Left = 13
|
BorderSpacing.Left = 13
|
||||||
BorderSpacing.Around = 7
|
BorderSpacing.Around = 7
|
||||||
@ -192,6 +192,21 @@ object ConvertSettingsForm: TConvertSettingsForm
|
|||||||
ShowHint = True
|
ShowHint = True
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
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
|
end
|
||||||
object ProjectPathEdit: TLabeledEdit
|
object ProjectPathEdit: TLabeledEdit
|
||||||
Left = 144
|
Left = 144
|
||||||
|
@ -56,6 +56,7 @@ type
|
|||||||
// Actual user settings.
|
// Actual user settings.
|
||||||
fBackupFiles: boolean;
|
fBackupFiles: boolean;
|
||||||
fTarget: TConvertTarget;
|
fTarget: TConvertTarget;
|
||||||
|
fKeepFileOpen: boolean;
|
||||||
fSameDFMFile: boolean;
|
fSameDFMFile: boolean;
|
||||||
fAutoRemoveProperties: boolean;
|
fAutoRemoveProperties: boolean;
|
||||||
fAutoReplaceUnits: boolean;
|
fAutoReplaceUnits: boolean;
|
||||||
@ -101,6 +102,7 @@ type
|
|||||||
|
|
||||||
property BackupFiles: boolean read fBackupFiles;
|
property BackupFiles: boolean read fBackupFiles;
|
||||||
property Target: TConvertTarget read fTarget;
|
property Target: TConvertTarget read fTarget;
|
||||||
|
property KeepFileOpen: boolean read fKeepFileOpen;
|
||||||
property SameDFMFile: boolean read fSameDFMFile;
|
property SameDFMFile: boolean read fSameDFMFile;
|
||||||
property AutoRemoveProperties: boolean read fAutoRemoveProperties;
|
property AutoRemoveProperties: boolean read fAutoRemoveProperties;
|
||||||
property AutoReplaceUnits: boolean read fAutoReplaceUnits;
|
property AutoReplaceUnits: boolean read fAutoReplaceUnits;
|
||||||
@ -117,6 +119,7 @@ type
|
|||||||
|
|
||||||
TConvertSettingsForm = class(TForm)
|
TConvertSettingsForm = class(TForm)
|
||||||
PropRemoveAutoCheckBox: TCheckBox;
|
PropRemoveAutoCheckBox: TCheckBox;
|
||||||
|
KeepFileOpenCheckBox: TCheckBox;
|
||||||
UnitReplaceAutoCheckBox: TCheckBox;
|
UnitReplaceAutoCheckBox: TCheckBox;
|
||||||
BackupCheckBox: TCheckBox;
|
BackupCheckBox: TCheckBox;
|
||||||
ButtonPanel1: TButtonPanel;
|
ButtonPanel1: TButtonPanel;
|
||||||
@ -352,6 +355,7 @@ begin
|
|||||||
fConfigStorage:=GetIDEConfigStorage('delphiconverter.xml', true);
|
fConfigStorage:=GetIDEConfigStorage('delphiconverter.xml', true);
|
||||||
fBackupFiles :=fConfigStorage.GetValue('BackupFiles', true);
|
fBackupFiles :=fConfigStorage.GetValue('BackupFiles', true);
|
||||||
fTarget:=TConvertTarget(fConfigStorage.GetValue('ConvertTarget', 0));
|
fTarget:=TConvertTarget(fConfigStorage.GetValue('ConvertTarget', 0));
|
||||||
|
fKeepFileOpen :=fConfigStorage.GetValue('KeepFileOpen', false);
|
||||||
fSameDFMFile :=fConfigStorage.GetValue('SameDFMFile', false);
|
fSameDFMFile :=fConfigStorage.GetValue('SameDFMFile', false);
|
||||||
fAutoReplaceUnits :=fConfigStorage.GetValue('AutoReplaceUnits', true);
|
fAutoReplaceUnits :=fConfigStorage.GetValue('AutoReplaceUnits', true);
|
||||||
fAutoRemoveProperties :=fConfigStorage.GetValue('AutoRemoveProperties', true);
|
fAutoRemoveProperties :=fConfigStorage.GetValue('AutoRemoveProperties', true);
|
||||||
@ -457,6 +461,7 @@ begin
|
|||||||
// Save possibly modified settings to ConfigStorage.
|
// Save possibly modified settings to ConfigStorage.
|
||||||
fConfigStorage.SetDeleteValue('BackupFiles', fBackupFiles, true);
|
fConfigStorage.SetDeleteValue('BackupFiles', fBackupFiles, true);
|
||||||
fConfigStorage.SetDeleteValue('ConvertTarget', integer(fTarget), 0);
|
fConfigStorage.SetDeleteValue('ConvertTarget', integer(fTarget), 0);
|
||||||
|
fConfigStorage.SetDeleteValue('KeepFileOpen', fKeepFileOpen, false);
|
||||||
fConfigStorage.SetDeleteValue('SameDFMFile', fSameDFMFile, false);
|
fConfigStorage.SetDeleteValue('SameDFMFile', fSameDFMFile, false);
|
||||||
fConfigStorage.SetDeleteValue('AutoReplaceUnits', fAutoReplaceUnits, true);
|
fConfigStorage.SetDeleteValue('AutoReplaceUnits', fAutoReplaceUnits, true);
|
||||||
fConfigStorage.SetDeleteValue('AutoRemoveProperties', fAutoRemoveProperties, true);
|
fConfigStorage.SetDeleteValue('AutoRemoveProperties', fAutoRemoveProperties, true);
|
||||||
@ -486,6 +491,7 @@ begin
|
|||||||
// Settings --> UI. Loaded from ConfigSettings earlier.
|
// Settings --> UI. Loaded from ConfigSettings earlier.
|
||||||
BackupCheckBox.Checked :=fBackupFiles;
|
BackupCheckBox.Checked :=fBackupFiles;
|
||||||
TargetRadioGroup.ItemIndex :=integer(fTarget);
|
TargetRadioGroup.ItemIndex :=integer(fTarget);
|
||||||
|
KeepFileOpenCheckBox.Checked :=fKeepFileOpen;
|
||||||
SameDFMCheckBox.Checked :=fSameDFMFile;
|
SameDFMCheckBox.Checked :=fSameDFMFile;
|
||||||
PropRemoveAutoCheckBox.Checked :=fAutoRemoveProperties;
|
PropRemoveAutoCheckBox.Checked :=fAutoRemoveProperties;
|
||||||
UnitReplaceAutoCheckBox.Checked :=fAutoReplaceUnits;
|
UnitReplaceAutoCheckBox.Checked :=fAutoReplaceUnits;
|
||||||
@ -497,6 +503,7 @@ begin
|
|||||||
// UI --> Settings. Will be saved to ConfigSettings later.
|
// UI --> Settings. Will be saved to ConfigSettings later.
|
||||||
fBackupFiles :=BackupCheckBox.Checked;
|
fBackupFiles :=BackupCheckBox.Checked;
|
||||||
fTarget :=TConvertTarget(TargetRadioGroup.ItemIndex);
|
fTarget :=TConvertTarget(TargetRadioGroup.ItemIndex);
|
||||||
|
fKeepFileOpen :=KeepFileOpenCheckBox.Checked;
|
||||||
fSameDFMFile :=SameDFMCheckBox.Checked;
|
fSameDFMFile :=SameDFMCheckBox.Checked;
|
||||||
fAutoRemoveProperties:=PropRemoveAutoCheckBox.Checked;
|
fAutoRemoveProperties:=PropRemoveAutoCheckBox.Checked;
|
||||||
fAutoReplaceUnits :=UnitReplaceAutoCheckBox.Checked;
|
fAutoReplaceUnits :=UnitReplaceAutoCheckBox.Checked;
|
||||||
@ -630,6 +637,9 @@ begin
|
|||||||
ButtonPanel1.HelpButton.Caption:=lisMenuHelp;
|
ButtonPanel1.HelpButton.Caption:=lisMenuHelp;
|
||||||
ButtonPanel1.CancelButton.Caption:=dlgCancel;
|
ButtonPanel1.CancelButton.Caption:=dlgCancel;
|
||||||
|
|
||||||
|
KeepFileOpenCheckBox.Caption:=lisKeepFileOpen;
|
||||||
|
KeepFileOpenCheckBox.Hint:=lisKeepFileOpenHint;
|
||||||
|
|
||||||
SameDFMCheckBox.Caption:=lisConvUseSameDFM;
|
SameDFMCheckBox.Caption:=lisConvUseSameDFM;
|
||||||
SameDFMCheckBox.Hint:=lisConvUseSameDFMHint;
|
SameDFMCheckBox.Hint:=lisConvUseSameDFMHint;
|
||||||
|
|
||||||
|
@ -463,6 +463,8 @@ resourcestring
|
|||||||
lisConvertTarget2 = 'Lazarus / LCL for Windows only';
|
lisConvertTarget2 = 'Lazarus / LCL for Windows only';
|
||||||
lisConvertTarget3 = 'Both Lazarus / LCL and Delphi';
|
lisConvertTarget3 = 'Both Lazarus / LCL and Delphi';
|
||||||
lisConvertTargetHint = 'Converter adds conditional compilation to support different targets';
|
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';
|
lisConvUseSameDFM = 'Lazarus uses the same DFM form file as Delphi';
|
||||||
lisConvUseSameDFMHint = 'Separate form files allow different properties';
|
lisConvUseSameDFMHint = 'Separate form files allow different properties';
|
||||||
lisConvAutoReplace = 'Replace automatically';
|
lisConvAutoReplace = 'Replace automatically';
|
||||||
|
Loading…
Reference in New Issue
Block a user