@@ -195,14 +195,7 @@ public class CollectionViewContainer<Element: Hashable, Content: View>: NSView,
195195 action ( )
196196 }
197197
198- func collectionView( _ collectionView : InteractiveCollectionView ,
199- contextMenuForSelection _: Set < IndexPath > ) -> NSMenu ? {
200-
201- guard let menuItems = delegate? . collectionViewContainer ( self , menuItemsForElements: selectedElements) ,
202- !menuItems. isEmpty
203- else {
204- return nil
205- }
198+ func contextMenu( for menuItems: [ MenuItem ] ) -> NSMenu {
206199 let menu = NSMenu ( )
207200 menu. items = menuItems. map { menuItem in
208201 switch menuItem. itemType {
@@ -214,11 +207,26 @@ public class CollectionViewContainer<Element: Hashable, Content: View>: NSView,
214207 return menuItem
215208 case . separator:
216209 return NSMenuItem . separator ( )
210+ case . menu( let title, let menuItems) :
211+ let menuItem = NSMenuItem ( title: title, action: nil , keyEquivalent: " " )
212+ menuItem. submenu = contextMenu ( for: menuItems)
213+ return menuItem
217214 }
218215 }
219216 return menu
220217 }
221218
219+ func collectionView( _ collectionView : InteractiveCollectionView ,
220+ contextMenuForSelection _: Set < IndexPath > ) -> NSMenu ? {
221+
222+ guard let menuItems = delegate? . collectionViewContainer ( self , menuItemsForElements: selectedElements) ,
223+ !menuItems. isEmpty
224+ else {
225+ return nil
226+ }
227+ return contextMenu ( for: menuItems)
228+ }
229+
222230 var selectedElements : Set < Element > {
223231 return Set ( collectionView. selectionIndexPaths. compactMap { dataSource? . itemIdentifier ( for: $0) } )
224232 }
0 commit comments