EditorSettings.pas 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. unit EditorSettings;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, SynEdit, ComCtrls, ExtCtrls, IniFiles, Main, LuaSyntax,
  6. Registry, ImgList, JvExControls, JvComponent, JvGroupHeader, JvPageList,
  7. JvExComCtrls, JvPageListTreeView, Buttons, JvxSlider, Mask, JvExMask,
  8. JvSpin, Misc, JvToolEdit, JvDotNetControls;
  9. const
  10. UM_MEASUREFONTS = WM_USER;
  11. type
  12. TfrmEditorSettings = class(TForm)
  13. Panel1: TPanel;
  14. Panel2: TPanel;
  15. btnCancel: TButton;
  16. btnOK: TButton;
  17. imgNotify: TImage;
  18. lblNotify: TLabel;
  19. jvSettingsTVSettings: TJvSettingsTreeView;
  20. jvPageListSettings: TJvPageList;
  21. JvStandardPage1: TJvStandardPage;
  22. JvGroupHeader1: TJvGroupHeader;
  23. chkFileAssociate: TCheckBox;
  24. chkKeepReportOpened: TCheckBox;
  25. chkShowExSaveDlg: TCheckBox;
  26. chkSaveProjectsInc: TCheckBox;
  27. chkSaveUnitsInc: TCheckBox;
  28. chkSaveBreakpoints: TCheckBox;
  29. JvStandardPage2: TJvStandardPage;
  30. txtTabWidth: TEdit;
  31. txtUndoLimit: TEdit;
  32. Label1: TLabel;
  33. Label2: TLabel;
  34. chkAutoIndent: TCheckBox;
  35. chkSmartTab: TCheckBox;
  36. chkTabIndent: TCheckBox;
  37. chkGroupUndo: TCheckBox;
  38. chkRightMouseMovesCursor: TCheckBox;
  39. chkEHomeKey: TCheckBox;
  40. chkTabsToSpaces: TCheckBox;
  41. chkHideScrollBars: TCheckBox;
  42. chkTrailBlanks: TCheckBox;
  43. chkKeepCaretX: TCheckBox;
  44. chkScrollPastEOL: TCheckBox;
  45. chkScrollPastEOF: TCheckBox;
  46. JvGroupHeader2: TJvGroupHeader;
  47. imlEditorSettings: TImageList;
  48. JvStandardPage3: TJvStandardPage;
  49. JvStandardPage4: TJvStandardPage;
  50. Label10: TLabel;
  51. txtLibraries: TEdit;
  52. btnBrowseLibraries: TButton;
  53. JvGroupHeader3: TJvGroupHeader;
  54. JvGroupHeader4: TJvGroupHeader;
  55. JvStandardPage5: TJvStandardPage;
  56. chkShowGutter: TCheckBox;
  57. chkShowLineNumbers: TCheckBox;
  58. chkLeadingZeros: TCheckBox;
  59. cboGutterColor: TColorBox;
  60. Label4: TLabel;
  61. txtGutterWidth: TEdit;
  62. Label3: TLabel;
  63. JvGroupHeader5: TJvGroupHeader;
  64. JvStandardPage6: TJvStandardPage;
  65. pnlPreview: TPanel;
  66. cboFonts: TComboBox;
  67. Label5: TLabel;
  68. cboFontSize: TComboBox;
  69. Label6: TLabel;
  70. JvGroupHeader6: TJvGroupHeader;
  71. JvStandardPage7: TJvStandardPage;
  72. synSample: TSynEdit;
  73. lstElement: TListBox;
  74. Label7: TLabel;
  75. chkBold: TCheckBox;
  76. chkItalic: TCheckBox;
  77. chkUnderline: TCheckBox;
  78. Label8: TLabel;
  79. cboForeground: TColorBox;
  80. Label9: TLabel;
  81. cboBackground: TColorBox;
  82. JvGroupHeader7: TJvGroupHeader;
  83. Label11: TLabel;
  84. cboColorSet: TComboBox;
  85. bitbtnDelete: TBitBtn;
  86. bitbtnSave: TBitBtn;
  87. bitbtnNew: TBitBtn;
  88. Splitter1: TSplitter;
  89. jvslAnimatedTabsSpeed: TJvxSlider;
  90. Label12: TLabel;
  91. Label13: TLabel;
  92. Label14: TLabel;
  93. chkShowStatusBar: TCheckBox;
  94. txtHomePage: TEdit;
  95. txtSearchPage: TEdit;
  96. chkHomePage: TCheckBox;
  97. chkSearchPage: TCheckBox;
  98. jvspinHistoryMaxAge: TJvSpinEdit;
  99. Label15: TLabel;
  100. Label16: TLabel;
  101. Label17: TLabel;
  102. txtTempFolder: TJvDotNetDirectoryEdit;
  103. JvStandardPage8: TJvStandardPage;
  104. JvGroupHeader15: TJvGroupHeader;
  105. jvspinMaxTablesSize: TJvSpinEdit;
  106. Label18: TLabel;
  107. chkAutoLoadLibBasic: TCheckBox;
  108. JvGroupHeader16: TJvGroupHeader;
  109. Panel3: TPanel;
  110. Bevel1: TBevel;
  111. Bevel2: TBevel;
  112. Bevel3: TBevel;
  113. Bevel4: TBevel;
  114. Bevel5: TBevel;
  115. Bevel6: TBevel;
  116. Bevel7: TBevel;
  117. Bevel8: TBevel;
  118. JvGroupHeader8: TJvGroupHeader;
  119. chkAutoLoadLibMath: TCheckBox;
  120. chkAutoLoadLibString: TCheckBox;
  121. chkAutoLoadLibTable: TCheckBox;
  122. chkAutoLoadLibOSIO: TCheckBox;
  123. chkAutoLoadLibDebug: TCheckBox;
  124. jvspinMaxSubTablesLevel: TJvSpinEdit;
  125. Label19: TLabel;
  126. chkAutoLoadLibPackage: TCheckBox;
  127. chkCheckCyclicReferencing: TCheckBox;
  128. JvGroupHeader9: TJvGroupHeader;
  129. chkShowStackTraceOnError: TCheckBox;
  130. procedure cboFontsMeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
  131. procedure cboFontsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
  132. procedure FormCreate(Sender: TObject);
  133. procedure cboFontsChange(Sender: TObject);
  134. procedure cboFontSizeKeyPress(Sender: TObject; var Key: Char);
  135. procedure cboFontSizeChange(Sender: TObject);
  136. procedure txtUndoLimitKeyPress(Sender: TObject; var Key: Char);
  137. procedure txtTabWidthKeyPress(Sender: TObject; var Key: Char);
  138. procedure txtGutterWidthKeyPress(Sender: TObject; var Key: Char);
  139. procedure btnOKClick(Sender: TObject);
  140. procedure chkShowGutterClick(Sender: TObject);
  141. procedure lstElementClick(Sender: TObject);
  142. procedure chkBoldClick(Sender: TObject);
  143. procedure chkItalicClick(Sender: TObject);
  144. procedure chkUnderlineClick(Sender: TObject);
  145. procedure cboForegroundChange(Sender: TObject);
  146. procedure cboBackgroundChange(Sender: TObject);
  147. procedure FormShow(Sender: TObject);
  148. procedure FormDestroy(Sender: TObject);
  149. procedure synEditSpecialLineColors(Sender: TObject; Line: Integer; var Special: Boolean; var FG, BG: TColor);
  150. procedure chkFileAssociateClick(Sender: TObject);
  151. procedure cboFontSizeMeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
  152. procedure btnBrowseLibrariesClick(Sender: TObject);
  153. procedure cboColorSetClick(Sender: TObject);
  154. procedure btnCancelClick(Sender: TObject);
  155. procedure bitbtnDeleteClick(Sender: TObject);
  156. procedure bitbtnNewClick(Sender: TObject);
  157. procedure bitbtnSaveClick(Sender: TObject);
  158. procedure chkHomePageClick(Sender: TObject);
  159. procedure chkSearchPageClick(Sender: TObject);
  160. private
  161. { Private declarations }
  162. public
  163. { Public declarations }
  164. procedure UMMeasureFonts(var msg: TMessage); message UM_MEASUREFONTS;
  165. procedure NotifyRestart(Notify: Boolean);
  166. procedure LoadEditorSettings(HandleColorSet: Boolean = True);
  167. procedure WriteEditorSettings;
  168. procedure WriteColorSet;
  169. procedure BuildColorSetList;
  170. end;
  171. var
  172. frmEditorSettings: TfrmEditorSettings;
  173. Options: TSynEditorOptions;
  174. lstEditorColorsTemp: TList;
  175. pTempUnit: TLuaEditUnit;
  176. implementation
  177. uses RegSetFileType, SearchPath;
  178. {$R *.dfm}
  179. procedure TfrmEditorSettings.UMMeasureFonts(var msg: TMessage);
  180. var
  181. i: Integer;
  182. MaxItemHeight: Integer;
  183. begin
  184. // use form canvas for measurements
  185. MaxItemHeight := 0;
  186. Canvas.Font.Size := 10;
  187. for i := 0 to cboFonts.Items.Count - 1 do
  188. begin
  189. Canvas.Font.Name := cboFonts.Items[i];
  190. if Canvas.TextHeight(cboFonts.Items[i]) > MaxItemHeight then
  191. MaxItemHeight := Canvas.TextHeight(cboFonts.Items[i]);
  192. cboFonts.Perform(CB_SETITEMHEIGHT, i, Canvas.TextHeight(cboFonts.Items[i]));
  193. end;
  194. for i := 0 to cboFontSize.Items.Count do
  195. begin
  196. cboFontSize.Perform(CB_SETITEMHEIGHT, MaxItemHeight, Canvas.TextHeight(cboFontSize.Items[i]));
  197. end;
  198. end;
  199. procedure TfrmEditorSettings.cboFontsMeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
  200. begin
  201. Height := (Control As TCombobox).ItemHeight+4;
  202. end;
  203. procedure TfrmEditorSettings.cboFontSizeMeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
  204. begin
  205. Height := (Control As TCombobox).ItemHeight+4;
  206. end;
  207. procedure TfrmEditorSettings.FormCreate(Sender: TObject);
  208. var
  209. HR: TSynLuaSyn;
  210. begin
  211. pTempUnit := TLuaEditUnit.Create('');
  212. pTempUnit.SynUnit.Free;
  213. pTempUnit.SynParams.Editor := synSample;
  214. pTempUnit.SynCompletion.Editor := synSample;
  215. pTempUnit.DebugPlugin := TDebugSupportPlugin.Create(synSample);
  216. pTempUnit.SynUnit := nil;
  217. pTempUnit.SynUnit := synSample;
  218. pTempUnit.DebugInfos.AddBreakpointAtLine(13);
  219. pTempUnit.DebugInfos.iLineError := 14;
  220. pTempUnit.DebugInfos.iCurrentLineDebug := 15;
  221. synSample.OnSpecialLineColors := synEditSpecialLineColors;
  222. synSample.Refresh;
  223. HR := TSynLuaSyn.Create(nil);
  224. synSample.Highlighter := HR;
  225. lstEditorColorsTemp := TList.Create;
  226. cboFonts.Items := Screen.Fonts;
  227. cboFonts.itemindex := 0;
  228. // Measure items after form has been shown
  229. PostMessage(Self.Handle, UM_MEASUREFONTS, 0, 0);
  230. // Fill color set list
  231. BuildColorSetList;
  232. end;
  233. procedure TfrmEditorSettings.synEditSpecialLineColors(Sender: TObject; Line: Integer; var Special: Boolean; var FG, BG: TColor);
  234. begin
  235. Special := False;
  236. if pTempUnit.DebugInfos.IsBreakPointLine(Line) then
  237. begin
  238. Special := True;
  239. BG := StringToColor(TEditorColors(lstEditorColorsTemp.Items[9]).Background);
  240. FG := StringToColor(TEditorColors(lstEditorColorsTemp.Items[9]).Foreground);
  241. end;
  242. if pTempUnit.DebugInfos.iCurrentLineDebug = Line then
  243. begin
  244. Special := True;
  245. BG := StringToColor(TEditorColors(lstEditorColorsTemp.Items[3]).Background);
  246. FG := StringToColor(TEditorColors(lstEditorColorsTemp.Items[3]).Foreground);
  247. end;
  248. if pTempUnit.DebugInfos.iLineError = Line then
  249. begin
  250. Special := True;
  251. BG := StringToColor(TEditorColors(lstEditorColorsTemp.Items[2]).Background);
  252. FG := StringToColor(TEditorColors(lstEditorColorsTemp.Items[2]).Foreground)
  253. end;
  254. end;
  255. procedure TfrmEditorSettings.cboFontsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
  256. var
  257. cb: TCombobox;
  258. begin
  259. cb := TCombobox(Control);
  260. cb.Canvas.FillRect(rect);
  261. if (index >= 0) and (index < cb.Items.Count) then
  262. begin
  263. if odComboBoxEdit in State then
  264. begin
  265. // Draw the edit portion of the control, use the controls
  266. // design-time font for this since the edit control is
  267. // fixed height and drawing a bunch of symbols if the selected
  268. // font is Symbol etc. is not very informative for the user.
  269. cb.Canvas.Font := cb.Font;
  270. if odSelected in State then
  271. cb.Canvas.Font.Color := clHighlightText;
  272. end
  273. else
  274. begin
  275. cb.Canvas.Font.Name := cb.Items[index];
  276. cb.Canvas.Font.Size := 10;
  277. end;
  278. cb.Canvas.TextRect(Rect, rect.left+2, rect.top+2, cb.Items[index]);
  279. end;
  280. end;
  281. procedure TfrmEditorSettings.cboFontsChange(Sender: TObject);
  282. begin
  283. cboFonts.Font.Name := cboFonts.Text;
  284. pnlPreview.Font.Name := cboFonts.Text;
  285. end;
  286. procedure TfrmEditorSettings.cboFontSizeKeyPress(Sender: TObject; var Key: Char);
  287. begin
  288. if not (Key in ['0'..'9', #8]) then
  289. Key := #0;
  290. end;
  291. procedure TfrmEditorSettings.cboFontSizeChange(Sender: TObject);
  292. begin
  293. if cboFontSize.Text <> '' then
  294. pnlPreview.Font.Size := StrToInt(cboFontSize.Text);
  295. end;
  296. procedure TfrmEditorSettings.txtUndoLimitKeyPress(Sender: TObject; var Key: Char);
  297. begin
  298. if not (Key in ['0'..'9', #8]) then
  299. Key := #0;
  300. end;
  301. procedure TfrmEditorSettings.txtTabWidthKeyPress(Sender: TObject; var Key: Char);
  302. begin
  303. if not (Key in ['0'..'9', #8]) then
  304. Key := #0;
  305. end;
  306. procedure TfrmEditorSettings.txtGutterWidthKeyPress(Sender: TObject; var Key: Char);
  307. begin
  308. if not (Key in ['0'..'9', #8]) then
  309. Key := #0;
  310. end;
  311. procedure TfrmEditorSettings.WriteEditorSettings;
  312. var
  313. pReg: TRegistry;
  314. x: Integer;
  315. begin
  316. Screen.Cursor := crHourGlass;
  317. pReg := TRegistry.Create();
  318. //Writing general settings
  319. if chkAutoIndent.Checked then
  320. Options := Options + [eoAutoIndent]
  321. else
  322. Options := Options - [eoAutoIndent];
  323. if chkGroupUndo.Checked then
  324. Options := Options + [eoGroupUndo]
  325. else
  326. Options := Options - [eoGroupUndo];
  327. if chkScrollPastEOF.Checked then
  328. Options := Options + [eoScrollPastEof]
  329. else
  330. Options := Options - [eoScrollPastEof];
  331. if chkHideScrollBars.Checked then
  332. Options := Options + [eoHideShowScrollbars]
  333. else
  334. Options := Options - [eoHideShowScrollbars];
  335. if chkTrailBlanks.Checked then
  336. Options := Options - [eoTrimTrailingSpaces]
  337. else
  338. Options := Options + [eoTrimTrailingSpaces];
  339. if chkTabIndent.Checked then
  340. Options := Options + [eoTabIndent]
  341. else
  342. Options := Options - [eoTabIndent];
  343. if chkEHomeKey.Checked then
  344. Options := Options + [eoEnhanceHomeKey]
  345. else
  346. Options := Options - [eoEnhanceHomeKey];
  347. if chkSmartTab.Checked then
  348. Options := Options + [eoSmartTabs]
  349. else
  350. Options := Options - [eoSmartTabs];
  351. if chkTabsToSpaces.Checked then
  352. Options := Options + [eoTabsToSpaces]
  353. else
  354. Options := Options - [eoTabsToSpaces];
  355. if chkScrollPastEOL.Checked then
  356. Options := Options + [eoScrollPastEol]
  357. else
  358. Options := Options - [eoScrollPastEol];
  359. if chkKeepCaretX.Checked then
  360. Options := Options + [eoKeepCaretX]
  361. else
  362. Options := Options - [eoKeepCaretX];
  363. if chkRightMouseMovesCursor.Checked then
  364. Options := Options + [eoRightMouseMovesCursor]
  365. else
  366. Options := Options - [eoRightMouseMovesCursor];
  367. pReg.OpenKey('\Software\LuaEdit\EditorSettings\General', True);
  368. pReg.WriteInteger('EditorOptions', Integer(Options));
  369. pReg.WriteInteger('UndoLimit', StrToInt(txtUndoLimit.Text));
  370. pReg.WriteInteger('TabWidth', StrToInt(txtTabWidth.Text));
  371. pReg.WriteInteger('AnimatedTabsSpeed', 2001 - jvslAnimatedTabsSpeed.Value);
  372. pReg.WriteInteger('HistoryMaxAge', Trunc(jvspinHistoryMaxAge.Value));
  373. pReg.WriteBool('SaveProjectsInc', chkSaveProjectsInc.Checked);
  374. pReg.WriteBool('SaveBreakpoints', chkSaveBreakpoints.Checked);
  375. pReg.WriteBool('SaveUnitsInc', chkSaveUnitsInc.Checked);
  376. pReg.WriteBool('AssociateFiles', chkFileAssociate.Checked);
  377. pReg.WriteBool('ShowExSaveDlg', chkShowExSaveDlg.Checked);
  378. pReg.WriteBool('KeepSIFWindowOpened', chkKeepReportOpened.Checked);
  379. pReg.WriteBool('ShowStatusBar', chkShowStatusBar.Checked);
  380. pReg.WriteString('HomePage', txtHomePage.Text);
  381. pReg.WriteString('SearchPage', txtSearchPage.Text);
  382. pReg.WriteString('TempFolder', txtTempFolder.Text);
  383. // Clean up old temporary folder if set to new one
  384. if TempFolder <> txtTempFolder.Text then
  385. frmLuaEditMain.CleanUpTempDir();
  386. if AssociateFiles <> chkFileAssociate.Checked then
  387. begin
  388. if chkFileAssociate.Checked then
  389. begin
  390. // Register file association for .lpr files
  391. RegSetAssociation('.lpr', 'LuaEdit.lpr', 'LuaEdit Project', 'LuaEdit/LuaEdit.lpr', PChar(GetLuaEditInstallPath() + '\Graphics\Project.ico'));
  392. RegSetOpenWith('LuaEdit.lpr', PChar(Application.ExeName+ ' "%1"'));
  393. // Register file association for .lua files
  394. RegSetAssociation('.lua', 'LuaEdit.lua', 'LuaEdit Unit', 'LuaEdit/LuaEdit.lua', PChar(GetLuaEditInstallPath() + '\Graphics\Unit.ico'));
  395. RegSetOpenWith('LuaEdit.lua', PChar(Application.ExeName + ' "%1"'));
  396. // Register file association for .lmc files
  397. RegSetAssociation('.lmc', 'LuaEdit.lmc', 'LuaEdit Macro', 'LuaEdit/LuaEdit.lmc', PChar(GetLuaEditInstallPath() + '\Graphics\LuaMacros.ico'));
  398. RegSetOpenWith('LuaEdit.lmc', PChar(Application.ExeName + ' "%1"'));
  399. // Register file association for .gui files
  400. RegSetAssociation('.gui', 'LuaEdit.gui', 'LuaEdit GUI Form', 'LuaEdit/LuaEdit.gui', PChar(GetLuaEditInstallPath() + '\Graphics\LuaGUIForm.ico'));
  401. RegSetOpenWith('LuaEdit.gui', PChar(Application.ExeName + ' "%1"'));
  402. end
  403. else
  404. begin
  405. // Clear file association registration for .lpr files
  406. RegClearIEOpenKey('.lpr');
  407. RegClearAssociation('.lpr', 'LuaEdit.lpr');
  408. // Clear file association registration for .lua files
  409. RegClearIEOpenKey('.lua');
  410. RegClearAssociation('.lua', 'LuaEdit.lua');
  411. // Clear file association registration for .lmc files
  412. RegClearIEOpenKey('.lmc');
  413. RegClearAssociation('.lmc', 'LuaEdit.lmc');
  414. // Clear file association registration for .gui files
  415. RegClearIEOpenKey('.gui');
  416. RegClearAssociation('.gui', 'LuaEdit.gui');
  417. end;
  418. if Application.MessageBox('You must restart your computer for some of the changes to take effect. Do you want to restart your computer now?', 'LuaEdit', MB_ICONQUESTION+MB_YESNO) = IDYES then
  419. begin
  420. if not WinExit(EWX_REBOOT) then
  421. Application.MessageBox('LuaEdit was unable to restart your computer!', 'LuaEdit', MB_OK+MB_ICONERROR);
  422. end;
  423. end;
  424. // Writing environement settings
  425. pReg.OpenKey('\Software\LuaEdit\EditorSettings\Environment', True);
  426. {if txtLibraries.Text[1] = '"' then
  427. txtLibraries.Text := Copy(txtLibraries.Text, 2, Length(txtLibraries.Text));
  428. if txtLibraries.Text[Length(txtLibraries.Text)] = '"' then
  429. txtLibraries.Text := Copy(txtLibraries.Text, 1, Length(txtLibraries.Text) - 1);}
  430. pReg.WriteString('LibrariesSearchPaths', txtLibraries.Text);
  431. // Writing debugger settings
  432. pReg.OpenKey('\Software\LuaEdit\EditorSettings\Debugger', True);
  433. pReg.WriteInteger('MaxTablesSize', Trunc(jvspinMaxTablesSize.Value));
  434. pReg.WriteInteger('MaxSubTablesLevel', Trunc(jvspinMaxSubTablesLevel.Value));
  435. pReg.WriteBool('CheckCyclicReferencing', chkCheckCyclicReferencing.Checked);
  436. pReg.WriteBool('AutoLoadLibBasic', chkAutoLoadLibBasic.Checked);
  437. pReg.WriteBool('AutoLoadLibPackage', chkAutoLoadLibPackage.Checked);
  438. pReg.WriteBool('AutoLoadLibTable', chkAutoLoadLibTable.Checked);
  439. pReg.WriteBool('AutoLoadLibString', chkAutoLoadLibString.Checked);
  440. pReg.WriteBool('AutoLoadLibMath', chkAutoLoadLibMath.Checked);
  441. pReg.WriteBool('AutoLoadLibOSIO', chkAutoLoadLibOSIO.Checked);
  442. pReg.WriteBool('AutoLoadLibDebug', chkAutoLoadLibDebug.Checked);
  443. pReg.WriteBool('ShowStackTraceOnError', chkShowStackTraceOnError.Checked);
  444. //Writing display settings
  445. pReg.OpenKey('\Software\LuaEdit\EditorSettings\Display', True);
  446. pReg.WriteBool('ShowGutter', chkShowGutter.Checked);
  447. pReg.WriteBool('ShowLineNumbers', chkShowLineNumbers.Checked);
  448. pReg.WriteBool('LeadingZeros', chkLeadingZeros.Checked);
  449. pReg.WriteInteger('GutterWidth', StrToInt(txtGutterWidth.Text));
  450. pReg.WriteString('GutterColor', ColorToString(cboGutterColor.Selected));
  451. pReg.WriteString('FontName', cboFonts.Text);
  452. pReg.WriteInteger('FontSize', StrToInt(cboFontSize.Text));
  453. pReg.WriteString('ColorSet', cboColorSet.Text);
  454. pReg.Free;
  455. WriteColorSet;
  456. frmLuaEditMain.LoadEditorSettingsFromReg;
  457. for x := 0 to LuaOpenedFiles.Count - 1 do
  458. frmLuaEditMain.ApplyValuesToEditor(TLuaEditUnit(LuaOpenedFiles.Items[x]).synUnit, EditorColors);
  459. Screen.Cursor := crDefault;
  460. end;
  461. procedure TfrmEditorSettings.WriteColorSet;
  462. var
  463. pColorSet: TIniFile;
  464. x: Integer;
  465. begin
  466. // Create .\Data directory if innexistant
  467. if not DirectoryExists(GetLuaEditInstallPath()+'\Data') then
  468. CreateDirectory(PChar(GetLuaEditInstallPath()+'\Data'), nil);
  469. // Creating/opening file
  470. pColorSet := TIniFile.Create(GetLuaEditInstallPath()+'\Data\' + cboColorSet.Text + '.dat');
  471. //Writing colors settings
  472. for x := 0 to lstElement.Items.Count - 1 do
  473. begin
  474. pColorSet.WriteBool(lstElement.Items.Strings[x], 'IsBold', TEditorColors(lstElement.Items.Objects[x]).IsBold);
  475. pColorSet.WriteBool(lstElement.Items.Strings[x], 'IsItalic', TEditorColors(lstElement.Items.Objects[x]).IsItalic);
  476. pColorSet.WriteBool(lstElement.Items.Strings[x], 'IsUnderline', TEditorColors(lstElement.Items.Objects[x]).IsUnderline);
  477. pColorSet.WriteString(lstElement.Items.Strings[x], 'ForegroundColor', TEditorColors(lstElement.Items.Objects[x]).Foreground);
  478. pColorSet.WriteString(lstElement.Items.Strings[x], 'BackgroundColor', TEditorColors(lstElement.Items.Objects[x]).Background);
  479. end;
  480. pColorSet.UpdateFile;
  481. pColorSet.Free;
  482. end;
  483. procedure TfrmEditorSettings.LoadEditorSettings(HandleColorSet: Boolean {= True});
  484. var
  485. x: Integer;
  486. begin
  487. lstEditorColorsTemp.Assign(EditorColors);
  488. Options := EditorOptions;
  489. if eoAutoIndent in Options then
  490. chkAutoIndent.Checked := True
  491. else
  492. chkAutoIndent.Checked := False;
  493. if eoGroupUndo in Options then
  494. chkGroupUndo.Checked := True
  495. else
  496. chkGroupUndo.Checked := False;
  497. if eoTabIndent in Options then
  498. chkTabIndent.Checked := True
  499. else
  500. chkTabIndent.Checked := False;
  501. if eoSmartTabs in Options then
  502. chkSmartTab.Checked := True
  503. else
  504. chkSmartTab.Checked := False;
  505. if eoRightMouseMovesCursor in Options then
  506. chkRightMouseMovesCursor.Checked := True
  507. else
  508. chkRightMouseMovesCursor.Checked := False;
  509. if eoEnhanceHomeKey in Options then
  510. chkEHomeKey.Checked := True
  511. else
  512. chkEHomeKey.Checked := False;
  513. if eoTabsToSpaces in Options then
  514. chkTabsToSpaces.Checked := True
  515. else
  516. chkTabsToSpaces.Checked := False;
  517. if eoHideShowScrollbars in Options then
  518. chkHideScrollBars.Checked := True
  519. else
  520. chkHideScrollBars.Checked := False;
  521. if eoScrollPastEof in Options then
  522. chkScrollPastEOF.Checked := True
  523. else
  524. chkScrollPastEOF.Checked := False;
  525. if eoScrollPastEol in Options then
  526. chkScrollPastEOL.Checked := True
  527. else
  528. chkScrollPastEOL.Checked := False;
  529. if eoKeepCaretX in Options then
  530. chkKeepCaretX.Checked := True
  531. else
  532. chkKeepCaretX.Checked := False;
  533. if eoTrimTrailingSpaces in Options then
  534. chkTrailBlanks.Checked := True
  535. else
  536. chkTrailBlanks.Checked := False;
  537. chkFileAssociate.Checked := AssociateFiles;
  538. chkSaveProjectsInc.Checked := SaveProjectsInc;
  539. chkSaveUnitsInc.Checked := SaveUnitsInc;
  540. chkShowExSaveDlg.Checked := ShowExSaveDlg;
  541. chkSaveBreakpoints.Checked := SaveBreakpoints;
  542. chkKeepReportOpened.Checked := KeepSIFWindowOpened;
  543. chkShowStatusBar.Checked := ShowStatusBar;
  544. jvslAnimatedTabsSpeed.Value := 2001 - AnimatedTabsSpeed;
  545. txtUndoLimit.Text := IntToStr(Main.UndoLimit);
  546. txtTabWidth.Text := IntToStr(Main.TabWidth);
  547. chkShowGutter.Checked := Main.ShowGutter;
  548. chkShowLineNumbers.Checked := Main.ShowLineNumbers;
  549. chkLeadingZeros.Checked := Main.LeadingZeros;
  550. txtGutterWidth.Text := IntToStr(Main.GutterWidth);
  551. cboGutterColor.Selected := StringToColor(Main.GutterColor);
  552. cboFonts.ItemIndex := cboFonts.Items.IndexOf(Main.FontName);
  553. cboFontSize.ItemIndex := cboFontSize.Items.IndexOf(IntToStr(Main.FontSize));
  554. txtHomePage.Text := HomePage;
  555. chkHomePage.Checked := (txtHomePage.Text <> '');
  556. txtHomePage.Enabled := chkHomePage.Checked;
  557. txtSearchPage.Text := SearchPage;
  558. chkSearchPage.Checked := (txtSearchPage.Text <> '');
  559. txtSearchPage.Enabled := chkSearchPage.Checked;
  560. txtTempFolder.Text := TempFolder;
  561. jvspinHistoryMaxAge.Value := HistoryMaxAge;
  562. jvspinMaxTablesSize.Value := MaxTablesSize;
  563. chkCheckCyclicReferencing.Checked := CheckCyclicReferencing;
  564. jvspinMaxSubTablesLevel.Value := MaxSubTablesLevel;
  565. chkAutoLoadLibBasic.Checked := AutoLoadLibBasic;
  566. chkAutoLoadLibPackage.Checked := AutoLoadLibPackage;
  567. chkAutoLoadLibTable.Checked := AutoLoadLibTable;
  568. chkAutoLoadLibString.Checked := AutoLoadLibString;
  569. chkAutoLoadLibMath.Checked := AutoLoadLibMath;
  570. chkAutoLoadLibOSIO.Checked := AutoLoadLibOSIO;
  571. chkAutoLoadLibDebug.Checked := AutoLoadLibDebug;
  572. chkShowStackTraceOnError.Checked := ShowStackTraceOnError;
  573. // Manage serach paths
  574. txtLibraries.Text := '';
  575. for x := 0 to LibrariesSearchPaths.Count - 1 do
  576. begin
  577. txtLibraries.Text := txtLibraries.Text + '"' + LibrariesSearchPaths.Strings[x];
  578. if x < LibrariesSearchPaths.Count - 1 then
  579. txtLibraries.Text := txtLibraries.Text + '", '
  580. else
  581. txtLibraries.Text := txtLibraries.Text + '"';
  582. end;
  583. // Manage colorset
  584. if HandleColorSet then
  585. begin
  586. for x := 0 to cboColorSet.Items.Count - 1 do
  587. begin
  588. if Main.ColorSet = cboColorSet.Items[x] then
  589. cboColorSet.ItemIndex := x;
  590. end;
  591. end;
  592. lstElement.Items.Clear;
  593. lstElement.Items.AddObject('Background', lstEditorColorsTemp.Items[0]);
  594. lstElement.Items.AddObject('Comment', lstEditorColorsTemp.Items[1]);
  595. lstElement.Items.AddObject('Error Line', lstEditorColorsTemp.Items[2]);
  596. lstElement.Items.AddObject('Execution Line', lstEditorColorsTemp.Items[3]);
  597. lstElement.Items.AddObject('Identifier', lstEditorColorsTemp.Items[4]);
  598. lstElement.Items.AddObject('Numbers', lstEditorColorsTemp.Items[5]);
  599. lstElement.Items.AddObject('Reserved Words', lstEditorColorsTemp.Items[6]);
  600. lstElement.Items.AddObject('Selection', lstEditorColorsTemp.Items[7]);
  601. lstElement.Items.AddObject('Strings', lstEditorColorsTemp.Items[8]);
  602. lstElement.Items.AddObject('Valid Breakpoint', lstEditorColorsTemp.Items[9]);
  603. frmLuaEditMain.ApplyValuesToEditor(synSample, lstEditorColorsTemp);
  604. lstElement.ItemIndex := 0;
  605. lstElementClick(lstElement);
  606. end;
  607. procedure TfrmEditorSettings.btnOKClick(Sender: TObject);
  608. begin
  609. ModalResult := mrNone;
  610. if ((txtUndoLimit.Text = '0') or (txtUndoLimit.Text = '')) then
  611. begin
  612. jvPageListSettings.ActivePageIndex := 1;
  613. Application.MessageBox('The limit of undo must be higher than zero.', 'LuaEdit', MB_OK+MB_ICONERROR);
  614. txtUndoLimit.SetFocus;
  615. end
  616. else if ((txtTabWidth.Text = '0') or (txtTabWidth.Text = '')) then
  617. begin
  618. jvPageListSettings.ActivePageIndex := 1;
  619. Application.MessageBox('The tab width must be higher than zero.', 'LuaEdit', MB_OK+MB_ICONERROR);
  620. txtTabWidth.SetFocus;
  621. end
  622. else if ((txtGutterWidth.Text = '0') or (txtGutterWidth.Text = '')) then
  623. begin
  624. jvPageListSettings.ActivePageIndex := 4;
  625. Application.MessageBox('The gutter width must be higher than zero.', 'LuaEdit', MB_OK+MB_ICONERROR);
  626. txtGutterWidth.SetFocus;
  627. end
  628. else if cboColorSet.Text = '' then
  629. begin
  630. jvPageListSettings.ActivePageIndex := 6;
  631. Application.MessageBox('The color set name can''t be empty.', 'LuaEdit', MB_OK+MB_ICONERROR);
  632. cboColorSet.SetFocus;
  633. end
  634. else
  635. begin
  636. WriteEditorSettings;
  637. ModalResult := mrOk;
  638. end;
  639. end;
  640. procedure TfrmEditorSettings.chkShowGutterClick(Sender: TObject);
  641. begin
  642. cboGutterColor.Enabled := chkShowGutter.Checked;
  643. txtGutterWidth.Enabled := chkShowGutter.Checked;
  644. chkShowLineNumbers.Enabled := chkShowGutter.Checked;
  645. chkLeadingZeros.Enabled := chkShowGutter.Checked;
  646. Label3.Enabled := chkShowGutter.Checked;
  647. Label4.Enabled := chkShowGutter.Checked;
  648. end;
  649. procedure TfrmEditorSettings.lstElementClick(Sender: TObject);
  650. var
  651. SelName: String;
  652. begin
  653. chkBold.Checked := TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).IsBold;
  654. chkItalic.Checked := TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).IsItalic;
  655. chkUnderline.Checked := TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).IsUnderline;
  656. cboForeground.Selected := StringToColor(TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).Foreground);
  657. cboBackground.Selected := StringToColor(TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).Background);
  658. SelName := lstElement.Items.Strings[lstElement.ItemIndex];
  659. if SelName = 'Background' then
  660. begin
  661. chkBold.Enabled := False;
  662. chkItalic.Enabled := False;
  663. chkUnderline.Enabled := False;
  664. cboForeground.Enabled := False;
  665. Label8.Enabled := False;
  666. cboBackground.Enabled := True;
  667. end
  668. else if ((SelName = 'Selection') or (SelName = 'Breakpoints') or (SelName = 'Error Line') or (SelName = 'Execution Line')) then
  669. begin
  670. chkBold.Enabled := False;
  671. chkItalic.Enabled := False;
  672. chkUnderline.Enabled := False;
  673. Label8.Enabled := True;
  674. cboForeground.Enabled := True;
  675. cboBackground.Enabled := True;
  676. end
  677. else
  678. begin
  679. chkBold.Enabled := True;
  680. chkItalic.Enabled := True;
  681. chkUnderline.Enabled := True;
  682. Label8.Enabled := True;
  683. cboForeground.Enabled := True;
  684. cboBackground.Enabled := True;
  685. end;
  686. end;
  687. procedure TfrmEditorSettings.chkBoldClick(Sender: TObject);
  688. begin
  689. TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).IsBold := chkBold.Checked;
  690. lstEditorColorsTemp.Items[lstElement.ItemIndex] := TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]);
  691. frmLuaEditMain.ApplyValuesToEditor(synSample, lstEditorColorsTemp);
  692. end;
  693. procedure TfrmEditorSettings.chkItalicClick(Sender: TObject);
  694. begin
  695. TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).IsItalic := chkItalic.Checked;
  696. lstEditorColorsTemp.Items[lstElement.ItemIndex] := TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]);
  697. frmLuaEditMain.ApplyValuesToEditor(synSample, lstEditorColorsTemp);
  698. end;
  699. procedure TfrmEditorSettings.chkUnderlineClick(Sender: TObject);
  700. begin
  701. TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).IsUnderline := chkUnderline.Checked;
  702. lstEditorColorsTemp.Items[lstElement.ItemIndex] := TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]);
  703. frmLuaEditMain.ApplyValuesToEditor(synSample, lstEditorColorsTemp);
  704. end;
  705. procedure TfrmEditorSettings.cboForegroundChange(Sender: TObject);
  706. begin
  707. TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).Foreground := ColorToString(cboForeground.Selected);
  708. lstEditorColorsTemp.Items[lstElement.ItemIndex] := TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]);
  709. frmLuaEditMain.ApplyValuesToEditor(synSample, lstEditorColorsTemp);
  710. end;
  711. procedure TfrmEditorSettings.cboBackgroundChange(Sender: TObject);
  712. begin
  713. TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]).Background := ColorToString(cboBackground.Selected);
  714. lstEditorColorsTemp.Items[lstElement.ItemIndex] := TEditorColors(lstElement.Items.Objects[lstElement.ItemIndex]);
  715. frmLuaEditMain.ApplyValuesToEditor(synSample, lstEditorColorsTemp);
  716. end;
  717. procedure TfrmEditorSettings.FormShow(Sender: TObject);
  718. begin
  719. jvPageListSettings.ActivePageIndex := 0;
  720. jvSettingsTVSettings.Selected := jvSettingsTVSettings.Items[1];
  721. lstEditorColorsTemp.Clear;
  722. BuildColorSetList;
  723. // Initializing settings
  724. LoadEditorSettings;
  725. // Hide notification
  726. NotifyRestart(False);
  727. end;
  728. procedure TfrmEditorSettings.BuildColorSetList;
  729. var
  730. srSearchRec: TSearchRec;
  731. begin
  732. cboColorSet.Clear;
  733. // Fill content of ColorSet combo box
  734. if FindFirst(GetLuaEditInstallPath()+'\Data\*.dat', faAnyFile, srSearchRec) = 0 then
  735. begin
  736. repeat
  737. cboColorSet.AddItem(Copy(srSearchRec.Name, 1, Length(srSearchRec.Name) - 4), nil);
  738. until FindNext(srSearchRec) <> 0;
  739. end;
  740. end;
  741. procedure TfrmEditorSettings.FormDestroy(Sender: TObject);
  742. begin
  743. lstEditorColorsTemp.Free;
  744. pTempUnit.Free;
  745. end;
  746. procedure TfrmEditorSettings.NotifyRestart(Notify: Boolean);
  747. begin
  748. lblNotify.Visible := Notify;
  749. imgNotify.Visible := Notify;
  750. end;
  751. procedure TfrmEditorSettings.chkFileAssociateClick(Sender: TObject);
  752. begin
  753. if chkFileAssociate.Checked <> AssociateFiles then
  754. NotifyRestart(True)
  755. else
  756. NotifyRestart(False);
  757. end;
  758. procedure TfrmEditorSettings.btnBrowseLibrariesClick(Sender: TObject);
  759. begin
  760. // Initialize search path form
  761. frmSearchPath := TfrmSearchPath.Create(nil);
  762. frmSearchPath.InitSearchPathForm(txtLibraries.Text, 'Libraries Search Paths', 'Select libraries search paths for LuaEdit to use when looking for *.lib files:');
  763. // Show form and replace current path string by the new one
  764. if frmSearchPath.ShowModal = mrOk then
  765. txtLibraries.Text := frmSearchPath.GetSearchPathString;
  766. // Free search path form
  767. frmSearchPath.Free;
  768. end;
  769. procedure TfrmEditorSettings.cboColorSetClick(Sender: TObject);
  770. begin
  771. frmLuaEditMain.GetColorSet(cboColorSet.Items[cboColorSet.ItemIndex]);
  772. LoadEditorSettings(False);
  773. end;
  774. procedure TfrmEditorSettings.btnCancelClick(Sender: TObject);
  775. begin
  776. frmLuaEditMain.LoadEditorSettingsFromReg;
  777. end;
  778. procedure TfrmEditorSettings.bitbtnDeleteClick(Sender: TObject);
  779. begin
  780. if Application.MessageBox(PChar('Are you sure you want to delete color set "' + cboColorSet.Text + '"?'), 'LuaEdit', MB_ICONQUESTION+MB_YESNO) = IDYES then
  781. begin
  782. DeleteFile(GetLuaEditInstallPath()+'\Data\'+cboColorSet.Text+'.dat');
  783. BuildColorSetList;
  784. cboColorSet.ItemIndex := 0;
  785. end;
  786. end;
  787. procedure TfrmEditorSettings.bitbtnNewClick(Sender: TObject);
  788. var
  789. sColorSet: String;
  790. x: Integer;
  791. begin
  792. sColorSet := 'New Color Set';
  793. if InputQuery('Add Color Set', 'Enter the name of the new color set:', sColorSet) then
  794. begin
  795. if sColorSet <> '' then
  796. begin
  797. if not FileExistsAbs(GetLuaEditInstallPath()+'\Data\'+sColorSet+'.dat') then
  798. begin
  799. if not DirectoryExists(GetLuaEditInstallPath()+'\Data\') then
  800. CreateDirectory(PChar(GetLuaEditInstallPath()+'\Data\'), nil);
  801. CloseHandle(CreateFile(PChar(GetLuaEditInstallPath()+'\Data\'+sColorSet+'.dat'), GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_NEW, 0, 0));
  802. BuildColorSetList;
  803. for x := 0 to cboColorSet.Items.Count - 1 do
  804. begin
  805. if sColorSet = cboColorSet.Items[x] then
  806. cboColorSet.ItemIndex := x;
  807. end;
  808. frmLuaEditMain.GetColorSet(cboColorSet.Items[cboColorSet.ItemIndex]);
  809. LoadEditorSettings;
  810. end
  811. else
  812. Application.MessageBox('The specified color set name already exists!', 'LuaEdit', MB_ICONERROR);
  813. end
  814. else
  815. Application.MessageBox('Invalid color set name!', 'LuaEdit', MB_ICONERROR);
  816. end;
  817. end;
  818. procedure TfrmEditorSettings.bitbtnSaveClick(Sender: TObject);
  819. begin
  820. if Application.MessageBox(PChar('Save changes to "' + cboColorSet.Text + '"?'), 'LuaEdit', MB_ICONQUESTION+MB_YESNO) = IDYES then
  821. WriteColorSet;
  822. {if cboColorSet.Items.Count > 0 then
  823. begin
  824. cboColorSet.ItemIndex := 0;
  825. TfrmLuaEditMain.GetColorSet(cboColorSet.Items[cboColorSet.ItemIndex]);
  826. LoadEditorSettings;
  827. end;}
  828. end;
  829. procedure TfrmEditorSettings.chkHomePageClick(Sender: TObject);
  830. begin
  831. if not chkHomePage.Checked then
  832. txtHomePage.Text := '';
  833. txtHomePage.Enabled := chkHomePage.Checked;
  834. end;
  835. procedure TfrmEditorSettings.chkSearchPageClick(Sender: TObject);
  836. begin
  837. if not chkSearchPage.Checked then
  838. txtSearchPage.Text := '';
  839. txtSearchPage.Enabled := chkSearchPage.Checked;
  840. end;
  841. end.