IDE: Implement import / export for compiler options of all build modes.

git-svn-id: trunk@45638 -
This commit is contained in:
juha 2014-06-23 18:51:19 +00:00
parent e1a399a0e7
commit 4b79aadd71
3 changed files with 125 additions and 70 deletions

View File

@ -2,12 +2,12 @@ object ImExportCompOptsDlg: TImExportCompOptsDlg
Left = 416
Height = 127
Top = 208
Width = 687
Width = 688
Caption = 'ImExportCompOptsDlg'
ClientHeight = 127
ClientWidth = 687
ClientWidth = 688
Constraints.MinHeight = 113
Constraints.MinWidth = 658
Constraints.MinWidth = 300
OnClose = ImExportCompOptsDlgCLOSE
OnCreate = ImExportCompOptsDlgCREATE
LCLVersion = '1.3'
@ -15,7 +15,7 @@ object ImExportCompOptsDlg: TImExportCompOptsDlg
Left = 6
Height = 41
Top = 80
Width = 675
Width = 676
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
@ -90,12 +90,12 @@ object ImExportCompOptsDlg: TImExportCompOptsDlg
AnchorSideLeft.Control = FileNameEdit
AnchorSideLeft.Side = asrBottom
Left = 488
Height = 60
Top = 3
Height = 62
Top = 6
Width = 185
AutoFill = True
BorderSpacing.Left = 15
Caption = 'Save compiler options of'
Caption = 'Compiler options of'
ChildSizing.LeftRightSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
@ -103,7 +103,7 @@ object ImExportCompOptsDlg: TImExportCompOptsDlg
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 41
ClientHeight = 43
ClientWidth = 181
ItemIndex = 0
Items.Strings = (
@ -111,7 +111,6 @@ object ImExportCompOptsDlg: TImExportCompOptsDlg
'All build modes'
)
TabOrder = 3
Visible = False
end
object RecentPopupMenu: TPopupMenu
left = 376

View File

