pas2jsdsgn: started options frame

git-svn-id: trunk@56745 -
This commit is contained in:
mattias 2017-12-14 18:50:05 +00:00
parent 14a1a07640
commit fbb5359a95
6 changed files with 296 additions and 3 deletions

2
.gitattributes vendored
View File

@ -3764,6 +3764,8 @@ components/pas2js/languages/pjsdsgnregister.pt_BR.po svneol=native#text/plain
components/pas2js/languages/pjsdsgnregister.ru.po svneol=native#text/plain
components/pas2js/pas2jsdsgn.lpk svneol=native#text/plain
components/pas2js/pas2jsdsgn.pas svneol=native#text/plain
components/pas2js/pjsdsgnoptsframe.lfm svneol=native#text/plain
components/pas2js/pjsdsgnoptsframe.pas svneol=native#text/plain
components/pas2js/pjsdsgnregister.pas svneol=native#text/plain
components/plotfunction/demo/event/frmmain.lfm svneol=native#text/plain
components/plotfunction/demo/event/frmmain.pp svneol=native#text/plain

View File

@ -18,12 +18,16 @@
<Description Value="Adds a Lazarus project for pas2js browser applications."/>
<License Value="Modified LGPL-2"/>
<Version Major="1" Release="1"/>
<Files Count="1">
<Files Count="2">
<Item1>
<Filename Value="pjsdsgnregister.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="pjsdsgnregister"/>
</Item1>
<Item2>
<Filename Value="pjsdsgnoptsframe.pas"/>
<UnitName Value="pjsdsgnoptsframe"/>
</Item2>
</Files>
<i18n>
<EnableI18N Value="True"/>

View File

@ -8,7 +8,7 @@ unit Pas2JSDsgn;
interface
uses
PJSDsgnRegister, LazarusPackageIntf;
PJSDsgnRegister, PJSDsgnOptsFrame, LazarusPackageIntf;
implementation

View File

@ -0,0 +1,58 @@
object Pas2jsOptionsFrame: TPas2jsOptionsFrame
Left = 0
Height = 315
Top = 0
Width = 425
ClientHeight = 315
ClientWidth = 425
TabOrder = 0
DesignLeft = 345
DesignTop = 158
object Pas2jsPathLabel: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Left = 6
Height = 16
Top = 6
Width = 100
BorderSpacing.Left = 6
BorderSpacing.Top = 6
Caption = 'Pas2jsPathLabel'
ParentColor = False
ParentShowHint = False
ShowHint = True
end
object Pas2jsPathComboBox: TComboBox
AnchorSideLeft.Control = Pas2jsPathLabel
AnchorSideTop.Control = Pas2jsPathLabel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Pas2jsPathBrowseButton
Left = 6
Height = 21
Top = 22
Width = 343
Anchors = [akTop, akLeft, akRight]
ItemHeight = 0
TabOrder = 0
Text = 'Pas2jsPathComboBox'
end
object Pas2jsPathBrowseButton: TButton
AnchorSideTop.Control = Pas2jsPathComboBox
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Pas2jsPathComboBox
AnchorSideBottom.Side = asrBottom
Left = 349
Height = 21
Top = 22
Width = 70
Anchors = [akTop, akRight, akBottom]
AutoSize = True
BorderSpacing.Right = 6
Caption = '...'
OnClick = Pas2jsPathBrowseButtonClick
ParentShowHint = False
ShowHint = True
TabOrder = 1
end
end

View File

