* More structured code, clearer dialog, fix some formatting

This commit is contained in:
Michaël Van Canneyt 2021-12-17 13:36:20 +01:00
parent e2d630da1d
commit eb90152af1
13 changed files with 239 additions and 121 deletions

View File

@ -119,6 +119,10 @@ resourcestring
sDocumentLocation = '&Location';
sDocumentRoot = '&Directory';
sUseThreads = 'Use &threads to serve requests in';
sFileServing = 'File serving';
sNoFiles = 'Do not serve files';
sDefaultRouteServesFiles = 'Default route serves files';
sCaption = 'Create a new JSON-RPC module';
sRegisterJSON = 'Register JSON-RPC handlers in factory';

View File

@ -8,35 +8,13 @@ object NewHTTPApplicationForm: TNewHTTPApplicationForm
ClientWidth = 462
OnCreate = FormCreate
LCLVersion = '2.3.0.0'
object DEDocumentroot: TDirectoryEdit
Left = 40
Height = 27
Top = 160
Width = 272
DialogTitle = 'Select directory'
ShowHidden = False
ButtonWidth = 23
NumGlyphs = 1
Enabled = False
MaxLength = 0
TabOrder = 0
end
object CBRegisterFiles: TCheckBox
Left = 16
Height = 23
Top = 14
Width = 239
Caption = 'Register location to serve files from'
OnChange = CBRegisterFilesChange
TabOrder = 1
end
object SEPort: TSpinEdit
Left = 34
Left = 26
Height = 27
Top = 232
Top = 256
Width = 98
MaxValue = 65355
TabOrder = 2
TabOrder = 0
Value = 8080
end
object ButtonPanel1: TButtonPanel
@ -52,56 +30,93 @@ object NewHTTPApplicationForm: TNewHTTPApplicationForm
CloseButton.DefaultCaption = True
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 3
TabOrder = 1
ShowButtons = [pbOK, pbCancel]
end
object LSEPort: TLabel
Left = 16
Left = 8
Height = 16
Top = 200
Top = 224
Width = 157
Caption = 'Port to listen for requests:'
FocusControl = SEPort
end
object ELocation: TEdit
Left = 40
Height = 27
Top = 64
Width = 80
Enabled = False
TabOrder = 4
end
object LELocation: TLabel
Left = 40
Height = 16
Top = 40
Width = 55
Caption = 'Location:'
FocusControl = ELocation
end
object LDEDocumentRoot: TLabel
Left = 18
Height = 16
Top = 136
Width = 171
Caption = '&Directory to serve files from:'
FocusControl = DEDocumentroot
end
object CBthreads: TCheckBox
Left = 18
Left = 10
Height = 23
Top = 272
Top = 296
Width = 217
Caption = 'Use threads to serve requests in'
TabOrder = 5
TabOrder = 2
end
object CBDefaultFileLocation: TCheckBox
Left = 16
Height = 23
Top = 98
Width = 178
Caption = 'Default route serves files'
OnChange = CBDefaultFileLocationChange
TabOrder = 6
object GBFileServing: TGroupBox
Left = 0
Height = 216
Top = 0
Width = 462
Align = alTop
Caption = 'File serving'
ClientHeight = 199
ClientWidth = 460
TabOrder = 3
object RBNoFiles: TRadioButton
Left = 16
Height = 23
Top = 16
Width = 132
Caption = 'Do not serve files'
OnChange = RBNoFilesChange
TabOrder = 0
end
object RBSingleRoute: TRadioButton
Left = 16
Height = 23
Top = 52
Width = 236
Caption = 'Use single URL route to serve files: '
OnChange = RBNoFilesChange
TabOrder = 1
end
object RBDefaultRoute: TRadioButton
Left = 16
Height = 23
Top = 96
Width = 178
Caption = 'Default route serves files'
Checked = True
OnChange = RBNoFilesChange
TabOrder = 2
TabStop = True
end
object ELocation: TEdit
Left = 280
Height = 27
Top = 48
Width = 166
Anchors = [akTop, akLeft, akRight]
Enabled = False
TabOrder = 3
end
object LDEDocumentRoot: TLabel
Left = 16
Height = 16
Top = 136
Width = 171
Caption = '&Directory to serve files from:'
FocusControl = DEDocumentroot
end
object DEDocumentroot: TDirectoryEdit
Left = 16
Height = 27
Top = 160
Width = 430
DialogTitle = 'Select directory'
ShowHidden = False
ButtonWidth = 23
NumGlyphs = 1
Enabled = False
MaxLength = 0
TabOrder = 4
end
end
end

