summaryrefslogtreecommitdiff
path: root/src/frm_configuration.pas
blob: 490c259657a6730a1e44ce78bc557d2d2b46ff68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
unit frm_configuration;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_tab, fpg_button,
  fpg_label, fpg_edit, fpg_panel, fpg_combobox, fpg_listbox;

type

  TConfigurationForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: ConfigurationForm}
    PageControl1: TfpgPageControl;
    btnSave: TfpgButton;
    btnCancel: TfpgButton;
    tsGeneral: TfpgTabSheet;
    tsFontsColor: TfpgTabSheet;
    Label1: TfpgLabel;
    edtNormalFont: TfpgEdit;
    btnNormalFont: TfpgButton;
    Label2: TfpgLabel;
    edtFixedFont: TfpgEdit;
    btnFixedFont: TfpgButton;
    btnHelp: TfpgButton;
    Panel1: TfpgPanel;
    cbIndexStyle: TfpgComboBox;
    lblIndexStyle: TfpgLabel;
    lblSearchDirs: TfpgLabel;
    btnSearchDirAdd: TfpgButton;
    lbSearchDirs: TfpgListBox;
    btnSearchDirDelete: TfpgButton;
    {@VFD_HEAD_END: ConfigurationForm}
    procedure ConfigurationFormShow(Sender: TObject);
    procedure btnHelpClick(Sender: TObject);
    procedure PageControl1Change(Sender: TObject; NewActiveSheet: TfpgTabSheet);
    procedure btnCancelClick(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
    procedure btnSearchDirAddClicked(Sender: TObject);
    procedure SettingsToGui;
    procedure GuiToSettings;
  public
    constructor Create(AOwner: TComponent); override;
    procedure AfterCreate; override;
  end;

{@VFD_NEWFORM_DECL}

procedure ShowConfigForm;

implementation

uses
  fpg_dialogs, SettingsUnit, dvConstants;

procedure ShowConfigForm;
var
  frm: TConfigurationForm;
begin
  frm := TConfigurationForm.Create(nil);
  try
    frm.ShowModal;
  finally
    frm.Free;
  end;
end;

{@VFD_NEWFORM_IMPL}

procedure TConfigurationForm.ConfigurationFormShow(Sender: TObject);
begin
  SettingsToGui;
  PageControl1.ActivePage := tsGeneral;
  // programatically seting a tab does not fire OnChange event, so we do it mantually
  PageControl1Change(self, tsGeneral);
end;

procedure TConfigurationForm.btnHelpClick(Sender: TObject);
begin
  ShowMessage(IntToStr(btnHelp.HelpContext));
end;

procedure TConfigurationForm.PageControl1Change(Sender: TObject;
  NewActiveSheet: TfpgTabSheet);
begin
  if NewActiveSheet = tsGeneral then
  begin
    btnHelp.HelpContext := hcConfigGeneralTab;
  end
  else if NewActiveSheet = tsFontsColor then
  begin
    btnHelp.HelpContext := hcConfigFontsColorTab;
  end;
end;

procedure TConfigurationForm.btnCancelClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TConfigurationForm.btnSaveClick(Sender: TObject);
begin
  GuiToSettings;
  SaveSettings;
  ModalResult := mrOK;
end;

procedure TConfigurationForm.btnSearchDirAddClicked(Sender: TObject);
var
  s: TfpgString;
begin
  s := SelectDirDialog('');
  if s <> '' then
    lbSearchDirs.Items.Add(s);
end;

procedure TConfigurationForm.SettingsToGui;
begin
  // General
  cbIndexStyle.FocusItem := Ord(Settings.IndexStyle);
  lbSearchDirs.Items.Assign(Settings.SearchDirectories);
  // Fonts & Color
  edtNormalFont.Text := Settings.NormalFont.FontDesc;
  edtFixedFont.Text := Settings.FixedFont.FontDesc;
end;

procedure TConfigurationForm.GuiToSettings;
begin
  // General
  Settings.IndexStyle := TIndexStyle(cbIndexStyle.FocusItem);
  Settings.SearchDirectories.Assign(lbSearchDirs.Items);
  // Fonts & Color
  Settings.NormalFont.Free;
  Settings.NormalFont := fpgGetFont(edtNormalFont.Text);
  Settings.FixedFont.Free;
  Settings.FixedFont := fpgGetFont(edtFixedFont.Text);
end;

constructor TConfigurationForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  OnShow := @ConfigurationFormShow;
end;

procedure TConfigurationForm.AfterCreate;
begin
  {%region 'Auto-generated GUI code' -fold}
  {@VFD_BODY_BEGIN: ConfigurationForm}
  Name := 'ConfigurationForm';
  SetPosition(310, 157, 515, 439);
  WindowTitle := 'Configuration';
  WindowPosition := wpOneThirdDown;

  PageControl1 := TfpgPageControl.Create(self);
  with PageControl1 do
  begin
    Name := 'PageControl1';
    SetPosition(4, 4, 506, 388);
    Anchors := [anLeft,anRight,anTop,anBottom];
    ActivePageIndex := 1;
    TabOrder := 0;
    OnChange := @PageControl1Change;
  end;

  btnSave := TfpgButton.Create(self);
  with btnSave do
  begin
    Name := 'btnSave';
    SetPosition(344, 408, 80, 24);
    Text := 'Save';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 1;
    OnClick := @btnSaveClick;
  end;

  btnCancel := TfpgButton.Create(self);
  with btnCancel do
  begin
    Name := 'btnCancel';
    SetPosition(428, 408, 80, 24);
    Text := 'Cancel';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 2;
    OnClick := @btnCancelClick;
  end;

  tsGeneral := TfpgTabSheet.Create(PageControl1);
  with tsGeneral do
  begin
    Name := 'tsGeneral';
    SetPosition(3, 24, 500, 361);
    Text := 'General';
  end;

  tsFontsColor := TfpgTabSheet.Create(PageControl1);
  with tsFontsColor do
  begin
    Name := 'tsFontsColor';
    SetPosition(3, 24, 500, 361);
    Text := 'Fonts & Color';
  end;

  Label1 := TfpgLabel.Create(tsFontsColor);
  with Label1 do
  begin
    Name := 'Label1';
    SetPosition(12, 20, 108, 16);
    FontDesc := '#Label1';
    Hint := '';
    Text := 'Normal Font';
  end;

  edtNormalFont := TfpgEdit.Create(tsFontsColor);
  with edtNormalFont do
  begin
    Name := 'edtNormalFont';
    SetPosition(124, 16, 248, 24);
    Anchors := [anLeft,anRight,anTop];
    TabOrder := 1;
    Text := '';
    FontDesc := '#Edit1';
  end;

  btnNormalFont := TfpgButton.Create(tsFontsColor);
  with btnNormalFont do
  begin
    Name := 'btnNormalFont';
    SetPosition(384, 16, 80, 24);
    Anchors := [anRight,anTop];
    Text := 'Select...';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 2;
  end;

  Label2 := TfpgLabel.Create(tsFontsColor);
  with Label2 do
  begin
    Name := 'Label2';
    SetPosition(12, 52, 104, 16);
    FontDesc := '#Label1';
    Hint := '';
    Text := 'Fixed Font';
  end;

  edtFixedFont := TfpgEdit.Create(tsFontsColor);
  with edtFixedFont do
  begin
    Name := 'edtFixedFont';
    SetPosition(124, 48, 248, 24);
    Anchors := [anLeft,anRight,anTop];
    TabOrder := 4;
    Text := '';
    FontDesc := '#Edit1';
  end;

  btnFixedFont := TfpgButton.Create(tsFontsColor);
  with btnFixedFont do
  begin
    Name := 'btnFixedFont';
    SetPosition(384, 48, 80, 24);
    Anchors := [anRight,anTop];
    Text := 'Select...';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 5;
  end;

  btnHelp := TfpgButton.Create(self);
  with btnHelp do
  begin
    Name := 'btnHelp';
    SetPosition(468, 356, 28, 24);
    Anchors := [anRight,anBottom];
    Text := '?';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 6;
    HelpType := htContext;
    OnClick := @btnHelpClick;
  end;

  Panel1 := TfpgPanel.Create(tsFontsColor);
  with Panel1 do
  begin
    Name := 'Panel1';
    SetPosition(128, 116, 204, 28);
    FontDesc := '#Label1';
    Style := bsLowered;
    Text := 'Panel';
  end;

  cbIndexStyle := TfpgComboBox.Create(tsGeneral);
  with cbIndexStyle do
  begin
    Name := 'cbIndexStyle';
    SetPosition(12, 32, 160, 22);
    FontDesc := '#List';
    Items.Add('Alphabetical');
    Items.Add('FileOnly');
    Items.Add('Full');
    TabOrder := 0;
  end;

  lblIndexStyle := TfpgLabel.Create(tsGeneral);
  with lblIndexStyle do
  begin
    Name := 'lblIndexStyle';
    SetPosition(12, 12, 212, 16);
    FontDesc := '#Label1';
    Hint := '';
    Text := 'Index style';
  end;

  lblSearchDirs := TfpgLabel.Create(tsGeneral);
  with lblSearchDirs do
  begin
    Name := 'lblSearchDirs';
    SetPosition(12, 64, 216, 16);
    FontDesc := '#Label1';
    Hint := '';
    Text := 'Search directories';
  end;

  btnSearchDirAdd := TfpgButton.Create(tsGeneral);
  with btnSearchDirAdd do
  begin
    Name := 'btnSearchDirAdd';
    SetPosition(408, 84, 80, 24);
    Text := 'Add...';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 4;
    OnClick :=@btnSearchDirAddClicked;
  end;

  lbSearchDirs := TfpgListBox.Create(tsGeneral);
  with lbSearchDirs do
  begin
    Name := 'lbSearchDirs';
    SetPosition(12, 84, 388, 148);
    FontDesc := '#List';
    HotTrack := False;
    PopupFrame := False;
    TabOrder := 5;
    Items.Duplicates := dupIgnore;
  end;

  btnSearchDirDelete := TfpgButton.Create(tsGeneral);
  with btnSearchDirDelete do
  begin
    Name := 'btnSearchDirDelete';
    SetPosition(408, 116, 80, 24);
    Text := 'Remove...';
    FontDesc := '#Label1';
    Hint := '';
    ImageName := '';
    TabOrder := 5;
  end;

  {@VFD_BODY_END: ConfigurationForm}
  {%endregion}
end;


end.