* Add DTStopas File-new item

This commit is contained in:
Michaël Van Canneyt 2022-02-21 10:00:37 +01:00
parent 86f222952f
commit 3727ad2dea
16 changed files with 1077 additions and 20 deletions

View File

@ -0,0 +1,262 @@
object DTSToPascalOptionsForm: TDTSToPascalOptionsForm
Left = 538
Height = 500
Top = 319
Width = 662
Caption = 'Convert typescript module declaration to pascal unit'
ClientHeight = 500
ClientWidth = 662
Constraints.MinHeight = 500
Constraints.MinWidth = 500
OnCreate = FormCreate
OnDestroy = FormDestroy
Position = poScreenCenter
LCLVersion = '2.3.0.0'
object BPOptions: TButtonPanel
Left = 6
Height = 38
Top = 456
Width = 650
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 = 0
ShowButtons = [pbOK, pbCancel]
end
object PCOptions: TPageControl
Left = 0
Height = 450
Top = 0
Width = 662
ActivePage = TSInput
Align = alClient
TabIndex = 0
TabOrder = 1
object TSInput: TTabSheet
Caption = 'Input'
ClientHeight = 420
ClientWidth = 652
object lblDeclarationFile: TLabel
AnchorSideTop.Control = FEDts
AnchorSideRight.Control = FEDts
AnchorSideBottom.Control = FEDts
AnchorSideBottom.Side = asrBottom
Left = 66
Height = 27
Top = 39
Width = 94
Anchors = [akTop, akRight, akBottom]
AutoSize = False
BorderSpacing.Right = 8
Caption = 'Declaration File'
Layout = tlCenter
end
object FEDts: TFileNameEdit
AnchorSideTop.Control = RBLocal
AnchorSideTop.Side = asrBottom
Left = 168
Height = 27
Top = 39
Width = 438
DialogTitle = 'Select Typescript declaration file'
DialogOptions = [ofFileMustExist, ofEnableSizing, ofViewDetail]
Filter = 'Typescript declaration files|*.d.ts|Typescript files|*.ts|All files|*.*'
FilterIndex = 0
DefaultExt = '.d.ts'
HideDirectories = False
ButtonWidth = 23
NumGlyphs = 1
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 8
MaxLength = 0
TabOrder = 0
OnEnter = FEDtsEnter
TextHint = 'Select a .d.ts file'
end
object RBLocal: TRadioButton
AnchorSideTop.Control = TSInput
Left = 16
Height = 23
Top = 8
Width = 81
BorderSpacing.Top = 8
Caption = 'Local file'
Checked = True
TabOrder = 1
TabStop = True
end
object RBService: TRadioButton
AnchorSideLeft.Control = RBLocal
AnchorSideTop.Control = FEDts
AnchorSideTop.Side = asrBottom
Left = 16
Height = 23
Top = 74
Width = 194
BorderSpacing.Top = 8
Caption = 'FPC DefinitelyTyped Service'
TabOrder = 2
end
object cbModule: TComboBox
AnchorSideTop.Control = RBService
AnchorSideTop.Side = asrBottom
Left = 165
Height = 27
Top = 105
Width = 413
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 8
ItemHeight = 0
OnEnter = cbModuleEnter
OnKeyUp = cbModuleKeyUp
TabOrder = 3
TextHint = 'type or select a module'
end
object lblModulename: TLabel
AnchorSideTop.Control = cbModule
AnchorSideBottom.Control = cbModule
AnchorSideBottom.Side = asrBottom
Left = 56
Height = 27
Top = 105
Width = 83
Anchors = [akTop, akLeft, akBottom]
AutoSize = False
Caption = 'Module name'
Layout = tlCenter
end
object VLEAliases: TValueListEditor
AnchorSideLeft.Control = edtUnits
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
Left = 40
Height = 166
Top = 254
Width = 536
AlternateColor = clMoneyGreen
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 8
DefaultColWidth = 128
FixedCols = 0
RowCount = 3
TabOrder = 4
DisplayOptions = [doColumnTitles, doAutoColResize]
KeyOptions = [keyEdit, keyAdd, keyDelete, keyUnique]
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goEditing, goAutoAddRows, goAlwaysShowEditor, goThumbTracking]
Strings.Strings = (
''
''
)
TitleCaptions.Strings = (
'Class'
'Alias'
)
ColWidths = (
267
267
)
end
object Label1: TLabel
AnchorSideLeft.Control = RBLocal
AnchorSideTop.Control = CBUseWeb
AnchorSideTop.Side = asrBottom
Left = 16
Height = 16
Top = 230
Width = 42
BorderSpacing.Top = 8
Caption = 'Aliases'
end
object edtUnits: TEdit
AnchorSideTop.Control = lblExtraUnits
AnchorSideTop.Side = asrBottom
Left = 40
Height = 27
Top = 164
Width = 536
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 8
TabOrder = 5
TextHint = 'Comma-separated list of units to use'
end
object lblExtraUnits: TLabel
AnchorSideLeft.Control = RBLocal
AnchorSideTop.Control = cbModule
AnchorSideTop.Side = asrBottom
Left = 16
Height = 16
Top = 140
Width = 65
BorderSpacing.Top = 8
Caption = 'Extra units'
end
object CBUseWeb: TCheckBox
AnchorSideTop.Control = edtUnits
AnchorSideTop.Side = asrBottom
Left = 16
Height = 23
Top = 199
Width = 174
BorderSpacing.Top = 8
Caption = 'Use Web unit and aliases'
Checked = True
State = cbChecked
TabOrder = 6
end
end
object TSOptions: TTabSheet
Caption = 'Code generation'
ClientHeight = 420
ClientWidth = 652
object CGOptions: TCheckGroup
Left = 8
Height = 200
Top = 8
Width = 633
Anchors = [akTop, akLeft, akRight, akBottom]
AutoFill = True
Caption = 'Options'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 2
ClientHeight = 183
ClientWidth = 631
Columns = 2
Items.Strings = (
'Raw code (no unit)'
'Generic Arrays'
'Use native type aliases'
'Use class local argument types'
'Untyped tuples'
'Dynamic tuples'
'External consts'
'Expand union-typed arguments'
'Add used options to header'
'Generate Interfaces as classes'
'Skip Import statements'
)
TabOrder = 0
Data = {
0B0000000202020202020202020202
}
end
end
end
object tmrComplete: TTimer
Enabled = False
Interval = 250
OnTimer = tmrCompleteTimer
Left = 276
Top = 39
end
end

View File

