summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fpgtk/src/editor/settingsrec.pp
blob: cbaf3a88ec984970f8eecc20d863be411a5695e3 (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
{$mode objfpc}{$h+}
unit SettingsRec;

{$define UseLog}

interface

uses FPgtk, FPgtkExt;

type

  TFileFormat = (ffComonentBin, ffComponentText, ffHomeText);

  PSettingsRec = ^TSettingsRec;
  TSettingsRec = record
    SaveOnClose : boolean;
    FileFormat : TFileFormat;
    Extention : string;
    MRUCount : integer;
    ShowProgress : boolean;
  end;

  TSettingsDialog = class (TFPgtkDialog)
  private
    FCBSaveOnClose : TFPgtkToggleButton;
    FEFileFormat : TFPgtkOptionMenu;
    FMenuFileFormat : TFPgtkMenu;
    FEExtention : TFPgtkCombo;
    FEMRUCount : TFPgtkSpinButton;
    FCBProgressWindow : TFPgtkToggleButton;
    procedure BuildDialog;
  protected
    procedure DoDialogResult (Action:integer; Sender:TFPgtkObject); override;
    procedure DoDialogInit (InitData:pointer); override;
  public
    Constructor Create;
  end;

procedure Log (s : string); overload;
procedure Log (fmt : string; params : array of const); overload;
procedure Log (indent:integer; s:string);
procedure Log (indent:integer; fmt:string; params:array of const);

implementation

uses GtkDefTexts, gdk, gtk, sysutils;

constructor TSettingsDialog.Create;
begin
  inherited;
  Title := sOptions;
  BuildDialog;
end;

procedure TSettingsDialog.BuildDialog;
var but : TFPgtkButton;
    b, box : TFPgtkBox;
    AG : integer;
    AGroup : PGtkAccelGroup;
begin
  // Action Area
  AG := AccelGroupNew;
  Agroup := AccelGroups[AG];

  Box := ActionArea;

  but := TFPgtkButton.CreateWithLabel (sOk, AGroup);
  box.PackEnd (but, false, false, 0);
  with but do
    begin
    Candefault := true;
    ConnectClicked (@CloseWithResult, inttopointer(drOk));
    GrabDefault;
    end;
  AcceleratorAdd (AG, but, sgClicked, GDK_Return, 0, GTK_ACCEL_VISIBLE);

  but := TFPgtkButton.CreateWithLabel (sCancel, AGroup);
  box.PackEnd (but, false, false, 0);
  with but do
    begin
    CanDefault := true;
    ConnectClicked (@CloseWithResult, inttopointer(drCancel));
    end;
  AcceleratorAdd (AG, but, sgClicked, GDK_Escape, 0, gtk_accel_visible);

  // Setting controls
  box := vbox;
  border := 15;

  FEFileFormat := TFPgtkOptionMenu.Create;
  FMenuFileFormat := NewMenu ('', [
         NewMenuItem (sComponentBin, sHintCompBin, '', nil, nil, nil),
         NewMenuItem (sComponentText, sHintCompText, '', nil, nil, nil),
         NewMenuItem (sHomeText, sHintHomeText, '', nil, nil, nil)
         ]);
  FEFileFormat.Menu := FMenuFileFormat;
  b := TFPgtkHBox.Create;
  b.PackStart (TFPgtkLabel.Create (sFileFormat), false, false, 0);
  b.PackStart (FEFileFormat, False, False, 10);
  box.PackStart (b, false, false, 0);

  b := TFPgtkHBox.Create;
  box.PackStart (b, true, true, 0);

  FCBSaveOnClose := TFPgtkCheckedButton.CreateWithLabel(sSaveonclose,AGroup);
  b.PackStart (FCBSaveOnClose, False, False, 10);

  FCBProgressWindow := TFPgtkCheckedButton.CreateWithLabel(sProgressWindow, AGroup);
  b.PackStart (FCBProgressWindow, False, False, 10);

  FEExtention := TFPgtkCombo.Create;
  with FEExtention do
    begin
    SetValueInList (false, false);
    List.Add (TFPgtkListItem.CreateWithLabel('pp'));
    List.Add (TFPgtkListItem.CreateWithLabel('pas'));
    end;
  b := TFPgtkHBox.Create;
  b.PackStart (TFPgtkLabel.Create (sExtention), false, false, 0);
  b.PackStart (FEExtention, false, false, 5);
  box.PackStart (b, false, false, 10);

  FEMRUCount := TFPgtkSpinButton.Create;
  with FEMRUCount do
    begin
    Configure (nil, 1.0, 0);
    SnapToTicks := True;
    Numeric := True;
    Wrap := False;
    Adjustment.configure (1.0, 10.0, 5.0, 1.0, 3.0, 1.0);
    end;
  b := TFPgtkHBox.Create;
  b.PackStart (TFPgtkLabel.Create (sMRUcount), false, false, 0);
  b.PackStart (FEMRUCount, false, false, 5);
  box.PackStart (b, false, false, 10);

end;

procedure TSettingsDialog.DoDialogResult (Action:integer; Sender:TFPgtkObject);
begin
  if Action = drOk then
    with PSettingsRec(DialogResult)^ do
      begin
      SaveOnClose := FCBSaveOnClose.Active;
      FileFormat := TFileFormat(FMenuFileFormat.ActiveIndex);
      Extention := FEExtention.Entry.Text;
      MRUCount := FEMRUCount.AsInteger;
      ShowProgress := FCBProgressWindow.Active;
      end;
  inherited;
end;

procedure TSettingsDialog.DoDialogInit (InitData:pointer);
begin
  with PSettingsRec(InitData)^ do
    begin
    FCBSaveOnClose.Active := SaveOnClose;
    FEFileFormat.SetHistory (ord(FileFormat));
    FEExtention.Entry.Text := Extention;
    FEMRUCount.AsInteger := MRUCount;
    FCBProgressWindow.Active := ShowProgress;
    end;
  inherited;
end;

procedure Log (s : string);
begin
  {$ifdef UseLog}
  writeln (s);
  {$endif}
end;

procedure Log (fmt : string; params : array of const);
begin
  Log (format (fmt, params));
end;

procedure Log (indent:integer; fmt:string; params:array of const);
begin
  Log (stringofchar(' ',indent) + format(fmt, params));
end;

procedure Log (indent:integer; s:string);
begin
  Log (stringofchar(' ',indent) + s);
end;

end.