From a15e64d58597749fd247b79ee48ec943e7f671ef Mon Sep 17 00:00:00 2001 From: Craig Campbell Date: Sun, 27 Apr 2025 22:17:56 -0400 Subject: [PATCH] Add option to use floating windows for model previews on macOS This adds a `Float Window` option to the `View` menu to allow a model window to float over other applications on macOS. This allows you to keep the preview open to the side of the document in your text editor to see changes in real time. --- Viewer/Mac/Base.lproj/Main.storyboard | 5 +++++ Viewer/Mac/Document.swift | 15 +++++++++++++++ docs/mac/getting-started.md | 2 ++ 3 files changed, 22 insertions(+) diff --git a/Viewer/Mac/Base.lproj/Main.storyboard b/Viewer/Mac/Base.lproj/Main.storyboard index a2d00c3a..1f3e4e45 100644 --- a/Viewer/Mac/Base.lproj/Main.storyboard +++ b/Viewer/Mac/Base.lproj/Main.storyboard @@ -238,6 +238,11 @@ + + + + + diff --git a/Viewer/Mac/Document.swift b/Viewer/Mac/Document.swift index 1d4c8f21..987a9578 100644 --- a/Viewer/Mac/Document.swift +++ b/Viewer/Mac/Document.swift @@ -423,6 +423,17 @@ class Document: NSDocument { isOrthographic.toggle() } + @IBAction func toggleFloatWindow(_: NSMenuItem) { + if let window = viewController?.view.window { + if window.level == .floating { + window.level = .normal + return + } + + window.level = .floating + } + } + // MARK: Menus override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool { @@ -461,6 +472,10 @@ class Document: NSDocument { case #selector(showModelInfo(_:)): menuItem.title = selectedGeometry == nil ? "Scene Info" : "Selected Shape Info" + case #selector(toggleFloatWindow(_:)): + if let window = viewController?.view.window { + menuItem.state = window.level == .floating ? .on : .off + } default: break } diff --git a/docs/mac/getting-started.md b/docs/mac/getting-started.md index bf8d1144..3387c7ef 100755 --- a/docs/mac/getting-started.md +++ b/docs/mac/getting-started.md @@ -37,6 +37,8 @@ No third-party editors currently support ShapeScript syntax directly, but if you 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-,**). +When using an external editor, it may be useful to have the window displaying the rendered model accessible in the same workspace so you do not have to use split-screen or switch applications every time you make a change to see the result. You can do this using the `View > Float Window` option. Note that this setting must be set independently for each window. + ## File Structure The first line of the default `.shape` document looks like this: