/packages/fpgtk/src/editor/settingsrec.pp

https://github.com/slibre/freepascal · Puppet · 188 lines · 158 code · 30 blank · 0 comment · 1 complexity · dee95a60da7c97d81e50a8f3877d320e MD5 · raw file

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