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 {%H-}Key: Word; {%H-}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; 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: String; 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)0 then begin Add(ModuleList[I]); Inc(aCount); end; Inc(I); end; if (aCount>=MaxCompletions) and (I