|
2 | 2 |
|
3 | 3 | interface |
4 | 4 |
|
| 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 | + |
5 | 18 | procedure Register; |
6 | 19 |
|
7 | 20 | implementation |
8 | 21 |
|
9 | 22 | uses |
10 | | - Classes, UIRibbon, UIRibbonActions, System.Actions; |
| 23 | + Classes, UIRibbon, SysUtils, UIRibbonActions, System.Actions, System.Win.Registry, |
| 24 | + Winapi.ShellAPI, Winapi.Windows, UIRibbonUtils, ToolsApi; |
11 | 25 |
|
12 | 26 | procedure Register; |
| 27 | +var |
| 28 | + lDesignerPath: string; |
13 | 29 | begin |
14 | 30 | 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); |
16 | 91 | end; |
17 | 92 |
|
18 | 93 | end. |
0 commit comments