1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
|
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)<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.
|