From 83e3138ddcc40d4ef14e36b6c6da45935c843f71 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 10 Apr 2021 15:07:29 +0200 Subject: [PATCH] Make preferences non-modal --- .../App/macOS/Base.lproj/Main.storyboard | 2 +- .../macOS/Base.lproj/Preferences.storyboard | 27 ++++++++++++++++++- .../App/macOS/Global/SwiftGen+Scenes.swift | 4 ++- .../App/macOS/Global/WindowManager.swift | 16 +++++------ Passepartout/App/macOS/Menu/MainMenu.swift | 4 +-- Passepartout/App/macOS/Menu/StatusMenu.swift | 4 +-- .../PreferencesViewController.swift | 1 - 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Passepartout/App/macOS/Base.lproj/Main.storyboard b/Passepartout/App/macOS/Base.lproj/Main.storyboard index 9b6ff5b6..f1eddc16 100644 --- a/Passepartout/App/macOS/Base.lproj/Main.storyboard +++ b/Passepartout/App/macOS/Base.lproj/Main.storyboard @@ -10,7 +10,7 @@ - + diff --git a/Passepartout/App/macOS/Base.lproj/Preferences.storyboard b/Passepartout/App/macOS/Base.lproj/Preferences.storyboard index 121ea3c0..a9cb1a26 100644 --- a/Passepartout/App/macOS/Base.lproj/Preferences.storyboard +++ b/Passepartout/App/macOS/Base.lproj/Preferences.storyboard @@ -1,5 +1,5 @@ - + @@ -383,6 +383,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Passepartout/App/macOS/Global/SwiftGen+Scenes.swift b/Passepartout/App/macOS/Global/SwiftGen+Scenes.swift index 6dbef7e8..3a9b4028 100644 --- a/Passepartout/App/macOS/Global/SwiftGen+Scenes.swift +++ b/Passepartout/App/macOS/Global/SwiftGen+Scenes.swift @@ -22,7 +22,9 @@ internal enum StoryboardScene { internal enum Preferences: StoryboardType { internal static let storyboardName = "Preferences" - internal static let initialScene = InitialSceneType(storyboard: Preferences.self) + internal static let initialScene = InitialSceneType(storyboard: Preferences.self) + + internal static let preferencesWindowController = SceneType(storyboard: Preferences.self, identifier: "PreferencesWindowController") } internal enum Purchase: StoryboardType { internal static let storyboardName = "Purchase" diff --git a/Passepartout/App/macOS/Global/WindowManager.swift b/Passepartout/App/macOS/Global/WindowManager.swift index a9a363f3..e53533ae 100644 --- a/Passepartout/App/macOS/Global/WindowManager.swift +++ b/Passepartout/App/macOS/Global/WindowManager.swift @@ -31,24 +31,22 @@ class WindowManager: NSObject { private var organizer: NSWindowController? -// private var preferences: NSWindowController? + private var preferences: NSWindowController? private override init() { } @discardableResult func showOrganizer() -> NSWindowController? { organizer = presentWindowController(StoryboardScene.Main.organizerWindowController, existing: organizer) + organizer?.window?.title = "Passepartout" return organizer } -// @discardableResult func showPreferences() -> NSWindowController? { -// preferences = presentWindowController( -// StoryboardScene.Preferences.initialScene.instantiate(), -// existing: preferences, -// title: L10n.App.Preferences.title -// ) -// return preferences -// } + @discardableResult func showPreferences() -> NSWindowController? { + preferences = presentWindowController(StoryboardScene.Preferences.preferencesWindowController, existing: preferences) + preferences?.window?.title = L10n.App.Preferences.title + return preferences + } func showAbout() { NSApp.orderFrontStandardAboutPanel(nil) diff --git a/Passepartout/App/macOS/Menu/MainMenu.swift b/Passepartout/App/macOS/Menu/MainMenu.swift index 4993669c..a21fb595 100644 --- a/Passepartout/App/macOS/Menu/MainMenu.swift +++ b/Passepartout/App/macOS/Menu/MainMenu.swift @@ -27,8 +27,6 @@ import Cocoa class MainMenu: NSObject { @IBAction private func showPreferences(_ sender: Any?) { - let organizer = WindowManager.shared.showOrganizer() - let preferences = StoryboardScene.Preferences.initialScene.instantiate() - organizer?.contentViewController?.presentAsModalWindow(preferences) + WindowManager.shared.showPreferences() } } diff --git a/Passepartout/App/macOS/Menu/StatusMenu.swift b/Passepartout/App/macOS/Menu/StatusMenu.swift index 6571b08f..e2f779ff 100644 --- a/Passepartout/App/macOS/Menu/StatusMenu.swift +++ b/Passepartout/App/macOS/Menu/StatusMenu.swift @@ -395,9 +395,7 @@ class StatusMenu: NSObject { } @objc private func showPreferences() { - let organizer = WindowManager.shared.showOrganizer() - let preferences = StoryboardScene.Preferences.initialScene.instantiate() - organizer?.contentViewController?.presentAsModalWindow(preferences) + WindowManager.shared.showPreferences() } @objc private func switchActiveProfile(_ sender: Any?) { diff --git a/Passepartout/App/macOS/Scenes/Preferences/PreferencesViewController.swift b/Passepartout/App/macOS/Scenes/Preferences/PreferencesViewController.swift index 2a7a5b6b..47c808c4 100644 --- a/Passepartout/App/macOS/Scenes/Preferences/PreferencesViewController.swift +++ b/Passepartout/App/macOS/Scenes/Preferences/PreferencesViewController.swift @@ -32,7 +32,6 @@ class PreferencesViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() - title = L10n.App.Preferences.title let labels = [ L10n.App.Preferences.Sections.General.header, L10n.Core.Service.Sections.Diagnostics.header