@ -23,7 +23,7 @@
* *
***************************************************************************
Author: Mattias Gaertner
Author: Mattias Gaertner, Juha Manninen
}
unit ImExportCompilerOpts;
@ -58,6 +58,7 @@ type
procedure SaveButtonCLICK(Sender: TObject);
private
FFilename: string;
procedure HideRadioButtons;
procedure InitExport;
procedure InitImport;
procedure LoadRecentList;
@ -69,11 +70,24 @@ type
property Filename: string read FFilename write SetFilename;
end;
{ TOptsImExport }
TOptsImExport = class
private
fXMLConfig: TXMLConfig;
function GetXMLPathForCompilerOptions: string;
function OpenXML(const Filename: string): TModalResult;
public
function DoImport(const Filename: string): TModalResult;
function DoExportOptions(const Filename: string): TModalResult;
function DoExportBuildModes(const Filename: string): TModalResult;
constructor Create;
destructor Destroy; override;
end;
function ShowImportCompilerOptionsDialog: TModalResult;
function ShowExportCompilerOptionsDialog: TModalResult;
function DoImportCompilerOptions(const Filename: string): TModalResult;
function DoExportCompilerOptions(const Filename: string): TModalResult;
implementation
@ -85,13 +99,19 @@ const
function ShowImportCompilerOptionsDialog: TModalResult;
var
ImExportCompOptsDlg: TImExportCompOptsDlg;
Importer: TOptsImExport;
begin
ImExportCompOptsDlg := TImExportCompOptsDlg.Create(nil);
try
ImExportCompOptsDlg.InitImport;
Result := ImExportCompOptsDlg.ShowModal;
if Result = mrOk then
Result := DoImportCompilerOptions(ImExportCompOptsDlg.Filename);
if Result <> mrOk then Exit;
Importer := TOptsImExport.Create;
try
Result := Importer.DoImport(ImExportCompOptsDlg.Filename);
finally
Importer.Free;
end;
finally
ImExportCompOptsDlg.Free;
end;
@ -100,19 +120,56 @@ end;
function ShowExportCompilerOptionsDialog: TModalResult;
var
ImExportCompOptsDlg: TImExportCompOptsDlg;
Exporter: TOptsImExport;
begin
ImExportCompOptsDlg := TImExportCompOptsDlg.Create(nil);
try
ImExportCompOptsDlg.InitExport;
Result := ImExportCompOptsDlg.ShowModal;
if Result = mrOk then
Result := DoExportCompilerOptions(ImExportCompOptsDlg.Filename);
if Result <> mrOk then Exit;
Exporter := TOptsImExport.Create;
try
case ImExportCompOptsDlg.ExportRadioGroup.ItemIndex of
0: Result := Exporter.DoExportOptions(ImExportCompOptsDlg.Filename);
1: Result := Exporter.DoExportBuildModes(ImExportCompOptsDlg.Filename);
end;
finally
Exporter.Free;
end;
finally
ImExportCompOptsDlg.Free;
end;
end;
function GetXMLPathForCompilerOptions(XMLConfig: TXMLConfig): string;
{ TOptsImExport }
constructor TOptsImExport.Create;
begin
end;
destructor TOptsImExport.Destroy;
begin
fXMLConfig.Free;
inherited Destroy;
end;
function TOptsImExport.OpenXML(const Filename: string): TModalResult;
begin
Result := mrOk;
try
fXMLConfig:=TXMLConfig.Create(Filename);
except
on E: Exception do
begin
Result:=MessageDlg(lisIECOErrorOpeningXml,
Format(lisIECOErrorOpeningXmlFile, [Filename, LineEnding, E.Message]),
mtError, [mbCancel], 0);
end;
end;
end;
function TOptsImExport.GetXMLPathForCompilerOptions: string;
const
OptPathSuffix = 'SearchPaths/CompilerPath/Value';
PkgCompilerOptPath = 'Package/CompilerOptions/';
@ -120,22 +177,22 @@ const
var
FileVersion: Integer;
begin
if XMLConfig.GetValue(OptPathSuffix,'')<>'' then
if fXMLConfig.GetValue(OptPathSuffix,'')<>'' then
// old lpi file
Result:=''
else if XMLConfig.GetValue(DefaultCompilerOptPath+OptPathSuffix,'')<>'' then
else if fXMLConfig.GetValue(DefaultCompilerOptPath+OptPathSuffix,'')<>'' then
// current lpi file
Result:=DefaultCompilerOptPath
else if XMLConfig.GetValue(PkgCompilerOptPath+OptPathSuffix,'')<>'' then
else if fXMLConfig.GetValue(PkgCompilerOptPath+OptPathSuffix,'')<>'' then
// current lpk file
Result:=PkgCompilerOptPath
else begin
// default: depending on file type
Result:=DefaultCompilerOptPath;
if CompareFileExt(XMLConfig.Filename,'.lpk',false)=0 then
if CompareFileExt(fXMLConfig.Filename,'.lpk',false)=0 then
begin
try
FileVersion:=XMLConfig.GetValue(PkgVersionPath,0);
FileVersion:=fXMLConfig.GetValue(PkgVersionPath,0);
except
FileVersion:=2; // On error assume version 2.
end;
@ -145,68 +202,56 @@ begin
end;
end;
function DoImportCompilerOptions(const Filename: string): TModalResult;
var
XMLConfig: TXMLConfig;
Path: String;
function TOptsImExport.DoImport(const Filename: string): TModalResult;
begin
Result := mrOk;
try
XMLConfig:=TXMLConfig.Create(Filename);
except
on E: Exception do
begin
Result:=MessageDlg(lisIECOErrorLoadingXml,
Format(lisIECOErrorLoadingXmlFile, [Filename, LineEnding, E.Message]),
mtError, [mbCancel], 0);
end;
end;
try
Path:=GetXMLPathForCompilerOptions(XMLConfig);
Project1.CompilerOptions.LoadFromXMLConfig(XMLConfig,Path);
finally
XMLConfig.Free;
Result := OpenXML(Filename);
if Result <> mrOK then Exit;
if Assigned(fXMLConfig.FindNode('BuildModes',False)) then begin
Project1.BuildModes.LoadProjOptsFromXMLConfig(fXMLConfig, '');
ShowMessageFmt(lisSuccesfullyImportedBuildModes, [Project1.BuildModes.Count, Filename]);
end
else begin
Project1.CompilerOptions.LoadFromXMLConfig(fXMLConfig, GetXMLPathForCompilerOptions);
ShowMessageFmt(lisSuccesfullyImportedCompilerOptions, [Filename]);
end;
end;
function DoExportCompilerOptions(const Filename: string): TModalResult;
var
XMLConfig: TXMLConfig;
Path: String;
function TOptsImExport.DoExportOptions(const Filename: string): TModalResult;
begin
Result:=mrOk;
try
InvalidateFileStateCache(Filename);
XMLConfig:=TXMLConfig.Create(Filename);
try
Path:=DefaultCompilerOptPath;
Project1.CompilerOptions.SaveToXMLConfig(XMLConfig,Path);
XMLConfig.Flush;
finally
XMLConfig.Free;
end;
except
on E: Exception do
begin
Result:=MessageDlg(lisIECOErrorAccessingXml,
Format(lisIECOErrorAccessingXmlFile, [Filename, LineEnding, E.Message]),
mtError, [mbCancel], 0);
end;
end;
Result := OpenXML(Filename);
if Result <> mrOK then Exit;
Project1.CompilerOptions.SaveToXMLConfig(fXMLConfig, DefaultCompilerOptPath);
fXMLConfig.Flush;
ShowMessageFmt(lisSuccesfullyExportedCompilerOptions, [Filename]);
end;
function TOptsImExport.DoExportBuildModes(const Filename: string): TModalResult;
begin
Result := OpenXML(Filename);
if Result <> mrOK then Exit;
Project1.BuildModes.SaveProjOptsToXMLConfig(fXMLConfig, '', False);
fXMLConfig.Flush;
ShowMessageFmt(lisSuccesfullyExportedBuildModes, [Project1.BuildModes.Count, Filename]);
end;
{ TImExportCompOptsDlg }
procedure TImExportCompOptsDlg.HideRadioButtons;
begin
Width:=ExportRadioGroup.Left;
ExportRadioGroup.Visible:=False;
end;
procedure TImExportCompOptsDlg.InitImport;
begin
Caption:=lisIECOImportCompilerOptions;
HideRadioButtons;
FileNameEdit.Filter:='XML file (*.xml)|*.xml|'
+'Project file (*.lpi)|*.lpi|'
+'Package file (*.lpk)|*.lpk|'
//+'Session file (*.lps)|*.lps|'
+'All files (*)|*';
FileNameEdit.DialogOptions:=FileNameEdit.DialogOptions+[ofFileMustExist];
ExportRadioGroup.Visible:=False;
with ButtonPanel1 do begin
OKButton.Caption:=lisIECOLoadFromFile;
OKButton.LoadGlyphFromStock(idButtonOpen);
@ -221,6 +266,8 @@ begin
Caption:=lisIECOExportCompilerOptions;
FileNameEdit.Filter:='XML file (*.xml)|*.xml|All files (*)|*';
FileNameEdit.DialogKind:=dkSave;
if Project1.BuildModes.Count <= 1 then
HideRadioButtons;
with ButtonPanel1 do begin
OKButton.Caption:=lisIECOSaveToFile;
OKButton.LoadGlyphFromStock(idButtonSave);
@ -235,6 +282,9 @@ begin
HistoryLabel.Caption:=lisIECORecentFiles;
HistoryLabel.Hint:=lisIECORecentFiles;
FileLabel.Caption:=lisFile;
ExportRadioGroup.Caption:=lisIECOCompilerOptionsOf;
ExportRadioGroup.Items.Strings[0] := lisIECOCurrentBuildMode;
ExportRadioGroup.Items.Strings[1] := lisIECOAllBuildModes;
LoadRecentList;
end;

