-
Notifications
You must be signed in to change notification settings - Fork 19
/
LogViewer.Factories.Toolbars.pas
238 lines (205 loc) · 6.69 KB
/
LogViewer.Factories.Toolbars.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
{
Copyright (C) 2013-2022 Tim Sinaeve [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
}
unit LogViewer.Factories.Toolbars;
{ Application toolbar factories. }
interface
uses
System.Classes, System.SysUtils,
Vcl.Controls, Vcl.Menus, Vcl.ActnList, Vcl.ComCtrls, Vcl.Toolwin,
LogViewer.Interfaces;
const
DEFAULT_EDGE_BORDERS = [ebLeft, ebTop, ebRight, ebBottom];
DEFAULT_EDGE_INNER = esNone;
DEFAULT_EDGE_OUTER = esNone;
DEFAULT_TRANSPARANT = True;
type
TLogViewerToolbarsFactory = class(TInterfacedObject, ILogViewerToolbarsFactory)
private
FActions : ILogViewerActions;
FMenus : ILogViewerMenus;
FEdgeBorders : TEdgeBorders;
FEdgeInner : TEdgeStyle;
FEdgeOuter : TEdgeStyle;
FTransparant : Boolean;
procedure ApplyDefaultProperties(AToolbar: TToolbar);
function CreateToolButton(
AParent : TToolBar;
AAction : TBasicAction = nil;
AStyle : TToolButtonStyle = tbsButton;
APopupMenu : TPopupMenu = nil
): TToolButton; overload;
function CreateToolButton(
AParent : TToolBar;
const AActionName : string;
AStyle : TToolButtonStyle = tbsButton;
APopupMenu : TPopupMenu = nil
): TToolButton; overload;
class procedure OnDropdownMenuButtonClick(Sender: TObject);
public
procedure AfterConstruction; override;
constructor Create(
AActions : ILogViewerActions;
AMenus : ILogViewerMenus
);
function CreateMainToolbar(
AOwner : TComponent;
AParent : TWinControl
): TToolbar;
function CreateRightTopToolbar(
AOwner : TComponent;
AParent : TWinControl
): TToolbar;
property EdgeBorders: TEdgeBorders
read FEdgeBorders write FEdgeBorders default DEFAULT_EDGE_BORDERS;
property EdgeInner: TEdgeStyle
read FEdgeInner write FEdgeInner default DEFAULT_EDGE_INNER;
property EdgeOuter: TEdgeStyle
read FEdgeOuter write FEdgeOuter default DEFAULT_EDGE_OUTER;
property Transparant: Boolean
read FTransparant write FTransparant default DEFAULT_TRANSPARANT;
end;
implementation
uses
Spring;
{$REGION 'construction and destruction'}
procedure TLogViewerToolbarsFactory.AfterConstruction;
begin
inherited AfterConstruction;
FEdgeBorders := DEFAULT_EDGE_BORDERS;
FEdgeInner := DEFAULT_EDGE_INNER;
FEdgeOuter := DEFAULT_EDGE_OUTER;
FTransparant := DEFAULT_TRANSPARANT;
end;
constructor TLogViewerToolbarsFactory.Create(AActions: ILogViewerActions;
AMenus: ILogViewerMenus);
begin
inherited Create;
Guard.CheckNotNull(AActions, 'AActions');
Guard.CheckNotNull(AMenus, 'AMenus');
FActions := AActions;
FMenus := AMenus;
end;
{$ENDREGION}
{$REGION 'private methods'}
procedure TLogViewerToolbarsFactory.ApplyDefaultProperties(AToolbar: TToolbar);
begin
Guard.CheckNotNull(AToolbar, 'AToolbar');
AToolbar.EdgeBorders := EdgeBorders;
AToolbar.EdgeInner := EdgeInner;
AToolbar.EdgeOuter := EdgeOuter;
AToolbar.Transparent := Transparant;
AToolbar.ParentColor := True;
AToolbar.AutoSize := True;
AToolbar.ShowHint := True;
end;
function TLogViewerToolbarsFactory.CreateToolButton(AParent: TToolBar;
const AActionName: string; AStyle: TToolButtonStyle; APopupMenu: TPopupMenu)
: TToolButton;
begin
if AActionName = '' then
Result := CreateToolButton(AParent)
else
Result :=
CreateToolButton(AParent, FActions[AActionName], AStyle, APopupMenu);
end;
class procedure TLogViewerToolbarsFactory.OnDropdownMenuButtonClick(Sender: TObject);
begin
(Sender as TToolButton).CheckMenuDropdown;
end;
function TLogViewerToolbarsFactory.CreateToolButton(AParent: TToolBar;
AAction: TBasicAction; AStyle: TToolButtonStyle; APopupMenu: TPopupMenu)
: TToolButton;
var
TB : TToolButton;
N : Integer;
begin
TB := TToolButton.Create(AParent);
N := AParent.ButtonCount - 1;
if N > -1 then
TB.Left := AParent.Buttons[N].Left + AParent.Buttons[N].Width
else
TB.Left := 0;
TB.Parent := AParent;
if not Assigned(AAction) then
begin
TB.Style := tbsSeparator;
TB.Width := 4;
end
else
begin
TB.Style := AStyle;
if Assigned(APopupMenu) then
begin
TB.Style := tbsDropDown;
TB.DropdownMenu := APopupMenu;
TB.OnClick := OnDropdownMenuButtonClick;
end;
TB.Action := AAction;
end;
AParent.Realign;
Result := TB;
end;
{$ENDREGION}
{$REGION 'public methods'}
function TLogViewerToolbarsFactory.CreateMainToolbar(AOwner: TComponent;
AParent: TWinControl): TToolbar;
var
TB : TToolbar;
begin
Guard.CheckNotNull(AOwner, 'AOwner');
Guard.CheckNotNull(AParent, 'AParent');
TB := TToolBar.Create(AOwner);
ApplyDefaultProperties(TB);
TB.Parent := AParent;
TB.Images := FActions.ActionList.Images;
TB.ButtonWidth := 10;
TB.AllowTextButtons := True;
CreateToolButton(TB, 'actDashboard', tbsTextButton);
CreateToolButton(TB);
CreateToolButton(TB, 'actStart', tbsTextButton);
CreateToolButton(TB, 'actStop', tbsTextButton);
CreateToolButton(TB);
CreateToolButton(TB, 'actSettings', tbsTextButton);
CreateToolButton(TB);
CreateToolButton(TB, 'actShowFilterView', tbsTextButton);
CreateToolButton(TB, 'actClearMessages', tbsTextButton);
CreateToolButton(TB);
CreateToolButton(TB, 'actCloseTerminatedProcesses', tbsTextButton);
CreateToolButton(TB);
CreateToolButton(TB, 'actCollapseAll', tbsTextButton);
CreateToolButton(TB, 'actExpandAll', tbsTextButton);
CreateToolButton(TB, 'actAutoScrollMessages', tbsTextButton);
CreateToolButton(TB, 'actToggleLeftPanelVisible', tbsTextButton);
CreateToolButton(TB, 'actToggleRightPanelVisible', tbsTextButton);
Result := TB;
end;
function TLogViewerToolbarsFactory.CreateRightTopToolbar(AOwner: TComponent;
AParent: TWinControl): TToolbar;
var
TB : TToolbar;
begin
Guard.CheckNotNull(AOwner, 'AOwner');
Guard.CheckNotNull(AParent, 'AParent');
TB := TToolBar.Create(AOwner);
ApplyDefaultProperties(TB);
TB.Parent := AParent;
TB.Images := FActions.ActionList.Images;
TB.ButtonWidth := 10;
TB.AllowTextButtons := True;
CreateToolButton(TB, 'actAbout');
CreateToolButton(TB);
CreateToolButton(TB, 'actToggleAlwaysOnTop');
Result := TB;
end;
{$ENDREGION}
end.