PrjSettings.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. unit PrjSettings;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, ExtCtrls, ComCtrls, Main, Mask, JvExMask, JvSpin,
  6. JvExStdCtrls, JvEdit, JvValidateEdit, JvPageList, JvExControls, Misc,
  7. JvComponent, JvExComCtrls, JvPageListTreeView, ImgList, JvGroupHeader,
  8. JvBaseDlg, JvSelectDirectory, JvDotNetControls, JvBrowseFolder;
  9. type
  10. TfrmPrjOptions = class(TForm)
  11. Panel1: TPanel;
  12. Panel2: TPanel;
  13. btnCancel: TButton;
  14. btnOk: TButton;
  15. odlgSelectFile: TOpenDialog;
  16. jvPageListSettings: TJvPageList;
  17. JvStandardPage1: TJvStandardPage;
  18. Label1: TLabel;
  19. txtPrjName: TEdit;
  20. Label7: TLabel;
  21. spinMajorVersion: TJvSpinEdit;
  22. spinMinorVersion: TJvSpinEdit;
  23. Label9: TLabel;
  24. Label10: TLabel;
  25. spinReleaseVersion: TJvSpinEdit;
  26. Label11: TLabel;
  27. spinRevisionVersion: TJvSpinEdit;
  28. chkAutoIncRevNumber: TCheckBox;
  29. JvStandardPage2: TJvStandardPage;
  30. Label3: TLabel;
  31. jvspinPort: TJvSpinEdit;
  32. txtIP1: TEdit;
  33. Label4: TLabel;
  34. Label5: TLabel;
  35. txtIP2: TEdit;
  36. Label6: TLabel;
  37. txtIP3: TEdit;
  38. Label12: TLabel;
  39. txtIP4: TEdit;
  40. txtUploadDir: TEdit;
  41. Label13: TLabel;
  42. JvStandardPage3: TJvStandardPage;
  43. Label2: TLabel;
  44. txtDebugInitializer: TEdit;
  45. btnBrowseFile: TButton;
  46. imlPrjSettings: TImageList;
  47. jvSettingsTVSettings: TJvSettingsTreeView;
  48. JvGroupHeader1: TJvGroupHeader;
  49. JvGroupHeader2: TJvGroupHeader;
  50. JvGroupHeader3: TJvGroupHeader;
  51. JvGroupHeader4: TJvGroupHeader;
  52. Label14: TLabel;
  53. txtRuntimeDir: TEdit;
  54. btnBrowseDir: TButton;
  55. Label15: TLabel;
  56. cboUnits: TComboBox;
  57. Splitter1: TSplitter;
  58. JvGroupHeader8: TJvGroupHeader;
  59. JvGroupHeader5: TJvGroupHeader;
  60. JvGroupHeader6: TJvGroupHeader;
  61. jvspinConnectTimeOut: TJvSpinEdit;
  62. Label16: TLabel;
  63. Label17: TLabel;
  64. txtCompileDir: TEdit;
  65. Label8: TLabel;
  66. btnBrowseDir2: TButton;
  67. Label18: TLabel;
  68. txtCompileExt: TEdit;
  69. jvSelectDir: TJvBrowseForFolderDialog;
  70. procedure FormShow(Sender: TObject);
  71. procedure btnBrowseFileClick(Sender: TObject);
  72. procedure btnOkClick(Sender: TObject);
  73. procedure txtIP1KeyPress(Sender: TObject; var Key: Char);
  74. procedure txtIP2KeyPress(Sender: TObject; var Key: Char);
  75. procedure txtIP3KeyPress(Sender: TObject; var Key: Char);
  76. procedure txtIP4KeyPress(Sender: TObject; var Key: Char);
  77. procedure txtIP1Exit(Sender: TObject);
  78. procedure txtIP2Exit(Sender: TObject);
  79. procedure txtIP3Exit(Sender: TObject);
  80. procedure txtIP4Exit(Sender: TObject);
  81. procedure btnBrowseDirClick(Sender: TObject);
  82. procedure txtUploadDirExit(Sender: TObject);
  83. procedure btnBrowseDir2Click(Sender: TObject);
  84. procedure txtCompileExtExit(Sender: TObject);
  85. procedure txtCompileDirExit(Sender: TObject);
  86. private
  87. { Private declarations }
  88. public
  89. procedure GetLuaProjectOptions(pLuaPrj: TLuaEditProject);
  90. procedure SetLuaProjectOptions(pLuaPrj: TLuaEditProject);
  91. function IsIP(IP: String): Boolean;
  92. function IsPortNumber(Port: Integer): Boolean;
  93. function GetLastChar(sLine: String): String;
  94. end;
  95. var
  96. frmPrjOptions: TfrmPrjOptions;
  97. implementation
  98. {$R *.dfm}
  99. procedure TfrmPrjOptions.FormShow(Sender: TObject);
  100. begin
  101. jvPageListSettings.ActivePageIndex := 0;
  102. jvSettingsTVSettings.Selected := jvSettingsTVSettings.Items[1];
  103. end;
  104. procedure TfrmPrjOptions.GetLuaProjectOptions(pLuaPrj: TLuaEditProject);
  105. var
  106. sTemp: String;
  107. function ExtractNextIPPart(sIn: String): String;
  108. begin
  109. Result := Copy(sIn, 1, Pos('.', sIn) - 1);
  110. end;
  111. function TruncateToNextIPPart(sIn: String): String;
  112. begin
  113. Result := Copy(sIn, Pos('.', sIn) + 1, Length(sIn) - Pos('.', sIn));
  114. end;
  115. procedure FillTargetList(pPrj: TLuaEditProject);
  116. var
  117. x: Integer;
  118. pLuaUnit: TLuaEditUnit;
  119. begin
  120. cboUnits.Clear;
  121. cboUnits.AddItem('[Current Unit]', nil);
  122. cboUnits.ItemIndex := 0;
  123. for x := 0 to pPrj.lstUnits.Count - 1 do
  124. begin
  125. pLuaUnit := pPrj.lstUnits[x];
  126. cboUnits.AddItem(pLuaUnit.Name, pLuaUnit);
  127. if pLuaUnit.Name = pPrj.sTargetLuaUnit then
  128. cboUnits.ItemIndex := x + 1;
  129. end;
  130. end;
  131. begin
  132. // Get General Options
  133. txtPrjName.Text := pLuaPrj.Name;
  134. spinMajorVersion.Value := pLuaPrj.iVersionMajor;
  135. spinMinorVersion.Value := pLuaPrj.iVersionMinor;
  136. spinReleaseVersion.Value := pLuaPrj.iVersionRelease;
  137. spinRevisionVersion.Value := pLuaPrj.iVersionRevision;
  138. chkAutoIncRevNumber.Checked := pLuaPrj.AutoIncRevNumber;
  139. // Get Debug Options
  140. txtDebugInitializer.Text := pLuaPrj.sInitializer;
  141. jvspinConnectTimeOut.Value := pLuaPrj.iConnectTimeOut;
  142. jvspinPort.Value := pLuaPrj.iRemotePort;
  143. // Extract all parts of the ip address
  144. sTemp := pLuaPrj.sRemoteIP;
  145. txtIP1.Text := ExtractNextIPPart(sTemp);
  146. sTemp := TruncateToNextIPPart(sTemp);
  147. txtIP2.Text := ExtractNextIPPart(sTemp);
  148. sTemp := TruncateToNextIPPart(sTemp);
  149. txtIP3.Text := ExtractNextIPPart(sTemp);
  150. sTemp := TruncateToNextIPPart(sTemp);
  151. txtIP4.Text := sTemp;
  152. txtUploadDir.Text := pLuaPrj.sRemoteDirectory;
  153. FillTargetList(pLuaPrj);
  154. txtRuntimeDir.Text := pLuaPrj.sRuntimeDirectory;
  155. txtCompileDir.Text := pLuaPrj.sCompileDirectory;
  156. txtCompileExt.Text := pLuaPrj.sCompileExtension;
  157. end;
  158. procedure TfrmPrjOptions.SetLuaProjectOptions(pLuaPrj: TLuaEditProject);
  159. begin
  160. //Set general options
  161. pLuaPrj.Name := txtPrjName.Text;
  162. pLuaPrj.iVersionMajor := Round(spinMajorVersion.Value);
  163. pLuaPrj.iVersionMinor := Round(spinMinorVersion.Value);
  164. pLuaPrj.iVersionRelease := Round(spinReleaseVersion.Value);
  165. pLuaPrj.iVersionRevision := Round(spinRevisionVersion.Value);
  166. pLuaPrj.AutoIncRevNumber := chkAutoIncRevNumber.Checked;
  167. // Set debug options
  168. pLuaPrj.sInitializer := txtDebugInitializer.Text;
  169. pLuaPrj.iRemotePort := Trunc(jvspinPort.Value);
  170. pLuaPrj.iConnectTimeOut := Trunc(jvspinConnectTimeOut.Value);
  171. pLuaPrj.sRemoteIP := txtIP1.Text + '.' + txtIP2.Text + '.' + txtIP3.Text + '.' + txtIP4.Text;
  172. pLuaPrj.sRemoteDirectory := txtUploadDir.Text;
  173. pLuaPrj.sRuntimeDirectory := txtRuntimeDir.Text;
  174. pLuaPrj.sTargetLuaUnit := cboUnits.Text;
  175. pLuaPrj.sCompileDirectory := txtCompileDir.Text;
  176. pLuaPrj.sCompileExtension := txtCompileExt.Text;
  177. if cboUnits.Items.Objects[cboUnits.ItemIndex] <> nil then
  178. pLuaPrj.pTargetLuaUnit := TLuaEditUnit(cboUnits.Items.Objects[cboUnits.ItemIndex])
  179. else
  180. pLuaPrj.pTargetLuaUnit := nil;
  181. end;
  182. // Validate a Port number. Expected Format: x (x in [1024..65535])
  183. function TfrmPrjOptions.IsPortNumber(Port: Integer): Boolean;
  184. begin
  185. Result := True;
  186. if ((Port < 1024) or (Port > 65535)) then
  187. Result := False;
  188. end;
  189. // Validate an IP address. Expected format: xxx.xxx.xxx.xxx (xxx in [0..255])
  190. function TfrmPrjOptions.IsIP(IP: String): Boolean;
  191. var
  192. Sl: TStringList;
  193. Value, Code, i: Integer;
  194. begin
  195. Result := True;
  196. Sl := TStringList.Create;
  197. try
  198. Sl.Delimiter := '.';
  199. Sl.QuoteChar := '"';
  200. Sl.DelimitedText := IP;
  201. if Sl.Count <> 4 then
  202. begin
  203. Result := False;
  204. Exit;
  205. end;
  206. for i := 0 to Sl.Count - 1 do
  207. begin
  208. Val(Sl[i], Value, Code);
  209. if Code <> 0 then
  210. begin
  211. Result := False;
  212. Break;
  213. end;
  214. if (Value < 0) or (Value > 255) then
  215. begin
  216. Result := False;
  217. Break;
  218. end;
  219. end;
  220. finally
  221. FreeAndNil(Sl);
  222. end;
  223. end;
  224. procedure TfrmPrjOptions.btnBrowseFileClick(Sender: TObject);
  225. begin
  226. odlgSelectFile.InitialDir := ExtractFileDir(txtDebugInitializer.Text);
  227. odlgSelectFile.Title := 'Select Initializer...';
  228. odlgSelectFile.Filter := 'Application Extension (*.dll)|*.dll';
  229. if odlgSelectFile.Execute then
  230. txtDebugInitializer.Text := odlgSelectFile.FileName;
  231. end;
  232. procedure TfrmPrjOptions.btnBrowseDirClick(Sender: TObject);
  233. begin
  234. jvSelectDir.Directory := txtRuntimeDir.Text;
  235. jvSelectDir.Title := 'Select Runtime Directory...';
  236. if jvSelectDir.Execute then
  237. begin
  238. txtRuntimeDir.Text := jvSelectDir.Directory;
  239. txtRuntimeDir.SetFocus;
  240. end;
  241. end;
  242. procedure TfrmPrjOptions.btnBrowseDir2Click(Sender: TObject);
  243. begin
  244. jvSelectDir.Directory := txtCompileDir.Text;
  245. jvSelectDir.Title := 'Select Compilation Output Directory...';
  246. if jvSelectDir.Execute then
  247. begin
  248. txtCompileDir.Text := jvSelectDir.Directory;
  249. txtCompileDir.SetFocus;
  250. end;
  251. end;
  252. procedure TfrmPrjOptions.btnOkClick(Sender: TObject);
  253. begin
  254. ModalResult := mrNone;
  255. if txtPrjName.Text = '' then
  256. begin
  257. Application.MessageBox('The project name can''t be empty.', 'LuaEdit', MB_OK+MB_ICONERROR);
  258. jvPageListSettings.ActivePageIndex := 0;
  259. txtPrjName.SetFocus;
  260. end
  261. else if txtCompileExt.Text = '' then
  262. begin
  263. Application.MessageBox('The compilation extension can''t be empty.', 'LuaEdit', MB_OK+MB_ICONERROR);
  264. jvPageListSettings.ActivePageIndex := 2;
  265. txtCompileExt.SetFocus;
  266. end
  267. else if not IsPortNumber(Trunc(jvspinPort.Value)) then
  268. begin
  269. Application.MessageBox('The remote port number is invalid. Value must be between 1024 and 65535.', 'LuaEdit', MB_OK+MB_ICONERROR);
  270. jvPageListSettings.ActivePageIndex := 1;
  271. jvspinPort.SetFocus;
  272. end
  273. else if not IsIP(txtIP1.Text + '.' + txtIP2.Text + '.' + txtIP3.Text + '.' + txtIP4.Text) then
  274. begin
  275. Application.MessageBox('The remote IP address is invalid.', 'LuaEdit', MB_OK+MB_ICONERROR);
  276. jvPageListSettings.ActivePageIndex := 1;
  277. txtIP1.SetFocus;
  278. end
  279. else
  280. ModalResult := mrOk;
  281. end;
  282. function TfrmPrjOptions.GetLastChar(sLine: String): String;
  283. begin
  284. Result := '';
  285. if sLine <> '' then
  286. Result := sLine[Length(sLine)];
  287. end;
  288. procedure TfrmPrjOptions.txtIP1KeyPress(Sender: TObject; var Key: Char);
  289. begin
  290. if Key in ['0'..'9', '.', #8] then
  291. begin
  292. if txtIP1.SelLength <> 3 then
  293. begin
  294. if Key = '.' then
  295. begin
  296. txtIP2.SetFocus;
  297. Key := #0;
  298. end
  299. else if Length(txtIP1.Text) = 3 then
  300. begin
  301. txtIP2.Text := Key;
  302. txtIP2.SetFocus;
  303. txtIP2.SelStart := 1;
  304. end;
  305. end
  306. else if Key = '.' then
  307. begin
  308. txtIP2.SetFocus;
  309. Key := #0;
  310. end;
  311. end
  312. else
  313. Key := #0;
  314. end;
  315. procedure TfrmPrjOptions.txtIP2KeyPress(Sender: TObject; var Key: Char);
  316. begin
  317. if Key in ['0'..'9', '.', #8] then
  318. begin
  319. if txtIP2.SelLength <> 3 then
  320. begin
  321. if Key = '.' then
  322. begin
  323. txtIP3.SetFocus;
  324. Key := #0;
  325. end
  326. else
  327. begin
  328. if ((Key = #8) and (Length(txtIP2.Text) = 0)) then
  329. begin
  330. txtIP1.SetFocus;
  331. end
  332. else if Length(txtIP2.Text) = 3 then
  333. begin
  334. txtIP3.Text := Key;
  335. txtIP3.SetFocus;
  336. txtIP3.SelStart := 1;
  337. end;
  338. end;
  339. end
  340. else if Key = '.' then
  341. begin
  342. txtIP3.SetFocus;
  343. Key := #0;
  344. end;
  345. end
  346. else
  347. Key := #0;
  348. end;
  349. procedure TfrmPrjOptions.txtIP3KeyPress(Sender: TObject; var Key: Char);
  350. begin
  351. if Key in ['0'..'9', '.', #8] then
  352. begin
  353. if txtIP1.SelLength <> 3 then
  354. begin
  355. if Key = '.' then
  356. begin
  357. txtIP4.SetFocus;
  358. Key := #0;
  359. end
  360. else
  361. begin
  362. if ((Key = #8) and (Length(txtIP3.Text) = 0)) then
  363. begin
  364. txtIP2.SetFocus;
  365. end
  366. else if Length(txtIP3.Text) = 3 then
  367. begin
  368. txtIP4.Text := Key;
  369. txtIP4.SetFocus;
  370. txtIP4.SelStart := 1;
  371. end;
  372. end;
  373. end
  374. else if Key = '.' then
  375. begin
  376. txtIP4.SetFocus;
  377. Key := #0;
  378. end;
  379. end
  380. else
  381. Key := #0;
  382. end;
  383. procedure TfrmPrjOptions.txtIP4KeyPress(Sender: TObject; var Key: Char);
  384. begin
  385. if Key in ['0'..'9', #8] then
  386. begin
  387. if ((Key = #8) and (Length(txtIP4.Text) = 0)) then
  388. txtIP3.SetFocus;
  389. end
  390. else
  391. Key := #0;
  392. end;
  393. procedure TfrmPrjOptions.txtIP1Exit(Sender: TObject);
  394. begin
  395. if txtIP1.Text = '' then
  396. txtIP1.Text := '0';
  397. end;
  398. procedure TfrmPrjOptions.txtIP2Exit(Sender: TObject);
  399. begin
  400. if txtIP2.Text = '' then
  401. txtIP2.Text := '0';
  402. end;
  403. procedure TfrmPrjOptions.txtIP3Exit(Sender: TObject);
  404. begin
  405. if txtIP3.Text = '' then
  406. txtIP3.Text := '0';
  407. end;
  408. procedure TfrmPrjOptions.txtIP4Exit(Sender: TObject);
  409. begin
  410. if txtIP4.Text = '' then
  411. txtIP4.Text := '0';
  412. end;
  413. procedure TfrmPrjOptions.txtUploadDirExit(Sender: TObject);
  414. begin
  415. if ((txtUploadDir.Text <> '') and (txtUploadDir.Text[Length(txtUploadDir.Text)] <> '\')) then
  416. txtUploadDir.Text := txtUploadDir.Text + '\';
  417. end;
  418. procedure TfrmPrjOptions.txtCompileExtExit(Sender: TObject);
  419. begin
  420. if txtCompileExt.Text <> '' then
  421. begin
  422. if txtCompileExt.Text[1] <> '.' then
  423. txtCompileExt.Text := '.' + txtCompileExt.Text;
  424. end;
  425. end;
  426. procedure TfrmPrjOptions.txtCompileDirExit(Sender: TObject);
  427. begin
  428. if txtCompileDir.Text <> '' then
  429. begin
  430. if GetLastChar(txtCompileDir.Text) <> '\' then
  431. txtCompileDir.Text := txtCompileDir.Text + '\';
  432. end;
  433. end;
  434. end.