diff --git a/.gitattributes b/.gitattributes index 2894f83d72..1a76779ba4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3764,6 +3764,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/pjsdsgnoptions.pas svneol=native#text/plain components/pas2js/pjsdsgnoptsframe.lfm svneol=native#text/plain components/pas2js/pjsdsgnoptsframe.pas svneol=native#text/plain components/pas2js/pjsdsgnregister.pas svneol=native#text/plain diff --git a/components/pas2js/pas2jsdsgn.lpk b/components/pas2js/pas2jsdsgn.lpk index eefcd5e092..f341ea8eac 100644 --- a/components/pas2js/pas2jsdsgn.lpk +++ b/components/pas2js/pas2jsdsgn.lpk @@ -16,27 +16,34 @@ - + - + - + - + + + + + - + - + + + + diff --git a/components/pas2js/pas2jsdsgn.pas b/components/pas2js/pas2jsdsgn.pas index 47e0dceea7..2625a872ec 100644 --- a/components/pas2js/pas2jsdsgn.pas +++ b/components/pas2js/pas2jsdsgn.pas @@ -8,7 +8,7 @@ unit Pas2JSDsgn; interface uses - PJSDsgnRegister, PJSDsgnOptsFrame, LazarusPackageIntf; + PJSDsgnRegister, PJSDsgnOptsFrame, PJSDsgnOptions, LazarusPackageIntf; implementation diff --git a/components/pas2js/pjsdsgnoptions.pas b/components/pas2js/pjsdsgnoptions.pas new file mode 100644 index 0000000000..99b07a0b22 --- /dev/null +++ b/components/pas2js/pjsdsgnoptions.pas @@ -0,0 +1,188 @@ +{ pas2js options + + Author: Mattias Gaertner +} +unit PJSDsgnOptions; + +{$mode objfpc}{$H+} +{$Inline on} + +interface + +uses + Classes, SysUtils, LazFileCache, LazConfigStorage, LazFileUtils, FileUtil, + MacroIntf, BaseIDEIntf, IDEUtils, + DefineTemplates; + +const + PJSDsgnOptsFile = 'pas2jsdsgnoptions.xml'; + PJSDefaultCompiler = '$MakeExe(IDE,pas2js)'; + +type + + { TPas2jsOptions } + + TPas2jsOptions = class + private + FChangeStamp: int64; + FSavedStamp: int64; + FCompilerFilename: string; + FCompilerFilenameStamp: int64; + FCompilerFilenameParsed: string; + function GetModified: boolean; + procedure SetModified(AValue: boolean); + procedure SetCompilerFilename(AValue: string); + public + constructor Create; + destructor Destroy; override; + procedure IncreaseChangeStamp; inline; + procedure Load; + procedure Save; + procedure LoadFromConfig(Cfg: TConfigStorage); + procedure SaveToConfig(Cfg: TConfigStorage); + function GetParsedCompilerFilename: string; + public + property CompilerFilename: string read FCompilerFilename write SetCompilerFilename; + property ChangeStamp: int64 read FChangeStamp; + property Modified: boolean read GetModified write SetModified; + end; + +var + PJSOptions: TPas2jsOptions = nil; + +function GetStandardPas2jsExe: string; +function GetPas2jsQuality(Filename: string; out Msg: string): boolean; + +implementation + +function GetStandardPas2jsExe: string; +begin + Result:='$MakeExe(IDE,pas2js)'; + if not IDEMacros.SubstituteMacros(Result) then + Result:='pas2js'; +end; + +function GetPas2jsQuality(Filename: string; out Msg: string): boolean; +var + ShortFile: String; +begin + Msg:=''; + Filename:=TrimFilename(Filename); + if (Filename='') then begin + Msg:='missing path to pas2js'; + exit(false); + end; + if not FileExistsCached(Filename) then begin + Msg:='file "'+Filename+'" not found'; + exit(false); + end; + if not DirPathExistsCached(ExtractFilePath(Filename)) then begin + Msg:='directory "'+ExtractFilePath(Filename)+'" not found'; + exit(false); + end; + if not FileIsExecutable(Filename) then begin + Msg:='file "'+Filename+'" not executable'; + exit(false); + end; + ShortFile:=ExtractFileNameOnly(Filename); + if not CompareText(LeftStr(ShortFile,length('pas2js')),'pas2js')<>0 then begin + Msg:='file name does not start with "pas2js"'; + exit(false); + end; + // run it + //RunTool(Filename); +end; + +{ 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; + IDEMacros.IncreaseBaseStamp; +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; + +function TPas2jsOptions.GetParsedCompilerFilename: string; +begin + if FCompilerFilenameStamp<>IDEMacros.BaseTimeStamp then begin + FCompilerFilenameStamp:=IDEMacros.BaseTimeStamp; + FCompilerFilenameParsed:=FCompilerFilename; + IDEMacros.SubstituteMacros(FCompilerFilenameParsed); + FCompilerFilenameParsed:=TrimFilename(FCompilerFilenameParsed); + if (FCompilerFilenameParsed<>'') + and not FilenameIsAbsolute(FCompilerFilenameParsed) then begin + FCompilerFilenameParsed:=FindDefaultExecutablePath(FCompilerFilenameParsed); + end; + end; + Result:=FCompilerFilenameParsed; +end; + +finalization + FreeAndNil(PJSOptions); +end. + diff --git a/components/pas2js/pjsdsgnoptsframe.pas b/components/pas2js/pjsdsgnoptsframe.pas index e2353c2733..c9cc586431 100644 --- a/components/pas2js/pjsdsgnoptsframe.pas +++ b/components/pas2js/pjsdsgnoptsframe.pas @@ -1,6 +1,6 @@ -{ Installs pas2js options frame in the Lazarus IDE. +{ IDE options frame for pas2js options - Copyright (C) 2017 Mattias Gaertner mattias@freepascal.org + Author: Mattias Gaertner } unit PJSDsgnOptsFrame; @@ -10,40 +10,12 @@ unit PJSDsgnOptsFrame; interface uses - Classes, SysUtils, Forms, Controls, StdCtrls, Dialogs, IDEOptionsIntf, - MacroIntf, BaseIDEIntf, IDEUtils, LazFileCache, LazConfigStorage, - LazFileUtils; - -const - PJSDsgnOptsFile = 'pas2jsdsgnoptions.xml'; - PJSDefaultCompiler = '$MakeExe(IDE,pas2js)'; + Classes, SysUtils, LazFileCache, LazConfigStorage, LazFileUtils, FileUtil, + Forms, Controls, StdCtrls, Dialogs, + IDEOptionsIntf, MacroIntf, BaseIDEIntf, IDEUtils, + PJSDsgnOptions; type - - { TPas2jsOptions } - - TPas2jsOptions = class - private - FChangeStamp: int64; - FSavedStamp: int64; - FCompilerFilename: string; - function GetModified: boolean; - procedure SetModified(AValue: boolean); - procedure SetCompilerFilename(AValue: string); - public - constructor Create; - destructor Destroy; override; - procedure IncreaseChangeStamp; inline; - procedure Load; - procedure Save; - procedure LoadFromConfig(Cfg: TConfigStorage); - procedure SaveToConfig(Cfg: TConfigStorage); - public - property CompilerFilename: string read FCompilerFilename write SetCompilerFilename; - property ChangeStamp: int64 read FChangeStamp; - property Modified: boolean read GetModified write SetModified; - end; - { TPas2jsOptionsFrame } TPas2jsOptionsFrame = class(TAbstractIDEOptionsEditor) @@ -55,101 +27,16 @@ type function CheckCompiler(Buttons: TMsgDlgButtons): boolean; public function GetTitle: String; override; - procedure Setup(ADialog: TAbstractOptionsEditorDialog); override; - procedure ReadSettings(AOptions: TAbstractIDEOptions); override; - procedure WriteSettings(AOptions: TAbstractIDEOptions); override; + procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override; + procedure ReadSettings({%H-}AOptions: TAbstractIDEOptions); override; + procedure WriteSettings({%H-}AOptions: TAbstractIDEOptions); override; class function SupportedOptionsClass: TAbstractIDEOptionsClass; override; end; -var - PJSOptions: TPas2jsOptions = nil; - -function GetStandardPas2jsExe: string; - implementation -function GetStandardPas2jsExe: string; -begin - Result:='$MakeExe(IDE,pas2js)'; - if not IDEMacros.SubstituteMacros(Result) then - Result:='pas2js'; -end; - {$R *.lfm} -{ TPas2jsOptions } - -procedure TPas2jsOptions.SetModified(AValue: boolean); -begin - if AValue then - IncreaseChangeStamp - else - FSavedStamp:=FChangeStamp; -end; - -function TPas2jsOptions.GetModified: boolean; -begin - Result:=FSavedStamp<>FChangeStamp; -end; - -procedure TPas2jsOptions.SetCompilerFilename(AValue: string); -begin - if FCompilerFilename=AValue then Exit; - FCompilerFilename:=AValue; - IncreaseChangeStamp; -end; - -constructor TPas2jsOptions.Create; -begin - FChangeStamp:=LUInvalidChangeStamp64; - FCompilerFilename:=PJSDefaultCompiler; -end; - -destructor TPas2jsOptions.Destroy; -begin - inherited Destroy; -end; - -procedure TPas2jsOptions.IncreaseChangeStamp; -begin - LUIncreaseChangeStamp64(FChangeStamp); -end; - -procedure TPas2jsOptions.Load; -var - Cfg: TConfigStorage; -begin - Cfg:=GetIDEConfigStorage(PJSDsgnOptsFile,true); - try - LoadFromConfig(Cfg); - finally - Cfg.Free; - end; -end; - -procedure TPas2jsOptions.Save; -var - Cfg: TConfigStorage; -begin - Cfg:=GetIDEConfigStorage(PJSDsgnOptsFile,false); - try - SaveToConfig(Cfg); - finally - Cfg.Free; - end; -end; - -procedure TPas2jsOptions.LoadFromConfig(Cfg: TConfigStorage); -begin - CompilerFilename:=Cfg.GetValue('compiler/value',PJSDefaultCompiler); - Modified:=false; -end; - -procedure TPas2jsOptions.SaveToConfig(Cfg: TConfigStorage); -begin - Cfg.SetDeleteValue('compiler/value',CompilerFilename,PJSDefaultCompiler); -end; - { TPas2jsOptionsFrame } procedure TPas2jsOptionsFrame.Pas2jsPathBrowseButtonClick(Sender: TObject); @@ -174,12 +61,13 @@ end; function TPas2jsOptionsFrame.CheckCompiler(Buttons: TMsgDlgButtons): boolean; var - NewExe: TCaption; + NewExe: string; begin NewExe:=Pas2jsPathComboBox.Text; if NewExe=PJSOptions.CompilerFilename then exit(true); Result:=false; PJSOptions.CompilerFilename:=NewExe; + // ToDo: check file //NewExe:=PJSOptions.GetParsedCompilerExe; end; @@ -214,7 +102,5 @@ begin Result:=IDEEditorGroups.GetByIndex(GroupEnvironment)^.GroupClass; end; -finalization - FreeAndNil(PJSOptions); end. diff --git a/components/pas2js/pjsdsgnregister.pas b/components/pas2js/pjsdsgnregister.pas index 692299071b..118de568d1 100644 --- a/components/pas2js/pjsdsgnregister.pas +++ b/components/pas2js/pjsdsgnregister.pas @@ -5,8 +5,9 @@ unit PJSDsgnRegister; interface uses - Classes, SysUtils, ProjectIntf, CompOptsIntf, LazIDEIntf, IDEOptionsIntf, - PJSDsgnOptsFrame, Forms, Controls; + Classes, SysUtils, Forms, Controls, + ProjectIntf, CompOptsIntf, LazIDEIntf, IDEOptionsIntf, + PJSDsgnOptions, PJSDsgnOptsFrame; const ProjDescNamePas2JSWebApp = 'Web Application';