mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-14 03:19:32 +02:00
* Some additional options for web browser project
git-svn-id: trunk@56765 -
This commit is contained in:
parent
06998e316b
commit
49642ee97b
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -3759,6 +3759,8 @@ components/pas2js/Makefile.compiled svneol=native#text/plain
|
||||
components/pas2js/Makefile.fpc svneol=native#text/plain
|
||||
components/pas2js/Pas2JSDsgn.compiled svneol=native#text/plain
|
||||
components/pas2js/fpmake.pp svneol=native#text/plain
|
||||
components/pas2js/frmpas2jsbrowserprojectoptions.lfm svneol=native#text/plain
|
||||
components/pas2js/frmpas2jsbrowserprojectoptions.pp svneol=native#text/plain
|
||||
components/pas2js/languages/pjsdsgnregister.po svneol=native#text/plain
|
||||
components/pas2js/languages/pjsdsgnregister.pt_BR.po svneol=native#text/plain
|
||||
components/pas2js/languages/pjsdsgnregister.ru.po svneol=native#text/plain
|
||||
|
153
components/pas2js/frmpas2jsbrowserprojectoptions.lfm
Normal file
153
components/pas2js/frmpas2jsbrowserprojectoptions.lfm
Normal file
@ -0,0 +1,153 @@
|
||||
object WebBrowserProjectOptionsForm: TWebBrowserProjectOptionsForm
|
||||
Left = 603
|
||||
Height = 344
|
||||
Top = 213
|
||||
Width = 426
|
||||
Caption = 'Pas2JS Browser project options'
|
||||
ClientHeight = 344
|
||||
ClientWidth = 426
|
||||
LCLVersion = '1.9.0.0'
|
||||
object CBCreateHTML: TCheckBox
|
||||
Left = 16
|
||||
Height = 22
|
||||
Top = 8
|
||||
Width = 162
|
||||
Caption = 'Create initial HTML page'
|
||||
OnChange = CBCreateHTMLChange
|
||||
TabOrder = 0
|
||||
end
|
||||
object CBUseBrowserApp: TCheckBox
|
||||
AnchorSideLeft.Control = CBCreateHTML
|
||||
AnchorSideTop.Control = CBRunOnReady
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 16
|
||||
Height = 22
|
||||
Top = 78
|
||||
Width = 198
|
||||
BorderSpacing.Top = 2
|
||||
Caption = 'Use Browser Application object'
|
||||
TabOrder = 1
|
||||
end
|
||||
object CBUseBrowserConsole: TCheckBox
|
||||
AnchorSideLeft.Control = CBCreateHTML
|
||||
AnchorSideTop.Control = CBUseBrowserApp
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 16
|
||||
Height = 22
|
||||
Top = 102
|
||||
Width = 312
|
||||
BorderSpacing.Top = 2
|
||||
Caption = 'Use Browser Console unit to display writeln() output'
|
||||
TabOrder = 2
|
||||
end
|
||||
object BPHelpOptions: TButtonPanel
|
||||
Left = 6
|
||||
Height = 42
|
||||
Top = 296
|
||||
Width = 414
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 3
|
||||
ShowButtons = [pbOK, pbCancel]
|
||||
end
|
||||
object SEPort: TSpinEdit
|
||||
AnchorSideLeft.Control = RBStartServerAt
|
||||
AnchorSideTop.Control = RBStartServerAt
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 80
|
||||
Height = 27
|
||||
Top = 174
|
||||
Width = 75
|
||||
BorderSpacing.Left = 32
|
||||
BorderSpacing.Top = 2
|
||||
MaxValue = 65354
|
||||
MinValue = 1024
|
||||
TabOrder = 4
|
||||
Value = 3000
|
||||
end
|
||||
object CBUseHTTPServer: TCheckBox
|
||||
AnchorSideLeft.Control = CBCreateHTML
|
||||
AnchorSideTop.Control = CBUseBrowserConsole
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 16
|
||||
Height = 22
|
||||
Top = 126
|
||||
Width = 183
|
||||
BorderSpacing.Top = 2
|
||||
Caption = 'Project needs a HTTP Server'
|
||||
TabOrder = 5
|
||||
end
|
||||
object RBStartServerAt: TRadioButton
|
||||
AnchorSideLeft.Control = CBCreateHTML
|
||||
AnchorSideTop.Control = CBUseHTTPServer
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 48
|
||||
Height = 22
|
||||
Top = 150
|
||||
Width = 167
|
||||
BorderSpacing.Left = 32
|
||||
BorderSpacing.Top = 2
|
||||
Caption = 'Start HTTP Server on port'
|
||||
Checked = True
|
||||
TabOrder = 6
|
||||
TabStop = True
|
||||
end
|
||||
object RBUseURL: TRadioButton
|
||||
AnchorSideLeft.Control = RBStartServerAt
|
||||
AnchorSideTop.Control = SEPort
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 48
|
||||
Height = 22
|
||||
Top = 203
|
||||
Width = 161
|
||||
BorderSpacing.Top = 2
|
||||
Caption = 'Use this URL to start app'
|
||||
TabOrder = 7
|
||||
end
|
||||
object CBServerURL: TComboBox
|
||||
AnchorSideLeft.Control = SEPort
|
||||
AnchorSideTop.Control = RBUseURL
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 80
|
||||
Height = 29
|
||||
Top = 227
|
||||
Width = 334
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 2
|
||||
BorderSpacing.Right = 12
|
||||
ItemHeight = 0
|
||||
TabOrder = 8
|
||||
Text = 'CBServerURL'
|
||||
end
|
||||
object CBMaintainPage: TCheckBox
|
||||
AnchorSideLeft.Control = CBCreateHTML
|
||||
AnchorSideTop.Control = CBCreateHTML
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 16
|
||||
Height = 22
|
||||
Top = 32
|
||||
Width = 140
|
||||
BorderSpacing.Top = 2
|
||||
Caption = 'Maintain HTML Page'
|
||||
TabOrder = 9
|
||||
end
|
||||
object CBRunOnReady: TCheckBox
|
||||
AnchorSideLeft.Control = CBCreateHTML
|
||||
AnchorSideTop.Control = CBMaintainPage
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 16
|
||||
Height = 22
|
||||
Top = 54
|
||||
Width = 183
|
||||
Caption = 'Run rtl in document.onReady'
|
||||
TabOrder = 10
|
||||
end
|
||||
end
|
121
components/pas2js/frmpas2jsbrowserprojectoptions.pp
Normal file
121
components/pas2js/frmpas2jsbrowserprojectoptions.pp
Normal file
@ -0,0 +1,121 @@
|
||||
unit frmpas2jsbrowserprojectoptions;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ButtonPanel,
|
||||
Spin;
|
||||
|
||||
type
|
||||
|
||||
{ TWebBrowserProjectOptionsForm }
|
||||
|
||||
TWebBrowserProjectOptionsForm = class(TForm)
|
||||
BPHelpOptions: TButtonPanel;
|
||||
CBCreateHTML: TCheckBox;
|
||||
CBUseBrowserApp: TCheckBox;
|
||||
CBUseBrowserConsole: TCheckBox;
|
||||
CBUseHTTPServer: TCheckBox;
|
||||
CBServerURL: TComboBox;
|
||||
CBMaintainPage: TCheckBox;
|
||||
CBRunOnReady: TCheckBox;
|
||||
RBUseURL: TRadioButton;
|
||||
RBStartServerAt: TRadioButton;
|
||||
SEPort: TSpinEdit;
|
||||
procedure CBCreateHTMLChange(Sender: TObject);
|
||||
private
|
||||
function GetB(AIndex: Integer): Boolean;
|
||||
function GetServerPort: Word;
|
||||
function GetURL: String;
|
||||
procedure SetB(AIndex: Integer; AValue: Boolean);
|
||||
procedure SetServerPort(AValue: Word);
|
||||
procedure SetURL(AValue: String);
|
||||
|
||||
public
|
||||
property CreateHTML : Boolean Index 0 read GetB Write SetB;
|
||||
property MaintainHTML : Boolean Index 1 read GetB Write SetB;
|
||||
property UseBrowserApp : Boolean Index 2 read GetB Write SetB;
|
||||
property UseBrowserConsole : Boolean Index 3 read GetB Write SetB;
|
||||
property StartHTTPServer : Boolean Index 4 read GetB Write SetB;
|
||||
property UseURL : Boolean Index 5 read GetB Write SetB;
|
||||
property UseRunOnReady : Boolean Index 6 read GetB Write SetB;
|
||||
Property ServerPort : Word Read GetServerPort Write SetServerPort;
|
||||
Property URL : String Read GetURL Write SetURL;
|
||||
end;
|
||||
|
||||
var
|
||||
WebBrowserProjectOptionsForm: TWebBrowserProjectOptionsForm;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TWebBrowserProjectOptionsForm }
|
||||
|
||||
procedure TWebBrowserProjectOptionsForm.CBCreateHTMLChange(Sender: TObject);
|
||||
|
||||
Procedure DOCB(CB : TCheckbox);
|
||||
|
||||
begin
|
||||
CB.Enabled:=CBCreateHTML.Checked;
|
||||
if not CB.Enabled then
|
||||
CB.Checked:=False;
|
||||
end;
|
||||
|
||||
begin
|
||||
DoCB(CBRunOnReady);
|
||||
DoCB(CBMaintainPage);
|
||||
end;
|
||||
|
||||
function TWebBrowserProjectOptionsForm.GetB(AIndex: Integer): Boolean;
|
||||
begin
|
||||
Case Aindex of
|
||||
0 : Result:=CBCreateHTML.Checked;
|
||||
1 : Result:=CBMaintainPage.Checked;
|
||||
2 : Result:=CBUseBrowserApp.Checked;
|
||||
3 : Result:=CBUseBrowserConsole.Checked;
|
||||
4 : Result:=RBStartServerAt.Checked;
|
||||
5 : Result:=RBUseURL.Checked;
|
||||
6 : Result:=CBRunOnReady.Checked;
|
||||
else
|
||||
Result:=False;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TWebBrowserProjectOptionsForm.GetServerPort: Word;
|
||||
begin
|
||||
Result:=SEPort.Value;
|
||||
end;
|
||||
|
||||
function TWebBrowserProjectOptionsForm.GetURL: String;
|
||||
begin
|
||||
Result:=CBServerURL.Text;
|
||||
end;
|
||||
|
||||
procedure TWebBrowserProjectOptionsForm.SetB(AIndex: Integer; AValue: Boolean);
|
||||
begin
|
||||
Case Aindex of
|
||||
0 : CBCreateHTML.Checked:=AValue;
|
||||
1 : CBMaintainPage.Checked:=AValue;
|
||||
2 : CBUseBrowserApp.Checked:=AValue;
|
||||
3 : CBUseBrowserConsole.Checked:=AValue;
|
||||
4 : RBStartServerAt.Checked:=AValue;
|
||||
5 : RBUseURL.Checked:=AValue;
|
||||
6 : CBRunOnReady.Checked:=Avalue;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TWebBrowserProjectOptionsForm.SetServerPort(AValue: Word);
|
||||
begin
|
||||
SEPort.Value:=AValue;
|
||||
end;
|
||||
|
||||
procedure TWebBrowserProjectOptionsForm.SetURL(AValue: String);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -14,6 +14,6 @@ msgid "A pas2js program running in the browser"
|
||||
msgstr ""
|
||||
|
||||
#: pjsdsgnregister.pjsdwebapplication
|
||||
msgid "Web Application"
|
||||
msgid "Web Browser Application"
|
||||
msgstr ""
|
||||
|
||||
|
@ -24,6 +24,8 @@ msgid "A pas2js program running in the browser"
|
||||
msgstr "Um programa pas2js executando no navegador"
|
||||
|
||||
#: pjsdsgnregister.pjsdwebapplication
|
||||
msgid "Web Application"
|
||||
#, fuzzy
|
||||
#| msgid "Web Application"
|
||||
msgid "Web Browser Application"
|
||||
msgstr "Aplicação Web"
|
||||
|
||||
|
@ -24,6 +24,8 @@ msgid "A pas2js program running in the browser"
|
||||
msgstr "Программа pas2js, запускаемая в браузере"
|
||||
|
||||
#: pjsdsgnregister.pjsdwebapplication
|
||||
msgid "Web Application"
|
||||
#, fuzzy
|
||||
#| msgid "Web Application"
|
||||
msgid "Web Browser Application"
|
||||
msgstr "Веб-приложение"
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
<Description Value="Adds a Lazarus project for pas2js browser applications."/>
|
||||
<License Value="GPL-2"/>
|
||||
<Version Major="1" Release="1"/>
|
||||
<Files Count="3">
|
||||
<Files Count="4">
|
||||
<Item1>
|
||||
<Filename Value="pjsdsgnregister.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
@ -29,9 +29,13 @@
|
||||
<UnitName Value="PJSDsgnOptsFrame"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Filename Value="frmpas2jsbrowserprojectoptions.pp"/>
|
||||
<UnitName Value="frmpas2jsbrowserprojectoptions"/>
|
||||
</Item3>
|
||||
<Item4>
|
||||
<Filename Value="pjsdsgnoptions.pas"/>
|
||||
<UnitName Value="PJSDsgnOptions"/>
|
||||
</Item3>
|
||||
</Item4>
|
||||
</Files>
|
||||
<i18n>
|
||||
<EnableI18N Value="True"/>
|
||||
|
@ -8,7 +8,8 @@ unit Pas2JSDsgn;
|
||||
interface
|
||||
|
||||
uses
|
||||
PJSDsgnRegister, PJSDsgnOptsFrame, PJSDsgnOptions, LazarusPackageIntf;
|
||||
PJSDsgnRegister, PJSDsgnOptsFrame, frmpas2jsbrowserprojectoptions,
|
||||
PJSDsgnOptions, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
@ -17,7 +17,48 @@ uses
|
||||
const
|
||||
PJSDsgnOptsFile = 'pas2jsdsgnoptions.xml';
|
||||
PJSDefaultCompiler = '$MakeExe(IDE,pas2js)';
|
||||
PJSDefaultHTTPServer = '$MakeExe(IDE,simpleserver)';
|
||||
PJSDefaultStartAtPort = 3000; // Simpleserver default
|
||||
PJSDefaultBrowser = '$MakeExe(IDE,firefox)';
|
||||
|
||||
Type
|
||||
{ TPas2jsOptions }
|
||||
|
||||
TPas2jsOptions = class
|
||||
private
|
||||
FBrowserFileName: String;
|
||||
FChangeStamp: int64;
|
||||
FHTTPServerFileName: string;
|
||||
FSavedStamp: int64;
|
||||
FCompilerFilename: string;
|
||||
FCompilerFilenameStamp: int64;
|
||||
FCompilerFilenameParsed: string;
|
||||
FStartAtPort: Word;
|
||||
function GetModified: boolean;
|
||||
procedure SetBrowserFileName(AValue: String);
|
||||
procedure SetHTTPServerFileName(AValue: string);
|
||||
procedure SetModified(AValue: boolean);
|
||||
procedure SetCompilerFilename(AValue: string);
|
||||
procedure SetStartAtPort(AValue: Word);
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure IncreaseChangeStamp; inline;
|
||||
procedure Load;
|
||||
procedure Save;
|
||||
function GetParsedCompilerFilename: string;
|
||||
procedure LoadFromConfig(Cfg: TConfigStorage);
|
||||
procedure SaveToConfig(Cfg: TConfigStorage);
|
||||
public
|
||||
property CompilerFilename: string read FCompilerFilename write SetCompilerFilename;
|
||||
Property HTTPServerFileName : string Read FHTTPServerFileName Write SetHTTPServerFileName;
|
||||
Property BrowserFileName : String Read FBrowserFileName Write SetBrowserFileName;
|
||||
Property StartAtPort : Word Read FStartAtPort Write SetStartAtPort;
|
||||
property ChangeStamp: int64 read FChangeStamp;
|
||||
property Modified: boolean read GetModified write SetModified;
|
||||
end;
|
||||
|
||||
(*
|
||||
type
|
||||
|
||||
{ TPas2jsOptions }
|
||||
@ -46,11 +87,14 @@ type
|
||||
property ChangeStamp: int64 read FChangeStamp;
|
||||
property Modified: boolean read GetModified write SetModified;
|
||||
end;
|
||||
*)
|
||||
|
||||
var
|
||||
PJSOptions: TPas2jsOptions = nil;
|
||||
|
||||
function GetStandardPas2jsExe: string;
|
||||
function GetStandardHTTPServer: string;
|
||||
function GetStandardBrowser: string;
|
||||
function GetPas2jsQuality(Filename: string; out Msg: string): boolean;
|
||||
|
||||
implementation
|
||||
@ -62,6 +106,36 @@ begin
|
||||
Result:='pas2js';
|
||||
end;
|
||||
|
||||
function GetStandardHTTPServer: string;
|
||||
|
||||
begin
|
||||
Result:='$MakeExe(IDE,simpleserver)';
|
||||
if not IDEMacros.SubstituteMacros(Result) then
|
||||
Result:='simpleserver';
|
||||
end;
|
||||
|
||||
function GetStandardBrowser: string;
|
||||
|
||||
begin
|
||||
Result:='$MakeExe(IDE,firefox)';
|
||||
if not IDEMacros.SubstituteMacros(Result) then
|
||||
begin
|
||||
Result:='$MakeExe(IDE,chrome)';
|
||||
{$ifdef windows}
|
||||
if not IDEMacros.SubstituteMacros(Result) then
|
||||
Result:='$MakeExe(IDE,iexplore)';
|
||||
{$else}
|
||||
{$ifdef darwin}
|
||||
if not IDEMacros.SubstituteMacros(Result) then
|
||||
Result:='$MakeExe(IDE,xdg-open)';
|
||||
{$endif}
|
||||
if not IDEMacros.SubstituteMacros(Result) then
|
||||
Result:='';
|
||||
{$endif}
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function GetPas2jsQuality(Filename: string; out Msg: string): boolean;
|
||||
var
|
||||
ShortFile: String;
|
||||
@ -182,7 +256,213 @@ begin
|
||||
Result:=FCompilerFilenameParsed;
|
||||
end;
|
||||
|
||||
finalization
|
||||
procedure TPas2jsOptions.SetBrowserFileName(AValue: String);
|
||||
begin
|
||||
if FBrowserFileName=AValue then Exit;
|
||||
FBrowserFileName:=AValue;
|
||||
IncreaseChangeStamp;
|
||||
end;
|
||||
|
||||
procedure TPas2jsOptions.SetHTTPServerFileName(AValue: string);
|
||||
begin
|
||||
if FHTTPServerFileName=AValue then Exit;
|
||||
FHTTPServerFileName:=AValue;
|
||||
IncreaseChangeStamp;
|
||||
end;
|
||||
|
||||
procedure TPas2jsOptions.SetStartAtPort(AValue: Word);
|
||||
begin
|
||||
if FStartAtPort=AValue then Exit;
|
||||
FStartAtPort:=AValue;
|
||||
IncreaseChangeStamp;
|
||||
end;
|
||||
|
||||
|
||||
Procedure DonePSJOptions;
|
||||
|
||||
begin
|
||||
try
|
||||
if PJSOptions.Modified then
|
||||
PJSOptions.Save;
|
||||
except
|
||||
end;
|
||||
FreeAndNil(PJSOptions);
|
||||
end;
|
||||
|
||||
|
||||
finalization
|
||||
DonePSJOptions;
|
||||
end.
|
||||
|
||||
(*
|
||||
|
||||
|
||||
<<<<<<< .mine
|
||||
{ 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;
|
||||
|
||||
Const
|
||||
KeyCompiler = 'compiler/value';
|
||||
KeyHTTPServer = 'webserver/value';
|
||||
KeyBrowser = 'webbrowser/value';
|
||||
KeyStartPortAt = 'webserver/startatport/value';
|
||||
|
||||
procedure TPas2jsOptions.LoadFromConfig(Cfg: TConfigStorage);
|
||||
|
||||
begin
|
||||
CompilerFilename:=Cfg.GetValue(KeyCompiler ,PJSDefaultCompiler);
|
||||
HTTPServerFileName:=Cfg.GetValue(KeyHTTPServer,PJSDefaultHTTPServer);
|
||||
BrowserFileName:=Cfg.GetValue(KeyBrowser,PJSDefaultBrowser);
|
||||
StartAtPort :=Cfg.GetValue(KeyStartPortAt,PJSDefaultStartAtPort);
|
||||
Modified:=false;
|
||||
end;
|
||||
|
||||
procedure TPas2jsOptions.SaveToConfig(Cfg: TConfigStorage);
|
||||
|
||||
begin
|
||||
Cfg.SetDeleteValue(KeyCompiler,CompilerFilename,PJSDefaultCompiler);
|
||||
Cfg.SetDeleteValue(KeyHTTPServer,HTTPServerFileName,PJSDefaultHTTPServer);
|
||||
Cfg.SetDeleteValue(KeyStartPortAt,StartAtPort,PJSDefaultStartAtPort);
|
||||
Cfg.SetDeleteValue(KeyBrowser,BrowserFileName,PJSDefaultBrowser);
|
||||
Modified:=false;
|
||||
end;
|
||||
|
||||
||||||| .r56758
|
||||
{ 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;
|
||||
|
||||
=======
|
||||
>>>>>>> .r56764
|
||||
|
||||
*)
|
||||
|
@ -1,10 +1,11 @@
|
||||
object Pas2jsOptionsFrame: TPas2jsOptionsFrame
|
||||
Left = 0
|
||||
Height = 315
|
||||
Height = 278
|
||||
Top = 0
|
||||
Width = 425
|
||||
ClientHeight = 315
|
||||
ClientWidth = 425
|
||||
Width = 427
|
||||
BorderSpacing.Left = 6
|
||||
ClientHeight = 278
|
||||
ClientWidth = 427
|
||||
TabOrder = 0
|
||||
DesignLeft = 345
|
||||
DesignTop = 158
|
||||
@ -12,12 +13,12 @@ object Pas2jsOptionsFrame: TPas2jsOptionsFrame
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 6
|
||||
Height = 16
|
||||
Height = 17
|
||||
Top = 6
|
||||
Width = 100
|
||||
Width = 160
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
Caption = 'Pas2jsPathLabel'
|
||||
Caption = 'Pas2JS command executable'
|
||||
ParentColor = False
|
||||
ParentShowHint = False
|
||||
ShowHint = True
|
||||
@ -28,13 +29,12 @@ object Pas2jsOptionsFrame: TPas2jsOptionsFrame
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Pas2jsPathBrowseButton
|
||||
Left = 6
|
||||
Height = 21
|
||||
Top = 22
|
||||
Width = 343
|
||||
Height = 29
|
||||
Top = 23
|
||||
Width = 396
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
ItemHeight = 0
|
||||
TabOrder = 0
|
||||
Text = 'Pas2jsPathComboBox'
|
||||
end
|
||||
object Pas2jsPathBrowseButton: TButton
|
||||
AnchorSideTop.Control = Pas2jsPathComboBox
|
||||
@ -42,10 +42,10 @@ object Pas2jsOptionsFrame: TPas2jsOptionsFrame
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = Pas2jsPathComboBox
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 349
|
||||
Height = 21
|
||||
Top = 22
|
||||
Width = 70
|
||||
Left = 402
|
||||
Height = 29
|
||||
Top = 23
|
||||
Width = 19
|
||||
Anchors = [akTop, akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Right = 6
|
||||
@ -55,4 +55,116 @@ object Pas2jsOptionsFrame: TPas2jsOptionsFrame
|
||||
ShowHint = True
|
||||
TabOrder = 1
|
||||
end
|
||||
object HTTPServerCmdLabel: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Pas2jsPathComboBox
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 60
|
||||
Width = 170
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 8
|
||||
Caption = 'Simple HTTP Server command'
|
||||
ParentColor = False
|
||||
end
|
||||
object HTTPServerBrowseButton: TButton
|
||||
AnchorSideTop.Control = HTTPServerCmdLabel
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 402
|
||||
Height = 29
|
||||
Top = 77
|
||||
Width = 19
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Right = 6
|
||||
Caption = '...'
|
||||
OnClick = HTTPServerBrowseButtonClick
|
||||
TabOrder = 2
|
||||
end
|
||||
object HTTPServerComboBox: TComboBox
|
||||
AnchorSideLeft.Control = HTTPServerCmdLabel
|
||||
AnchorSideTop.Control = HTTPServerCmdLabel
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = HTTPServerBrowseButton
|
||||
Left = 6
|
||||
Height = 29
|
||||
Top = 77
|
||||
Width = 396
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
ItemHeight = 0
|
||||
TabOrder = 3
|
||||
end
|
||||
object ServerPortSpinEdit: TSpinEdit
|
||||
AnchorSideLeft.Control = ServerPortLabel
|
||||
AnchorSideTop.Control = ServerPortLabel
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 27
|
||||
Top = 131
|
||||
Width = 74
|
||||
MaxValue = 65353
|
||||
MinValue = 1024
|
||||
TabOrder = 4
|
||||
Value = 3000
|
||||
end
|
||||
object ServerPortLabel: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = HTTPServerComboBox
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 114
|
||||
Width = 116
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 8
|
||||
Caption = 'Standard server port'
|
||||
ParentColor = False
|
||||
end
|
||||
object BrowserComboBox: TComboBox
|
||||
AnchorSideLeft.Control = BrowserLabel
|
||||
AnchorSideTop.Control = BrowserLabel
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = BBrowserBrowseButton
|
||||
Left = 6
|
||||
Height = 29
|
||||
Top = 187
|
||||
Width = 395
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Right = 1
|
||||
ItemHeight = 0
|
||||
TabOrder = 5
|
||||
Text = 'BrowserComboBox'
|
||||
end
|
||||
object BrowserLabel: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ServerPortSpinEdit
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 164
|
||||
Width = 260
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
Caption = 'Browser to launch when opening project HTML'
|
||||
ParentColor = False
|
||||
end
|
||||
object BBrowserBrowseButton: TButton
|
||||
AnchorSideTop.Control = BrowserLabel
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 402
|
||||
Height = 29
|
||||
Top = 187
|
||||
Width = 19
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Right = 6
|
||||
Caption = '...'
|
||||
OnClick = BBrowserBrowseButtonClick
|
||||
TabOrder = 6
|
||||
end
|
||||
end
|
||||
|
@ -10,18 +10,27 @@ unit PJSDsgnOptsFrame;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LazFileCache, LazConfigStorage, LazFileUtils, FileUtil,
|
||||
Forms, Controls, StdCtrls, Dialogs,
|
||||
IDEOptionsIntf, MacroIntf, BaseIDEIntf, IDEUtils,
|
||||
PJSDsgnOptions;
|
||||
Classes, SysUtils, Forms, Controls, StdCtrls, Dialogs, Spin, IDEOptionsIntf,
|
||||
MacroIntf, BaseIDEIntf, IDEUtils, LazFileCache, LazConfigStorage, PJSDsgnOptions,
|
||||
LazFileUtils;
|
||||
|
||||
type
|
||||
Type
|
||||
{ TPas2jsOptionsFrame }
|
||||
|
||||
TPas2jsOptionsFrame = class(TAbstractIDEOptionsEditor)
|
||||
BBrowserBrowseButton: TButton;
|
||||
BrowserComboBox: TComboBox;
|
||||
HTTPServerBrowseButton: TButton;
|
||||
HTTPServerComboBox: TComboBox;
|
||||
HTTPServerCmdLabel: TLabel;
|
||||
BrowserLabel: TLabel;
|
||||
ServerPortLabel: TLabel;
|
||||
Pas2jsPathBrowseButton: TButton;
|
||||
Pas2jsPathComboBox: TComboBox;
|
||||
Pas2jsPathLabel: TLabel;
|
||||
ServerPortSpinEdit: TSpinEdit;
|
||||
procedure BBrowserBrowseButtonClick(Sender: TObject);
|
||||
procedure HTTPServerBrowseButtonClick(Sender: TObject);
|
||||
procedure Pas2jsPathBrowseButtonClick(Sender: TObject);
|
||||
private
|
||||
function CheckCompiler(Buttons: TMsgDlgButtons): boolean;
|
||||
@ -35,6 +44,8 @@ type
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TPas2jsOptionsFrame }
|
||||
@ -59,9 +70,54 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TPas2jsOptionsFrame.HTTPServerBrowseButtonClick(Sender: TObject);
|
||||
|
||||
var
|
||||
OpenDialog: TOpenDialog;
|
||||
AFilename: String;
|
||||
|
||||
begin
|
||||
OpenDialog:=TOpenDialog.Create(nil);
|
||||
try
|
||||
//InputHistories.ApplyFileDialogSettings(OpenDialog);
|
||||
OpenDialog.Options:=OpenDialog.Options+[ofPathMustExist];
|
||||
OpenDialog.Title:='Select simpleserver executable';
|
||||
if OpenDialog.Execute then begin
|
||||
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
|
||||
SetComboBoxText(HTTPServerComboBox,AFilename,cstFilename,30);
|
||||
PJSOptions.HTTPServerFileName:=AFileName;
|
||||
end;
|
||||
finally
|
||||
OpenDialog.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TPas2jsOptionsFrame.BBrowserBrowseButtonClick(Sender: TObject);
|
||||
var
|
||||
OpenDialog: TOpenDialog;
|
||||
AFilename: String;
|
||||
|
||||
begin
|
||||
OpenDialog:=TOpenDialog.Create(nil);
|
||||
try
|
||||
//InputHistories.ApplyFileDialogSettings(OpenDialog);
|
||||
OpenDialog.Options:=OpenDialog.Options+[ofPathMustExist];
|
||||
OpenDialog.Title:='Select browser executable';
|
||||
if OpenDialog.Execute then begin
|
||||
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
|
||||
SetComboBoxText(BrowserComboBox,AFilename,cstFilename,30);
|
||||
PJSOptions.BrowserFileName:=AFileName;
|
||||
end;
|
||||
finally
|
||||
OpenDialog.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TPas2jsOptionsFrame.CheckCompiler(Buttons: TMsgDlgButtons): boolean;
|
||||
|
||||
var
|
||||
NewExe: string;
|
||||
|
||||
begin
|
||||
NewExe:=Pas2jsPathComboBox.Text;
|
||||
if NewExe=PJSOptions.CompilerFilename then exit(true);
|
||||
@ -77,24 +133,46 @@ begin
|
||||
end;
|
||||
|
||||
procedure TPas2jsOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
|
||||
|
||||
var
|
||||
ExeName: String;
|
||||
ServerName : String;
|
||||
BrowserName : String;
|
||||
|
||||
begin
|
||||
ExeName:=GetStandardPas2jsExe;
|
||||
ServerName:=GetStandardHTTPServer;
|
||||
BrowserName:=GetStandardBrowser;
|
||||
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';
|
||||
HTTPServerCmdLabel.Caption:='Path of '+ServerName;
|
||||
HTTPServerCmdLabel.Hint:='You can use IDE macros like $MakeExe(). Without a full path, '+ServerName+' is searched in PATH.';
|
||||
HTTPServerBrowseButton.Caption:='...';
|
||||
HTTPServerBrowseButton.Hint:='Browse';
|
||||
ServerPortLabel.Caption:='Port numbers to start allocating from '+ServerName;
|
||||
ServerPortLabel.Hint:='Server instances will be started with a port starting from this number, increasing per new project';
|
||||
BrowserLabel.Caption:='Browser to use when opening HTML page';
|
||||
BrowserLabel.Hint:='Use this browser when opening the URL or HTML file of a web browser project';
|
||||
end;
|
||||
|
||||
procedure TPas2jsOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
|
||||
begin
|
||||
SetComboBoxText(Pas2jsPathComboBox,PJSOptions.CompilerFilename,cstFilename,30);
|
||||
SetComboBoxText(HTTPServerComboBox,PJSOptions.HTTPServerFileName,cstFilename,30);
|
||||
SetComboBoxText(BrowserComboBox,PJSOptions.BrowserFileName,cstFilename,30);
|
||||
ServerPortSpinEdit.Value:=PJSOptions.StartAtPort;
|
||||
end;
|
||||
|
||||
procedure TPas2jsOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
|
||||
begin
|
||||
PJSOptions.CompilerFilename:=Pas2jsPathComboBox.Text;
|
||||
PJSOptions.HTTPServerFileName:=HTTPServerComboBox.Text;
|
||||
PJSOptions.BrowserFileName:=BrowserComboBox.Text;
|
||||
PJSOptions.StartAtPort:=ServerPortSpinEdit.Value;
|
||||
If PJSOptions.Modified then
|
||||
PJSOptions.Save;
|
||||
end;
|
||||
|
||||
class function TPas2jsOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
|
||||
|
@ -14,7 +14,7 @@ const
|
||||
ProjDescNamePas2JSNodeJSApp = 'NodeJS Application';
|
||||
|
||||
resourcestring
|
||||
pjsdWebApplication = 'Web Application';
|
||||
pjsdWebApplication = 'Web Browser Application';
|
||||
pjsdWebAppDescription = 'A pas2js program running in the browser';
|
||||
pjsdNodeJSApplication = 'Node.js Application';
|
||||
pjsdNodeJSAppDescription = 'A pas2js program running in node.js';
|
||||
@ -22,14 +22,38 @@ resourcestring
|
||||
type
|
||||
|
||||
{ TProjectPas2JSWebApp }
|
||||
TBrowserApplicationOption = (baoCreateHtml, // Create template HTML page
|
||||
baoMaintainHTML, // Maintain the template HTML page
|
||||
baoRunOnReady, // Run in document.onReady
|
||||
baoUseBrowserApp, // Use browser app object
|
||||
baoUseBrowserConsole, // use browserconsole unit to display Writeln()
|
||||
baoStartServer, // Start simple server
|
||||
baoUseURL // Use this URL to run/show project in browser
|
||||
);
|
||||
TBrowserApplicationOptions = set of TBrowserApplicationOption;
|
||||
|
||||
TProjectPas2JSWebApp = class(TProjectDescriptor)
|
||||
private
|
||||
FOptions: TBrowserApplicationOptions;
|
||||
FProjectPort: integer;
|
||||
FProjectURL: String;
|
||||
function CreateHTMLFile(AProject: TLazProject; AFileName: String
|
||||
): TLazProjectFile;
|
||||
function CreateProjectSource: String;
|
||||
function GetNextPort: Word;
|
||||
protected
|
||||
function ShowOptionsDialog: TModalResult; virtual;
|
||||
public
|
||||
constructor Create; override;
|
||||
function GetBrowserCommand(AFileName: string): String;
|
||||
Function DoInitDescriptor : TModalResult; override;
|
||||
function GetLocalizedName: string; override;
|
||||
function GetLocalizedDescription: string; override;
|
||||
function InitProject(AProject: TLazProject): TModalResult; override;
|
||||
function CreateStartFiles(AProject: TLazProject): TModalResult; override;
|
||||
Property Options : TBrowserApplicationOptions read FOptions Write Foptions;
|
||||
Property ProjectPort : integer Read FProjectPort Write FProjectPort;
|
||||
Property ProjectURL : String Read FProjectURL Write FProjectURL;
|
||||
end;
|
||||
|
||||
{ TProjectPas2JSNodeJSApp }
|
||||
@ -50,7 +74,10 @@ procedure Register;
|
||||
|
||||
implementation
|
||||
|
||||
uses frmpas2jsbrowserprojectoptions;
|
||||
|
||||
procedure Register;
|
||||
|
||||
begin
|
||||
PJSOptions:=TPas2jsOptions.Create;
|
||||
PJSOptions.Load;
|
||||
@ -67,7 +94,7 @@ end;
|
||||
constructor TProjectPas2JSNodeJSApp.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
Name:=ProjDescNamePas2JSWebApp;
|
||||
Name:= ProjDescNamePas2JSNodeJSApp;
|
||||
Flags:=DefaultProjectNoApplicationFlags-[pfRunnable];
|
||||
end;
|
||||
|
||||
@ -86,6 +113,8 @@ function TProjectPas2JSNodeJSApp.InitProject(AProject: TLazProject
|
||||
var
|
||||
MainFile: TLazProjectFile;
|
||||
CompOpts: TLazCompilerOptions;
|
||||
RunParams : TAbstractRunParamsOptions;
|
||||
|
||||
NewSource: String;
|
||||
begin
|
||||
Result:=inherited InitProject(AProject);
|
||||
@ -102,6 +131,9 @@ begin
|
||||
CompOpts.TargetFilename:='project1';
|
||||
CompOpts.SetAlternativeCompile(
|
||||
'$MakeExe(pas2js) -Jc -Jminclude -Tnodejs "-Fu$(ProjUnitPath)" $Name($(ProjFile))',true);
|
||||
RunParams:=AProject.RunParameters;
|
||||
RunParams.UseLaunchingApplication:=True;
|
||||
RunParams.LaunchingApplicationPathPlusParams:='$MakeExe(IDE,nodejs) "$MakeDir($(ProjPath))$NameOnly($(ProjFile)).js"';
|
||||
|
||||
// create program source
|
||||
NewSource:='program Project1;'+LineEnding
|
||||
@ -135,6 +167,94 @@ begin
|
||||
Flags:=DefaultProjectNoApplicationFlags-[pfRunnable];
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.GetBrowserCommand(AFileName : string): String;
|
||||
|
||||
Var
|
||||
S : String;
|
||||
|
||||
begin
|
||||
S:=PJSOptions.BrowserFileName;
|
||||
if S='' then
|
||||
S:=GetStandardBrowser;
|
||||
if (baoStartServer in Options) then
|
||||
S:=S+Format(' http://localhost:%d/%s',[ProjectPort,ProjectURL])
|
||||
else if (baoUseURL in Options) then
|
||||
S:=S+' '+ProjectURL
|
||||
else
|
||||
S:=S+' "$MakeDir($(ProjPath))$NameOnly($(ProjFile)).html"';
|
||||
Result:=S;
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.GetNextPort : Word;
|
||||
|
||||
begin
|
||||
Result:=PJSOptions.StartAtPort+1;
|
||||
PJSOptions.StartAtPort:=1;
|
||||
PJSOptions.Save;
|
||||
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.ShowOptionsDialog : TModalResult;
|
||||
|
||||
Function Co(o : TBrowserApplicationOption) : boolean;
|
||||
|
||||
begin
|
||||
Result:=O in Options;
|
||||
end;
|
||||
|
||||
Procedure So(Value : Boolean; o : TBrowserApplicationOption);
|
||||
|
||||
begin
|
||||
if Value then
|
||||
Include(Foptions,O);
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
With TWebBrowserProjectOptionsForm.Create(Nil) do
|
||||
try
|
||||
CreateHTML:=CO(baoCreateHtml);
|
||||
MaintainHTML:=CO(baoCreateHtml) and Co(baoMaintainHTML);
|
||||
UseBrowserApp:=CO(baoUseBrowserApp);
|
||||
UseBrowserConsole:=CO(baoUseBrowserConsole);
|
||||
StartHTTPServer:=CO(baoStartServer);
|
||||
UseRunOnReady:=CO(baoRunOnReady);
|
||||
if CO(baoStartServer) then
|
||||
ServerPort:=GetNextPort
|
||||
else
|
||||
begin
|
||||
UseURL:=CO(baoUseURL);
|
||||
if CO(baoUseURL) then
|
||||
URL:='';
|
||||
end;
|
||||
Result:=ShowModal;
|
||||
if Result=mrOK then
|
||||
begin
|
||||
SO(CreateHTML,baoCreateHtml);
|
||||
SO(MaintainHTML,baoCreateHtml);
|
||||
SO(UseBrowserApp,baoUseBrowserApp);
|
||||
SO(UseBrowserConsole,baoUseBrowserConsole);
|
||||
SO(StartHTTPServer,baoStartServer);
|
||||
SO(UseRunOnReady,baoRunOnReady);
|
||||
if CO(baoStartServer) then
|
||||
Self.ProjectPort:=ServerPort
|
||||
else
|
||||
begin
|
||||
UseURL:=CO(baoUseURL);
|
||||
if CO(baoUseURL) then
|
||||
URL:='';
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.DoInitDescriptor: TModalResult;
|
||||
begin
|
||||
Result:=ShowOptionsDialog;
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.GetLocalizedName: string;
|
||||
begin
|
||||
Result:=pjsdWebApplication;
|
||||
@ -145,11 +265,127 @@ begin
|
||||
Result:=pjsdWebAppDescription;
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.CreateHTMLFile(AProject: TLazProject;
|
||||
AFileName: String): TLazProjectFile;
|
||||
|
||||
Const
|
||||
ConsoleDiv = '<div id="pasjsconsole"></div>'+LineEnding;
|
||||
TemplateHTMLSource =
|
||||
'<!doctype html>'+LineEnding
|
||||
+'<html lang="en">'+LineEnding
|
||||
+'<head>'+LineEnding
|
||||
+' <meta charset="utf-8">'+LineEnding
|
||||
+' <title>Project1</title>'+LineEnding
|
||||
+'<style>'+LineEnding
|
||||
+'<script src="%s"></script>'+LineEnding
|
||||
+'</head>'+LineEnding
|
||||
+'<script>'+LineEnding
|
||||
+'%s'+LineEnding
|
||||
+'</script>'+LineEnding
|
||||
+'%s'+LineEnding
|
||||
+'<body>'+LineEnding;
|
||||
|
||||
Var
|
||||
HTMLFile : TLazProjectFile;
|
||||
HTMLSource : String;
|
||||
RunScript,Content : String;
|
||||
|
||||
begin
|
||||
HTMLFile:=AProject.CreateProjectFile('project1.html');
|
||||
HTMLFile.IsPartOfProject:=true;
|
||||
AProject.AddFile(HTMLFile,false);
|
||||
Content:='';
|
||||
if baoUseBrowserConsole in Options then
|
||||
Content:=ConsoleDiv;
|
||||
if baoRunOnReady in Options then
|
||||
RunScript:='document.onReady = rtl.run;'+LineEnding
|
||||
else
|
||||
RunScript:='rtl.run();'+LineEnding;
|
||||
HTMLSource:=Format(TemplateHTMLSource,[aFileName,RunScript,Content]);
|
||||
HTMLFile.SetSourceText(HTMLSource);
|
||||
Result:=HTMLFile;
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.CreateProjectSource : String;
|
||||
|
||||
Var
|
||||
Src : TStrings;
|
||||
units : string;
|
||||
|
||||
Procedure Add(aLine : String);
|
||||
|
||||
begin
|
||||
Src.Add(aLine);
|
||||
end;
|
||||
|
||||
Procedure AddLn(aLine : String);
|
||||
|
||||
begin
|
||||
if (Aline<>'') then
|
||||
Aline:=Aline+';';
|
||||
Add(Aline);
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
Units:='';
|
||||
if baoUseBrowserConsole in Options then
|
||||
Units:=' browserconsole,';
|
||||
if baoUseBrowserApp in Options then
|
||||
Units:=Units+' browserapp,' ;
|
||||
Units:=Units+' JS, Classes, SysUtils, Web';
|
||||
Src:=TStringList.Create;
|
||||
try
|
||||
// create program source
|
||||
AddLn('program Project1');
|
||||
AddLn('');
|
||||
Add('{$mode objfpc}');
|
||||
Add('');
|
||||
Add('uses');
|
||||
AddLn(units) ;
|
||||
Add('');
|
||||
if baoUseBrowserApp in Options then
|
||||
begin
|
||||
Add('Type');
|
||||
Add(' TMyApplication = Class(TBrowserApplication)');
|
||||
AddLn(' procedure doRun; override');
|
||||
AddLn(' end');
|
||||
Add('');
|
||||
AddLn('Procedure TMyApplication.doRun');
|
||||
Add('');
|
||||
Add('begin');
|
||||
Add(' // Your code here');
|
||||
AddLn(' Terminate');
|
||||
AddLn('end');
|
||||
Add('');
|
||||
Add('var');
|
||||
AddLn(' Application : TMyApplication');
|
||||
Add('');
|
||||
end;
|
||||
Add('begin');
|
||||
if Not (baoUseBrowserApp in Options) then
|
||||
Add(' // Your code here')
|
||||
else
|
||||
begin
|
||||
AddLn(' Application:=TMyApplication.Create(Nil)');
|
||||
AddLn(' Application.Initialize');
|
||||
AddLn(' Application.Run');
|
||||
AddLn(' Application.Free');
|
||||
end;
|
||||
Add('end.');
|
||||
Result:=Src.Text;
|
||||
finally
|
||||
Src.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.InitProject(AProject: TLazProject): TModalResult;
|
||||
|
||||
var
|
||||
MainFile, HTMLFile: TLazProjectFile;
|
||||
MainFile : TLazProjectFile;
|
||||
CompOpts: TLazCompilerOptions;
|
||||
NewSource: String;
|
||||
RunParams : TAbstractRunParamsOptions;
|
||||
|
||||
begin
|
||||
Result:=inherited InitProject(AProject);
|
||||
|
||||
@ -164,42 +400,19 @@ begin
|
||||
CompOpts.UnitOutputDirectory:='js';
|
||||
CompOpts.TargetFilename:='project1';
|
||||
CompOpts.SetAlternativeCompile(
|
||||
'$MakeExe(pas2js) -Jc -Jminclude -Tbrowser "-Fu$(ProjUnitPath)" $Name($(ProjFile))',true);
|
||||
'$MakeExe(pas2js) -Jirtl.js -Jc -Jminclude -Tbrowser "-Fu$(ProjUnitPath)" $Name($(ProjFile))',true);
|
||||
RunParams:=AProject.RunParameters;
|
||||
RunParams.UseLaunchingApplication:=True;
|
||||
RunParams.LaunchingApplicationPathPlusParams:=GetBrowserCommand(CompOpts.TargetFileName);
|
||||
AProject.MainFile.SetSourceText(CreateProjectSource,true);
|
||||
|
||||
// create program source
|
||||
NewSource:='program Project1;'+LineEnding
|
||||
+LineEnding
|
||||
+'{$mode objfpc}'+LineEnding
|
||||
+LineEnding
|
||||
+'uses'+LineEnding
|
||||
+' JS, Classes, SysUtils, Web;'+LineEnding
|
||||
+LineEnding
|
||||
+'begin'+LineEnding
|
||||
+'end.'+LineEnding
|
||||
+LineEnding;
|
||||
AProject.MainFile.SetSourceText(NewSource,true);
|
||||
|
||||
HTMLFile:=AProject.CreateProjectFile('project1.html');
|
||||
HTMLFile.IsPartOfProject:=true;
|
||||
AProject.AddFile(HTMLFile,false);
|
||||
// create html source
|
||||
NewSource:=
|
||||
'<!doctype html>'+LineEnding
|
||||
+'<html lang="en">'+LineEnding
|
||||
+'<head>'+LineEnding
|
||||
+' <meta charset="utf-8">'+LineEnding
|
||||
+' <title>Project1</title>'+LineEnding
|
||||
+'<style>'+LineEnding
|
||||
+'<script src="project1.js"></script>'+LineEnding
|
||||
+'</head>'+LineEnding
|
||||
+'<div>Project1</div>'+LineEnding
|
||||
+'<script>'+LineEnding
|
||||
+' rtl.run();'+LineEnding
|
||||
+'</script>'+LineEnding
|
||||
+'<body>'+LineEnding;
|
||||
HTMLFile.SetSourceText(NewSource);
|
||||
if baoCreateHtml in Options then
|
||||
CreateHTMLFile(aProject,'project1.js');
|
||||
|
||||
AProject.AddPackageDependency('pas2js_rtl');
|
||||
if baoUseBrowserApp in Options then
|
||||
AProject.AddPackageDependency('fcl_base_pas2js');
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.CreateStartFiles(AProject: TLazProject
|
||||
|
Loading…
Reference in New Issue
Block a user