Skip to content

Commit

Permalink
Displaying workspace settings in a sheet instead of a window. Added m…
Browse files Browse the repository at this point in the history
…inimum width to workspace settings bottons.
  • Loading branch information
austincondiff committed Aug 1, 2024
1 parent 2e0a704 commit 766bb81
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import SwiftUI

struct CEWorkspaceSettingsView: View {
var dismiss: () -> Void

@EnvironmentObject var workspaceSettingsManager: CEWorkspaceSettings
@EnvironmentObject var workspace: WorkspaceDocument

Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -75,5 +83,5 @@ struct CEWorkspaceSettingsView: View {
}

#Preview {
CEWorkspaceSettingsView(window: nil)
CEWorkspaceSettingsView(dismiss: { print("Dismiss") })
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 766bb81

Please sign in to comment.