View File

@ -11,38 +11,37 @@ uses
type
{ TNewHTTPApplicationForm }
TServeFiles = (sfNoFiles, sfSingleRoute, sfDefaultRoute);
TNewHTTPApplicationForm = class(TForm)
ButtonPanel1: TButtonPanel;
CBRegisterFiles: TCheckBox;
CBthreads: TCheckBox;
CBDefaultFileLocation: TCheckBox;
DEDocumentroot: TDirectoryEdit;
ELocation: TEdit;
LSEPort: TLabel;
LELocation: TLabel;
GBFileServing: TGroupBox;
LDEDocumentRoot: TLabel;
LSEPort: TLabel;
RBSingleRoute: TRadioButton;
RBDefaultRoute: TRadioButton;
RBNoFiles: TRadioButton;
SEPort: TSpinEdit;
procedure CBDefaultFileLocationChange(Sender: TObject);
procedure CBRegisterFilesChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure RBNoFilesChange(Sender: TObject);
private
function GetD: String;
function GetL: String;
function GetR: String;
function GetP: Integer;
function GetS: Boolean;
function GetSD: Boolean;
function Gett: Boolean;
function GetS: TServeFiles;
function GetT: Boolean;
procedure LocalizeForm;
{ private declarations }
public
{ public declarations }
Property ServeFiles : Boolean Read GetS;
Property Location : String Read GetL;
Property ServeFiles : TServeFiles Read GetS;
Property FileRoute : String Read GetR;
Property Directory : String Read GetD;
Property Port: Integer Read GetP;
Property Threaded : Boolean Read Gett;
Property ServeFilesDefault : Boolean Read GetSD;
end;
var
@ -61,37 +60,30 @@ begin
LocalizeForm;
end;
procedure TNewHTTPApplicationForm.CBRegisterFilesChange(Sender: TObject);
procedure TNewHTTPApplicationForm.RBNoFilesChange(Sender: TObject);
Var
B : Boolean;
SF : TServeFiles;
begin
B:=GetS;
ELocation.Enabled:=B;
DEDocumentRoot.Enabled:=B;
CBDefaultFileLocation.Enabled:=Not B;
if not CBDefaultFileLocation.Enabled then
CBDefaultFileLocation.Checked:=False
end;
procedure TNewHTTPApplicationForm.CBDefaultFileLocationChange(Sender: TObject);
begin
CBRegisterFiles.Enabled:=Not CBDefaultFileLocation.Checked;
ELocation.Enabled:=Not CBDefaultFileLocation.Checked;
if not CBRegisterFiles.Enabled then
begin
CBRegisterFiles.Checked:=False;
SF:=ServeFiles;
ELocation.Enabled:=(Sf=sfSingleRoute);
if not ELocation.Enabled then
ELocation.Text:='';
end;
DEDocumentRoot.Enabled:=(Sf<>sfNoFiles);
if not DEDocumentRoot.Enabled then
DEDocumentRoot.Directory:='';
end;
procedure TNewHTTPApplicationForm.LocalizeForm;
begin
Caption:=sNewHTTPApp;
CBRegisterFiles.Caption:=sRegisterFiles;
LELocation.Caption:=sDocumentLocation;
GBFileServing.Caption:=sFileServing;
RBNoFiles.Caption:=sNoFiles;
RBSingleRoute.Caption:=sRegisterFiles;
RBDefaultRoute.Caption:=sDefaultRouteServesFiles;
LDEDocumentRoot.Caption:=sDocumentRoot;
LSEPort.Caption:=sHTTPPort;
CBthreads.Caption:=sUseThreads;
@ -102,7 +94,7 @@ begin
Result:=DEDocumentRoot.Text;
end;
function TNewHTTPApplicationForm.GetL: String;
function TNewHTTPApplicationForm.GetR: String;
begin
Result:=ELocation.Text;
end;
@ -112,17 +104,18 @@ begin
Result:=SEPort.Value;
end;
function TNewHTTPApplicationForm.GetS: Boolean;
function TNewHTTPApplicationForm.GetS: TServeFiles;
begin
Result:=CBRegisterFiles.Checked;
if RBNoFiles.Checked then
Result:=sfNoFiles
else if RBSingleRoute.Checked then
Result:=sfSingleRoute
else
Result:=sfDefaultRoute;
end;
function TNewHTTPApplicationForm.GetSD: Boolean;
begin
Result:=CBDefaultFileLocation.Checked;
end;
function TNewHTTPApplicationForm.Gett: Boolean;
function TNewHTTPApplicationForm.GeTT: Boolean;
begin
Result:=CBThreads.Checked;
end;

