@@ -22,9 +22,7 @@ public void BuildUI(IExtension extension, ExtensionAssemblyInfo assemblyInfo)
22
22
return ;
23
23
24
24
foreach ( var obj in extension . Children as IEnumerable < object > ?? Enumerable . Empty < object > ( ) )
25
- {
26
25
RecursivelyBuildUI ( obj , null , null , extension . Name , assemblyInfo ) ;
27
- }
28
26
}
29
27
30
28
private void RecursivelyBuildUI ( object obj , object parentComponent , RibbonPanel parentPanel , string tabName , ExtensionAssemblyInfo assemblyInfo )
@@ -39,84 +37,133 @@ private void RecursivelyBuildUI(object obj, object parentComponent, RibbonPanel
39
37
{
40
38
case CommandComponentType . Tab :
41
39
try { _uiApp . CreateRibbonTab ( component . Name ) ; } catch { }
42
- foreach ( var child in component . Children as IEnumerable < object > ?? Enumerable . Empty < object > ( ) )
40
+ foreach ( var child in component . Children ?? Enumerable . Empty < object > ( ) )
43
41
RecursivelyBuildUI ( child , component , null , component . Name , assemblyInfo ) ;
44
42
break ;
45
43
46
44
case CommandComponentType . Panel :
47
45
var panel = _uiApp . GetRibbonPanels ( tabName ) . FirstOrDefault ( p => p . Name == component . Name )
48
46
?? _uiApp . CreateRibbonPanel ( tabName , component . Name ) ;
49
- foreach ( var child in component . Children as IEnumerable < object > ?? Enumerable . Empty < object > ( ) )
47
+ foreach ( var child in component . Children ?? Enumerable . Empty < object > ( ) )
50
48
RecursivelyBuildUI ( child , component , panel , tabName , assemblyInfo ) ;
51
49
break ;
52
50
53
51
case CommandComponentType . Stack :
54
- var buttonDatas = new List < RibbonItemData > ( ) ;
52
+ var itemDataList = new List < RibbonItemData > ( ) ;
53
+ var originalItems = new List < ICommandComponent > ( ) ;
55
54
56
55
foreach ( var child in component . Children as IEnumerable < object > ?? Enumerable . Empty < object > ( ) )
57
56
{
58
57
var subCmd = child as ICommandComponent ;
59
- if ( subCmd == null ) continue ;
58
+ if ( subCmd == null )
59
+ continue ;
60
60
61
61
var subType = CommandComponentTypeExtensions . FromExtension ( subCmd . Type ) ;
62
- switch ( subType )
62
+
63
+ if ( subType == CommandComponentType . PushButton )
64
+ {
65
+ itemDataList . Add ( new PushButtonData ( subCmd . UniqueId , subCmd . Name , assemblyInfo . Location , subCmd . UniqueId ) ) ;
66
+ originalItems . Add ( subCmd ) ;
67
+ }
68
+ else if ( subType == CommandComponentType . PullDown )
63
69
{
64
- case CommandComponentType . PushButton :
65
- buttonDatas . Add ( new PushButtonData ( subCmd . Name , subCmd . Name , assemblyInfo . Location , subCmd . UniqueId ) ) ;
66
- break ;
67
- case CommandComponentType . PullDown :
68
- buttonDatas . Add ( new PulldownButtonData ( subCmd . Name , subCmd . Name ) ) ;
69
- break ;
70
+ var pdData = new PulldownButtonData ( subCmd . UniqueId , subCmd . Name ) ;
71
+ itemDataList . Add ( pdData ) ;
72
+ originalItems . Add ( subCmd ) ; // to match later
70
73
}
71
74
}
72
75
73
- if ( buttonDatas . Count == 2 )
74
- parentPanel ? . AddStackedItems ( buttonDatas [ 0 ] , buttonDatas [ 1 ] ) ;
75
- else if ( buttonDatas . Count >= 3 )
76
- parentPanel ? . AddStackedItems ( buttonDatas [ 0 ] , buttonDatas [ 1 ] , buttonDatas [ 2 ] ) ;
76
+ if ( itemDataList . Count >= 2 )
77
+ {
78
+ IList < RibbonItem > stackedItems = null ;
79
+ if ( itemDataList . Count == 2 )
80
+ stackedItems = parentPanel ? . AddStackedItems ( itemDataList [ 0 ] , itemDataList [ 1 ] ) ;
81
+ else if ( itemDataList . Count >= 3 )
82
+ stackedItems = parentPanel ? . AddStackedItems ( itemDataList [ 0 ] , itemDataList [ 1 ] , itemDataList [ 2 ] ) ;
83
+
84
+ // Now post-process pulldowns to add nested pushbuttons
85
+ if ( stackedItems != null )
86
+ {
87
+ for ( int i = 0 ; i < stackedItems . Count ; i ++ )
88
+ {
89
+ var ribbonItem = stackedItems [ i ] ;
90
+ var origComponent = originalItems [ i ] ;
91
+
92
+ if ( ribbonItem is PulldownButton pdBtn )
93
+ {
94
+ foreach ( var child in origComponent . Children ?? Enumerable . Empty < object > ( ) )
95
+ {
96
+ if ( child is ICommandComponent subCmd &&
97
+ CommandComponentTypeExtensions . FromExtension ( subCmd . Type ) == CommandComponentType . PushButton )
98
+ {
99
+ var subData = new PushButtonData ( subCmd . UniqueId , subCmd . Name , assemblyInfo . Location , subCmd . UniqueId ) ;
100
+ pdBtn . AddPushButton ( subData ) ;
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
77
107
break ;
78
-
79
108
case CommandComponentType . PushButton :
80
109
case CommandComponentType . SmartButton :
81
- var pbData = new PushButtonData ( component . Name , component . Name , assemblyInfo . Location , component . UniqueId ) ;
110
+ var pbData = new PushButtonData ( component . UniqueId , component . Name , assemblyInfo . Location , component . UniqueId ) ;
82
111
var btn = parentPanel ? . AddItem ( pbData ) as PushButton ;
83
112
if ( ! string . IsNullOrEmpty ( component . Tooltip ) )
84
113
btn . ToolTip = component . Tooltip ;
85
114
break ;
86
115
87
116
case CommandComponentType . PullDown :
88
- var pdBtnData = new PulldownButtonData ( component . Name , component . Name ) ;
89
- var pdBtn = parentPanel ? . AddItem ( pdBtnData ) as PulldownButton ;
90
- if ( pdBtn == null ) return ;
91
-
92
- foreach ( var child in component . Children as IEnumerable < object > ?? Enumerable . Empty < object > ( ) )
93
- {
94
- if ( child is ICommandComponent subCmd &&
95
- CommandComponentTypeExtensions . FromExtension ( subCmd . Type ) == CommandComponentType . PushButton )
96
- {
97
- var subData = new PushButtonData ( subCmd . Name , subCmd . Name , assemblyInfo . Location , subCmd . UniqueId ) ;
98
- pdBtn . AddPushButton ( subData ) ;
99
- }
100
- }
117
+ CreatePulldown ( component , parentPanel , tabName , assemblyInfo , true ) ;
101
118
break ;
102
119
103
120
case CommandComponentType . SplitButton :
104
121
case CommandComponentType . SplitPushButton :
105
- var splitData = new SplitButtonData ( component . Name , component . Name ) ;
122
+ var splitData = new SplitButtonData ( component . UniqueId , component . Name ) ;
106
123
var splitBtn = parentPanel ? . AddItem ( splitData ) as SplitButton ;
107
124
if ( splitBtn == null ) return ;
108
125
109
- foreach ( var child in component . Children as IEnumerable < object > ?? Enumerable . Empty < object > ( ) )
126
+ foreach ( var child in component . Children ?? Enumerable . Empty < object > ( ) )
110
127
{
111
128
if ( child is ICommandComponent subCmd &&
112
129
CommandComponentTypeExtensions . FromExtension ( subCmd . Type ) == CommandComponentType . PushButton )
113
130
{
114
- var subData = new PushButtonData ( subCmd . Name , subCmd . Name , assemblyInfo . Location , subCmd . UniqueId ) ;
131
+ var subData = new PushButtonData ( subCmd . UniqueId , subCmd . Name , assemblyInfo . Location , subCmd . UniqueId ) ;
115
132
splitBtn . AddPushButton ( subData ) ;
116
133
}
117
134
}
118
135
break ;
119
136
}
120
137
}
138
+
139
+ private PulldownButtonData CreatePulldown (
140
+ ICommandComponent component ,
141
+ RibbonPanel parentPanel ,
142
+ string tabName ,
143
+ ExtensionAssemblyInfo assemblyInfo ,
144
+ bool addToPanel )
145
+ {
146
+ var pdData = new PulldownButtonData ( component . UniqueId , component . Name ) ;
147
+
148
+ if ( ! addToPanel )
149
+ return pdData ;
150
+
151
+ PulldownButton pdBtn = parentPanel . AddItem ( pdData ) as PulldownButton ;
152
+ if ( pdBtn == null )
153
+ return null ;
154
+
155
+
156
+ foreach ( var child in component . Children ?? Enumerable . Empty < object > ( ) )
157
+ {
158
+ if ( child is ICommandComponent subCmd &&
159
+ CommandComponentTypeExtensions . FromExtension ( subCmd . Type ) == CommandComponentType . PushButton )
160
+ {
161
+ var subData = new PushButtonData ( subCmd . UniqueId , subCmd . Name , assemblyInfo . Location , subCmd . UniqueId ) ;
162
+ pdBtn . AddPushButton ( subData ) ;
163
+ }
164
+ }
165
+
166
+ return pdData ;
167
+ }
121
168
}
122
- }
169
+ }
0 commit comments