/packages/fpgtk/src/editor/settingsrec.pp
Puppet | 188 lines | 158 code | 30 blank | 0 comment | 1 complexity | dee95a60da7c97d81e50a8f3877d320e MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
1{$mode objfpc}{$h+} 2unit SettingsRec; 3 4{$define UseLog} 5 6interface 7 8uses FPgtk, FPgtkExt; 9 10type 11 12 TFileFormat = (ffComonentBin, ffComponentText, ffHomeText); 13 14 PSettingsRec = ^TSettingsRec; 15 TSettingsRec = record 16 SaveOnClose : boolean; 17 FileFormat : TFileFormat; 18 Extention : string; 19 MRUCount : integer; 20 ShowProgress : boolean; 21 end; 22 23 TSettingsDialog = class (TFPgtkDialog) 24 private 25 FCBSaveOnClose : TFPgtkToggleButton; 26 FEFileFormat : TFPgtkOptionMenu; 27 FMenuFileFormat : TFPgtkMenu; 28 FEExtention : TFPgtkCombo; 29 FEMRUCount : TFPgtkSpinButton; 30 FCBProgressWindow : TFPgtkToggleButton; 31 procedure BuildDialog; 32 protected 33 procedure DoDialogResult (Action:integer; Sender:TFPgtkObject); override; 34 procedure DoDialogInit (InitData:pointer); override; 35 public 36 Constructor Create; 37 end; 38 39procedure Log (s : string); overload; 40procedure Log (fmt : string; params : array of const); overload; 41procedure Log (indent:integer; s:string); 42procedure Log (indent:integer; fmt:string; params:array of const); 43 44implementation 45 46uses GtkDefTexts, gdk, gtk, sysutils; 47 48constructor TSettingsDialog.Create; 49begin 50 inherited; 51 Title := sOptions; 52 BuildDialog; 53end; 54 55procedure TSettingsDialog.BuildDialog; 56var but : TFPgtkButton; 57 b, box : TFPgtkBox; 58 AG : integer; 59 AGroup : PGtkAccelGroup; 60begin 61 // Action Area 62 AG := AccelGroupNew; 63 Agroup := AccelGroups[AG]; 64 65 Box := ActionArea; 66 67 but := TFPgtkButton.CreateWithLabel (sOk, AGroup); 68 box.PackEnd (but, false, false, 0); 69 with but do 70 begin 71 Candefault := true; 72 ConnectClicked (@CloseWithResult, inttopointer(drOk)); 73 GrabDefault; 74 end; 75 AcceleratorAdd (AG, but, sgClicked, GDK_Return, 0, GTK_ACCEL_VISIBLE); 76 77 but := TFPgtkButton.CreateWithLabel (sCancel, AGroup); 78 box.PackEnd (but, false, false, 0); 79 with but do 80 begin 81 CanDefault := true; 82 ConnectClicked (@CloseWithResult, inttopointer(drCancel)); 83 end; 84 AcceleratorAdd (AG, but, sgClicked, GDK_Escape, 0, gtk_accel_visible); 85 86 // Setting controls 87 box := vbox; 88 border := 15; 89 90 FEFileFormat := TFPgtkOptionMenu.Create; 91 FMenuFileFormat := NewMenu ('', [ 92 NewMenuItem (sComponentBin, sHintCompBin, '', nil, nil, nil), 93 NewMenuItem (sComponentText, sHintCompText, '', nil, nil, nil), 94 NewMenuItem (sHomeText, sHintHomeText, '', nil, nil, nil) 95 ]); 96 FEFileFormat.Menu := FMenuFileFormat; 97 b := TFPgtkHBox.Create; 98 b.PackStart (TFPgtkLabel.Create (sFileFormat), false, false, 0); 99 b.PackStart (FEFileFormat, False, False, 10); 100 box.PackStart (b, false, false, 0); 101 102 b := TFPgtkHBox.Create; 103 box.PackStart (b, true, true, 0); 104 105 FCBSaveOnClose := TFPgtkCheckedButton.CreateWithLabel(sSaveonclose,AGroup); 106 b.PackStart (FCBSaveOnClose, False, False, 10); 107 108 FCBProgressWindow := TFPgtkCheckedButton.CreateWithLabel(sProgressWindow, AGroup); 109 b.PackStart (FCBProgressWindow, False, False, 10); 110 111 FEExtention := TFPgtkCombo.Create; 112 with FEExtention do 113 begin 114 SetValueInList (false, false); 115 List.Add (TFPgtkListItem.CreateWithLabel('pp')); 116 List.Add (TFPgtkListItem.CreateWithLabel('pas')); 117 end; 118 b := TFPgtkHBox.Create; 119 b.PackStart (TFPgtkLabel.Create (sExtention), false, false, 0); 120 b.PackStart (FEExtention, false, false, 5); 121 box.PackStart (b, false, false, 10); 122 123 FEMRUCount := TFPgtkSpinButton.Create; 124 with FEMRUCount do 125 begin 126 Configure (nil, 1.0, 0); 127 SnapToTicks := True; 128 Numeric := True; 129 Wrap := False; 130 Adjustment.configure (1.0, 10.0, 5.0, 1.0, 3.0, 1.0); 131 end; 132 b := TFPgtkHBox.Create; 133 b.PackStart (TFPgtkLabel.Create (sMRUcount), false, false, 0); 134 b.PackStart (FEMRUCount, false, false, 5); 135 box.PackStart (b, false, false, 10); 136 137end; 138 139procedure TSettingsDialog.DoDialogResult (Action:integer; Sender:TFPgtkObject); 140begin 141 if Action = drOk then 142 with PSettingsRec(DialogResult)^ do 143 begin 144 SaveOnClose := FCBSaveOnClose.Active; 145 FileFormat := TFileFormat(FMenuFileFormat.ActiveIndex); 146 Extention := FEExtention.Entry.Text; 147 MRUCount := FEMRUCount.AsInteger; 148 ShowProgress := FCBProgressWindow.Active; 149 end; 150 inherited; 151end; 152 153procedure TSettingsDialog.DoDialogInit (InitData:pointer); 154begin 155 with PSettingsRec(InitData)^ do 156 begin 157 FCBSaveOnClose.Active := SaveOnClose; 158 FEFileFormat.SetHistory (ord(FileFormat)); 159 FEExtention.Entry.Text := Extention; 160 FEMRUCount.AsInteger := MRUCount; 161 FCBProgressWindow.Active := ShowProgress; 162 end; 163 inherited; 164end; 165 166procedure Log (s : string); 167begin 168 {$ifdef UseLog} 169 writeln (s); 170 {$endif} 171end; 172 173procedure Log (fmt : string; params : array of const); 174begin 175 Log (format (fmt, params)); 176end; 177 178procedure Log (indent:integer; fmt:string; params:array of const); 179begin 180 Log (stringofchar(' ',indent) + format(fmt, params)); 181end; 182 183procedure Log (indent:integer; s:string); 184begin 185 Log (stringofchar(' ',indent) + s); 186end; 187 188end.