PreferencesUnit.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. {
  2. TIGCC IDE
  3. Copyright (C) 2000-2004 Sebastian Reichelt
  4. Copyright (C) 2006 Kevin Kofler
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. }
  17. unit PreferencesUnit;
  18. interface
  19. uses
  20. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  21. StdCtrls, ExtCtrls, ComCtrls, SourceEditUnit{$IFDEF CODINGEXT}, PrefFrame{$ENDIF};
  22. type
  23. TPreferencesForm = class(TForm)
  24. OKButton: TButton;
  25. CancelButton: TButton;
  26. ColorDlg: TColorDialog;
  27. FontDlg: TFontDialog;
  28. PageController: TPageControl;
  29. GeneralSheet: TTabSheet;
  30. StopCompilationBox: TCheckBox;
  31. FlatButtonsCheckBox: TCheckBox;
  32. MenuBitmapsCheckBox: TCheckBox;
  33. AutoSaveCheckBox: TCheckBox;
  34. EditorSheet: TTabSheet;
  35. Label2: TLabel;
  36. CTabSizeEdit: TEdit;
  37. ColorCheckBox: TCheckBox;
  38. ChangeColorButton: TButton;
  39. Label3: TLabel;
  40. ChangeFontButton: TButton;
  41. FontLabel: TPanel;
  42. SyntaxHighlightingSheet: TTabSheet;
  43. Label4: TLabel;
  44. ASMTabSizeEdit: TEdit;
  45. LanguageSelectionBox: TComboBox;
  46. Label5: TLabel;
  47. SyntaxEnabledBox: TCheckBox;
  48. Button1: TButton;
  49. Button2: TButton;
  50. Button3: TButton;
  51. Button4: TButton;
  52. Button5: TButton;
  53. Button6: TButton;
  54. ObjectTree: TTreeView;
  55. Button7: TButton;
  56. Button8: TButton;
  57. Button9: TButton;
  58. OKTimer: TTimer;
  59. OpenFolderBox: TCheckBox;
  60. DeleteObjectFilesBox: TCheckBox;
  61. ResetButton: TButton;
  62. OnFlyCheckBox: TCheckBox;
  63. DeleteErrorsCheckBox: TCheckBox;
  64. AutoBlockCheckBox: TCheckBox;
  65. SplitFilesCheckBox: TCheckBox;
  66. DeleteAssemblyFilesBox: TCheckBox;
  67. AllowImplicitCheckBox: TCheckBox;
  68. AutoNewsCheckBox: TCheckBox;
  69. TransferSheet: TTabSheet;
  70. TargetBox: TGroupBox;
  71. VTIBox: TRadioButton;
  72. RealCalcBox: TRadioButton;
  73. PortBox: TGroupBox;
  74. PortCOM1Box: TRadioButton;
  75. PortCOM2Box: TRadioButton;
  76. PortCOM3Box: TRadioButton;
  77. PortCOM4Box: TRadioButton;
  78. CableBox: TGroupBox;
  79. CableBlackBox: TRadioButton;
  80. CableGrayBox: TRadioButton;
  81. NoneBox: TRadioButton;
  82. VTIPathEdit: TEdit;
  83. VTIPathBrowseButton: TButton;
  84. BrowseDlg: TOpenDialog;
  85. DragDropEditCheckBox: TCheckBox;
  86. RemoveTrailingSpcCheckBox: TCheckBox;
  87. JumpToErrorBox: TCheckBox;
  88. procedure ColorCheckBoxClick(Sender: TObject);
  89. procedure ChangeColorButtonClick(Sender: TObject);
  90. procedure ChangeFontButtonClick(Sender: TObject);
  91. procedure FormCreate(Sender: TObject);
  92. procedure FormDestroy(Sender: TObject);
  93. procedure FormShow(Sender: TObject);
  94. procedure LanguageSelectionBoxChange(Sender: TObject);
  95. procedure ObjectTreeChange(Sender: TObject; Node: TTreeNode);
  96. procedure SyntaxEnabledBoxClick(Sender: TObject);
  97. procedure Button1Click(Sender: TObject);
  98. procedure Button3Click(Sender: TObject);
  99. procedure Button2Click(Sender: TObject);
  100. procedure Button4Click(Sender: TObject);
  101. procedure Button6Click(Sender: TObject);
  102. procedure Button5Click(Sender: TObject);
  103. procedure ObjectTreeKeyDown(Sender: TObject; var Key: Word;
  104. Shift: TShiftState);
  105. procedure EditItem(Sender: TObject);
  106. procedure Button7Click(Sender: TObject);
  107. procedure Button8Click(Sender: TObject);
  108. procedure ObjectTreeEdited(Sender: TObject; Node: TTreeNode;
  109. var S: String);
  110. procedure ObjectTreeEditing(Sender: TObject; Node: TTreeNode;
  111. var AllowEdit: Boolean);
  112. procedure OKTimerTimer(Sender: TObject);
  113. procedure ResetButtonClick(Sender: TObject);
  114. procedure PageControllerChange(Sender: TObject);
  115. procedure TargetBoxClick(Sender: TObject);
  116. procedure VTIPathBrowseButtonClick(Sender: TObject);
  117. private
  118. public
  119. BackColor: TColor;
  120. EditorFont: TFont;
  121. SyntaxC: TSyntaxColoring;
  122. SyntaxAsmGNU: TSyntaxColoring;
  123. SyntaxAsm: TSyntaxColoring;
  124. SyntaxQuill: TSyntaxColoring;
  125. Syntax: TSyntaxColoring;
  126. SyntaxTabClicked: Boolean;
  127. {$IFDEF CODINGEXT}
  128. procedure InitCodingExt;
  129. {$ENDIF}
  130. end;
  131. implementation
  132. {$R *.DFM}
  133. uses
  134. MasterUnit,
  135. UtilsDos, UtilsWin,
  136. MainUnit, StyleSelectionUnit, ColorsUnit, CustomStyleUnit, WordListUnit;
  137. procedure TPreferencesForm.ColorCheckBoxClick(Sender: TObject);
  138. begin
  139. ChangeColorButton.Enabled := ColorCheckBox.Checked;
  140. end;
  141. procedure TPreferencesForm.ChangeColorButtonClick(Sender: TObject);
  142. begin
  143. with ColorDlg do begin
  144. Color := BackColor;
  145. if Execute then
  146. BackColor := Color;
  147. end;
  148. end;
  149. procedure TPreferencesForm.ChangeFontButtonClick(Sender: TObject);
  150. begin
  151. with FontDlg do begin
  152. Font.Assign (EditorFont);
  153. if Execute then begin
  154. EditorFont.Assign (Font);
  155. FontLabel.Caption := EditorFont.Name;
  156. FontLabel.Font.Assign (EditorFont);
  157. end;
  158. end;
  159. end;
  160. procedure TPreferencesForm.FormCreate(Sender: TObject);
  161. begin
  162. EditorFont := TFont.Create;
  163. SyntaxC := TSyntaxColoring.Create (nil);
  164. SyntaxAsm := TSyntaxColoring.Create (nil);
  165. SyntaxAsmGNU := TSyntaxColoring.Create (nil);
  166. SyntaxQuill := TSyntaxColoring.Create (nil);
  167. if ssA68k in SpecialSupport then
  168. LanguageSelectionBox.Items.Add ('A68k ASM Files');
  169. if ssQuill in SpecialSupport then
  170. LanguageSelectionBox.Items.Add ('Quill Files');
  171. LanguageSelectionBox.ItemIndex := 0;
  172. {$IFDEF CODINGEXT}
  173. InitCodingExt;
  174. {$ENDIF}
  175. end;
  176. procedure TPreferencesForm.FormDestroy(Sender: TObject);
  177. begin
  178. SyntaxQuill.Free;
  179. SyntaxAsmGNU.Free;
  180. SyntaxAsm.Free;
  181. SyntaxC.Free;
  182. EditorFont.Free;
  183. end;
  184. procedure TPreferencesForm.FormShow(Sender: TObject);
  185. begin
  186. SyntaxTabClicked := PageController.ActivePage = SyntaxHighlightingSheet;
  187. TargetBoxClick (Sender);
  188. ColorCheckBoxClick (Sender);
  189. FontLabel.Caption := EditorFont.Name;
  190. FontLabel.Font.Assign (EditorFont);
  191. LanguageSelectionBoxChange (Sender);
  192. end;
  193. procedure TPreferencesForm.LanguageSelectionBoxChange(Sender: TObject);
  194. label
  195. Done;
  196. var
  197. I: Integer;
  198. begin
  199. I := LanguageSelectionBox.ItemIndex;
  200. if I <= 0 then begin
  201. Syntax := SyntaxC;
  202. goto Done;
  203. end;
  204. Dec (I);
  205. if I <= 0 then begin
  206. Syntax := SyntaxAsmGNU;
  207. goto Done;
  208. end;
  209. if ssA68k in SpecialSupport then begin
  210. Dec (I);
  211. if I <= 0 then begin
  212. Syntax := SyntaxAsm;
  213. goto Done;
  214. end;
  215. end;
  216. if ssQuill in SpecialSupport then begin
  217. Dec (I);
  218. if I <= 0 then begin
  219. Syntax := SyntaxQuill;
  220. goto Done;
  221. end;
  222. end;
  223. Done:
  224. SyntaxEnabledBox.Checked := Syntax.Enabled;
  225. SyntaxEnabledBoxClick (Sender);
  226. ObjectTree.Items.BeginUpdate;
  227. with ObjectTree.Items [0] do begin
  228. Item[0].DeleteChildren;
  229. Item[1].DeleteChildren;
  230. end;
  231. with Syntax do begin
  232. with CustomStyles do
  233. for I := 0 to Count - 1 do
  234. ObjectTree.Items.AddChildObject (ObjectTree.Items[0].Item[0], Items[I].Caption, Pointer (Items [I]));
  235. with WordLists do
  236. for I := 0 to Count - 1 do
  237. ObjectTree.Items.AddChildObject (ObjectTree.Items[0].Item[1], Items[I].Caption, Pointer (Items [I]));
  238. end;
  239. ObjectTree.FullExpand;
  240. ObjectTree.Items.EndUpdate;
  241. ObjectTreeChange (Sender, nil);
  242. end;
  243. procedure TPreferencesForm.ObjectTreeChange(Sender: TObject;
  244. Node: TTreeNode);
  245. begin
  246. Button9.Enabled := SyntaxEnabledBox.Checked and Assigned (ObjectTree.Selected) and Assigned (ObjectTree.Selected.Data);
  247. end;
  248. procedure TPreferencesForm.SyntaxEnabledBoxClick(Sender: TObject);
  249. begin
  250. Syntax.Enabled := SyntaxEnabledBox.Checked;
  251. Button1.Enabled := SyntaxEnabledBox.Checked;
  252. Button2.Enabled := SyntaxEnabledBox.Checked;
  253. Button3.Enabled := SyntaxEnabledBox.Checked;
  254. Button4.Enabled := SyntaxEnabledBox.Checked;
  255. Button5.Enabled := SyntaxEnabledBox.Checked;
  256. Button6.Enabled := SyntaxEnabledBox.Checked;
  257. Button7.Enabled := SyntaxEnabledBox.Checked;
  258. Button8.Enabled := SyntaxEnabledBox.Checked;
  259. ObjectTree.Enabled := SyntaxEnabledBox.Checked;
  260. ObjectTreeChange (Sender, nil);
  261. end;
  262. procedure TPreferencesForm.Button1Click(Sender: TObject);
  263. begin
  264. ColorDlg.Color := Syntax.NumberColor;
  265. if ColorDlg.Execute then
  266. Syntax.NumberColor := ColorDlg.Color;
  267. end;
  268. procedure TPreferencesForm.Button3Click(Sender: TObject);
  269. begin
  270. ColorDlg.Color := Syntax.SymbolColor;
  271. if ColorDlg.Execute then
  272. Syntax.SymbolColor := ColorDlg.Color;
  273. end;
  274. procedure TPreferencesForm.Button2Click(Sender: TObject);
  275. begin
  276. with TStyleSelectionForm.Create (Self) do try
  277. CustomStyle := Syntax.NumberCustomStyle;
  278. Style := Syntax.NumberStyle;
  279. if ShowModal = mrOK then begin
  280. Syntax.NumberCustomStyle := CustomStyle;
  281. Syntax.NumberStyle := Style;
  282. end;
  283. finally
  284. Free;
  285. end;
  286. end;
  287. procedure TPreferencesForm.Button4Click(Sender: TObject);
  288. begin
  289. with TStyleSelectionForm.Create (Self) do try
  290. CustomStyle := Syntax.SymbolCustomStyle;
  291. Style := Syntax.SymbolStyle;
  292. if ShowModal = mrOK then begin
  293. Syntax.SymbolCustomStyle := CustomStyle;
  294. Syntax.SymbolStyle := Style;
  295. end;
  296. finally
  297. Free;
  298. end;
  299. end;
  300. procedure TPreferencesForm.Button6Click(Sender: TObject);
  301. begin
  302. with TStyleSelectionForm.Create (Self) do try
  303. CustomStyle := Syntax.ParenthesisCustomStyle;
  304. Style := Syntax.ParenthesisStyle;
  305. if ShowModal = mrOK then begin
  306. Syntax.ParenthesisCustomStyle := CustomStyle;
  307. Syntax.ParenthesisStyle := Style;
  308. end;
  309. finally
  310. Free;
  311. end;
  312. end;
  313. procedure TPreferencesForm.Button5Click(Sender: TObject);
  314. begin
  315. with TMultipleColorsForm.Create (Self) do try
  316. ColorBox.Items.Assign (Syntax.ParenthesisColors);
  317. if ShowModal = mrOK then
  318. Syntax.ParenthesisColors.Assign (ColorBox.Items);
  319. finally
  320. Free;
  321. end;
  322. end;
  323. procedure TPreferencesForm.ObjectTreeKeyDown(Sender: TObject;
  324. var Key: Word; Shift: TShiftState);
  325. var
  326. ItemData: TCollectionItem;
  327. begin
  328. if Key = vk_Delete then begin
  329. if Assigned (ObjectTree.Selected) and Assigned (ObjectTree.Selected.Data) then begin
  330. ItemData := TCollectionItem (ObjectTree.Selected.Data);
  331. ObjectTree.Selected.Delete;
  332. ItemData.Free;
  333. end;
  334. end;
  335. end;
  336. procedure TPreferencesForm.EditItem(Sender: TObject);
  337. var
  338. ItemData: TCollectionItem;
  339. begin
  340. if Assigned (ObjectTree.Selected) and Assigned (ObjectTree.Selected.Data) then begin
  341. ItemData := TCollectionItem (ObjectTree.Selected.Data);
  342. if ItemData is TCustomStyle then
  343. with TCustomStyleForm.Create (Self) do try
  344. Style.Assign (ItemData);
  345. if ShowModal = mrOK then
  346. ItemData.Assign (Style);
  347. finally
  348. Free;
  349. end
  350. else if ItemData is TWordList then
  351. with TWordListForm.Create (Self) do try
  352. List.Assign (ItemData);
  353. if ShowModal = mrOK then
  354. ItemData.Assign (List);
  355. finally
  356. Free;
  357. end;
  358. end;
  359. end;
  360. procedure TPreferencesForm.Button7Click(Sender: TObject);
  361. var
  362. ItemData: TCustomStyle;
  363. begin
  364. if ObjectTree.Enabled then
  365. ObjectTree.SetFocus;
  366. ItemData := Syntax.CustomStyles.Add;
  367. ItemData.Caption := 'New Style';
  368. with ObjectTree.Items.AddChildObject (ObjectTree.Items[0].Item[0], ItemData.Caption, Pointer (ItemData)) do begin
  369. MakeVisible;
  370. EditText;
  371. end;
  372. end;
  373. procedure TPreferencesForm.Button8Click(Sender: TObject);
  374. var
  375. ItemData: TWordList;
  376. begin
  377. if ObjectTree.Enabled then
  378. ObjectTree.SetFocus;
  379. ItemData := Syntax.WordLists.Add;
  380. ItemData.Caption := 'New List';
  381. with ObjectTree.Items.AddChildObject (ObjectTree.Items[0].Item[1], ItemData.Caption, Pointer (ItemData)) do begin
  382. MakeVisible;
  383. EditText;
  384. end;
  385. end;
  386. procedure TPreferencesForm.ObjectTreeEdited(Sender: TObject;
  387. Node: TTreeNode; var S: String);
  388. var
  389. ItemData: TCollectionItem;
  390. begin
  391. OKButton.Enabled := True;
  392. if Assigned (Node.Data) then begin
  393. ItemData := TCollectionItem (Node.Data);
  394. if ItemData is TCustomStyle then
  395. TCustomStyle(ItemData).Caption := S;
  396. if ItemData is TWordList then
  397. TWordList(ItemData).Caption := S;
  398. end;
  399. ObjectTree.Selected := Node;
  400. end;
  401. procedure TPreferencesForm.ObjectTreeEditing(Sender: TObject;
  402. Node: TTreeNode; var AllowEdit: Boolean);
  403. begin
  404. AllowEdit := Assigned (Node.Data);
  405. if AllowEdit then begin
  406. OKButton.Enabled := False;
  407. OKTimer.Enabled := True;
  408. end;
  409. end;
  410. procedure TPreferencesForm.OKTimerTimer(Sender: TObject);
  411. begin
  412. if not ObjectTree.IsEditing then begin
  413. OKButton.Enabled := True;
  414. OKTimer.Enabled := False;
  415. end;
  416. end;
  417. procedure TPreferencesForm.ResetButtonClick(Sender: TObject);
  418. begin
  419. if Syntax = SyntaxC then
  420. Syntax.Assign (MainForm.SyntaxCBackup)
  421. else if Syntax = SyntaxAsmGNU then
  422. Syntax.Assign (MainForm.SyntaxAsmGNUBackup)
  423. else if Syntax = SyntaxAsm then
  424. Syntax.Assign (MainForm.SyntaxAsmBackup)
  425. else if Syntax = SyntaxQuill then
  426. Syntax.Assign (MainForm.SyntaxQuillBackup);
  427. LanguageSelectionBoxChange (Sender);
  428. end;
  429. procedure TPreferencesForm.PageControllerChange(Sender: TObject);
  430. begin
  431. if PageController.ActivePage = SyntaxHighlightingSheet then
  432. SyntaxTabClicked := True;
  433. end;
  434. procedure TPreferencesForm.TargetBoxClick(Sender: TObject);
  435. begin
  436. VTIPathEdit.Enabled := VTIBox.Checked;
  437. VTIPathBrowseButton.Enabled := VTIPathEdit.Enabled;
  438. PortBox.Enabled := RealCalcBox.Checked;
  439. PortCOM1Box.Enabled := PortBox.Enabled;
  440. PortCOM2Box.Enabled := PortBox.Enabled;
  441. PortCOM3Box.Enabled := PortBox.Enabled;
  442. PortCOM4Box.Enabled := PortBox.Enabled;
  443. CableBox.Enabled := PortBox.Enabled;
  444. CableBlackBox.Enabled := CableBox.Enabled;
  445. CableGrayBox.Enabled := CableBox.Enabled;
  446. end;
  447. procedure TPreferencesForm.VTIPathBrowseButtonClick(Sender: TObject);
  448. begin
  449. with BrowseDlg do begin
  450. FileName := VTIPathEdit.Text;
  451. if Execute then
  452. VTIPathEdit.Text := FileName;
  453. end;
  454. end;
  455. {$IFDEF CODINGEXT}
  456. procedure TPreferencesForm.InitCodingExt;
  457. var
  458. Tab: TTabSheet;
  459. Frame: TCodingExt;
  460. begin
  461. Tab := TTabSheet.Create(Self);
  462. Tab.PageControl := PageController;
  463. Tab.Caption := 'Co&ding';
  464. Frame := TCodingExt.Create(Self);
  465. Frame.Parent := Tab;
  466. Tab.OnShow := Frame.OnShow;
  467. end;
  468. {$ENDIF}
  469. end.