Skip to content

Commit 78513cd

Browse files
author
Joachim Marder
committed
Issue #22: Add ability to start Ribbon Desginer to right click menu of TUiRibbon control
1 parent 1ad0835 commit 78513cd

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

Lib/UIRibbon.Register.pas

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,92 @@
22

33
interface
44

5+
uses
6+
DesignIntf, DesignEditors;
7+
8+
type
9+
// Adds ability to start RibbonDesigner to right click menu of TUIRibbon control in IDE desginer
10+
TMyRibbonFrameworkEditor=class(TComponentEditor)
11+
public
12+
class function GetDesignerPath(): string;
13+
function GetVerbCount: Integer; override;
14+
function GetVerb(pIndex: Integer): string; override;
15+
procedure ExecuteVerb(pIndex: Integer); override;
16+
end;
17+
518
procedure Register;
619

720
implementation
821

922
uses
10-
Classes, UIRibbon, UIRibbonActions, System.Actions;
23+
Classes, UIRibbon, SysUtils, UIRibbonActions, System.Actions, System.Win.Registry,
24+
Winapi.ShellAPI, Winapi.Windows, UIRibbonUtils, ToolsApi;
1125

1226
procedure Register;
27+
var
28+
lDesignerPath: string;
1329
begin
1430
RegisterComponents('Windows Ribbon Framework for Delphi', [TUIRibbon]);
15-
RegisterActions('Ribbon Framework', [TRibbonCollectionAction, TRibbonFontAction, TRibbonColorAction], nil);
31+
RegisterActions(cPackageTitle, [TRibbonCollectionAction, TRibbonFontAction, TRibbonColorAction], nil);
32+
33+
lDesignerPath := TMyRibbonFrameworkEditor.GetDesignerPath();
34+
if lDesignerPath.IsEmpty then begin
35+
// Search designer based on project path
36+
lDesignerPath := ExtractFilePath(ExcludeTrailingPathDelimiter(ExtractFilePath(getActiveProject.fileName)));
37+
lDesignerPath := IncludeTrailingPathDelimiter(lDesignerPath) + 'Designer\Bin\RibbonDesigner.exe';
38+
if not FileExists(lDesignerPath) then
39+
lDesignerPath := ''
40+
else begin
41+
// Write the path to the Ribbon Designer to the registry, so that the designtime package knows where to find it
42+
With TRegistry.Create do
43+
try
44+
OpenKey(cRegistryPath, True);
45+
WriteString(cRegistryKeyDesigner, lDesignerPath);
46+
finally
47+
Free;
48+
end;
49+
end;
50+
end;
51+
52+
if not lDesignerPath.IsEmpty then begin
53+
RegisterComponentEditor(TUIRibbon, TMyRibbonFrameworkEditor);
54+
end;//if lDesignerPath
55+
end;
56+
57+
{ TMyRibbonFrameworkEditor }
58+
59+
class function TMyRibbonFrameworkEditor.GetDesignerPath: string;
60+
begin
61+
With TRegistry.Create do
62+
try
63+
OpenKeyReadOnly(cRegistryPath);
64+
Result := ReadString(cRegistryKeyDesigner);
65+
finally
66+
Free;
67+
end;
68+
end;
69+
70+
procedure TMyRibbonFrameworkEditor.ExecuteVerb(pIndex: Integer);
71+
//var
72+
// lRibbon: TUIRibbon;
73+
begin
74+
inherited;
75+
// lRibbon := (Self.Component as TUiRibbon);
76+
case pIndex of
77+
0: ShellExecute(0, 'open', PChar(GetDesignerPath()), nil, nil, SW_SHOWNORMAL);
78+
end;
79+
end;
80+
81+
function TMyRibbonFrameworkEditor.GetVerb(pIndex: Integer): string;
82+
begin
83+
case pIndex of
84+
0: Result := '&Ribbon Designer';
85+
end;
86+
end;
87+
88+
function TMyRibbonFrameworkEditor.GetVerbCount: Integer;
89+
begin
90+
Exit(1);
1691
end;
1792

1893
end.

Package/UIRibbonPackage.dpk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ package UIRibbonPackage;
2828
{$IMPLICITBUILD ON}
2929

3030
requires
31-
rtl,
31+
DesignIDE,
3232
vcl,
3333
vclimg;
3434

Package/UIRibbonPackage.dproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<DelphiCompile Include="$(MainSource)">
8080
<MainSource>MainSource</MainSource>
8181
</DelphiCompile>
82-
<DCCReference Include="rtl.dcp"/>
82+
<DCCReference Include="DesignIDE.dcp"/>
8383
<DCCReference Include="vcl.dcp"/>
8484
<DCCReference Include="vclimg.dcp"/>
8585
<DCCReference Include="..\Lib\UIRibbon.pas"/>

0 commit comments

Comments
 (0)