@ -0,0 +1,220 @@
{ Installs pas2js options frame in the Lazarus IDE.
Copyright (C) 2017 Mattias Gaertner mattias@freepascal.org
}
unit PJSDsgnOptsFrame;
{$mode objfpc}{$H+}
{$Inline on}
interface
uses
Classes, SysUtils, Forms, Controls, StdCtrls, Dialogs, IDEOptionsIntf,
MacroIntf, BaseIDEIntf, IDEUtils, LazFileCache, LazConfigStorage,
LazFileUtils;
const
PJSDsgnOptsFile = 'pas2jsdsgnoptions.xml';
PJSDefaultCompiler = '$MakeExe(IDE,pas2js)';
type
{ TPas2jsOptions }
TPas2jsOptions = class
private
FChangeStamp: int64;
FSavedStamp: int64;
FCompilerFilename: string;
function GetModified: boolean;
procedure SetModified(AValue: boolean);
procedure SetCompilerFilename(AValue: string);
public
constructor Create;
destructor Destroy; override;
procedure IncreaseChangeStamp; inline;
procedure Load;
procedure Save;
procedure LoadFromConfig(Cfg: TConfigStorage);
procedure SaveToConfig(Cfg: TConfigStorage);
public
property CompilerFilename: string read FCompilerFilename write SetCompilerFilename;
property ChangeStamp: int64 read FChangeStamp;
property Modified: boolean read GetModified write SetModified;
end;
{ TPas2jsOptionsFrame }
TPas2jsOptionsFrame = class(TAbstractIDEOptionsEditor)
Pas2jsPathBrowseButton: TButton;
Pas2jsPathComboBox: TComboBox;
Pas2jsPathLabel: TLabel;
procedure Pas2jsPathBrowseButtonClick(Sender: TObject);
private
function CheckCompiler(Buttons: TMsgDlgButtons): boolean;
public
function GetTitle: String; override;
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end;
var
PJSOptions: TPas2jsOptions = nil;
function GetStandardPas2jsExe: string;
implementation
function GetStandardPas2jsExe: string;
begin
Result:='$MakeExe(IDE,pas2js)';
if not IDEMacros.SubstituteMacros(Result) then
Result:='pas2js';
end;
{$R *.lfm}
{ TPas2jsOptions }
procedure TPas2jsOptions.SetModified(AValue: boolean);
begin
if AValue then
IncreaseChangeStamp
else
FSavedStamp:=FChangeStamp;
end;
function TPas2jsOptions.GetModified: boolean;
begin
Result:=FSavedStamp<>FChangeStamp;
end;
procedure TPas2jsOptions.SetCompilerFilename(AValue: string);
begin
if FCompilerFilename=AValue then Exit;
FCompilerFilename:=AValue;
IncreaseChangeStamp;
end;
constructor TPas2jsOptions.Create;
begin
FChangeStamp:=LUInvalidChangeStamp64;
FCompilerFilename:=PJSDefaultCompiler;
end;
destructor TPas2jsOptions.Destroy;
begin
inherited Destroy;
end;
procedure TPas2jsOptions.IncreaseChangeStamp;
begin
LUIncreaseChangeStamp64(FChangeStamp);
end;
procedure TPas2jsOptions.Load;
var
Cfg: TConfigStorage;
begin
Cfg:=GetIDEConfigStorage(PJSDsgnOptsFile,true);
try
LoadFromConfig(Cfg);
finally
Cfg.Free;
end;
end;
procedure TPas2jsOptions.Save;
var
Cfg: TConfigStorage;
begin
Cfg:=GetIDEConfigStorage(PJSDsgnOptsFile,false);
try
SaveToConfig(Cfg);
finally
Cfg.Free;
end;
end;
procedure TPas2jsOptions.LoadFromConfig(Cfg: TConfigStorage);
begin
CompilerFilename:=Cfg.GetValue('compiler/value',PJSDefaultCompiler);
Modified:=false;
end;
procedure TPas2jsOptions.SaveToConfig(Cfg: TConfigStorage);
begin
Cfg.SetDeleteValue('compiler/value',CompilerFilename,PJSDefaultCompiler);
end;
{ TPas2jsOptionsFrame }
procedure TPas2jsOptionsFrame.Pas2jsPathBrowseButtonClick(Sender: TObject);
var
OpenDialog: TOpenDialog;
AFilename: String;
begin
OpenDialog:=TOpenDialog.Create(nil);
try
//InputHistories.ApplyFileDialogSettings(OpenDialog);
OpenDialog.Options:=OpenDialog.Options+[ofPathMustExist];
OpenDialog.Title:='Select pas2js executable';
if OpenDialog.Execute then begin
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
SetComboBoxText(Pas2jsPathComboBox,AFilename,cstFilename,30);
CheckCompiler([mbOk]);
end;
finally
OpenDialog.Free;
end;
end;
function TPas2jsOptionsFrame.CheckCompiler(Buttons: TMsgDlgButtons): boolean;
var
NewExe: TCaption;
begin
NewExe:=Pas2jsPathComboBox.Text;
if NewExe=PJSOptions.CompilerFilename then exit(true);
Result:=false;
PJSOptions.CompilerFilename:=NewExe;
//NewExe:=PJSOptions.GetParsedCompilerExe;
end;
function TPas2jsOptionsFrame.GetTitle: String;
begin
Result:='Pas2JS';
end;
procedure TPas2jsOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
var
ExeName: String;
begin
ExeName:=GetStandardPas2jsExe;
Pas2jsPathLabel.Caption:='Path of '+ExeName;
Pas2jsPathLabel.Hint:='You can use IDE macros like $MakeExe(). Without a full path, '+ExeName+' is searched in PATH.';
Pas2jsPathBrowseButton.Caption:='...';
Pas2jsPathBrowseButton.Hint:='Browse';
end;
procedure TPas2jsOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
begin
SetComboBoxText(Pas2jsPathComboBox,PJSOptions.CompilerFilename,cstFilename,30);
end;
procedure TPas2jsOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
begin
PJSOptions.CompilerFilename:=Pas2jsPathComboBox.Text;
end;
class function TPas2jsOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result:=IDEEditorGroups.GetByIndex(GroupEnvironment)^.GroupClass;
end;
finalization
FreeAndNil(PJSOptions);
end.

View File

@ -5,7 +5,8 @@ unit PJSDsgnRegister;
interface
uses
Classes, SysUtils, ProjectIntf, CompOptsIntf, LazIDEIntf, Forms, Controls;
Classes, SysUtils, ProjectIntf, CompOptsIntf, LazIDEIntf, IDEOptionsIntf,
PJSDsgnOptsFrame, Forms, Controls;
const
ProjDescNamePas2JSWebApp = 'Web Application';
@ -41,6 +42,8 @@ type
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
end;
var
PJSOptionsFrameID: integer = 1000;
procedure Register;
@ -48,8 +51,14 @@ implementation
procedure Register;
begin
PJSOptions:=TPas2jsOptions.Create;
PJSOptions.Load;
// register new-project items
RegisterProjectDescriptor(TProjectPas2JSWebApp.Create);
RegisterProjectDescriptor(TProjectPas2JSNodeJSApp.Create);
// add options frame
PJSOptionsFrameID:=RegisterIDEOptionsEditor(GroupEnvironment,TPas2jsOptionsFrame,
PJSOptionsFrameID)^.Index;
end;
{ TProjectPas2JSNodeJSApp }