frmoptions.pp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. {$mode objfpc}
  2. {$h+}
  3. unit frmoptions;
  4. interface
  5. uses fpgtk,gtk,classes,sysutils;
  6. Type
  7. TOptionsForm = Class (TFPGtkWindow)
  8. Private
  9. FTable : TFPGtkTable;
  10. FLVerbose,
  11. FLCreateMsgFile,
  12. FLCreateRCFile,
  13. FLCreatePasFile,
  14. FLEscapePath,
  15. FLLocale,
  16. FLSubLocale,
  17. FLUnitName : TFPGtkLabel;
  18. FVerbose,
  19. FCreateMsgFile,
  20. FCreatePasFile,
  21. FCreateRCFile,
  22. FEscapePath : TFPGtkToggleButton;
  23. FUnitName,
  24. FLocale,
  25. FSubLocale : TFPGtkEntry;
  26. FMaxRecentUsed : TFPGtkSpinButton;
  27. FSeparator : TFPGtkHSeparator;
  28. FVBox : TFPgtkVBox;
  29. FHBox : TFPgtkHBox;
  30. FOK,
  31. FCancel : TFPGtkButton;
  32. FButtonBox: TFPgtkHBox;
  33. Public
  34. Constructor Create;
  35. Procedure CreateWindow;
  36. Procedure OnShow(Sender : TFpGtkObject;Data : Pointer);
  37. Procedure SaveResult(Sender : TFpGtkObject;Data : Pointer);
  38. Function GetBoolProp (Index : Integer) : Boolean;
  39. Procedure SetBoolProp (Index : Integer; Value : Boolean);
  40. Function GetStringProp (Index : Integer) : String;
  41. Procedure SetStringProp (Index : Integer; Value : String);
  42. Property CreateMsgFile : Boolean Index 1 Read GetBoolProp Write SetBoolProp;
  43. Property CreatePasFile : Boolean Index 2 Read GetBoolProp Write SetBoolProp;
  44. Property CreateRCFile : Boolean Index 3 Read GetBoolProp Write SetBoolProp;
  45. Property EscapePath : Boolean Index 4 Read GetBoolProp Write SetBoolProp;
  46. Property Verbose : Boolean Index 5 Read GetBoolProp Write SetBoolProp;
  47. Property Locale : String Index 1 Read GetStringProp Write SetStringProp;
  48. Property SubLocale : String Index 2 Read GetStringProp Write SetStringProp;
  49. Property UnitName : String Index 3 Read GetStringProp Write SetStringProp;
  50. end;
  51. Implementation
  52. ResourceString
  53. SOptCreateMsgFile = 'Create message file';
  54. SOptCreateRCFile = 'Create RC file';
  55. SOptCreatePasFile = 'Create pascal file';
  56. SOptEscapePath = 'Escape path delimiters';
  57. SOptLocale = 'Locale ID';
  58. SOptSubLocale = 'Sublocale ID';
  59. SOptUnitName = 'Unit name';
  60. SOK = 'OK';
  61. SCancel = 'Cancel';
  62. SOptVerbose = 'Be verbose';
  63. Function MakeLabel(Caption : String) : TFPgtkLabel;
  64. begin
  65. Result:=TFPGtkLabel.Create(Caption);
  66. Result.Justify:=GTK_JUSTIFY_RIGHT;
  67. end;
  68. Function MakeCheck : TFPgtkToggleButton;
  69. begin
  70. Result:=TFPgtkToggleButton.create;
  71. Result.SetUsize(14,14);
  72. end;
  73. Constructor TOptionsForm.Create;
  74. begin
  75. Inherited Create(GTK_WINDOW_DIALOG);
  76. CreateWindow;
  77. end;
  78. Function PackBox(W : TFpGtkWidget) : TFpGtkHbox;
  79. begin
  80. Result:=TFPGtkHBox.Create;
  81. Result.PackStart(W,True,False,0);
  82. end;
  83. Procedure ToptionsForm.CreateWindow;
  84. Var
  85. OH,OV : TgtkAttachOPtions;
  86. B : TfpgtkHbox;
  87. begin
  88. FVBox:=TFPGtkVBox.Create;
  89. FVBox.Spacing:=4;
  90. FVBox.Border:=8;
  91. Add(FVBox);
  92. // Table area
  93. FTable:=TFPGtkTable.Create(2,8);
  94. FLVerbose:=MakeLabel(SOptVerbose);
  95. FLCreateMsgFile:=MakeLabel(SOptCreateMsgFile);
  96. FLCreateRCFile:=MakeLabel(SOptCreateRCFile);
  97. FLCreatePasFile:=MakeLabel(SOptCreatePasFile);
  98. FLEscapePath:=MakeLabel(SOptEscapePath);
  99. FLLocale:=MakeLabel(SOptLocale);
  100. FLSubLocale:=MakeLabel(SOptSubLocale);
  101. FLUnitName:=MakeLabel(SOptUnitName);
  102. FVerbose:=MakeCheck;
  103. FEscapePath:=MakeCheck;
  104. FCreateMsgFile:=MakeCheck;
  105. FCreateRCFile:=MakeCheck;
  106. FCreatePasFile:=MakeCheck;
  107. FUnitName:=TFpGtkEntry.Create;
  108. FLocale:=TFpGtkEntry.Create;
  109. FSubLocale:=TFpGtkEntry.Create;
  110. OH:=GTK_EXPAND or GTK_FILL;
  111. FTable.Attach(FLVerbose ,0,1,0,1,GTK_FILL,0,4,4);
  112. FTable.Attach(FLCreateMsgFile ,0,1,1,2,GTK_FILL,0,4,4);
  113. FTable.Attach(FLCreatePasFile ,0,1,2,3,GTK_FILL,0,4,4);
  114. FTable.Attach(FLCreateRCFile ,0,1,3,4,GTK_FILL,0,4,4);
  115. FTable.Attach(FLEscapePath ,0,1,4,5,GTK_FILL,0,4,4);
  116. FTable.Attach(FLUnitName ,0,1,5,6,GTK_FILL,0,4,4);
  117. FTable.Attach(FLLocale ,0,1,6,7,GTK_FILL,0,4,4);
  118. FTable.Attach(FLSubLocale ,0,1,7,8,GTK_FILL,0,4,4);
  119. FTable.Attach(PackBox(FVerbose) ,1,2,0,1,0,GTK_FILL,4,4);
  120. FTable.Attach(PackBox(FCreateMsgFile) ,1,2,1,2,0,GTK_FILL,4,4);
  121. FTable.Attach(PackBox(FCreatePasFile) ,1,2,2,3,0,GTK_FILL,4,4);
  122. FTable.Attach(PackBox(FCreateRCFile) ,1,2,3,4,0,GTK_FILL,4,4);
  123. FTable.Attach(PackBox(FEscapePath) ,1,2,4,5,0,GTK_FILL,4,4);
  124. FTable.Attach(FUnitName ,1,2,5,6,0,GTK_FILL,4,4);
  125. FTable.Attach(FLocale ,1,2,6,7,0,GTK_FILL,4,4);
  126. FTable.Attach(FSubLocale ,1,2,7,8,0,GTK_FILL,4,4);
  127. // button area
  128. FOK:=TFpGtkButton.CreateWithLabel(SOK);
  129. FOK.ConnectClicked(@SaveResult,Nil);
  130. FCancel:=TFPgtkButton.CreateWithLabel(SCancel);
  131. FCancel.ConnectCLicked(@CloseWindow,Nil);
  132. FSeparator:=TFPgtkHSeparator.Create;
  133. FButtonBox:=TfpGtkHBox.Create;
  134. FButtonBox.Spacing:=4;
  135. FButtonBox.PackEnd(FOK,false,false,4);
  136. FButtonBox.PackEnd(FCancel,false,false,4);
  137. // Add to window
  138. FVBox.PackStart(FTable,False,False,0);
  139. FVBox.PackStart(FSeparator,False,False,4);
  140. FVBox.PackStart(FButtonBox,false,false,0);
  141. // Some events;
  142. ConnectShow(@OnShow,Nil);
  143. end;
  144. Procedure TOptionsForm.OnShow(Sender : TFpgtkObject; Data : Pointer);
  145. begin
  146. FocusedWidget(FCreateMsgFile);
  147. end;
  148. Procedure TOptionsForm.SaveResult(Sender : TFpgtkObject; Data : Pointer);
  149. begin
  150. CloseWithResult(Sender,IntToPointer(drOK));
  151. end;
  152. Function TOptionsForm.GetBoolProp (Index : Integer) : Boolean;
  153. begin
  154. Result:=False;
  155. Case Index of
  156. 1 : Result:=FCreateMsgFile.Active;
  157. 2 : Result:=FCreatePasFile.Active;
  158. 3 : Result:=FCreateRCFile.Active;
  159. 4 : Result:=FEscapePath.Active;
  160. 5 : Result:=FVerbose.Active;
  161. end;
  162. end;
  163. Procedure TOptionsForm.SetBoolProp (Index : Integer; Value : Boolean);
  164. begin
  165. Case Index of
  166. 1 : FCreateMsgFile.Active:=Value;
  167. 2 : FCreatePasFile.Active:=Value;
  168. 3 : FCreateRCFile.Active:=Value;
  169. 4 : FEscapePath.Active:=Value;
  170. 5 : FVerbose.Active:=Value;
  171. end;
  172. end;
  173. Function TOptionsForm.GetStringProp (Index : Integer) : String;
  174. begin
  175. Result:='';
  176. Case Index of
  177. 1 : Result:=Flocale.Text;
  178. 2 : Result:=FSublocale.Text;
  179. 3 : Result:=FUnitName.Text;
  180. end;
  181. end;
  182. Procedure TOptionsForm.SetStringProp (Index : Integer; Value : String);
  183. begin
  184. Case Index of
  185. 1 : Flocale.Text:=Value;
  186. 2 : FSublocale.Text:=Value;
  187. 3 : FUnitName.Text:=Value;
  188. end;
  189. end;
  190. end.