View File

@ -128,6 +128,10 @@ msgstr "Vytvořit nový CSS soubor ..."
msgid "Enter your classes/style definitions here"
msgstr "Vložte své třídy/dinice stylů sem"
#: fpwebstrconsts.sdefaultrouteservesfiles
msgid "Default route serves files"
msgstr ""
#: fpwebstrconsts.sdocumentlocation
msgid "&Location"
msgstr "Umístění"
@ -140,6 +144,10 @@ msgstr "&Složka"
msgid "Enter your text ..."
msgstr "Vložte svůj text ..."
#: fpwebstrconsts.sfileserving
msgid "File serving"
msgstr ""
#: fpwebstrconsts.shtmlautor
msgid "Html &author - <meta name=\"author\">"
msgstr "Html &autor - <meta name=\"author\">"
@ -501,6 +509,10 @@ msgstr "Nové vlastnosti HTML souboru"
msgid "New HTTP application"
msgstr "Nová HTTP aplikace"
#: fpwebstrconsts.snofiles
msgid "Do not serve files"
msgstr ""
#: fpwebstrconsts.sregisterfiles
msgid "&Register location to serve files from"
msgstr "&Registrovat umístění, odkud se budou souvory \"servírovat\""

View File

@ -116,6 +116,10 @@ msgstr "Erzeuge neue CSS-Datei..."
msgid "Enter your classes/style definitions here"
msgstr ""
#: fpwebstrconsts.sdefaultrouteservesfiles
msgid "Default route serves files"
msgstr ""
#: fpwebstrconsts.sdocumentlocation
msgid "&Location"
msgstr ""
@ -129,6 +133,10 @@ msgctxt "fpwebstrconsts.senteryoutext"
msgid "Enter your text ..."
msgstr ""
#: fpwebstrconsts.sfileserving
msgid "File serving"
msgstr ""
#: fpwebstrconsts.shtmlautor
msgid "Html &author - <meta name=\"author\">"
msgstr ""
@ -530,6 +538,10 @@ msgstr "Neue HTML-Datei-Eigenschaften"
msgid "New HTTP application"
msgstr "Neue HTTP-Anwendung"
#: fpwebstrconsts.snofiles
msgid "Do not serve files"
msgstr ""
#: fpwebstrconsts.sregisterfiles
msgid "&Register location to serve files from"
msgstr ""

View File

@ -137,6 +137,10 @@ msgstr "Créer un nouveau fichier CSS..."
msgid "Enter your classes/style definitions here"
msgstr "Insérez vos définitions de classes et de styles ici"
#: fpwebstrconsts.sdefaultrouteservesfiles
msgid "Default route serves files"
msgstr ""
#: fpwebstrconsts.sdocumentlocation
msgid "&Location"
msgstr "&Emplacement"
@ -149,6 +153,10 @@ msgstr "&Répertoire"
msgid "Enter your text ..."
msgstr "Entrez votre texte..."
#: fpwebstrconsts.sfileserving
msgid "File serving"
msgstr ""
#: fpwebstrconsts.shtmlautor
msgid "Html &author - <meta name=\"author\">"
msgstr "&Auteur HTML - <meta name=\"author\">"
@ -510,6 +518,10 @@ msgstr "Propriétés du nouveau fichier HTML"
msgid "New HTTP application"
msgstr "Nouvelle application HTTP"
#: fpwebstrconsts.snofiles
msgid "Do not serve files"
msgstr ""
#: fpwebstrconsts.sregisterfiles
msgid "&Register location to serve files from"
msgstr "&Enregistrer l'emplacement source des fichiers"

View File

@ -137,6 +137,10 @@ msgstr "Új CSS fájl létrehozása ..."
msgid "Enter your classes/style definitions here"
msgstr "Írja ide az osztály/stílus meghatározásokat"
#: fpwebstrconsts.sdefaultrouteservesfiles
msgid "Default route serves files"
msgstr ""
#: fpwebstrconsts.sdocumentlocation
msgid "&Location"
msgstr "&Hely"
@ -149,6 +153,10 @@ msgstr "&Könyvtár"
msgid "Enter your text ..."
msgstr "Írja be a szöveget ..."
#: fpwebstrconsts.sfileserving
msgid "File serving"
msgstr ""
#: fpwebstrconsts.shtmlautor
msgid "Html &author - <meta name=\"author\">"
msgstr "HTML &szerző - <meta name=\"author\">"
@ -510,6 +518,10 @@ msgstr "Új HTML fájl tulajdonságok"
msgid "New HTTP application"
msgstr "Új HTTP alkalmazás"
#: fpwebstrconsts.snofiles
msgid "Do not serve files"
msgstr ""
#: fpwebstrconsts.sregisterfiles
msgid "&Register location to serve files from"
msgstr "Hely &bejegyzése a fájlok kiszolgálására"