@ -0,0 +1,345 @@
unit frmdtstopas;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, EditBtn,
ButtonPanel, ValEdit, ExtCtrls, ComCtrls;
Const
MinCompleteLength = 2;
MaxCompletions = 500;
Var
ModuleList : TStringList;
OnModuleListChanged : TNotifyEvent;
type
TConversionOption = (coRaw,coGenericArrays,coUseNativeTypeAliases,coLocalArgumentTypes, coUntypedTuples, coDynamicTuples,
coExternalConst,coExpandUnionTypeArgs,coaddOptionsToheader,coInterfaceAsClass,coSkipImportStatements);
TConversionOptions = Set of TConversionOption;
TDTSToPascalMode = (dpmLocal,dpmService);
{ TDTSToPascalOptionsForm }
TDTSToPascalOptionsForm = class(TForm)
BPOptions: TButtonPanel;
cbModule: TComboBox;
CBUseWeb: TCheckBox;
CGOptions: TCheckGroup;
edtUnits: TEdit;
FEDts: TFileNameEdit;
Label1: TLabel;
lblDeclarationFile: TLabel;
lblExtraUnits: TLabel;
lblModulename: TLabel;
PCOptions: TPageControl;
RBLocal: TRadioButton;
RBService: TRadioButton;
tmrComplete: TTimer;
TSInput: TTabSheet;
TSOptions: TTabSheet;
VLEAliases: TValueListEditor;
procedure cbModuleEnter(Sender: TObject);
procedure cbModuleKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FEDtsEnter(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure tmrCompleteTimer(Sender: TObject);
private
FLastText : String;
procedure CheckModuleList;
procedure DoGetList(Sender: TObject);
function GetAliases: TStrings;
function GetExtraUnits: String;
function GetLocalFile: String;
function GetMode: TDTSToPascalMode;
function GetModule: String;
function GetOptions: TConversionOptions;
function GetUseWeb: Boolean;
procedure SetAliases(AValue: TStrings);
procedure SetExtraUnits(AValue: String);
procedure SetLocalFile(AValue: String);
procedure SetMode(AValue: TDTSToPascalMode);
procedure SetModule(AValue: String);
procedure SetOptions(AValue: TConversionOptions);
procedure SetUseWeb(AValue: Boolean);
public
Property Aliases : TStrings Read GetAliases Write SetAliases;
Property UseWeb : Boolean Read GetUseWeb Write SetUseWeb;
Property Mode : TDTSToPascalMode Read GetMode Write SetMode;
Property Module : String Read GetModule Write SetModule;
Property LocalFile : String Read GetLocalFile Write SetLocalFile;
Property ExtraUnits : String Read GetExtraUnits Write SetExtraUnits;
Property Options : TConversionOptions Read GetOptions Write SetOptions;
end;
var
DTSToPascalOptionsForm: TDTSToPascalOptionsForm;
implementation
uses fpJSON, httpprotocol, FPHTTPClient, PJSDsgnOptions, lazloggerbase, IDEExternToolIntf, IDEMsgIntf, strpas2jsdesign;
Const
SMessageDTS2Pas = 'DTS2PasService';
{$R *.lfm}
Type
{ TGetModulesThread }
TGetModulesThread = Class(TThread)
Private
FURL : String;
FError : String;
FResponse : TStrings;
Procedure DoLogError;
Procedure DoSetStringList;
Public
Destructor Destroy; override;
Procedure Execute; override;
end;
{ TGetModulesThread }
procedure TGetModulesThread.DoLogError;
begin
IDEMessagesWindow.AddCustomMessage(TMessageLineUrgency.mluError,Format(rsHTTPRequestFailed,[FURL,FError]),'',0,0,SMessageDTS2Pas)
end;
procedure TGetModulesThread.DoSetStringList;
Var
I : Integer;
begin
ModuleList.Clear;
ModuleList.BeginUpdate;
try
ModuleList.Capacity:=FResponse.Count;
ModuleList.AddStrings(FResponse);
ModuleList.Sort;
finally
ModuleList.EndUpdate;
end;
If Assigned(OnModuleListChanged) then
OnModuleListChanged(ModuleList);
end;
destructor TGetModulesThread.Destroy;
begin
FreeAndNil(FResponse);
inherited Destroy;
end;
procedure TGetModulesThread.Execute;
Var
URL,Res : String;
I : Integer;
begin
FreeOnTerminate:=true;
try
URL:=IncludeHTTPPathDelimiter(PJSOptions.DTS2PasServiceURL)+'list?raw=1';
FResponse:=TStringList.Create;
FResponse.Capacity:=50*1000;
TFPHTTPClient.SimpleGet(URL,FResponse);
Synchronize(@DoSetStringList);
Except
On E : Exception do
begin
FError:=E.Message;
Synchronize(@DoLogError);
end;
end;
end;
{ TDTSToPascalOptionsForm }
procedure TDTSToPascalOptionsForm.FEDtsEnter(Sender: TObject);
begin
RBLocal.Checked:=True;
end;
procedure TDTSToPascalOptionsForm.FormCreate(Sender: TObject);
begin
if (ModuleList=Nil) then
begin
if (PJSOptions.DTS2PasServiceURL<>'') then
begin
ModuleList:=TStringList.Create;
OnModuleListChanged:=@DoGetList;
TGetModulesThread.Create(False);
end;
end
else
begin
DoGetList(ModuleList);
end;
end;
procedure TDTSToPascalOptionsForm.FormDestroy(Sender: TObject);
begin
OnModuleListChanged:=Nil;
end;
procedure TDTSToPascalOptionsForm.CheckModuleList;
Var
S : String;
I,aCount : Integer;
begin
if (Length(CBModule.Text)<MinCompleteLength) or Not Assigned(ModuleList) then
Exit;
S:=UpperCase(CBModule.Text);
if S=FLastText then
exit;
With cbModule.Items do
try
BeginUpdate;
Clear;
aCount:=0;
I:=0;
While (aCount<MaxCompletions) and (I<ModuleList.Count) do
begin
if Pos(S,UpperCase(ModuleList[I]))>0 then
begin
Add(ModuleList[I]);
Inc(aCount);
end;
Inc(I);
end;
if (aCount>=MaxCompletions) and (I<ModuleList.Count-1) then
Add('...');
finally
EndUpdate;
end;
end;
procedure TDTSToPascalOptionsForm.tmrCompleteTimer(Sender: TObject);
begin
tmrComplete.Enabled:=False;
CheckModuleList;
end;
procedure TDTSToPascalOptionsForm.DoGetList(Sender: TObject);
begin
CheckModuleList;
end;
procedure TDTSToPascalOptionsForm.cbModuleEnter(Sender: TObject);
begin
RBService.Checked:=True;
end;
procedure TDTSToPascalOptionsForm.cbModuleKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
With tmrComplete do
begin
Enabled:=False;
Enabled:=True;
end;
end;
function TDTSToPascalOptionsForm.GetAliases: TStrings;
begin
Result:=VLEAliases.Strings;
end;
function TDTSToPascalOptionsForm.GetExtraUnits: String;
begin
Result:=edtUnits.Text;
end;
function TDTSToPascalOptionsForm.GetLocalFile: String;
begin
Result:=FEDts.FileName;
end;
function TDTSToPascalOptionsForm.GetMode: TDTSToPascalMode;
begin
If RBLocal.Checked then
result:=dpmLocal
else
Result:=dpmService;
end;
function TDTSToPascalOptionsForm.GetModule: String;
begin
Result:=CBModule.Text;
end;
function TDTSToPascalOptionsForm.GetOptions: TConversionOptions;
Var
CO : TConversionOption;
begin
Result:=[];
For CO in TConversionOption do
if CGOptions.Checked[Ord(CO)] then
Include(Result,CO);
end;
function TDTSToPascalOptionsForm.GetUseWeb: Boolean;
begin
Result:=CBUseWeb.Checked;
end;
procedure TDTSToPascalOptionsForm.SetAliases(AValue: TStrings);
begin
VLEAliases.Strings.Assign(aValue);
end;
procedure TDTSToPascalOptionsForm.SetExtraUnits(AValue: String);
begin
EDTUnits.Text:=aValue;
end;
procedure TDTSToPascalOptionsForm.SetLocalFile(AValue: String);
begin
FEDTS.FileName:=aValue;
end;
procedure TDTSToPascalOptionsForm.SetMode(AValue: TDTSToPascalMode);
begin
if aValue=dpmLocal then
rbLocal.Checked:=True
else
RBService.Checked:=True;
end;
procedure TDTSToPascalOptionsForm.SetModule(AValue: String);
begin
CBModule.Text:=aValue;
end;
procedure TDTSToPascalOptionsForm.SetOptions(AValue: TConversionOptions);
Var
CO : TConversionOption;
begin
For CO in TConversionOption do
CGOptions.Checked[Ord(CO)]:=CO in aValue;
end;
procedure TDTSToPascalOptionsForm.SetUseWeb(AValue: Boolean);
begin
CBUseWeb.Checked:=aValue;
end;
Finalization
OnModuleListChanged:=Nil;
FreeAndNil(ModuleList);
end.

View File

@ -0,0 +1,197 @@
unit idedtstopas;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, IDEExternToolIntf, frmdtstopas;
Const
DefaultOptions = [coInterfaceAsClass,coExpandUnionTypeArgs,coaddOptionsToheader,coDynamicTuples,coUseNativeTypeAliases];
Type
TDTSToPascalMode = frmdtstopas.TDTSToPascalMode;
TConversionOptions = frmdtstopas.TConversionOptions;
{ TCreateUnitFromDTS }
TCreateUnitFromDTS = Class(TComponent)
private
FAliases: TStrings;
FConversionOptions: TConversionOptions;
FExtraUnits: String;
FLocalFileName: String;
FMode: TDTSToPascalMode;
FModuleName: String;
FSource: TStrings;
FTargetUnitName: String;
FUseWeb: Boolean;
procedure ExecuteLocal;
procedure ExecuteService;
procedure SetAliases(AValue: TStrings);
Public
Constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
Function ShowOptionsDialog : Boolean;
Procedure Execute;
Property Source : TStrings Read FSource;
Property TargetUnitName : String Read FTargetUnitName Write FTargetUnitName;
Property Aliases : TStrings Read FAliases Write SetAliases;
Property UseWeb : Boolean Read FUseWeb Write FUseWeb;
Property Mode : TDTSToPascalMode Read FMode Write FMode;
Property ExtraUnits : String Read FExtraUnits Write FExtraUnits;
Property ModuleName : String Read FModuleName Write FModuleName;
Property LocalFileName : String Read FLocalFileName Write FLocalFileName;
Property ConversionOptions : TConversionOptions Read FConversionOptions Write FConversionOptions;
end;
implementation
uses Typinfo, PJSDsgnOptions, controls, strpas2jsdesign, idemsgintf, httpprotocol, fphttpclient;
Const
SMessageDTS2Pas = 'DST2Pas';
{ TCreateUnitFromDTS }
procedure TCreateUnitFromDTS.SetAliases(AValue: TStrings);
begin
if FAliases=AValue then Exit;
FAliases.Assign(AValue);
end;
constructor TCreateUnitFromDTS.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FConversionOptions:=DefaultOptions;
FUseWeb:=True;
FAliases:=TStringList.Create;
FSource:=TStringList.Create;
end;
destructor TCreateUnitFromDTS.Destroy;
begin
FreeAndNil(FAliases);
FreeAndNil(FSource);
inherited Destroy;
end;
function TCreateUnitFromDTS.ShowOptionsDialog: Boolean;
Var
Frm : TDTSToPascalOptionsForm;
begin
Frm:=TDTSToPascalOptionsForm.Create(Self);
try
Frm.Aliases := Aliases;
frm.Mode := Mode;
frm.ExtraUnits := ExtraUnits;
frm.UseWeb := UseWeb;
frm.Module := ModuleName;
Frm.LocalFile := LocalFileName;
Frm.Options:=ConversionOptions;
Result:=Frm.ShowModal=mrOK;
if Result then
begin
Aliases:=Frm.Aliases;
Mode:=frm.Mode;
ExtraUnits:=frm.ExtraUnits;
UseWeb:=frm.UseWeb;
ModuleName:=frm.Module;
LocalFileName:=Frm.LocalFile;
ConversionOptions:=Frm.Options;
end;
finally
Frm.Free;
end;
end;
procedure TCreateUnitFromDTS.ExecuteLocal;
Function MaybeQuote(s : string) : string;
begin
if Pos(' ',S)=0 then
Result:=S
else
Result:=AnsiQuotedStr(S,'"');
end;
Var
ToolOpts : TIDEExternalToolOptions;
InFN,AliasFN,OutFN,Opts : string;
begin
AliasFN:='';
OutFN:='';
ToolOpts:=TIDEExternalToolOptions.Create;
try
ToolOpts.Parsers.Add(SubToolDefault);
OutFN:=GetTempFileName;
ToolOpts.Executable:=PJSOptions.DTS2Pas;
ToolOpts.ResolveMacros:=True;
InFN:=LocalFileName;
Opts:='-i '+MaybeQuote(LocalFileName)+' -o '+MaybeQuote(outFN)+' -u '+TargetUnitName;
if UseWeb then
opts:=Opts+' -w';
if Aliases.Count>0 then
begin
AliasFN:=GetTempFileName;
Aliases.SaveToFile(AliasFN);
Opts:=Opts+' -a @'+aliasFN;
end;
If ExtraUnits<>'' then
Opts:=Opts+'-x '+StringReplace(ExtraUnits,' ','',[rfReplaceAll]);
ToolOpts.CmdLineParams:=Opts;
if not (RunExternalTool(ToolOpts) and FileExists(OutFN)) then
IDEMessagesWindow.AddCustomMessage(TMessageLineUrgency.mluError,rsDTSDidNotProduceOutput,'',0,0,SMessageDTS2Pas)
else
FSource.LoadFromFile(OutFN)
finally
if AliasFN<>'' then
DeleteFile(aliasFN);
if OutFN<>'' then
DeleteFile(OutFN);
ToolOpts.Free;
end;
end;
procedure TCreateUnitFromDTS.ExecuteService;
Var
URL : String;
CO : TConversionOption;
begin
URL:=IncludeHTTPPathDelimiter(PJSOptions.DTS2PasServiceURL)+'/convert';
URL:=URL+'?file='+HTTPEncode(ModuleName);
URL:=URL+'&unit='+HTTPEncode(TargetUnitName);
URL:=URL+'&prependLog=1';
for CO in TConversionOption do
if CO in ConversionOptions then
URL:=URL+'&'+GetEnumName(TypeInfo(TConversionOption),Ord(CO))+'=1';
if aliases.Count>0 then
URL:=URL+'&Aliases='+HTTPEncode(Aliases.CommaText);
if Not UseWeb then
URL:=URL+'&SkipWeb=1';
If ExtraUnits<>'' then
URL:=URL+'&ExtraUnits='+HTTPEncode(ExtraUnits);
TFPHTTPClient.SimpleGet(URL,FSource);
end;
procedure TCreateUnitFromDTS.Execute;
begin
if TargetUnitName='' then
TargetUnitName:='libtsmodule';
If Mode=dpmLocal then
ExecuteLocal
else
ExecuteService;
end;
end.

View File

@ -58,7 +58,7 @@ msgstr "fichier \"%s\" non trouvé"
#: strpas2jsdesign.pjsdhtmlfilenotfound #: strpas2jsdesign.pjsdhtmlfilenotfound
#, object-pascal-format #, object-pascal-format
msgid "" msgid ""
"Cannot find the HTML Source file for this class:\n" "Cannot find the HTML Source file for the class in unit %s:\n"
"%s\n" "%s\n"
"Would you like to select the file from disk?" "Would you like to select the file from disk?"
msgstr "" msgstr ""
@ -298,6 +298,23 @@ msgstr ""
msgid "Pas2JS class definition from HTML file" msgid "Pas2JS class definition from HTML file"
msgstr "" msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescript
msgid "Pas2JS import unit from Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescriptdescription
msgid "Create a Pas2JS import unit from a Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rsdtsdidnotproduceoutput
msgid "The DTS2pas tool did not produce an output file."
msgstr ""
#: strpas2jsdesign.rshttprequestfailed
#, object-pascal-format
msgid "HTML request to service URL %s failed: %s"
msgstr ""
#: strpas2jsdesign.spasjswebservercaption #: strpas2jsdesign.spasjswebservercaption
msgctxt "strpas2jsdesign.spasjswebservercaption" msgctxt "strpas2jsdesign.spasjswebservercaption"
msgid "Pas2JS WebServers" msgid "Pas2JS WebServers"

View File

@ -58,7 +58,7 @@ msgstr "a(z) \"%s\" fájl nem található"
#: strpas2jsdesign.pjsdhtmlfilenotfound #: strpas2jsdesign.pjsdhtmlfilenotfound
#, object-pascal-format #, object-pascal-format
msgid "" msgid ""
"Cannot find the HTML Source file for this class:\n" "Cannot find the HTML Source file for the class in unit %s:\n"
"%s\n" "%s\n"
"Would you like to select the file from disk?" "Would you like to select the file from disk?"
msgstr "" msgstr ""
@ -302,6 +302,23 @@ msgstr ""
msgid "Pas2JS class definition from HTML file" msgid "Pas2JS class definition from HTML file"
msgstr "" msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescript
msgid "Pas2JS import unit from Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescriptdescription
msgid "Create a Pas2JS import unit from a Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rsdtsdidnotproduceoutput
msgid "The DTS2pas tool did not produce an output file."
msgstr ""
#: strpas2jsdesign.rshttprequestfailed
#, object-pascal-format
msgid "HTML request to service URL %s failed: %s"
msgstr ""
#: strpas2jsdesign.spasjswebservercaption #: strpas2jsdesign.spasjswebservercaption
msgctxt "strpas2jsdesign.spasjswebservercaption" msgctxt "strpas2jsdesign.spasjswebservercaption"
msgid "Pas2JS WebServers" msgid "Pas2JS WebServers"

View File

@ -48,7 +48,7 @@ msgstr ""
#: strpas2jsdesign.pjsdhtmlfilenotfound #: strpas2jsdesign.pjsdhtmlfilenotfound
#, object-pascal-format #, object-pascal-format
msgid "" msgid ""
"Cannot find the HTML Source file for this class:\n" "Cannot find the HTML Source file for the class in unit %s:\n"
"%s\n" "%s\n"
"Would you like to select the file from disk?" "Would you like to select the file from disk?"
msgstr "" msgstr ""
@ -288,6 +288,23 @@ msgstr ""
msgid "Pas2JS class definition from HTML file" msgid "Pas2JS class definition from HTML file"
msgstr "" msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescript
msgid "Pas2JS import unit from Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescriptdescription
msgid "Create a Pas2JS import unit from a Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rsdtsdidnotproduceoutput
msgid "The DTS2pas tool did not produce an output file."
msgstr ""
#: strpas2jsdesign.rshttprequestfailed
#, object-pascal-format
msgid "HTML request to service URL %s failed: %s"
msgstr ""
#: strpas2jsdesign.spasjswebservercaption #: strpas2jsdesign.spasjswebservercaption
msgctxt "strpas2jsdesign.spasjswebservercaption" msgctxt "strpas2jsdesign.spasjswebservercaption"
msgid "Pas2JS WebServers" msgid "Pas2JS WebServers"

View File

@ -58,7 +58,7 @@ msgstr "arquivo \"%s\" não encontrado"
#: strpas2jsdesign.pjsdhtmlfilenotfound #: strpas2jsdesign.pjsdhtmlfilenotfound
#, object-pascal-format #, object-pascal-format
msgid "" msgid ""
"Cannot find the HTML Source file for this class:\n" "Cannot find the HTML Source file for the class in unit %s:\n"
"%s\n" "%s\n"
"Would you like to select the file from disk?" "Would you like to select the file from disk?"
msgstr "" msgstr ""
@ -301,6 +301,23 @@ msgstr ""
msgid "Pas2JS class definition from HTML file" msgid "Pas2JS class definition from HTML file"
msgstr "" msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescript
msgid "Pas2JS import unit from Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescriptdescription
msgid "Create a Pas2JS import unit from a Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rsdtsdidnotproduceoutput
msgid "The DTS2pas tool did not produce an output file."
msgstr ""
#: strpas2jsdesign.rshttprequestfailed
#, object-pascal-format
msgid "HTML request to service URL %s failed: %s"
msgstr ""
#: strpas2jsdesign.spasjswebservercaption #: strpas2jsdesign.spasjswebservercaption
msgctxt "strpas2jsdesign.spasjswebservercaption" msgctxt "strpas2jsdesign.spasjswebservercaption"
msgid "Pas2JS WebServers" msgid "Pas2JS WebServers"

View File

@ -58,7 +58,7 @@ msgstr "файл \"%s\" не найден"
#: strpas2jsdesign.pjsdhtmlfilenotfound #: strpas2jsdesign.pjsdhtmlfilenotfound
#, object-pascal-format #, object-pascal-format
msgid "" msgid ""
"Cannot find the HTML Source file for this class:\n" "Cannot find the HTML Source file for the class in unit %s:\n"
"%s\n" "%s\n"
"Would you like to select the file from disk?" "Would you like to select the file from disk?"
msgstr "" msgstr ""
@ -301,6 +301,23 @@ msgstr "Создать объявление класса \"формы\" Pas2JS
msgid "Pas2JS class definition from HTML file" msgid "Pas2JS class definition from HTML file"
msgstr "Объявление класса Pas2JS из файла HTML" msgstr "Объявление класса Pas2JS из файла HTML"
#: strpas2jsdesign.rscreateunitfromtypescript
msgid "Pas2JS import unit from Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescriptdescription
msgid "Create a Pas2JS import unit from a Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rsdtsdidnotproduceoutput
msgid "The DTS2pas tool did not produce an output file."
msgstr ""
#: strpas2jsdesign.rshttprequestfailed
#, object-pascal-format
msgid "HTML request to service URL %s failed: %s"
msgstr ""
#: strpas2jsdesign.spasjswebservercaption #: strpas2jsdesign.spasjswebservercaption
msgctxt "strpas2jsdesign.spasjswebservercaption" msgctxt "strpas2jsdesign.spasjswebservercaption"
msgid "Pas2JS WebServers" msgid "Pas2JS WebServers"

View File

@ -58,7 +58,7 @@ msgstr ""
#: strpas2jsdesign.pjsdhtmlfilenotfound #: strpas2jsdesign.pjsdhtmlfilenotfound
#, object-pascal-format #, object-pascal-format
msgid "" msgid ""
"Cannot find the HTML Source file for this class:\n" "Cannot find the HTML Source file for the class in unit %s:\n"
"%s\n" "%s\n"
"Would you like to select the file from disk?" "Would you like to select the file from disk?"
msgstr "" msgstr ""
@ -302,6 +302,23 @@ msgstr ""
msgid "Pas2JS class definition from HTML file" msgid "Pas2JS class definition from HTML file"
msgstr "" msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescript
msgid "Pas2JS import unit from Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescriptdescription
msgid "Create a Pas2JS import unit from a Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rsdtsdidnotproduceoutput
msgid "The DTS2pas tool did not produce an output file."
msgstr ""
#: strpas2jsdesign.rshttprequestfailed
#, object-pascal-format
msgid "HTML request to service URL %s failed: %s"
msgstr ""
#: strpas2jsdesign.spasjswebservercaption #: strpas2jsdesign.spasjswebservercaption
#, fuzzy #, fuzzy
msgctxt "strpas2jsdesign.spasjswebservercaption" msgctxt "strpas2jsdesign.spasjswebservercaption"

View File

@ -60,7 +60,7 @@ msgstr "файл \"%s\" не знайдено"
#: strpas2jsdesign.pjsdhtmlfilenotfound #: strpas2jsdesign.pjsdhtmlfilenotfound
#, object-pascal-format #, object-pascal-format
msgid "" msgid ""
"Cannot find the HTML Source file for this class:\n" "Cannot find the HTML Source file for the class in unit %s:\n"
"%s\n" "%s\n"
"Would you like to select the file from disk?" "Would you like to select the file from disk?"
msgstr "" msgstr ""
@ -300,6 +300,23 @@ msgstr ""
msgid "Pas2JS class definition from HTML file" msgid "Pas2JS class definition from HTML file"
msgstr "" msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescript
msgid "Pas2JS import unit from Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescriptdescription
msgid "Create a Pas2JS import unit from a Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rsdtsdidnotproduceoutput
msgid "The DTS2pas tool did not produce an output file."
msgstr ""
#: strpas2jsdesign.rshttprequestfailed
#, object-pascal-format
msgid "HTML request to service URL %s failed: %s"
msgstr ""
#: strpas2jsdesign.spasjswebservercaption #: strpas2jsdesign.spasjswebservercaption
msgctxt "strpas2jsdesign.spasjswebservercaption" msgctxt "strpas2jsdesign.spasjswebservercaption"
msgid "Pas2JS WebServers" msgid "Pas2JS WebServers"

View File

@ -59,7 +59,7 @@ msgstr ""
#: strpas2jsdesign.pjsdhtmlfilenotfound #: strpas2jsdesign.pjsdhtmlfilenotfound
#, object-pascal-format #, object-pascal-format
msgid "" msgid ""
"Cannot find the HTML Source file for this class:\n" "Cannot find the HTML Source file for the class in unit %s:\n"
"%s\n" "%s\n"
"Would you like to select the file from disk?" "Would you like to select the file from disk?"
msgstr "" msgstr ""
@ -303,6 +303,23 @@ msgstr ""
msgid "Pas2JS class definition from HTML file" msgid "Pas2JS class definition from HTML file"
msgstr "" msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescript
msgid "Pas2JS import unit from Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rscreateunitfromtypescriptdescription
msgid "Create a Pas2JS import unit from a Typescript declaration module."
msgstr ""
#: strpas2jsdesign.rsdtsdidnotproduceoutput
msgid "The DTS2pas tool did not produce an output file."
msgstr ""
#: strpas2jsdesign.rshttprequestfailed
#, object-pascal-format
msgid "HTML request to service URL %s failed: %s"
msgstr ""
#: strpas2jsdesign.spasjswebservercaption #: strpas2jsdesign.spasjswebservercaption
#, fuzzy #, fuzzy
msgctxt "strpas2jsdesign.spasjswebservercaption" msgctxt "strpas2jsdesign.spasjswebservercaption"

View File

@ -18,7 +18,7 @@
<Description Value="Adds a Lazarus project for pas2js browser applications."/> <Description Value="Adds a Lazarus project for pas2js browser applications."/>
<License Value="GPL-2"/> <License Value="GPL-2"/>
<Version Major="1" Release="2"/> <Version Major="1" Release="2"/>
<Files Count="18"> <Files Count="20">
<Item1> <Item1>
<Filename Value="pjsdsgnregister.pas"/> <Filename Value="pjsdsgnregister.pas"/>
<HasRegisterProc Value="True"/> <HasRegisterProc Value="True"/>
@ -94,6 +94,14 @@
<Filename Value="idehtml2class.pas"/> <Filename Value="idehtml2class.pas"/>
<UnitName Value="idehtml2class"/> <UnitName Value="idehtml2class"/>
</Item18> </Item18>
<Item19>
<Filename Value="frmdtstopas.pas"/>
<UnitName Value="frmdtstopas"/>
</Item19>
<Item20>
<Filename Value="idedtstopas.pas"/>
<UnitName Value="idedtstopas"/>
</Item20>
</Files> </Files>
<CompatibilityMode Value="True"/> <CompatibilityMode Value="True"/>
<i18n> <i18n>

View File

@ -12,8 +12,8 @@ uses
PJSDsgnOptions, frmpas2jsnodejsprojectoptions, pjscontroller, PJSDsgnOptions, frmpas2jsnodejsprojectoptions, pjscontroller,
frmpas2jswebservers, strpas2jsdesign, pjsprojectoptions, frmpas2jswebservers, strpas2jsdesign, pjsprojectoptions,
frmPas2jsAtomPackageSettings, regpas2jsatom, regpas2jsvscode, frmPas2jsAtomPackageSettings, regpas2jsatom, regpas2jsvscode,
frmPas2jsVSCodeExtensionSettings, frmhtmltoform, idehtml2class, frmPas2jsVSCodeExtensionSettings, frmhtmltoform, idehtml2class, frmdtstopas,
LazarusPackageIntf; idedtstopas, LazarusPackageIntf;
implementation implementation

View File

@ -21,6 +21,8 @@ uses
const const
PJSDsgnOptsFile = 'pas2jsdsgnoptions.xml'; PJSDsgnOptsFile = 'pas2jsdsgnoptions.xml';
PJSDefaultCompiler = '$MakeExe(IDE,pas2js)'; PJSDefaultCompiler = '$MakeExe(IDE,pas2js)';
PJSDefaultDTS2Pas = '$MakeExe(IDE,dts2pas)';
PJSDefaultDTS2PasService = 'https://www.freepascal.org/~michael/service/dts2pas.cgi';
PJSDefaultWebServerName = 'compileserver'; PJSDefaultWebServerName = 'compileserver';
PJSDefaultWebServer = '$MakeExe(IDE,'+PJSDefaultWebServerName+')'; PJSDefaultWebServer = '$MakeExe(IDE,'+PJSDefaultWebServerName+')';
PJSDefaultStartAtPort = 3000; // compileserver default port PJSDefaultStartAtPort = 3000; // compileserver default port
@ -36,9 +38,12 @@ Type
p2jcoHTTPServerPort, p2jcoHTTPServerPort,
p2jcoNodeJSFilename, p2jcoNodeJSFilename,
p2jcoAtomTemplateDir, p2jcoAtomTemplateDir,
p2jcoVSCodeTemplateDir p2jcoVSCodeTemplateDir,
p2jcoDTSToPas,
p2jcoDTSToPasServiceURL
); );
TPas2jsCachedOptions = set of TPas2jsCachedOption; TPas2jsCachedOptions = set of TPas2jsCachedOption;
const const
p2jcoFilenames = [ p2jcoFilenames = [
p2jcoCompilerFilename, p2jcoCompilerFilename,
@ -46,7 +51,8 @@ const
p2jcoHTTPServerFilename, p2jcoHTTPServerFilename,
p2jcoNodeJSFilename, p2jcoNodeJSFilename,
p2jcoAtomTemplateDir, p2jcoAtomTemplateDir,
p2jcoVSCodeTemplateDir p2jcoVSCodeTemplateDir,
p2jcoDTSToPas
]; ];
type type
@ -70,6 +76,8 @@ type
function GetAtomTemplateDir: String; function GetAtomTemplateDir: String;
function GetBrowserFileName: String; function GetBrowserFileName: String;
function GetCompilerFilename: string; function GetCompilerFilename: string;
function GetDTS2Pas: String;
function GetDTS2PasService: String;
function GetStartAtPort: Word; function GetStartAtPort: Word;
function GetVSCodeTemplateDir: String; function GetVSCodeTemplateDir: String;
function GetWebServerFileName: string; function GetWebServerFileName: string;
@ -78,6 +86,8 @@ type
function GetParsedOptionValue(Option: TPas2jsCachedOption): string; function GetParsedOptionValue(Option: TPas2jsCachedOption): string;
procedure SetAtomTemplateDir(AValue: String); procedure SetAtomTemplateDir(AValue: String);
procedure SetBrowserFileName(AValue: String); procedure SetBrowserFileName(AValue: String);
procedure SetDTS2Pas(AValue: String);
procedure SetDTS2PasService(AValue: String);
procedure SetVSCodeTemplateDir(AValue: String); procedure SetVSCodeTemplateDir(AValue: String);
procedure SetWebServerFileName(AValue: string); procedure SetWebServerFileName(AValue: string);
procedure SetHTTPServerOpts(AValue: TStrings); procedure SetHTTPServerOpts(AValue: TStrings);
@ -110,6 +120,8 @@ type
property Modified: boolean read GetModified write SetModified; property Modified: boolean read GetModified write SetModified;
Property AtomTemplateDir : String Read GetAtomTemplateDir Write SetAtomTemplateDir; Property AtomTemplateDir : String Read GetAtomTemplateDir Write SetAtomTemplateDir;
Property VSCodeTemplateDir : String Read GetVSCodeTemplateDir Write SetVSCodeTemplateDir; Property VSCodeTemplateDir : String Read GetVSCodeTemplateDir Write SetVSCodeTemplateDir;
Property DTS2Pas : String Read GetDTS2Pas Write SetDTS2Pas;
Property DTS2PasServiceURL : String Read GetDTS2PasService Write SetDTS2PasService;
end; end;
var var
@ -237,6 +249,16 @@ begin
Result:=FCachedOptions[p2jcoCompilerFilename].RawValue; Result:=FCachedOptions[p2jcoCompilerFilename].RawValue;
end; end;
function TPas2jsOptions.GetDTS2Pas: String;
begin
Result:=FCachedOptions[p2jcoDTSToPas].RawValue
end;
function TPas2jsOptions.GetDTS2PasService: String;
begin
Result:=FCachedOptions[p2jcoDTSToPasServiceURL].RawValue
end;
function TPas2jsOptions.GetStartAtPort: Word; function TPas2jsOptions.GetStartAtPort: Word;
begin begin
Result:=StrToIntDef(FCachedOptions[p2jcoHTTPServerPort].RawValue,PJSDefaultStartAtPort); Result:=StrToIntDef(FCachedOptions[p2jcoHTTPServerPort].RawValue,PJSDefaultStartAtPort);
@ -280,6 +302,8 @@ begin
FCachedOptions[p2jcoBrowserFilename].RawValue:=PJSDefaultBrowser; FCachedOptions[p2jcoBrowserFilename].RawValue:=PJSDefaultBrowser;
FCachedOptions[p2jcoAtomTemplateDir].RawValue:=''; FCachedOptions[p2jcoAtomTemplateDir].RawValue:='';
FCachedOptions[p2jcoVSCodeTemplateDir].RawValue:=''; FCachedOptions[p2jcoVSCodeTemplateDir].RawValue:='';
FCachedOptions[p2jcoDTSToPas].RawValue:=PJSDefaultDTS2Pas;
FCachedOptions[p2jcoDTSToPasServiceURL].RawValue:=PJSDefaultDTS2PasService;
for o in TPas2jsCachedOption do for o in TPas2jsCachedOption do
FCachedOptions[o].Stamp:=LUInvalidChangeStamp64; FCachedOptions[o].Stamp:=LUInvalidChangeStamp64;
FHTTPServerOpts:=TStringList.Create; FHTTPServerOpts:=TStringList.Create;
@ -330,6 +354,8 @@ Const
KeyAtomTemplate = 'atomtemplate/value'; KeyAtomTemplate = 'atomtemplate/value';
KeyVSCodeTemplate = 'vscodetemplate/value'; KeyVSCodeTemplate = 'vscodetemplate/value';
KeyStartPortAt = 'webserver/startatport/value'; KeyStartPortAt = 'webserver/startatport/value';
KeyDTS2PasTool = 'dts2pastool/value';
KeyDTS2PasServiceURL= 'dts2passerviceurl/value';
procedure TPas2jsOptions.LoadFromConfig(Cfg: TConfigStorage); procedure TPas2jsOptions.LoadFromConfig(Cfg: TConfigStorage);
@ -340,6 +366,8 @@ begin
NodeJSFileName:=Cfg.GetValue(KeyNodeJS,PJSDefaultNodeJS); NodeJSFileName:=Cfg.GetValue(KeyNodeJS,PJSDefaultNodeJS);
AtomTemplateDir:=Cfg.GetValue(KeyAtomTemplate,''); AtomTemplateDir:=Cfg.GetValue(KeyAtomTemplate,'');
VSCodeTemplateDir:=Cfg.GetValue(KeyVSCodeTemplate,''); VSCodeTemplateDir:=Cfg.GetValue(KeyVSCodeTemplate,'');
DTS2Pas:=cfg.GetValue(KeyDTS2PasTool,PJSDefaultDTS2Pas);
DTS2PasServiceURL:=cfg.GetValue(KeyDTS2PasServiceURL,PJSDefaultDTS2PasService);
StartAtPort :=Cfg.GetValue(KeyStartPortAt,PJSDefaultStartAtPort); StartAtPort :=Cfg.GetValue(KeyStartPortAt,PJSDefaultStartAtPort);
Cfg.GetValue(KeyHTTPServerOptions,FHTTPServerOpts); Cfg.GetValue(KeyHTTPServerOptions,FHTTPServerOpts);
Modified:=false; Modified:=false;
@ -355,6 +383,8 @@ begin
Cfg.SetDeleteValue(KeyBrowser,BrowserFileName,PJSDefaultBrowser); Cfg.SetDeleteValue(KeyBrowser,BrowserFileName,PJSDefaultBrowser);
Cfg.SetDeleteValue(KeyAtomTemplate,AtomTemplateDir,''); Cfg.SetDeleteValue(KeyAtomTemplate,AtomTemplateDir,'');
Cfg.SetDeleteValue(KeyVSCodeTemplate,VSCodeTemplateDir,''); Cfg.SetDeleteValue(KeyVSCodeTemplate,VSCodeTemplateDir,'');
cfg.SetDeleteValue(KeyDTS2PasTool,DTS2Pas,PJSDefaultDTS2Pas);
cfg.SetDeleteValue(KeyDTS2PasServiceURL,DTS2PasServiceURL,PJSDefaultDTS2PasService);
Cfg.SetValue(KeyHTTPServerOptions,FHTTPServerOpts); Cfg.SetValue(KeyHTTPServerOptions,FHTTPServerOpts);
Modified:=false; Modified:=false;
end; end;
@ -443,6 +473,17 @@ begin
SetCachedOption(p2jcoBrowserFilename,AValue); SetCachedOption(p2jcoBrowserFilename,AValue);
end; end;
procedure TPas2jsOptions.SetDTS2Pas(AValue: String);
begin
AValue:=TrimFilename(AValue);
SetCachedOption(p2jcoDTSToPas,AValue);
end;
procedure TPas2jsOptions.SetDTS2PasService(AValue: String);
begin
SetCachedOption(p2jcoDTSToPasServiceURL,AValue);
end;
procedure TPas2jsOptions.SetVSCodeTemplateDir(AValue: String); procedure TPas2jsOptions.SetVSCodeTemplateDir(AValue: String);
begin begin
AValue:=TrimFilename(AValue); AValue:=TrimFilename(AValue);

