From 51d1a9137f7bda5fc49f2937e7cac6ceddc7194e Mon Sep 17 00:00:00 2001 From: david-swift Date: Sat, 7 Dec 2024 23:22:27 +0100 Subject: [PATCH] Fix windows and help menus --- Sources/Core/Model/MacApp.swift | 11 ++++++++--- Sources/Core/Window/MenuBar.swift | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Sources/Core/Model/MacApp.swift b/Sources/Core/Model/MacApp.swift index cd2dedb..afec3b5 100644 --- a/Sources/Core/Model/MacApp.swift +++ b/Sources/Core/Model/MacApp.swift @@ -50,7 +50,6 @@ public class MacApp: AppStorage { /// The windows menu. func windowsMenu() { let windowsMenu = NSMenu() - mainMenu.addItem(windowsItem) windowsItem.submenu = windowsMenu app.windowsMenu = windowsMenu } @@ -58,18 +57,24 @@ public class MacApp: AppStorage { /// The help menu. func helpMenu() { let helpMenu = NSMenu() - mainMenu.addItem(helpItem) helpItem.submenu = helpMenu app.helpMenu = helpMenu } + /// Add the windows and help menus. + func addMenus() { + mainMenu.addItem(windowsItem) + mainMenu.addItem(helpItem) + } + /// Execute the app. /// - Parameter setup: Set the scene elements up. public func run(setup: @escaping () -> Void) { appMenu() - setup() windowsMenu() helpMenu() + setup() + addMenus() app.run() } diff --git a/Sources/Core/Window/MenuBar.swift b/Sources/Core/Window/MenuBar.swift index 2bb8fab..f91ed2f 100644 --- a/Sources/Core/Window/MenuBar.swift +++ b/Sources/Core/Window/MenuBar.swift @@ -59,9 +59,14 @@ public struct MenuBar: MacSceneElement { let scene = SceneStorage(id: id, pointer: app.mainMenu) { } let data = WidgetData(sceneStorage: scene, appStorage: app) let storage = MenuCollection { self.content }.getMenu(data: data, menu: app.mainMenu) + print(app.helpItem.submenu) let appStorage = MenuCollection { self.app }.getMenu(data: data, menu: app.appItem.submenu) + let windowStorage = MenuCollection { self.window }.getMenu(data: data, menu: app.windowsItem.submenu) + let helpStorage = MenuCollection { self.help }.getMenu(data: data, menu: app.helpItem.submenu) scene.content[.mainContent] = [storage] scene.content["app"] = [appStorage] + scene.content["window"] = [windowStorage] + scene.content["help"] = [helpStorage] return scene } @@ -79,6 +84,12 @@ public struct MenuBar: MacSceneElement { if let content = storage.content["app"]?.first { self.app.updateStorage(content, data: data, updateProperties: updateProperties, type: MenuContext.self) } + if let content = storage.content["window"]?.first { + self.window.updateStorage(content, data: data, updateProperties: updateProperties, type: MenuContext.self) + } + if let content = storage.content["help"]?.first { + self.help.updateStorage(content, data: data, updateProperties: updateProperties, type: MenuContext.self) + } guard let content = storage.content[.mainContent]?.first else { return }