mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-14 07:59:35 +02:00
* IDE macros for Pas2JS settings
git-svn-id: trunk@56772 -
This commit is contained in:
parent
3af018e5b0
commit
b727fbfb4c
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -3768,6 +3768,7 @@ 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/pjscontroller.pp svneol=native#text/plain
|
||||
components/pas2js/pjsdsgnoptions.pas svneol=native#text/plain
|
||||
components/pas2js/pjsdsgnoptsframe.lfm svneol=native#text/plain
|
||||
components/pas2js/pjsdsgnoptsframe.pas svneol=native#text/plain
|
||||
|
@ -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="5">
|
||||
<Files Count="6">
|
||||
<Item1>
|
||||
<Filename Value="pjsdsgnregister.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
@ -40,6 +40,10 @@
|
||||
<Filename Value="frmpas2jsnodejsprojectoptions.pp"/>
|
||||
<UnitName Value="frmpas2jsnodejsprojectoptions"/>
|
||||
</Item5>
|
||||
<Item6>
|
||||
<Filename Value="pjscontroller.pp"/>
|
||||
<UnitName Value="pjscontroller"/>
|
||||
</Item6>
|
||||
</Files>
|
||||
<i18n>
|
||||
<EnableI18N Value="True"/>
|
||||
|
@ -9,7 +9,8 @@ interface
|
||||
|
||||
uses
|
||||
PJSDsgnRegister, PJSDsgnOptsFrame, frmpas2jsbrowserprojectoptions,
|
||||
PJSDsgnOptions, frmpas2jsnodejsprojectoptions, LazarusPackageIntf;
|
||||
PJSDsgnOptions, frmpas2jsnodejsprojectoptions, pjscontroller,
|
||||
LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
118
components/pas2js/pjscontroller.pp
Normal file
118
components/pas2js/pjscontroller.pp
Normal file
@ -0,0 +1,118 @@
|
||||
unit pjscontroller;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, MacroIntf, MacroDefIntf, lazideintf;
|
||||
|
||||
Type
|
||||
|
||||
{ TPJSController }
|
||||
|
||||
TPJSController = Class
|
||||
Private
|
||||
function GetPasJSBrowser(const s: string; const Data: PtrInt; var Abort: boolean): string;
|
||||
function GetPasJSNodeJS(const s: string; const Data: PtrInt; var Abort: boolean): string;
|
||||
function GetProjectURL(const s: string; const Data: PtrInt; var Abort: boolean): string;
|
||||
Public
|
||||
Constructor Create;
|
||||
Destructor Destroy; override;
|
||||
Procedure Hook; virtual;
|
||||
Procedure UnHook; virtual;
|
||||
end;
|
||||
|
||||
Const
|
||||
// Custom settings in .lpi
|
||||
PJSProjectWebBrowser = 'PasJSWebBrowserProject';
|
||||
PJSProjectURL = 'PasJSURL';
|
||||
PJSProjectHTMLFile = 'PasJSHTMLFile';
|
||||
PJSProjectPort = 'PasJSPort';
|
||||
|
||||
Function PJSController : TPJSController;
|
||||
|
||||
implementation
|
||||
|
||||
uses PJSDsgnOptions;
|
||||
|
||||
Var
|
||||
ctrl : TPJSController;
|
||||
|
||||
Function PJSController : TPJSController;
|
||||
|
||||
begin
|
||||
if ctrl=Nil then
|
||||
Ctrl:=TPJSController.Create;
|
||||
Result:=Ctrl;
|
||||
end;
|
||||
|
||||
{ TPJSController }
|
||||
|
||||
function TPJSController.GetPasJSBrowser(const s: string; const Data: PtrInt;
|
||||
var Abort: boolean): string;
|
||||
begin
|
||||
Abort:=False;
|
||||
Result:=PJSOptions.BrowserFileName;
|
||||
if Result='' then
|
||||
Result:=GetStandardBrowser;
|
||||
end;
|
||||
|
||||
function TPJSController.GetPasJSNodeJS(const s: string; const Data: PtrInt;
|
||||
var Abort: boolean): string;
|
||||
begin
|
||||
Abort:=False;
|
||||
Result:=PJSOptions.NodeJSFileName;
|
||||
if Result='' then
|
||||
Result:=GetStandardNodeJS;
|
||||
end;
|
||||
|
||||
function TPJSController.GetProjectURL(const s: string; const Data: PtrInt; var Abort: boolean): string;
|
||||
|
||||
Var
|
||||
FN : String;
|
||||
|
||||
begin
|
||||
Abort:=LazarusIDE.ActiveProject.CustomData[PJSProjectWebBrowser]<>'1';
|
||||
if Abort then
|
||||
exit;
|
||||
Result:=LazarusIDE.ActiveProject.CustomData[PJSProjectURL];
|
||||
if (Result='') then
|
||||
begin
|
||||
FN:=LazarusIDE.ActiveProject.CustomData[PJSProjectHTMLFile];
|
||||
if (FN='') then
|
||||
FN:=ChangeFileExt(ExtractFileName(LazarusIDE.ActiveProject.ProjectInfoFile),'.html');
|
||||
Result:=LazarusIDE.ActiveProject.CustomData[PJSProjectPort];
|
||||
if (Result<>'') then
|
||||
Result:=Format('http://localhost:%s/%s',[Result,FN])
|
||||
end;
|
||||
Abort:=(Result='');
|
||||
end;
|
||||
|
||||
constructor TPJSController.Create;
|
||||
begin
|
||||
Hook;
|
||||
end;
|
||||
|
||||
destructor TPJSController.Destroy;
|
||||
begin
|
||||
Unhook;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TPJSController.Hook;
|
||||
begin
|
||||
IDEMacros.Add(TTransferMacro.Create('Pas2JSBrowser','','Pas2JS selected Browser executable',@GetPasJSBrowser,[]));
|
||||
IDEMacros.Add(TTransferMacro.Create('Pas2JSNodeJS','','Pas2JS selected NodeJS xecutable',@GetPasJSNodeJS,[]));
|
||||
IDEMacros.Add(TTransferMacro.Create('Pas2JSProjectURL','','Pas2JS current project URL',@GetProjectURL,[]));
|
||||
end;
|
||||
|
||||
procedure TPJSController.UnHook;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
finalization
|
||||
FreeAndNil(Ctrl);
|
||||
end.
|
||||
|
@ -83,7 +83,7 @@ procedure Register;
|
||||
|
||||
implementation
|
||||
|
||||
uses frmpas2jsnodejsprojectoptions, frmpas2jsbrowserprojectoptions;
|
||||
uses frmpas2jsnodejsprojectoptions, frmpas2jsbrowserprojectoptions, pjscontroller;
|
||||
|
||||
procedure Register;
|
||||
|
||||
@ -247,13 +247,14 @@ begin
|
||||
'$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"';
|
||||
RunParams.LaunchingApplicationPathPlusParams:='$(Pas2JSNodeJS) "$MakeDir($(ProjPath))$NameOnly($(ProjFile)).js"';
|
||||
|
||||
// create program source
|
||||
NewSource:=CreateProjectSource;
|
||||
AProject.MainFile.SetSourceText(NewSource,true);
|
||||
|
||||
AProject.AddPackageDependency('pas2js_rtl');
|
||||
|
||||
end;
|
||||
|
||||
function TProjectPas2JSNodeJSApp.CreateStartFiles(AProject: TLazProject
|
||||
@ -274,20 +275,8 @@ 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;
|
||||
Result:='$(Pas2JSBrowser) $(Pas2SProjectURL)';
|
||||
end;
|
||||
|
||||
function TProjectPas2JSWebApp.GetNextPort : Word;
|
||||
@ -398,6 +387,7 @@ Var
|
||||
begin
|
||||
HTMLFile:=AProject.CreateProjectFile('project1.html');
|
||||
HTMLFile.IsPartOfProject:=true;
|
||||
AProject.CustomData.Values[PJSProjectHTMLFile]:=HTMLFile.Filename;
|
||||
AProject.AddFile(HTMLFile,false);
|
||||
Content:='';
|
||||
if baoUseBrowserConsole in Options then
|
||||
@ -510,7 +500,17 @@ begin
|
||||
RunParams.UseLaunchingApplication:=True;
|
||||
RunParams.LaunchingApplicationPathPlusParams:=GetBrowserCommand(CompOpts.TargetFileName);
|
||||
AProject.MainFile.SetSourceText(CreateProjectSource,true);
|
||||
|
||||
AProject.CustomData.Values[PJSProjectWebBrowser]:='1';
|
||||
if baoUseURL in Options then
|
||||
begin
|
||||
AProject.CustomData.Values[PJSProjectPort]:='';
|
||||
AProject.CustomData.Values[PJSProjectURL]:=ProjectURL;
|
||||
end
|
||||
else
|
||||
begin
|
||||
AProject.CustomData.Values[PJSProjectPort]:=IntToStr(ProjectPort);
|
||||
AProject.CustomData.Values[PJSProjectURL]:='';
|
||||
end;
|
||||
// create html source
|
||||
if baoCreateHtml in Options then
|
||||
CreateHTMLFile(aProject,'project1.js');
|
||||
|
Loading…
Reference in New Issue
Block a user