cmdlinecfg: the initial files commit

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2802 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
skalogryz
2013-10-02 03:46:44 +00:00
parent 0bea6f57ca
commit 6ee63d67b1
36 changed files with 4625 additions and 0 deletions

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="4">
<PathDelim Value="\"/>
<Name Value="cfgcompopt"/>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<OtherUnitFiles Value=".."/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Files Count="13">
<Item1>
<Filename Value="optviewform.pas"/>
<UnitName Value="optviewform"/>
</Item1>
<Item2>
<Filename Value="..\cmdlinelclctrlsbox.pas"/>
<UnitName Value="cmdlinelclctrlsbox"/>
</Item2>
<Item3>
<Filename Value="..\cmdlinelclpropgrid.pas"/>
<UnitName Value="cmdlinelclpropgrid"/>
</Item3>
<Item4>
<Filename Value="..\cmdlinelclutils.pas"/>
<UnitName Value="cmdlinelclutils"/>
</Item4>
<Item5>
<Filename Value="..\cmdlinecfg.pas"/>
<UnitName Value="cmdlinecfg"/>
</Item5>
<Item6>
<Filename Value="..\cmdlinecfgjson.pas"/>
<UnitName Value="cmdlinecfgjson"/>
</Item6>
<Item7>
<Filename Value="..\cmdlinecfgparser.pas"/>
<UnitName Value="cmdlinecfgparser"/>
</Item7>
<Item8>
<Filename Value="..\cmdlinecfgui.pas"/>
<UnitName Value="cmdlinecfgui"/>
</Item8>
<Item9>
<Filename Value="..\cmdlinecfguijson.pas"/>
<UnitName Value="cmdlinecfguijson"/>
</Item9>
<Item10>
<Filename Value="..\cmdlinecfgutils.pas"/>
<UnitName Value="cmdlinecfgutils"/>
</Item10>
<Item11>
<Filename Value="..\cmdlinefpccond.pas"/>
<UnitName Value="cmdlinefpccond"/>
</Item11>
<Item12>
<Filename Value="cfgcompoptreg.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="cfgcompoptreg"/>
</Item12>
<Item13>
<Filename Value="optviewform.lfm"/>
<Type Value="LFM"/>
</Item13>
</Files>
<Type Value="DesignTime"/>
<RequiredPkgs Count="3">
<Item1>
<PackageName Value="IDEIntf"/>
</Item1>
<Item2>
<PackageName Value="lcl"/>
</Item2>
<Item3>
<PackageName Value="FCL"/>
</Item3>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<CustomOptions Items="ExternHelp" Version="2">
<_ExternHelp Items="Count"/>
</CustomOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,24 @@
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
}
unit cfgcompopt;
interface
uses
optviewform, cmdlinelclctrlsbox, cmdlinelclpropgrid, cmdlinelclutils,
cmdlinecfg, cmdlinecfgjson, cmdlinecfgparser, cmdlinecfgui,
cmdlinecfguijson, cmdlinecfgutils, cmdlinefpccond, cfgcompoptreg,
LazarusPackageIntf;
implementation
procedure Register;
begin
RegisterUnit('cfgcompoptreg', @cfgcompoptreg.Register);
end;
initialization
RegisterPackage('cfgcompopt', @Register);
end.

View File

@ -0,0 +1,126 @@
unit cfgcompoptreg;
{$mode delphi}{$H+}
interface
uses
Classes, SysUtils, Forms, Dialogs
, LazIDEIntf, MenuIntf
, cmdlinecfg, cmdlinecfgutils
, cmdlinecfgjson, cmdlinecfgui, cmdlinecfguijson
, optviewform
, XMLConf;
procedure Register;
var
listOfOpt : TList;
listOfLayout : TList;
CompOptVers : string; // the version of fpc compiler used
CompOptCfg : TCmdLineCfg; // fpc compiler options
CfgLayout : TCmdLineLayoutInfo; // compiler options layout hints
implementation
resourcestring
mnuViewCfgCompilerOpt = 'Review Compiler Options';
function GetCompilerPath: string;
var
path : string;
xml : TXMLConfig;
begin
//appears to be a hack, but is there a better way to do that?
path := LazarusIDE.GetPrimaryConfigPath;
xml := TXMLConfig.Create(nil);
try
xml.RootName:='CONFIG';
xml.Filename:=IncludeTrailingPathDelimiter(path)+'environmentoptions.xml';
Result:=xml.GetValue('EnvironmentOptions/CompilerFilename/Value', '');
finally
xml.Free;
end;
end;
procedure ReviewCompOpt(Sender: TObject);
var
cmp : string;
begin
if not Assigned(CompOptCfg) then begin
cmp:=GetCompilerPath;
if cmp<>'' then
CompOptCfg:=CmdLineCfgDetect(listOfOpt, ExtractFileDir(cmp), cmp);
end;
//todo: better selection of default options
if not Assigned(CompOptCfg) and (listOfOpt.Count>0) then
CompOptCfg:=TCmdLineCfg(listOfOpt[0]);
if not Assigned(CompOptCfg) then begin
ShowMessage('Unable to detect the compiler version.');
Exit;
end;
if Assigned(LazarusIDE.ActiveProject) then begin
if not Assigned(OptView) then OptView:=TOptView.Create(Application);
ReviewOpts(CompOptCfg, CfgLayout);
end;
end;
procedure DoRegister;
var
cmd : TIDEMenuCommand;
begin
cmd := RegisterIDEMenuCommand(itmProjectWindowSection, 'showCfgCompOpt',
mnuViewCfgCompilerOpt, nil, ReviewCompOpt, nil, '');
end;
procedure ReadConfig;
var
path : string;
begin
path:=ExcludeTrailingPathDelimiter(LazarusIDE.GetPrimaryConfigPath);
if not DirectoryExists( path ) then path:=ExcludeTrailingPathDelimiter(LazarusIDE.GetSecondaryConfigPath );
CmdLineCfgJSONLoadFilesFromDir( path , listOfOpt );
CmdLineCfgUIJSONLoadFilesFromDir( path , listOfLayout );
//todo: make a smarter layout selection
if listOfLayout.Count>0 then CfgLayout:=TCmdLineLayoutInfo(listOfLayout[0]);
end;
procedure Register;
begin
try
DoRegister;
ReadConfig;
except
end;
end;
procedure Init;
begin
listOfOpt := TList.Create;
listOfLayout := TList.Create;
end;
procedure Release;
var
i : integer;
begin
for i:=0 to listOfOpt.Count-1 do TObject(listOfOpt[i]).Free;
listOfOpt.Free;
for i:=0 to listOfLayout.Count-1 do TObject(listOfLayout[i]).Free;
listOfLayout.Free;
end;
initialization
Init;
finalization
Release;
end.

