frmoptions.pp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. {$mode objfpc}
  2. {$h+}
  3. unit frmoptions;
  4. interface
  5. uses fpgtk,gtk,classes,sysutils;
  6. Type
  7. TOptionsForm = Class (TFPGtkWindow)
  8. FTable : TFPGtkTable;
  9. FLCreateBackup,
  10. FLSkipEmptyNodes,
  11. FLConfirmDelete,
  12. FLMaxRecentUsed,
  13. FLbackupExtension,
  14. FLDefaultExtension : TFPGtkLabel;
  15. FCreateBackup,
  16. FSkipEmptyNodes,
  17. FConfirmDelete : TFPGtkToggleButton;
  18. FBackupExtension,
  19. FDefaultExtension : TFPGtkEntry;
  20. FMaxRecentUsed : TFPGtkSpinButton;
  21. FSeparator : TFPGtkHSeparator;
  22. FVBox : TFPgtkVBox;
  23. FHBox : TFPgtkHBox;
  24. FOK,
  25. FCancel : TFPGtkButton;
  26. FButtonBox: TFPgtkHBox;
  27. Constructor Create;
  28. Procedure CreateWindow;
  29. Procedure OnShow(Sender : TFpGtkObject;Data : Pointer);
  30. Procedure SaveResult(Sender : TFpGtkObject;Data : Pointer);
  31. Procedure OptionsToForm;
  32. Procedure FormToOptions;
  33. end;
  34. Implementation
  35. uses fpdemsg,fpdeopts;
  36. Function MakeLabel(Caption : String) : TFPgtkLabel;
  37. begin
  38. Result:=TFPGtkLabel.Create(Caption);
  39. Result.Justify:=GTK_JUSTIFY_RIGHT;
  40. end;
  41. Function MakeCheck : TFPgtkToggleButton;
  42. begin
  43. Result:=TFPgtkToggleButton.create;
  44. Result.SetUsize(14,14);
  45. end;
  46. Constructor TOptionsForm.Create;
  47. begin
  48. Inherited Create(GTK_WINDOW_DIALOG);
  49. CreateWindow;
  50. end;
  51. Function PackBox(W : TFpGtkWidget) : TFpGtkHbox;
  52. begin
  53. Result:=TFPGtkHBox.Create;
  54. Result.PackStart(W,True,False,0);
  55. end;
  56. Procedure ToptionsForm.CreateWindow;
  57. Var
  58. OH,OV : TgtkAttachOPtions;
  59. B : TfpgtkHbox;
  60. begin
  61. FVBox:=TFPGtkVBox.Create;
  62. FVBox.Spacing:=4;
  63. FVBox.Border:=8;
  64. Add(FVBox);
  65. // Table area
  66. FTable:=TFPGtkTable.Create(2,6);
  67. FLCreateBackup:=MakeLabel(SOptCreateBackup);
  68. FLSkipEmptyNodes:=MakeLabel(SOptSkipEmptyNodes);
  69. FLConfirmDelete:=MakeLabel(SOptConfirmDelete);
  70. FLbackupExtension:=MakeLabel(SOptBackupExtension);
  71. FLDefaultExtension:=MakeLabel(SOptDefaultExtension);
  72. FLMaxRecentUsed:=MakeLabel(SOptMaxRecentUsed);
  73. FCreateBackup:=MakeCheck;
  74. FSkipEmptyNodes:=MakeCheck;
  75. FConfirmDelete:=MakeCheck;
  76. FBackupExtension:=TFpGtkEntry.Create;
  77. FDefaultExtension:=TFpGtkEntry.Create;
  78. FMaxRecentUsed:=TFPGtkSpinButton.Create;
  79. FMaxRecentUsed.Adjustment.Upper:=32;
  80. OH:=GTK_EXPAND or GTK_FILL;
  81. FTable.Attach(FLConfirmDelete ,0,1,0,1,GTK_FILL,0,4,4);
  82. FTable.Attach(FLSkipEmptyNodes ,0,1,1,2,GTK_FILL,0,4,4);
  83. FTable.Attach(FLCreatebackup ,0,1,2,3,GTK_FILL,0,4,4);
  84. FTable.Attach(FLBackupExtension ,0,1,3,4,GTK_FILL,0,4,4);
  85. FTable.Attach(FLDefaultExtension ,0,1,4,5,GTK_FILL,0,4,4);
  86. FTable.Attach(FLMaxrecentUSed ,0,1,5,6,GTK_FILL,0,4,4);
  87. FTable.Attach(PackBox(FConfirmDelete) ,1,2,0,1,0,GTK_FILL,4,4);
  88. FTable.Attach(PackBox(FSkipEmptyNodes) ,1,2,1,2,0,GTK_FILL,4,4);
  89. FTable.Attach(PackBox(FCreatebackup) ,1,2,2,3,0,GTK_FILL,4,4);
  90. FTable.Attach(FBackupExtension ,1,2,3,4,0,GTK_FILL,4,4);
  91. FTable.Attach(FDefaultExtension ,1,2,4,5,0,GTK_FILL,4,4);
  92. FTable.Attach(FMaxRecentUsed ,1,2,5,6,0,GTK_FILL,4,4);
  93. // button area
  94. FOK:=TFpGtkButton.CreateWithLabel(SOK);
  95. FOK.ConnectClicked(@SaveResult,Nil);
  96. FCancel:=TFPgtkButton.CreateWithLabel(SCancel);
  97. FCancel.ConnectCLicked(@CloseWithResult,IntToPointer(drCancel));
  98. FSeparator:=TFPgtkHSeparator.Create;
  99. FButtonBox:=TfpGtkHBox.Create;
  100. FButtonBox.Spacing:=4;
  101. FButtonBox.PackEnd(FOK,false,false,4);
  102. FButtonBox.PackEnd(FCancel,false,false,4);
  103. // Add to window
  104. FVBox.PackStart(FTable,False,False,0);
  105. FVBox.PackStart(FSeparator,False,False,4);
  106. FVBox.PackStart(FButtonBox,false,false,0);
  107. // Some events;
  108. ConnectShow(@OnShow,Nil);
  109. end;
  110. Procedure TOptionsForm.OnShow(Sender : TFpgtkObject; Data : Pointer);
  111. begin
  112. OptionsToForm;
  113. FocusedWidget(FConfirmDelete);
  114. end;
  115. Procedure TOptionsForm.SaveResult(Sender : TFpgtkObject; Data : Pointer);
  116. begin
  117. FormToOptions;
  118. CloseWithResult(Sender,IntToPointer(drOK));
  119. end;
  120. Procedure TOptionsForm.OptionsToForm;
  121. begin
  122. FCreateBackup.Active:=CreateBackup;
  123. FSkipEmptyNodes.Active:=SkipEmptyNodes;
  124. FConfirmDelete.Active:=ConfirmDelete;
  125. FBackupExtension.Text:=BackupExtension;
  126. FDefaultExtension.Text:=DefaultExtension;
  127. FMaxRecentUsed.AsInteger:=MaxRecentUsed;
  128. end;
  129. Procedure TOptionsForm.FormToOptions;
  130. begin
  131. CreateBackup:=FCreateBackup.Active;
  132. SkipEmptyNodes:=FSkipEmptyNodes.Active;
  133. ConfirmDelete:=FConfirmDelete.Active;
  134. BackupExtension:=FBackupExtension.Text;
  135. DefaultExtension:=FDefaultExtension.Text;
  136. MaxRecentUsed:=FMaxRecentUsed.AsInteger;
  137. SaveOptions;
  138. end;
  139. end.