PageRenderTime 30ms CodeModel.GetById 19ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

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