Skip to content

Commit 4c690eb

Browse files
committed
Merge branch 'feature/90-refactor-UClassHelpers-unit' into develop
Fixes #90
2 parents 277adba + af62080 commit 4c690eb

14 files changed

+152
-99
lines changed

Src/ClassHelpers.UActions.pas

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at https://mozilla.org/MPL/2.0/
5+
*
6+
* Copyright (C) 2012-2024, Peter Johnson (gravatar.com/delphidabbler).
7+
*
8+
* Class helper for TCustomActionList
9+
*
10+
* Extracted in 2024 from original UClassHelpers unit (2012-2021)
11+
}
12+
13+
unit ClassHelpers.UActions;
14+
15+
interface
16+
17+
uses
18+
// Delphi
19+
ActnList;
20+
21+
type
22+
/// <summary>Class helper that adds a method to TCustomActionList that can
23+
/// update all the actions in the list.</summary>
24+
TActionListHelper = class helper for TCustomActionList
25+
public
26+
/// <summary>Updates all actions in the action list by calling their Update
27+
/// methods.</summary>
28+
procedure Update;
29+
end;
30+
31+
implementation
32+
33+
{ TActionListHelper }
34+
35+
procedure TActionListHelper.Update;
36+
var
37+
Action: TContainedAction; // each action in list
38+
begin
39+
for Action in Self do
40+
Action.Update;
41+
end;
42+
43+
end.

Src/ClassHelpers.UControls.pas

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at https://mozilla.org/MPL/2.0/
5+
*
6+
* Copyright (C) 2012-2024, Peter Johnson (gravatar.com/delphidabbler).
7+
*
8+
* Class helper for TControl.
9+
*
10+
* Extracted in 2024 from original UClassHelpers unit (2012-2021).
11+
}
12+
13+
unit ClassHelpers.UControls;
14+
15+
interface
16+
17+
uses
18+
// Delphi
19+
Controls, Menus;
20+
21+
type
22+
/// <summary>Class helper that adds functionality to TControl.</summary>
23+
TControlHelper = class helper for TControl
24+
public
25+
/// <summary>Gets reference to pop-up menu assigned to protected PopupMenu
26+
/// property.</summary>
27+
function GetPopupMenu: TPopupMenu;
28+
/// <summary>Checks if protected PopupMenu property is assigned.</summary>
29+
function HasPopupMenu: Boolean;
30+
/// <summary>Refreshes control's action. Any changes in action that affect
31+
/// state of control are reflected in control.</summary>
32+
procedure RefreshAction;
33+
/// <summary>Refreshes all owned controls to reflect any changes in their
34+
/// associated actions.</summary>
35+
procedure RefreshActions;
36+
end;
37+
38+
implementation
39+
40+
{ TControlHelper }
41+
42+
function TControlHelper.GetPopupMenu: TPopupMenu;
43+
begin
44+
Result := PopupMenu;
45+
end;
46+
47+
function TControlHelper.HasPopupMenu: Boolean;
48+
begin
49+
Result := Assigned(PopupMenu);
50+
end;
51+
52+
procedure TControlHelper.RefreshAction;
53+
begin
54+
if Assigned(Action) then
55+
ActionChange(Action, False);
56+
end;
57+
58+
procedure TControlHelper.RefreshActions;
59+
var
60+
Idx: Integer; // loops through all controls
61+
begin
62+
for Idx := 0 to Pred(ComponentCount) do
63+
if Components[Idx] is TControl then
64+
(Components[Idx] as TControl).RefreshAction;
65+
end;
66+
67+
end.
68+

Src/UClassHelpers.pas renamed to Src/ClassHelpers.UGraphics.pas

+6-78
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,20 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2012-2021, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2012-2024, Peter Johnson (gravatar.com/delphidabbler).
77
*
8-
* Provides various class helpers for VCL classes.
8+
* Provides class helpers for VCL image classes.
9+
*
10+
* Extracted from in 2024 original UClassHelpers unit (2012-2021).
911
}
1012

11-
12-
unit UClassHelpers;
13-
14-
{ TODO: Separate different helpers into their own units, within a ClassHelpers
15-
scope. E.g. ClassHelpers.Controls, ClassHelper.Graphics }
13+
unit ClassHelpers.UGraphics;
1614

1715
interface
1816