View File

@ -138,6 +138,10 @@ msgstr "Crea un nuovo file CSS ..."
msgid "Enter your classes/style definitions here"
msgstr "Scrivi qui le tue definizioni di classi e stili"
#: fpwebstrconsts.sdefaultrouteservesfiles
msgid "Default route serves files"
msgstr ""
#: fpwebstrconsts.sdocumentlocation
msgid "&Location"
msgstr "&Posizione:"
@ -150,6 +154,10 @@ msgstr "&Cartella"
msgid "Enter your text ..."
msgstr "Inserisci il tuo testo ..."
#: fpwebstrconsts.sfileserving
msgid "File serving"
msgstr ""
#: fpwebstrconsts.shtmlautor
msgid "Html &author - <meta name=\"author\">"
msgstr "&Autore html - <meta name=\"autore\">"
@ -511,6 +519,10 @@ msgstr "Proprietà del nuovo file HTML"
msgid "New HTTP application"
msgstr "Nuova applicazione HTTP"
#: fpwebstrconsts.snofiles
msgid "Do not serve files"
msgstr ""
#: fpwebstrconsts.sregisterfiles
msgid "&Register location to serve files from"
msgstr "&Registra la locazione da cui servire i file"

View File

@ -137,6 +137,10 @@ msgstr "Kurti naują CSS failą…"
msgid "Enter your classes/style definitions here"
msgstr "Čia reikia įvesti klasių/stilių apibrėžtis"
#: fpwebstrconsts.sdefaultrouteservesfiles
msgid "Default route serves files"
msgstr ""
#: fpwebstrconsts.sdocumentlocation
msgid "&Location"
msgstr "&Vieta"
@ -149,6 +153,10 @@ msgstr "&Aplankas"
msgid "Enter your text ..."
msgstr "Įveskite tekstą…"
#: fpwebstrconsts.sfileserving
msgid "File serving"
msgstr ""
#: fpwebstrconsts.shtmlautor
msgid "Html &author - <meta name=\"author\">"
msgstr "Html au&torius - <meta name=\"author\">"
@ -510,6 +518,10 @@ msgstr "Naujo Html failo savybės"
msgid "New HTTP application"
msgstr "Nauja HTTP programa"
#: fpwebstrconsts.snofiles
msgid "Do not serve files"
msgstr ""
#: fpwebstrconsts.sregisterfiles
msgid "&Register location to serve files from"
msgstr "Re&gistruoti vietą, iš kurios bus tiekiami failai"

View File

@ -116,6 +116,10 @@ msgstr "Utwórz nowy plik CSS..."
msgid "Enter your classes/style definitions here"
msgstr ""
#: fpwebstrconsts.sdefaultrouteservesfiles
msgid "Default route serves files"
msgstr ""
#: fpwebstrconsts.sdocumentlocation
msgid "&Location"
msgstr ""
@ -128,6 +132,10 @@ msgstr "&Folder"
msgid "Enter your text ..."
msgstr ""
#: fpwebstrconsts.sfileserving
msgid "File serving"
msgstr ""
#: fpwebstrconsts.shtmlautor
msgid "Html &author - <meta name=\"author\">"
msgstr ""
@ -489,6 +497,10 @@ msgstr ""
msgid "New HTTP application"
msgstr ""
#: fpwebstrconsts.snofiles
msgid "Do not serve files"
msgstr ""
#: fpwebstrconsts.sregisterfiles
msgid "&Register location to serve files from"
msgstr ""

View File

@ -117,6 +117,10 @@ msgstr "Создать новый файл CSS ..."
msgid "Enter your classes/style definitions here"
msgstr "Введите здесь объявления классов/стилей"
#: fpwebstrconsts.sdefaultrouteservesfiles
msgid "Default route serves files"
msgstr ""
#: fpwebstrconsts.sdocumentlocation
msgid "&Location"
msgstr "&Расположение"
@ -130,6 +134,10 @@ msgctxt "fpwebstrconsts.senteryoutext"
msgid "Enter your text ..."
msgstr "Введите текст ..."
#: fpwebstrconsts.sfileserving
msgid "File serving"
msgstr ""
#: fpwebstrconsts.shtmlautor
msgid "Html &author - <meta name=\"author\">"
msgstr "&Автор HTML - <meta name=\"author\">"
@ -531,6 +539,10 @@ msgstr "Свойства нового файла HTML"
msgid "New HTTP application"
msgstr "Новое приложение HTTP"
#: fpwebstrconsts.snofiles
msgid "Do not serve files"
msgstr ""
#: fpwebstrconsts.sregisterfiles
msgid "&Register location to serve files from"
msgstr "&Зарегистрировать расположение файлов для выдачи"

