From 766bb81613e3fe0652e0a706cc505feb9a69d058 Mon Sep 17 00:00:00 2001 From: Austin Condiff Date: Thu, 1 Aug 2024 15:15:34 -0500 Subject: [PATCH] Displaying workspace settings in a sheet instead of a window. Added minimum width to workspace settings bottons. --- .../Views/AddCETaskView.swift | 11 +++++++-- .../Views/CEWorkspaceSettingsView.swift | 18 +++++++++++---- .../Views/EditCETaskView.swift | 12 ++++++++-- .../CodeEditWindowControllerExtensions.swift | 23 ++++++++++--------- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/AddCETaskView.swift b/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/AddCETaskView.swift index 0f9f21f2a..577c5b3e9 100644 --- a/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/AddCETaskView.swift +++ b/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/AddCETaskView.swift @@ -22,15 +22,22 @@ struct AddCETaskView: View { CETaskFormView(task: newTask) Divider() HStack { - Button("Cancel") { + Button { dismiss() + } label: { + Text("Cancel") + .frame(minWidth: 56) } Spacer() - Button("Save") { + Button { workspaceSettingsManager.settings.tasks.append(newTask) try? workspaceSettingsManager.savePreferences() dismiss() + } label: { + Text("Save") + .frame(minWidth: 56) } + .buttonStyle(.borderedProminent) .disabled(newTask.isInvalid) } .padding() diff --git a/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/CEWorkspaceSettingsView.swift b/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/CEWorkspaceSettingsView.swift index 939349f35..70772e47d 100644 --- a/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/CEWorkspaceSettingsView.swift +++ b/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/CEWorkspaceSettingsView.swift @@ -8,6 +8,8 @@ import SwiftUI struct CEWorkspaceSettingsView: View { + var dismiss: () -> Void + @EnvironmentObject var workspaceSettingsManager: CEWorkspaceSettings @EnvironmentObject var workspace: WorkspaceDocument @@ -16,7 +18,6 @@ struct CEWorkspaceSettingsView: View { @State var selectedTaskID: UUID? @State var showAddTaskSheet: Bool = false - let window: NSWindow? var body: some View { VStack(spacing: 0) { Form { @@ -50,13 +51,20 @@ struct CEWorkspaceSettingsView: View { } } .formStyle(.grouped) + .scrollContentBackground(.hidden) + Divider() HStack { Spacer() - Button("Done") { - window?.close() + Button { + dismiss() + } label: { + Text("Done") + .frame(minWidth: 56) } - }.padding() + .buttonStyle(.borderedProminent) + } + .padding() } .environmentObject(settingsViewModel) .sheet(isPresented: $showAddTaskSheet) { @@ -75,5 +83,5 @@ struct CEWorkspaceSettingsView: View { } #Preview { - CEWorkspaceSettingsView(window: nil) + CEWorkspaceSettingsView(dismiss: { print("Dismiss") }) } diff --git a/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/EditCETaskView.swift b/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/EditCETaskView.swift index 82ba8294e..179c92c1d 100644 --- a/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/EditCETaskView.swift +++ b/CodeEdit/Features/CEWorkSpaceSettings/CEWorkspaceSettings/Views/EditCETaskView.swift @@ -22,21 +22,29 @@ struct EditCETaskView: View { CETaskFormView(task: task) Divider() HStack { - Button("Delete") { + Button(role: .destructive) { workspaceSettingsManager.settings.tasks.removeAll(where: { $0.id == task.id }) try? workspaceSettingsManager.savePreferences() taskManger.deleteTask(taskID: task.id) self.dismiss() + } label: { + Text("Delete") + .foregroundStyle(.red) + .frame(minWidth: 56) } Spacer() - Button("Done") { + Button { try? workspaceSettingsManager.savePreferences() self.dismiss() + } label: { + Text("Done") + .frame(minWidth: 56) } + .buttonStyle(.borderedProminent) .disabled(task.isInvalid) } .padding() diff --git a/CodeEdit/Features/Documents/Controllers/CodeEditWindowControllerExtensions.swift b/CodeEdit/Features/Documents/Controllers/CodeEditWindowControllerExtensions.swift index 1c47aca56..4490bfc0c 100644 --- a/CodeEdit/Features/Documents/Controllers/CodeEditWindowControllerExtensions.swift +++ b/CodeEdit/Features/Documents/Controllers/CodeEditWindowControllerExtensions.swift @@ -112,17 +112,18 @@ extension CodeEditWindowController { } else { let settingsWindow = NSWindow() self.workspaceSettingsWindow = settingsWindow - let contentView = CEWorkspaceSettingsView(window: settingsWindow) - .environmentObject(workspaceSettingsManager) - .environmentObject(workspace) - .environmentObject(taskManager) - - settingsWindow.contentView = NSHostingView(rootView: contentView) - settingsWindow.titlebarAppearsTransparent = true - settingsWindow.setContentSize(NSSize(width: 515, height: 515)) - settingsWindow.makeKeyAndOrderFront(self) - - window.addCenteredChildWindow(settingsWindow, over: window) + let contentView = CEWorkspaceSettingsView( + dismiss: { self.window?.endSheet(settingsWindow) } + ) + .environmentObject(workspaceSettingsManager) + .environmentObject(workspace) + .environmentObject(taskManager) + + settingsWindow.contentView = NSHostingView(rootView: contentView) + settingsWindow.titlebarAppearsTransparent = true + settingsWindow.setContentSize(NSSize(width: 515, height: 515)) + + window.beginSheet(settingsWindow, completionHandler: nil) } } }