Skip to content

Commit 3017dd6

Browse files
committed
Make Float Window persistent and rename to Keep in Front
1 parent 0a706ac commit 3017dd6

File tree

7 files changed

+46
-38
lines changed

7 files changed

+46
-38
lines changed

Viewer/Mac/AppDelegate.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
4848
Settings.shared.previousAppVersion = Settings.shared.appVersion
4949
Settings.shared.appVersion = appVersion
5050
}
51-
if WelcomeViewController.shouldShowAtStartup {
51+
if Settings.shared.showWelcomeScreenAtStartup {
5252
welcomeWindowController.showWindow(self)
5353
dismissOpenSavePanel()
5454
} else if firstLaunchOfNewVersion {
@@ -65,6 +65,31 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
6565
exportMenuProvider?.updateExportMenu()
6666
}
6767

68+
func applicationWillBecomeActive(_: Notification) {
69+
for window in documentWindows where window.level == .floating {
70+
window.level = .normal
71+
}
72+
}
73+
74+
func applicationWillResignActive(_: Notification) {
75+
guard Settings.shared.keepWindowInFront else {
76+
return
77+
}
78+
for window in documentWindows where window == NSApp.mainWindow && window.isVisible {
79+
window.level = .floating
80+
}
81+
}
82+
83+
private var documentWindows: [NSWindow] {
84+
NSDocumentController.shared.documents.flatMap {
85+
$0.windowControllers.compactMap(\.window)
86+
}
87+
}
88+
89+
@IBAction func toggleKeepInFront(_: NSMenuItem) {
90+
Settings.shared.keepWindowInFront.toggle()
91+
}
92+
6893
func applicationShouldOpenUntitledFile(_: NSApplication) -> Bool {
6994
if NSApp.windows.allSatisfy({ !$0.isVisible }) {
7095
NSDocumentController.shared.openDocument(nil)
@@ -136,6 +161,9 @@ extension AppDelegate: NSMenuItemValidation {
136161
case #selector(selectCameras(_:)):
137162
menuItem.title = "Camera"
138163
return false
164+
case #selector(AppDelegate.toggleKeepInFront(_:)):
165+
menuItem.state = Settings.shared.keepWindowInFront ? .on : .off
166+
return true
139167
default:
140168
return true
141169
}

Viewer/Mac/Base.lproj/Main.storyboard

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,6 @@
238238
</connections>
239239
</menuItem>
240240
<menuItem isSeparatorItem="YES" id="Qpm-Qs-Vdp"/>
241-
<menuItem title="Float Window" keyEquivalent="F" id="kog-Ka-X5i">
242-
<connections>
243-
<action selector="toggleFloatWindow:" target="Ady-hI-5gd" id="HQv-XV-Nm1"/>
244-
</connections>
245-
</menuItem>
246-
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
247-
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
248-
<connections>
249-
<action selector="toggleSidebar:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
250-
</connections>
251-
</menuItem>
252241
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
253242
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
254243
<connections>
@@ -287,6 +276,11 @@
287276
<action selector="arrangeInFront:" target="Ady-hI-5gd" id="DRN-fu-gQh"/>
288277
</connections>
289278
</menuItem>
279+
<menuItem title="Keep in Front" keyEquivalent="F" id="m1j-Jw-XB7">
280+
<connections>
281+
<action selector="toggleKeepInFront:" target="Ady-hI-5gd" id="M4c-m9-qqy"/>
282+
</connections>
283+
</menuItem>
290284
</items>
291285
</menu>
292286
</menuItem>

Viewer/Mac/Document.swift

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,6 @@ final class Document: NSDocument {
426426
isOrthographic.toggle()
427427
}
428428

429-
@IBAction func toggleFloatWindow(_: NSMenuItem) {
430-
if let window = viewController?.view.window {
431-
if window.level == .floating {
432-
window.level = .normal
433-
return
434-
}
435-
436-
window.level = .floating
437-
}
438-
}
439-
440429
// MARK: Menus
441430

442431
override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
@@ -473,12 +462,7 @@ final class Document: NSDocument {
473462
case #selector(clearSelection(_:)):
474463
return selectedGeometry != nil
475464
case #selector(showModelInfo(_:)):
476-
menuItem.title = selectedGeometry == nil ?
477-
"Scene Info" : "Selected Shape Info"
478-
case #selector(toggleFloatWindow(_:)):
479-
if let window = viewController?.view.window {
480-
menuItem.state = window.level == .floating ? .on : .off
481-
}
465+
menuItem.title = selectedGeometry == nil ? "Scene Info" : "Selected Shape Info"
482466
default:
483467
break
484468
}

Viewer/Mac/WelcomeViewController.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,14 @@ final class WelcomeViewController: NSViewController {
1616
super.viewDidLoad()
1717
welcomeView.textStorage?.setAttributedString(loadRTF("Welcome"))
1818
shouldShowAtStartupCheckbox.state =
19-
WelcomeViewController.shouldShowAtStartup ? .on : .off
19+
Settings.shared.showWelcomeScreenAtStartup ? .on : .off
2020
}
2121

2222
@IBAction func openGettingStartedGuide(_: Any) {
2323
NSWorkspace.shared.open(onlineHelpURL.appendingPathComponent("getting-started"))
2424
}
2525

2626
@IBAction func toggleShowAtStartup(_ sender: NSButton) {
27-
WelcomeViewController.shouldShowAtStartup = (sender.state == .on)
28-
}
29-
30-
static var shouldShowAtStartup: Bool {
31-
get { Settings.shared.showWelcomeScreenAtStartup }
32-
set { Settings.shared.showWelcomeScreenAtStartup = newValue }
27+
Settings.shared.showWelcomeScreenAtStartup = (sender.state == .on)
3328
}
3429
}

Viewer/Shared/Settings.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ final class Settings {
9292
get { defaults.object(forKey: #function) as? Bool ?? true }
9393
set { defaults.set(newValue, forKey: #function) }
9494
}
95+
96+
// MARK: Floating window
97+
98+
var keepWindowInFront: Bool {
99+
get { defaults.object(forKey: #function) as? Bool ?? false }
100+
set { defaults.set(newValue, forKey: #function) }
101+
}
95102
}
96103

97104
private extension Document {

docs/mac/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ No third-party editors currently support ShapeScript syntax directly, but if you
3535

3636
ShapeScript will only ask you which editor you want to use the *first* time you edit a file, then it will remember your choice. If you change your mind later, you can select a different editor in Preferences (select the `ShapeScript > Preferences…` menu or press **Cmd-,**).
3737

38-
When using an external editor it can be useful to have the window displaying the rendered model visible in the same workspace, so that you do not have to use split-screen or switch applications to see the results of your changes. You can do this using the `View > Float Window` option. Note that this setting must be set independently for each window.
38+
When using an external editor it can be useful to have the rendered model visible in the same workspace, so that you do not have to use split-screen or switch applications to see the results of your changes. Toggle the `Window > Keep in Front` menu item or press **Cmd-Shift-F** to keep the focused ShapeScript window in front when you switch to another application.
3939

4040
## File Structure
4141

docs/src/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ No third-party editors currently support ShapeScript syntax directly, but if you
3535

3636
ShapeScript will only ask you which editor you want to use the *first* time you edit a file, then it will remember your choice. If you change your mind later, you can select a different editor in Preferences (select the `ShapeScript > Preferences…` menu or press **Cmd-,**).
3737

38-
When using an external editor it can be useful to have the window displaying the rendered model visible in the same workspace, so that you do not have to use split-screen or switch applications to see the results of your changes. You can do this using the `View > Float Window` option. Note that this setting must be set independently for each window.
38+
When using an external editor it can be useful to have the rendered model visible in the same workspace, so that you do not have to use split-screen or switch applications to see the results of your changes. Toggle the `Window > Keep in Front` menu item or press **Cmd-Shift-F** to keep the focused ShapeScript window in front when you switch to another application.
3939

4040
## File Structure
4141

0 commit comments

Comments
 (0)