-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### Description <!--- REQUIRED: Describe what changed in detail --> The issue is described in detail in #1684. ~I tried to resolve a related issue, #1696, but it was harder than I anticipated since the state of the Utility Area is stored separate to the other panes for some reason. Any ideas to resolve this slight issue would be welcome :)~ **EDIT:** I think I fixed it! ### Related Issues <!--- REQUIRED: Tag all related issues (e.g. * #123) --> <!--- If this PR resolves the issue please specify (e.g. * closes #123) --> <!--- If this PR addresses multiple issues, these issues must be related to one other --> * Closes #1684 * Closes #1696 ### Checklist <!--- Add things that are not yet implemented above --> - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots <!--- REQUIRED: if issue is UI related --> https://github.com/CodeEditApp/CodeEdit/assets/65467530/166d9b35-ede1-47b8-8814-cf1cbb1a61f2
- Loading branch information
Showing
4 changed files
with
189 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
CodeEdit/Features/Documents/Controllers/CodeEditWindowController+Toolbar.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// | ||
// CodeEditWindowController+Toolbar.swift | ||
// CodeEdit | ||
// | ||
// Created by Daniel Zhu on 5/10/24. | ||
// | ||
|
||
import AppKit | ||
import SwiftUI | ||
|
||
extension CodeEditWindowController { | ||
internal func setupToolbar() { | ||
let toolbar = NSToolbar(identifier: UUID().uuidString) | ||
toolbar.delegate = self | ||
toolbar.displayMode = .labelOnly | ||
toolbar.showsBaselineSeparator = false | ||
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 | ||
// style the toolbar background in native tab bar style. | ||
self.window?.titlebarSeparatorStyle = .none | ||
} else { | ||
// In Xcode tab bar style, we use default toolbar background with | ||
// line separator. | ||
self.window?.titlebarSeparatorStyle = .automatic | ||
} | ||
self.window?.toolbar = toolbar | ||
} | ||
|
||
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { | ||
[ | ||
.toggleFirstSidebarItem, | ||
.sidebarTrackingSeparator, | ||
.branchPicker, | ||
.flexibleSpace, | ||
.itemListTrackingSeparator, | ||
.flexibleSpace, | ||
.toggleLastSidebarItem | ||
] | ||
} | ||
|
||
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { | ||
[ | ||
.toggleFirstSidebarItem, | ||
.sidebarTrackingSeparator, | ||
.flexibleSpace, | ||
.itemListTrackingSeparator, | ||
.toggleLastSidebarItem, | ||
.branchPicker | ||
] | ||
} | ||
|
||
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, | ||
willBeInsertedIntoToolbar flag: Bool | ||
) -> NSToolbarItem? { | ||
switch itemIdentifier { | ||
case .itemListTrackingSeparator: | ||
guard let splitViewController else { return nil } | ||
|
||
return NSTrackingSeparatorToolbarItem( | ||
identifier: .itemListTrackingSeparator, | ||
splitView: splitViewController.splitView, | ||
dividerIndex: 1 | ||
) | ||
case .toggleFirstSidebarItem: | ||
let toolbarItem = NSToolbarItem(itemIdentifier: NSToolbarItem.Identifier.toggleFirstSidebarItem) | ||
toolbarItem.label = "Navigator Sidebar" | ||
toolbarItem.paletteLabel = " Navigator Sidebar" | ||
toolbarItem.toolTip = "Hide or show the Navigator" | ||
toolbarItem.isBordered = true | ||
toolbarItem.target = self | ||
toolbarItem.action = #selector(self.toggleFirstPanel) | ||
toolbarItem.image = NSImage( | ||
systemSymbolName: "sidebar.leading", | ||
accessibilityDescription: nil | ||
)?.withSymbolConfiguration(.init(scale: .large)) | ||
|
||
return toolbarItem | ||
case .toggleLastSidebarItem: | ||
let toolbarItem = NSToolbarItem(itemIdentifier: NSToolbarItem.Identifier.toggleLastSidebarItem) | ||
toolbarItem.label = "Inspector Sidebar" | ||
toolbarItem.paletteLabel = "Inspector Sidebar" | ||
toolbarItem.toolTip = "Hide or show the Inspectors" | ||
toolbarItem.isBordered = true | ||
toolbarItem.target = self | ||
toolbarItem.action = #selector(self.toggleLastPanel) | ||
toolbarItem.image = NSImage( | ||
systemSymbolName: "sidebar.trailing", | ||
accessibilityDescription: nil | ||
)?.withSymbolConfiguration(.init(scale: .large)) | ||
|
||
return toolbarItem | ||
case .branchPicker: | ||
let toolbarItem = NSToolbarItem(itemIdentifier: .branchPicker) | ||
let view = NSHostingView( | ||
rootView: ToolbarBranchPicker( | ||
workspaceFileManager: workspace?.workspaceFileManager | ||
) | ||
) | ||
toolbarItem.view = view | ||
|
||
return toolbarItem | ||
|
||
default: | ||
return NSToolbarItem(itemIdentifier: itemIdentifier) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.