forked from zsdwxm/KernowSoftwareFMX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ksComponentEditors.pas
133 lines (106 loc) · 3.08 KB
/
ksComponentEditors.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
unit ksComponentEditors;
interface
uses Classes, DesignEditors, DesignIntf;
const
C_VERB_ABOUT = 'About';
C_ADD_TAB = '&Add Tab';
C_NEXT_TAB = '&Next Tab';
C_PREV_TAB = '&Previous Tab';
type
TksBaseComponentEditor = class(TComponentEditor)
private
FVerbs: TStringList;
protected
procedure BuildVerbs(AVerbs: TStrings); virtual;
public
constructor Create(AComponent: TComponent; ADesigner: IDesigner); override;
destructor Destroy; override;
function GetVerbCount: Integer; override;
function GetVerb(Index: Integer): string; override;
procedure ExecuteVerb(Index: Integer); override;
end;
TksTabControlComponentEditor = class(TksBaseComponentEditor)
private
protected
procedure BuildVerbs(AVerbs: TStrings); override;
public
procedure ExecuteVerb(Index: Integer); override;
end;
procedure Register;
implementation
uses SysUtils, FMX.Types, FMX.Dialogs, ksTabControl, ksTypes;
procedure Register;
begin
RegisterComponentEditor(TksComponent, TksBaseComponentEditor);
RegisterComponentEditor(TksControl, TksBaseComponentEditor);
// tab control...
RegisterComponentEditor(TksTabControl, TksTabControlComponentEditor);
RegisterComponentEditor(TksTabItem, TksTabControlComponentEditor);
end;
{ TksTabControlComponentEditor }
procedure TksTabControlComponentEditor.BuildVerbs(AVerbs: TStrings);
begin
inherited;
AVerbs.Add(C_ADD_TAB);
AVerbs.Add('-');
AVerbs.Add(C_PREV_TAB);
AVerbs.Add(C_NEXT_TAB);
end;
procedure TksTabControlComponentEditor.ExecuteVerb(Index: Integer);
var
ItemParent: TFmxObject;
ATabControl: TksTabControl;
begin
inherited;
ATabControl := nil;
if Component is TksTabControl then
ATabControl := (Component as TksTabControl);
if Component is TksTabItem then
ATabControl := TksTabControl(TksTabItem(Component).Parent);
if FVerbs[Index] = C_ADD_TAB then
begin
if ATabControl <> nil then
begin
ItemParent := TFmxObject((ATabControl as IItemsContainer).GetObject);
Designer.CreateChild(TksTabItem, ItemParent);
end;
end;
if FVerbs[Index] = C_PREV_TAB then ATabControl.PrevTab;
if FVerbs[Index] = C_NEXT_TAB then ATabControl.NextTab;
end;
{ TksBaseComponentEditor }
procedure TksBaseComponentEditor.BuildVerbs(AVerbs: TStrings);
begin
end;
constructor TksBaseComponentEditor.Create(AComponent: TComponent; ADesigner: IDesigner);
begin
inherited;
FVerbs := TStringList.Create;
BuildVerbs(FVerbs);
if FVerbs.Count > 0 then
FVerbs.Add('-');
FVerbs.Add(C_VERB_ABOUT);
FVerbs.Add('-');
end;
destructor TksBaseComponentEditor.Destroy;
begin
FVerbs.Free;
inherited;
end;
procedure TksBaseComponentEditor.ExecuteVerb(Index: Integer);
begin
inherited;
if FVerbs[Index] = C_VERB_ABOUT then
ShowMessage('ksComponents - Components for FireMonkey'+#13+#13+
'Twitter: @kscomponents'+#13+#13+
'Copyright © 2016 Graham Murt');
end;
function TksBaseComponentEditor.GetVerb(Index: Integer): string;
begin
Result := FVerbs[Index];
end;
function TksBaseComponentEditor.GetVerbCount: Integer;
begin
Result := FVerbs.Count;
end;
end.