19-
2017
uses
2118
// Delphi
22-
Controls, Menus, ImgList, Graphics, ActnList, GIFImg;
23-
24-
25-
type
26-
/// <summary>Class helper that adds functionality to TControl.</summary>
27-
TControlHelper = class helper for TControl
28-
public
29-
/// <summary>Gets reference to pop-up menu assigned to protected PopupMenu
30-
/// property.</summary>
31-
function GetPopupMenu: TPopupMenu;
32-
/// <summary>Checks if protected PopupMenu property is assigned.</summary>
33-
function HasPopupMenu: Boolean;
34-
/// <summary>Refreshes control's action. Any changes in action that affect
35-
/// state of control are reflected in control.</summary>
36-
procedure RefreshAction;
37-
/// <summary>Refreshes all owned controls to reflect any changes in their
38-
/// associated actions.</summary>
39-
procedure RefreshActions;
40-
end;
19+
ImgList, Graphics, GIFImg;
4120

4221
type
4322
/// <summary>Class helper that adds a method to TCustomImageList that can
@@ -62,16 +41,6 @@ TImageListHelper = class helper for TCustomImageList
6241
Size: Integer; MaskColour: TColor);
6342
end;
6443

65-
type
66-
/// <summary>Class helper that adds a method to TCustomActionList that can
67-
/// update all the actions in the list.</summary>
68-
TActionListHelper = class helper for TCustomActionList
69-
public
70-
/// <summary>Updates all actions in the action list by calling their Update
71-
/// methods.</summary>
72-
procedure Update;
73-
end;
74-
7544
type
7645
/// <summary>Class helper that adds a method to TGIFImage that adds a similar
7746
/// method to one present in 3rd party TGIFImage to load an image from
@@ -87,42 +56,12 @@ TGIFImageHelper = class helper for TGIFImage
8756
const ResType: PChar);
8857
end;
8958

90-
9159
implementation
9260

93-
9461
uses
9562
// Delphi
9663
Classes;
9764

98-
99-
{ TControlHelper }
100-
101-
function TControlHelper.GetPopupMenu: TPopupMenu;
102-
begin
103-
Result := PopupMenu;
104-
end;
105-
106-
function TControlHelper.HasPopupMenu: Boolean;
107-
begin
108-
Result := Assigned(PopupMenu);
109-
end;
110-
111-
procedure TControlHelper.RefreshAction;
112-
begin
113-
if Assigned(Action) then
114-
ActionChange(Action, False);
115-
end;
116-
117-
procedure TControlHelper.RefreshActions;
118-
var
119-
Idx: Integer; // loops through all controls
120-
begin
121-
for Idx := 0 to Pred(ComponentCount) do
122-
if Components[Idx] is TControl then
123-
(Components[Idx] as TControl).RefreshAction;
124-
end;
125-
12665
{ TImageListHelper }
12766

