Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to hide toolbar #1683

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs

@Published var navigatorCollapsed = false
@Published var inspectorCollapsed = false
@Published var toolbarCollapsed = false

var observers: [NSKeyValueObservation] = []

Expand Down Expand Up @@ -126,7 +127,7 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
toolbar.delegate = self
toolbar.displayMode = .labelOnly
toolbar.showsBaselineSeparator = false
self.window?.titleVisibility = .hidden
self.window?.titleVisibility = toolbarCollapsed ? .visible : .hidden
self.window?.toolbarStyle = .unifiedCompact
if Settings[\.general].tabBarStyle == .native {
// Set titlebar background as transparent by default in order to
Expand Down Expand Up @@ -165,6 +166,22 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
]
}

func toggleToolbar() {
toolbarCollapsed.toggle()
updateToolbarVisibility()
}

private func updateToolbarVisibility() {
if toolbarCollapsed {
window?.titleVisibility = .visible
window?.title = workspace?.workspaceFileManager?.folderUrl.lastPathComponent ?? "Empty"
window?.toolbar = nil
} else {
window?.titleVisibility = .hidden
setupToolbar()
}
}

func toolbar(
_ toolbar: NSToolbar,
itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,
Expand Down Expand Up @@ -219,6 +236,7 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
toolbarItem.view = view

return toolbarItem

default:
return NSToolbarItem(itemIdentifier: itemIdentifier)
}
Expand Down
12 changes: 12 additions & 0 deletions CodeEdit/Features/WindowCommands/ViewCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ struct ViewCommands: Commands {
windowController?.navigatorCollapsed ?? false
}

var toolbarCollapsed: Bool {
windowController?.toolbarCollapsed ?? false
}

var body: some Commands {

CommandGroup(after: .toolbar) {
Button("Show Command Palette") {
NSApp.sendAction(#selector(CodeEditWindowController.openCommandPalette(_:)), to: nil, from: nil)
Expand Down Expand Up @@ -90,6 +95,7 @@ struct ViewCommands: Commands {
windowController = window?.windowController as? CodeEditWindowController
}


Button("\(inspectorCollapsed ? "Show" : "Hide") Inspector") {
windowController?.toggleLastPanel()
}
Expand All @@ -102,6 +108,12 @@ struct ViewCommands: Commands {
.disabled(windowController == nil)
.keyboardShortcut("y", modifiers: [.shift, .command])

Button("\(navigatorCollapsed ? "Show" : "Hide") Toolbar") {
windowController?.toggleToolbar()
}
.disabled(windowController == nil)
.keyboardShortcut("t", modifiers: [.option, .command])

Divider()

Button("\(showEditorPathBar ? "Hide" : "Show") Path Bar") {
Expand Down
Loading