View File

@ -0,0 +1,50 @@
object OptView: TOptView
Left = 359
Height = 240
Top = 214
Width = 320
Caption = 'OptView'
ClientHeight = 240
ClientWidth = 320
OnDestroy = FormDestroy
OnShow = FormShow
LCLVersion = '1.1'
object Panel1: TPanel
Left = 0
Height = 190
Top = 0
Width = 320
Align = alClient
Caption = 'Panel1'
TabOrder = 0
end
object Panel2: TPanel
Left = 0
Height = 50
Top = 190
Width = 320
Align = alBottom
Caption = 'Panel2'
ClientHeight = 50
ClientWidth = 320
TabOrder = 1
object btnOk: TButton
Left = 33
Height = 25
Top = 15
Width = 75
Caption = 'Ok'
ModalResult = 1
TabOrder = 0
end
object btnCancel: TButton
Left = 115
Height = 25
Top = 15
Width = 75
Caption = 'Cancel'
ModalResult = 2
TabOrder = 1
end
end
end

View File

@ -0,0 +1,108 @@
unit optviewform;
{$mode delphi}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
LCLIntf,
StdCtrls, LazIDEIntf, IDEOptionsIntf, ProjectIntf, CompOptsIntf, cmdlinecfg,
cmdlinecfgjson, cmdlinecfgui, cmdlinecfguijson, cmdlinelclctrlsbox, cmdlinelazcompopt;
type
{ TOptView }
TOptView = class(TForm)
btnOk: TButton;
btnCancel: TButton;
Panel1: TPanel;
Panel2: TPanel;
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ private declarations }
cmd : TCmdLineScrollBoxControl;
cfg : TCmdLineCfg;
layout : TCmdLineLayoutInfo;
procedure InitOpts(acfg: TCmdLineCfg; alayout: TCmdLineLayoutInfo);
public
{ public declarations }
function ShowForOpts(opt: TLazCompilerOptions): Integer;
end;
var
OptView: TOptView = nil;
function ReviewOpts(acfg: TCmdLineCfg; alayout: TCmdLineLayoutInfo; opt: TLazCompilerOptions = nil): Integer;
implementation
{$R *.lfm}
{ TOptView }
function ReviewOpts(acfg: TCmdLineCfg; alayout: TCmdLineLayoutInfo; opt: TLazCompilerOptions = nil): Integer;
begin
if not Assigned(OptView) then OptView:=TOptView.Create(Application);
if (OptView.cfg<>acfg) or (OptView.layout<>alayout) then
OptView.InitOpts(acfg, alayout);
if not Assigned(opt) and Assigned(LazarusIDE.ActiveProject) then
opt:=LazarusIDE.ActiveProject.LazCompilerOptions;
if Assigned(OptView.cmd) and Assigned(opt) then
Result:=OptView.ShowForOpts(opt)
else
Result:=mrCancel;
end;
procedure TOptView.FormDestroy(Sender: TObject);
begin
cmd.Free;
end;
procedure TOptView.FormShow(Sender: TObject);
begin
end;
procedure TOptView.InitOpts(acfg: TCmdLineCfg; alayout: TCmdLineLayoutInfo);
begin
ReleaseScrollBox(cmd);
cmd.Free;
cfg:=acfg;
layout:=alayout;
cmd:=TCmdLineScrollBoxControl.Create(Panel1);
cmd.Init(cfg, layout);
end;
function TOptView.ShowForOpts(opt: TLazCompilerOptions): Integer;
var
list : TList;
i : Integer;
begin
list := TList.Create;
try
LazCompOptToVals(opt, cfg, list);
cmd.SetValues(list);
for i:=0 to list.Count-1 do TObject(list[i]).Free;
Result:=ShowModal;
if Result=mrOK then begin
list.Clear;
cmd.Serialize(list);
ValsToLazCompOpt(list, opt);
for i:=0 to list.Count-1 do TObject(list[i]).Free;
end;
finally
list.Free;
end;
end;
initialization
end.