12867
procedure TImageListHelper.LoadFromResource(ResType: PChar;
@@ -181,16 +120,6 @@ procedure TImageListHelper.LoadFromResource(ResType: PChar;
181120
end;
182121
end;
183122

184-
{ TActionListHelper }
185-
186-
procedure TActionListHelper.Update;
187-
var
188-
Action: TContainedAction; // each action in list
189-
begin
190-
for Action in Self do
191-
Action.Update;
192-
end;
193-
194123
{ TGIFImageHelper }
195124

196125
procedure TGIFImageHelper.LoadFromResource(const Module: HMODULE;
@@ -207,4 +136,3 @@ procedure TGIFImageHelper.LoadFromResource(const Module: HMODULE;
207136
end;
208137

209138
end.
210-

Src/CodeSnip.dpr

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2005-2023, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2005-2024, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* CodeSnip application project file.
99
}
@@ -192,7 +192,7 @@ uses
192192
UBrowseProtocol in 'UBrowseProtocol.pas',
193193
UCategoryAction in 'UCategoryAction.pas',
194194
UCategoryListAdapter in 'UCategoryListAdapter.pas',
195-
UClassHelpers in 'UClassHelpers.pas',
195+
ClassHelpers.UControls in 'ClassHelpers.UControls.pas',
196196
UClipboardHelper in 'UClipboardHelper.pas',
197197
UCodeImportExport in 'UCodeImportExport.pas',
198198
UCodeImportMgr in 'UCodeImportMgr.pas',
@@ -372,7 +372,9 @@ uses
372372
FmDeleteUserDBDlg in 'FmDeleteUserDBDlg.pas' {DeleteUserDBDlg},
373373
Compilers.UAutoDetect in 'Compilers.UAutoDetect.pas',
374374
Compilers.USettings in 'Compilers.USettings.pas',
375-
FmRegisterCompilersDlg in 'FmRegisterCompilersDlg.pas' {RegisterCompilersDlg};
375+
FmRegisterCompilersDlg in 'FmRegisterCompilersDlg.pas' {RegisterCompilersDlg},
376+
ClassHelpers.UGraphics in 'ClassHelpers.UGraphics.pas',
377+
ClassHelpers.UActions in 'ClassHelpers.UActions.pas';
376378

377379
// Include resources
378380
{$Resource ExternalObj.tlb} // Type library file

Src/CodeSnip.dproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@
394394
<DCCReference Include="UBrowseProtocol.pas"/>
395395
<DCCReference Include="UCategoryAction.pas"/>
396396
<DCCReference Include="UCategoryListAdapter.pas"/>
397-
<DCCReference Include="UClassHelpers.pas"/>
397+
<DCCReference Include="ClassHelpers.UControls.pas"/>
398398
<DCCReference Include="UClipboardHelper.pas"/>
399399
<DCCReference Include="UCodeImportExport.pas"/>
400400
<DCCReference Include="UCodeImportMgr.pas"/>
@@ -579,6 +579,8 @@
579579
<DCCReference Include="FmRegisterCompilersDlg.pas">
580580
<Form>RegisterCompilersDlg</Form>
581581
</DCCReference>
582+
<DCCReference Include="ClassHelpers.UGraphics.pas"/>
583+
<DCCReference Include="ClassHelpers.UActions.pas"/>
582584
<None Include="CodeSnip.todo"/>
583585
<BuildConfiguration Include="Base">
584586
<Key>Base</Key>

Src/FmBase.pas

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2005-2021, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2005-2024, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* Implements a form that provides the ancestor of all forms in the application.
99
* Provides default names for form window classes along with various operations
@@ -136,7 +136,8 @@ implementation
136136
// Delphi
137137
SysUtils, Windows, Menus,
138138
// Project
139-
UAppInfo, UBaseObjects, UClassHelpers, UFontHelper, UKeysHelper, UMenus,
139+
ClassHelpers.UControls,
140+
UAppInfo, UBaseObjects, UFontHelper, UKeysHelper, UMenus,
140141
UNulFormAligner, UStrUtils;
141142

142143
{$R *.dfm}

Src/FmCompilersDlg.FrSearchDirs.pas

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2011-2021, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2011-2024, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* Implements a frame used to edit lists of search directories used for a
99
* compiler being edited in TCompilersDlg.
@@ -109,7 +109,10 @@ implementation
109109
// Delphi
110110
SysUtils, Windows, Graphics,
111111
// Project
112-
UBrowseForFolderDlg, UClassHelpers, UCtrlArranger, UStrUtils;
112+
ClassHelpers.UActions,
113+
ClassHelpers.UControls,
114+
ClassHelpers.UGraphics,
115+
UBrowseForFolderDlg, UCtrlArranger, UStrUtils;
113116

114117
{$R *.dfm}
115118

Src/FmMain.pas

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2005-2023, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2005-2024, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* Application's main form. Handles the program's main window display and user
99
* interaction.
@@ -583,9 +583,11 @@ implementation
583583
// Delphi
584584
Windows, Graphics,
585585
// Project
586+
ClassHelpers.UControls,
587+
ClassHelpers.UGraphics,
586588
DB.UCategory, DB.UMain, DB.USnippet, FmSplash, FmTrappedBugReportDlg,
587589
FmWaitDlg, IntfFrameMgrs, UActionFactory, UAppInfo,
588-
UClassHelpers, UCodeShareMgr, UCommandBars, UConsts, UCopyInfoMgr,
590+
UCodeShareMgr, UCommandBars, UConsts, UCopyInfoMgr,
589591
UCopySourceMgr, UDatabaseLoader, UDatabaseLoaderUI, UDetailTabAction,
590592
UEditSnippetAction, UExceptions, UHelpMgr, UHistoryMenus, UKeysHelper,
591593
UMessageBox, UNotifier, UNulDropTarget, UPrintMgr, UQuery, USaveSnippetMgr,

Src/FmPrintDlg.pas

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2007-2023, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2007-2024, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* Implements a print dialogue box.
99
}
@@ -76,7 +76,8 @@ implementation
7676
// Delphi
7777
Printers, Graphics,
7878
// Project
79-
FmPreferencesDlg, FrPrintingPrefs, UClassHelpers, UConsts, UMessageBox,
79+
ClassHelpers.UGraphics,
80+
FmPreferencesDlg, FrPrintingPrefs, UConsts, UMessageBox,
8081
UPageSetupDlgMgr, UPrintInfo, UStructs, UStrUtils;
8182

8283

Src/FmSplash.pas

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2007-2023, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2007-2024, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* Implements the program's splash screen.
99
}
@@ -68,7 +68,8 @@ implementation
6868
// Delphi
6969
Windows, Graphics, GIFImg,
7070
// Project
71-
UAppInfo, UClassHelpers, UColours, UStructs, UWindowSettings;
71+
ClassHelpers.UGraphics,
72+
UAppInfo, UColours, UStructs, UWindowSettings;
7273

7374

7475
{$R *.dfm}

0 commit comments

Comments
 (0)