/ide/frames/help_general_options.pas

http://github.com/graemeg/lazarus · Pascal · 216 lines · 186 code · 26 blank · 4 comment · 12 complexity · 0f803839fff36046013e4bca6237c0a1 MD5 · raw file

  1. unit help_general_options;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, FileUtil, Forms, Controls, StdCtrls, ExtCtrls, EditBtn,
  6. IDEOptionsIntf, HelpOptions, LazarusIDEStrConsts, EnvironmentOpts,
  7. ObjectInspector, LazHelpIntf;
  8. type
  9. { THelpGeneralOptionsFrame }
  10. THelpGeneralOptionsFrame = class(TAbstractIDEOptionsEditor)
  11. Bevel1: TBevel;
  12. Bevel2: TBevel;
  13. Bevel3: TBevel;
  14. Bevel4: TBevel;
  15. Bevel5: TBevel;
  16. Bevel6: TBevel;
  17. DatabasesListBox: TListBox;
  18. DataBasesPropsGroupBox: TGroupBox;
  19. FPCDocHTMLEdit: TDirectoryEdit;
  20. FPCDocHTMLLabel: TLabel;
  21. lblMiddle1: TLabel;
  22. lblMiddle: TLabel;
  23. lblViewers: TLabel;
  24. lblDatabases: TLabel;
  25. ViewerPropsGroupBox: TGroupBox;
  26. ViewersListBox: TListBox;
  27. procedure DatabasesListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
  28. procedure ViewersListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
  29. private
  30. ViewersPropertiesGrid: TCustomPropertiesGrid;
  31. DatabasesPropertiesGrid: TCustomPropertiesGrid;
  32. procedure FillViewersList;
  33. procedure FillViewerPropGrid;
  34. procedure FillDatabasesList;
  35. procedure FillDatabasesPropGrid;
  36. public
  37. constructor Create(AOwner: TComponent); override;
  38. function GetTitle: String; override;
  39. procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
  40. procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
  41. procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
  42. class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
  43. end;
  44. implementation
  45. {$R *.lfm}
  46. { THelpGeneralOptionsFrame }
  47. procedure THelpGeneralOptionsFrame.DatabasesListBoxSelectionChange(
  48. Sender: TObject; User: boolean);
  49. begin
  50. FillDatabasesPropGrid;
  51. end;
  52. procedure THelpGeneralOptionsFrame.ViewersListBoxSelectionChange(
  53. Sender: TObject; User: boolean);
  54. begin
  55. FillViewerPropGrid;
  56. end;
  57. procedure THelpGeneralOptionsFrame.FillViewersList;
  58. var
  59. i: Integer;
  60. Viewer: THelpViewer;
  61. begin
  62. if (HelpViewers = nil) then
  63. begin
  64. ViewersListBox.Items.Clear;
  65. Exit;
  66. end;
  67. ViewersListBox.Items.BeginUpdate;
  68. for i := 0 to HelpViewers.Count - 1 do
  69. begin
  70. Viewer := HelpViewers[i];
  71. if ViewersListBox.Items.Count > i then
  72. ViewersListBox.Items[i] := Viewer.GetLocalizedName
  73. else
  74. ViewersListBox.Items.Add(Viewer.GetLocalizedName);
  75. end;
  76. while ViewersListBox.Items.Count>HelpViewers.Count do
  77. ViewersListBox.Items.Delete(ViewersListBox.Items.Count - 1);
  78. if (ViewersListBox.ItemIndex < 0) and (ViewersListBox.Items.Count > 0) then
  79. ViewersListBox.ItemIndex := 0;
  80. ViewersListBox.Items.EndUpdate;
  81. end;
  82. procedure THelpGeneralOptionsFrame.FillViewerPropGrid;
  83. var
  84. i: LongInt;
  85. begin
  86. i := ViewersListBox.ItemIndex;
  87. if (HelpViewers = nil) or (i < 0) or (i >= HelpViewers.Count) then
  88. ViewersPropertiesGrid.TIObject := nil
  89. else
  90. ViewersPropertiesGrid.TIObject := HelpViewers[i];
  91. end;
  92. procedure THelpGeneralOptionsFrame.FillDatabasesList;
  93. var
  94. i: Integer;
  95. HelpDB: THelpDatabase;
  96. begin
  97. if (HelpDatabases = nil) then
  98. begin
  99. DatabasesListBox.Items.Clear;
  100. Exit;
  101. end;
  102. DatabasesListBox.Items.BeginUpdate;
  103. for i := 0 to HelpDatabases.Count - 1 do
  104. begin
  105. HelpDB := HelpDatabases[i];
  106. if DatabasesListBox.Items.Count > i then
  107. DatabasesListBox.Items[i] := HelpDB.GetLocalizedName
  108. else
  109. DatabasesListBox.Items.Add(HelpDB.GetLocalizedName);
  110. end;
  111. while DatabasesListBox.Items.Count>HelpDatabases.Count do
  112. DatabasesListBox.Items.Delete(DatabasesListBox.Items.Count - 1);
  113. if (DatabasesListBox.ItemIndex < 0) and (DatabasesListBox.Items.Count > 0) then
  114. DatabasesListBox.ItemIndex := 0;
  115. DatabasesListBox.Items.EndUpdate;
  116. end;
  117. procedure THelpGeneralOptionsFrame.FillDatabasesPropGrid;
  118. var
  119. i: LongInt;
  120. begin
  121. i := DatabasesListBox.ItemIndex;
  122. if (HelpDatabases = nil) or (i < 0) or (i>=HelpDatabases.Count) then
  123. DatabasesPropertiesGrid.TIObject := nil
  124. else
  125. DatabasesPropertiesGrid.TIObject := HelpDatabases[i];
  126. end;
  127. constructor THelpGeneralOptionsFrame.Create(AOwner: TComponent);
  128. begin
  129. inherited Create(AOwner);
  130. ViewersPropertiesGrid := TCustomPropertiesGrid.Create(Self);
  131. with ViewersPropertiesGrid do
  132. begin
  133. Name := 'ViewersPropertiesGrid';
  134. Parent := ViewerPropsGroupBox;
  135. Align := alClient;
  136. BorderSpacing.Around := 6;
  137. PreferredSplitterX := 150;
  138. end;
  139. DatabasesPropertiesGrid := TCustomPropertiesGrid.Create(Self);
  140. with DatabasesPropertiesGrid do
  141. begin
  142. Name := 'DatabasesPropertiesGrid';
  143. Parent := DataBasesPropsGroupBox;
  144. Align := alClient;
  145. BorderSpacing.Around := 6;
  146. PreferredSplitterX := 150;
  147. end;
  148. end;
  149. function THelpGeneralOptionsFrame.GetTitle: String;
  150. begin
  151. Result := lisHlpOptsHelpOptions;
  152. end;
  153. procedure THelpGeneralOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
  154. begin
  155. FPCDocHTMLLabel.Caption := lisHOFPCDocHTMLPath;
  156. lblViewers.Caption := lisHlpOptsViewers;
  157. ViewerPropsGroupBox.Caption := lisHlpOptsProperties;
  158. lblDatabases.Caption := lisHlpOptsDatabases;
  159. DataBasesPropsGroupBox.Caption := lisHlpOptsProperties;
  160. with EnvironmentOptions.ObjectInspectorOptions do
  161. begin
  162. AssignTo(ViewersPropertiesGrid);
  163. AssignTo(DatabasesPropertiesGrid);
  164. end;
  165. end;
  166. procedure THelpGeneralOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
  167. begin
  168. with AOptions as THelpOptions do
  169. begin
  170. FPCDocHTMLEdit.Text := FPCDocsHTMLDirectory;
  171. end;
  172. FillViewersList;
  173. FillViewerPropGrid;
  174. FillDatabasesList;
  175. FillDatabasesPropGrid;
  176. end;
  177. procedure THelpGeneralOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
  178. begin
  179. with AOptions as THelpOptions do
  180. begin
  181. FPCDocsHTMLDirectory := FPCDocHTMLEdit.Text;
  182. end;
  183. end;
  184. class function THelpGeneralOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
  185. begin
  186. Result := THelpOptions;
  187. end;
  188. initialization
  189. RegisterIDEOptionsEditor(GroupHelp, THelpGeneralOptionsFrame, HlpOptionsGeneral);
  190. end.