-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
ChatGPT.TextEditor.pas
89 lines (74 loc) · 2.26 KB
/
ChatGPT.TextEditor.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
unit ChatGPT.TextEditor;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
ChatGPT.Overlay, FMX.Objects, FMX.Controls.Presentation, FMX.Layouts,
FMX.ListBox, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo;
type
TFrameTextEditor = class(TFrameOveraly)
LayoutClient: TLayout;
RectangleFrame: TRectangle;
LayoutActions: TLayout;
ButtonOk: TButton;
LabelCaption: TLabel;
Rectangle1: TRectangle;
MemoText: TMemo;
ButtonCancel: TButton;
procedure FrameResize(Sender: TObject);
procedure ButtonOkClick(Sender: TObject);
procedure ButtonCancelClick(Sender: TObject);
private
FProcCallback: TProc<TFrameTextEditor, Boolean>;
FLayoutClientWidth, FLayoutClientHeight: Single;
public
constructor Create(AOwner: TComponent); override;
procedure Cancel; override;
class procedure Execute(AParent: TControl; ProcSet: TProc<TFrameTextEditor>; ProcExecuted: TProc<TFrameTextEditor, Boolean>);
end;
var
FrameTextEditor: TFrameTextEditor;
implementation
uses
System.Math;
{$R *.fmx}
procedure TFrameTextEditor.ButtonCancelClick(Sender: TObject);
begin
Cancel;
end;
procedure TFrameTextEditor.ButtonOkClick(Sender: TObject);
begin
if Assigned(FProcCallback) then
FProcCallback(Self, True);
Release;
end;
procedure TFrameTextEditor.Cancel;
begin
if Assigned(FProcCallback) then
FProcCallback(Self, False);
Release;
end;
constructor TFrameTextEditor.Create(AOwner: TComponent);
begin
inherited;
Name := '';
FLayoutClientWidth := LayoutClient.Width;
FLayoutClientHeight := LayoutClient.Height;
end;
class procedure TFrameTextEditor.Execute(AParent: TControl; ProcSet: TProc<TFrameTextEditor>; ProcExecuted: TProc<TFrameTextEditor, Boolean>);
begin
var Frame := TFrameTextEditor.Create(AParent);
Frame.Parent := AParent;
Frame.FProcCallback := ProcExecuted;
Frame.Align := TAlignLayout.Contents;
Frame.BringToFront;
if Assigned(ProcSet) then
ProcSet(Frame);
Frame.MemoText.SetFocus;
end;
procedure TFrameTextEditor.FrameResize(Sender: TObject);
begin
LayoutClient.Width := Min(FLayoutClientWidth, Width);
LayoutClient.Height := Min(FLayoutClientHeight, Height);
end;
end.