frmbrookactedit.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. (*
  2. Brook for Free Pascal
  3. Copyright (C) 2014-2019 Silvio Clecio
  4. See the file LICENSE.txt, included in this distribution,
  5. for details about the copyright.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. *)
  10. { Action edit unit. }
  11. unit frmBrookActEdit;
  12. {$i brook.inc}
  13. interface
  14. uses
  15. Forms, ExtCtrls, Buttons, StdCtrls, Controls, SysUtils, Dialogs;
  16. type
  17. TfrBrookActEdit = class(TForm)
  18. btOK: TBitBtn;
  19. btCancel: TBitBtn;
  20. cbDefault: TCheckBox;
  21. edName: TEdit;
  22. edPattern: TEdit;
  23. lbInfo: TLabel;
  24. lbName: TLabel;
  25. lbPattern: TLabel;
  26. pnClient: TPanel;
  27. pnBottom: TPanel;
  28. sbClient: TScrollBox;
  29. procedure edNameExit(Sender: TObject);
  30. procedure edNameKeyPress(Sender: TObject; var Key: char);
  31. procedure edPatternKeyPress(Sender: TObject; var Key: char);
  32. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  33. private
  34. FQuiet: Boolean;
  35. public
  36. class function Execute(const ACapType: ShortString;
  37. var AName, APattern: string; var ADefault: Boolean;
  38. const AQuiet: Boolean = False): Boolean;
  39. procedure AssertData(const AExpr: Boolean; const AMsg: string;
  40. AControl: TWinControl);
  41. end;
  42. implementation
  43. {$R *.lfm}
  44. uses
  45. frmBrookNewProject;
  46. procedure TfrBrookActEdit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  47. var
  48. VForm: TfrBrookNewProject;
  49. begin
  50. if ModalResult <> mrOK then
  51. Exit;
  52. CanClose := False;
  53. AssertData(edName.Text <> '',
  54. 'Please specify a name for the action.', edName);
  55. if not FQuiet then
  56. begin
  57. VForm := TfrBrookNewProject.Instante;
  58. VForm.lvActions.Selected := nil;
  59. VForm.ValidateData(edName.Text, edPattern.Text, cbDefault.Checked);
  60. end;
  61. CanClose := True;
  62. end;
  63. procedure TfrBrookActEdit.edNameKeyPress(Sender: TObject; var Key: char);
  64. begin
  65. OnlyAlphaNumeric(Key);
  66. end;
  67. procedure TfrBrookActEdit.edNameExit(Sender: TObject);
  68. begin
  69. if (edName.Text <> '') and (edPattern.Text = '') then
  70. begin
  71. edPattern.Text := '/' + LowerCase(edName.Text);
  72. edPattern.SetFocus;
  73. end;
  74. end;
  75. procedure TfrBrookActEdit.edPatternKeyPress(Sender: TObject; var Key: char);
  76. begin
  77. case Key of
  78. '*', ':', '/':;
  79. '\': Key := '/';
  80. else
  81. OnlyAlphaNumeric(Key);
  82. end;
  83. end;
  84. class function TfrBrookActEdit.Execute(const ACapType: ShortString;
  85. var AName, APattern: string; var ADefault: Boolean;
  86. const AQuiet: Boolean): Boolean;
  87. begin
  88. with Self.Create(nil) do
  89. try
  90. FQuiet := AQuiet;
  91. Caption := Format(Caption, [ACapType]);
  92. edName.Text := AName;
  93. edPattern.Text := APattern;
  94. cbDefault.Checked := ADefault;
  95. Result := ShowModal = mrOK;
  96. if Result then
  97. begin
  98. AName := edName.Text;
  99. APattern := edPattern.Text;
  100. ADefault := cbDefault.Checked;
  101. end;
  102. finally
  103. Free;
  104. end;
  105. end;
  106. procedure TfrBrookActEdit.AssertData(const AExpr: Boolean; const AMsg: string;
  107. AControl: TWinControl);
  108. begin
  109. if not AExpr then
  110. begin
  111. if AControl.CanFocus then
  112. AControl.SetFocus;
  113. ShowMessage(AMsg);
  114. Abort;
  115. end;
  116. end;
  117. end.