View File

@ -932,10 +932,16 @@ resourcestring
+'%s(Other settings will be kept.)';
lisIECOImportCompilerOptions = 'Import Compiler Options';
lisIECOExportCompilerOptions = 'Export Compiler Options';
lisIECOErrorAccessingXml = 'Error accessing xml';
lisIECOErrorLoadingXml = 'Error loading xml';
lisIECOErrorLoadingXmlFile = 'Error loading xml file "%s":%s%s';
lisIECOErrorAccessingXmlFile = 'Error accessing xml file "%s":%s%s';
lisIECOCompilerOptionsOf = 'Compiler options of';
lisIECOCurrentBuildMode = 'Current build mode';
lisIECOAllBuildModes = 'All build modes';
lisIECOErrorOpeningXml = 'Error opening XML';
lisIECOErrorOpeningXmlFile = 'Error opening XML file "%s":%s%s';
lisSuccesfullyImportedBuildModes = 'Succesfully imported %d BuildModes from "%s".';
lisSuccesfullyExportedBuildModes = 'Succesfully exported %d BuildModes to "%s".';
lisSuccesfullyImportedCompilerOptions = 'Succesfully imported compiler options from "%s".';
lisSuccesfullyExportedCompilerOptions = 'Succesfully exported compiler options to "%s".';
lisIECORecentFiles = 'Recent files';
lisIECOSaveToFile = 'Save to file';
lisIECOLoadFromFile = 'Load from file';