View File

@ -138,6 +138,10 @@ msgstr "创建新CSS文件..."
msgid "Enter your classes/style definitions here"
msgstr "输入你的类/样式定义"
#: fpwebstrconsts.sdefaultrouteservesfiles
msgid "Default route serves files"
msgstr ""
#: fpwebstrconsts.sdocumentlocation
msgid "&Location"
msgstr "位置(&L)"
@ -150,6 +154,10 @@ msgstr "目录(&D)"
msgid "Enter your text ..."
msgstr "输入你的文本..."
#: fpwebstrconsts.sfileserving
msgid "File serving"
msgstr ""
#: fpwebstrconsts.shtmlautor
msgid "Html &author - <meta name=\"author\">"
msgstr "Html &作者- <meta name=\"作者\">"
@ -511,6 +519,10 @@ msgstr "新建Html文件属性"
msgid "New HTTP application"
msgstr "新建HTTP应用"
#: fpwebstrconsts.snofiles
msgid "Do not serve files"
msgstr ""
#: fpwebstrconsts.sregisterfiles
msgid "&Register location to serve files from"
msgstr "注册位置以服务文件从(&R)"

View File

@ -36,6 +36,7 @@ uses
{$ENDIF}
webjsonrpc,
Controls, Dialogs, Forms,
frmnewhttpapp,
LazFileUtils,
IDEExternToolIntf, ProjectIntf,
LazIDEIntf, SrcEditorIntf, IDEMsgIntf,
@ -177,8 +178,8 @@ type
{ THTTPApplicationDescriptor }
THTTPApplicationDescriptor = class(TProjectDescriptor)
private
FThreaded,
fReg : Boolean;
FThreaded : Boolean;
fServeFiles : TServeFiles;
FDir,
FLoc : String;
FPort : Integer;
@ -211,7 +212,7 @@ procedure Register;
implementation
uses LazarusPackageIntf,FormEditingIntf, PropEdits, DBPropEdits, sqldbwebdata, LResources,
frmrpcmoduleoptions,frmnewhttpapp, registersqldb, sqlstringspropertyeditordlg;
frmrpcmoduleoptions, registersqldb, sqlstringspropertyeditordlg;
Const
fpWebTab = 'fpWeb';
@ -817,15 +818,10 @@ begin
begin
FThreaded:=Threaded;
FPort:=Port;
FReg:=ServeFiles;
if Freg then
FServeFiles:=ServeFiles;
if FServeFiles<>sfNoFiles then
begin
FLoc:=Location;
FDir:=Directory;
end
else
begin
FDefaultFiles:=ServeFilesDefault;
FLoc:=FileRoute;
FDir:=Directory;
end
end;
@ -858,23 +854,25 @@ begin
+'{$mode objfpc}{$H+}'+le
+le
+'uses'+le;
if FReg then
if FServeFiles<>sfNoFiles then
NewSource:=NewSource+' fpwebfile,'+le;
NewSource:=NewSource
+' fphttpapp;'+le
+le
+'begin'+le;
if Freg then
Case FServeFiles of
sfSingleRoute:
begin
S:=Format(' RegisterFileLocation(''%s'',''%s'');',[FLoc,FDir]);
NewSource:=NewSource+S+le
end
else if FDefaultFiles then
end;
sfDefaultRoute:
begin
S:='TSimpleFileModule.BaseDir:='+Format('''%s'';',[StringReplace(FDir,'''','''''',[rfReplaceAll])]);
S:=S+le+'TSimpleFileModule.RegisterDefaultRoute;';
S:=' TSimpleFileModule.BaseDir:='+Format('''%s'';',[StringReplace(FDir,'''','''''',[rfReplaceAll])]);
S:=S+le+' TSimpleFileModule.RegisterDefaultRoute;';
NewSource:=NewSource+S+le;
end;
end;
NewSource:=NewSource
+' Application.Title:=''httpproject1'';'+le
+Format(' Application.Port:=%d;'+le,[FPort]);