View File

@ -13,7 +13,7 @@ uses
// IdeIntf // IdeIntf
ProjectIntf, CompOptsIntf, LazIDEIntf, IDEOptionsIntf, IDEOptEditorIntf, IDEMsgIntf, IDEExternToolIntf, ProjectIntf, CompOptsIntf, LazIDEIntf, IDEOptionsIntf, IDEOptEditorIntf, IDEMsgIntf, IDEExternToolIntf,
// Pas2js // Pas2js
idehtml2class, PJSDsgnOptions, PJSDsgnOptsFrame; idehtml2class, PJSDsgnOptions, PJSDsgnOptsFrame, idedtstopas;
const const
ProjDescNamePas2JSWebApp = 'Web Application'; ProjDescNamePas2JSWebApp = 'Web Application';
@ -113,6 +113,23 @@ type
function GetLocalizedDescription: string; override; function GetLocalizedDescription: string; override;
end; end;
{ TPas2JSDTSToPasUnitDef }
TPas2JSDTSToPasUnitDef = class(TFileDescPascalUnit)
private
FConverter : TCreateUnitFromDTS;
public
constructor Create; override;
destructor destroy; override;
function Init(var {%H-}NewFilename: string; {%H-}NewOwner: TObject;
var {%H-}NewSource: string; {%H-}Quiet: boolean): TModalResult; override;
function CreateSource(const Filename, SourceName,
ResourceName: string): string; override;
function GetLocalizedName: string; override;
function GetLocalizedDescription: string; override;
end;
var var
PJSOptionsFrameID: integer = 1000; PJSOptionsFrameID: integer = 1000;
@ -158,7 +175,7 @@ Type
Procedure OnSrcEditPopup(Sender : TObject); Procedure OnSrcEditPopup(Sender : TObject);
Procedure OnPrjInspPopup(Sender : TObject); Procedure OnPrjInspPopup(Sender : TObject);
private private
function AskUserFile(aHTMLFileName: String): string; function AskUserFile(aUnitName,aHTMLFileName: String): string;
function RefreshHTML(aFile: TLazProjectFile; out aSource: String): Boolean; function RefreshHTML(aFile: TLazProjectFile; out aSource: String): Boolean;
end; end;
@ -167,6 +184,7 @@ Const
Var Var
Pas2JSHTMLClassDef : TPas2JSHTMLClassDef; Pas2JSHTMLClassDef : TPas2JSHTMLClassDef;
Pas2JSDTSToPasUnitDef : TPas2JSDTSToPasUnitDef;
MenuHandler : TPas2JSMenuHandler; MenuHandler : TPas2JSMenuHandler;
procedure Register; procedure Register;
@ -187,6 +205,8 @@ begin
RegisterProjectDescriptor(TProjectPas2JSModuleApp.Create); RegisterProjectDescriptor(TProjectPas2JSModuleApp.Create);
Pas2JSHTMLClassDef:=TPas2JSHTMLClassDef.Create; Pas2JSHTMLClassDef:=TPas2JSHTMLClassDef.Create;
RegisterProjectFileDescriptor(Pas2JSHTMLClassDef); RegisterProjectFileDescriptor(Pas2JSHTMLClassDef);
Pas2JSDTSToPasUnitDef:=TPas2JSDTSToPasUnitDef.Create;
RegisterProjectFileDescriptor(Pas2JSDTSToPasUnitDef);
// add IDE options frame // add IDE options frame
PJSOptionsFrameID:=RegisterIDEOptionsEditor(GroupEnvironment,TPas2jsOptionsFrame, PJSOptionsFrameID:=RegisterIDEOptionsEditor(GroupEnvironment,TPas2jsOptionsFrame,
@ -213,6 +233,49 @@ begin
end; end;
{ TPas2JSDTSToPasUnitDef }
constructor TPas2JSDTSToPasUnitDef.Create;
begin
inherited Create;
FConverter:=TCreateUnitFromDTS.Create(Nil);
end;
destructor TPas2JSDTSToPasUnitDef.destroy;
begin
FreeAndNil(FConverter);
inherited destroy;
end;
function TPas2JSDTSToPasUnitDef.Init(var NewFilename: string;
NewOwner: TObject; var NewSource: string; Quiet: boolean): TModalResult;
begin
inherited Init(NewFilename, NewOwner, NewSource, Quiet);
If FConverter.ShowOptionsDialog then
Result:=mrOK
else
Result:=mrCancel;
end;
function TPas2JSDTSToPasUnitDef.CreateSource(const Filename, SourceName,
ResourceName: string): string;
begin
FConverter.TargetUnitName:=ChangeFileExt(ExtractFileName(SourceName),'');
FConverter.Execute;
Result:=FConverter.Source.Text;
end;
function TPas2JSDTSToPasUnitDef.GetLocalizedName: string;
begin
Result:=rsCreateUnitFromTypeScript;
end;
function TPas2JSDTSToPasUnitDef.GetLocalizedDescription: string;
begin
Result:=rsCreateUnitFromTypeScriptDescription;
end;
{ TPas2JSMenuHandler } { TPas2JSMenuHandler }
procedure TPas2JSMenuHandler.DoConvLog(Sender: TObject; const Msg: String); procedure TPas2JSMenuHandler.DoConvLog(Sender: TObject; const Msg: String);
@ -277,7 +340,7 @@ begin
PrjMnuItemAll.Visible:=AnyOK; PrjMnuItemAll.Visible:=AnyOK;
end; end;
function TPas2JSMenuHandler.AskUserFile(aHTMLFileName: String): string; function TPas2JSMenuHandler.AskUserFile(aUnitName,aHTMLFileName: String): string;
Var Var
Dlg : TOpenDialog; Dlg : TOpenDialog;
@ -285,7 +348,7 @@ Var
begin begin
Result:=''; Result:='';
if mrOK<>QuestionDlg(pjsdHTMLSourceFileNotFound, if mrOK<>QuestionDlg(pjsdHTMLSourceFileNotFound,
Format(pjsdHTMLFileNotFOund,[aHTMLFileName]),mtInformation, Format(pjsdHTMLFileNotFOund,[aUnitName,aHTMLFileName]),mtInformation,
[mrOK,pjsdBtnSelectFile,mrCancel,pjsdButtonCancel],0) then [mrOK,pjsdBtnSelectFile,mrCancel,pjsdButtonCancel],0) then
Exit; Exit;
Dlg:=TOpenDialog.Create(Application); Dlg:=TOpenDialog.Create(Application);
@ -335,7 +398,7 @@ begin
aOptions.FromJSON(aFile.CustomData.Values[SHTML2FormOptions]); aOptions.FromJSON(aFile.CustomData.Values[SHTML2FormOptions]);
if Not FileExists(aOptions.HTMLFileName) then if Not FileExists(aOptions.HTMLFileName) then
begin begin
aFileName:=AskUserFile(aOptions.HTMLFileName); aFileName:=AskUserFile(aFile.Unit_Name, aOptions.HTMLFileName);
if aFileName='' then if aFileName='' then
exit; exit;
aOptions.HTMLFileName:=aFileName; aOptions.HTMLFileName:=aFileName;

View File

@ -95,6 +95,10 @@ Resourcestring
rsCreateClassFromHTMLName = 'Pas2JS class definition from HTML file'; rsCreateClassFromHTMLName = 'Pas2JS class definition from HTML file';
rsCreateClassFromHTMLDescription = 'Create a Pas2JS "form" class definition from HTML file using ID attributes in the HTML file.'; rsCreateClassFromHTMLDescription = 'Create a Pas2JS "form" class definition from HTML file using ID attributes in the HTML file.';
rsCreateUnitFromTypeScript = 'Pas2JS import unit from Typescript declaration module.';
rsCreateUnitFromTypeScriptDescription = 'Create a Pas2JS import unit from a Typescript declaration module.';
rsDTSDidNotProduceOutput = 'The DTS2pas tool did not produce an output file.';
// Macros names // Macros names
pjsdPas2JSExecutable = 'Pas2JS executable'; pjsdPas2JSExecutable = 'Pas2JS executable';
@ -112,14 +116,15 @@ Resourcestring
pjsdFileNameDoesNotStartWithPas2js = 'filename does not start with "pas2js"'; pjsdFileNameDoesNotStartWithPas2js = 'filename does not start with "pas2js"';
pjsdHTMLFilter = 'HTML Files|*.html|All files|*.*'; pjsdHTMLFilter = 'HTML Files|*.html|All files|*.*';
pjsdHTMLSourceFileNotFound = 'HTML Source not found'; pjsdHTMLSourceFileNotFound = 'HTML Source not found';
pjsdHTMLFileNotFound = 'Cannot find the HTML Source file for this class:'+LineEnding+ pjsdHTMLFileNotFound = 'Cannot find the HTML Source file for the class in unit %s:'#13#10+
'%s'+LineEnding+ '%s'#13#10+
'Would you like to select the file from disk?'; 'Would you like to select the file from disk?';
pjsdBtnSelectFile = 'Select the file'; pjsdBtnSelectFile = 'Select the file';
pjsdButtonCancel = 'Cancel refresh'; pjsdButtonCancel = 'Cancel refresh';
pjsRefreshClassFromHTML = 'Refresh class from HTML source'; pjsRefreshClassFromHTML = 'Refresh class from HTML source';
pjsRefreshAllClassesFromHTML = 'Refresh all classes from HTML source'; pjsRefreshAllClassesFromHTML = 'Refresh all classes from HTML source';
rsHTTPRequestFailed = 'HTML request to service URL %s failed: %s';
function SafeFormat(const Fmt: String; const Args: Array of const): String; function SafeFormat(const Fmt: String; const Args: Array of const): String;