Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CodeEdit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
</dict>
</array>
<key>GitHash</key>
<string>f757c49a7b8bb16b2a531a8c7e7a6a77435484c4</string>
<string>cdaf6b982864a55727edc3b1b3201e689bc2ff6d</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OutlineTableViewCell: NSTableCellView {
self.label.drawsBackground = false
self.label.isBordered = false
self.label.isEditable = false
self.label.font = .preferredFont(forTextStyle: .subheadline)
self.label.font = .labelFont(ofSize: fontSize)

self.addSubview(label)
self.textField = label
Expand All @@ -32,26 +32,36 @@ class OutlineTableViewCell: NSTableCellView {

self.icon = NSImageView(frame: .zero)
self.icon.translatesAutoresizingMaskIntoConstraints = false
self.icon.symbolConfiguration = .init(textStyle: .callout, scale: .medium)
self.icon.symbolConfiguration = .init(pointSize: fontSize, weight: .regular, scale: .medium)

self.addSubview(icon)
self.imageView = icon

// Icon constraints

self.icon.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0).isActive = true
self.icon.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: -2).isActive = true
self.icon.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
self.icon.widthAnchor.constraint(equalToConstant: 21).isActive = true
self.icon.widthAnchor.constraint(equalToConstant: 25).isActive = true
self.icon.heightAnchor.constraint(equalToConstant: frameRect.height).isActive = true

// Label constraints

self.label.leadingAnchor.constraint(equalTo: icon.trailingAnchor, constant: 2).isActive = true
self.label.leadingAnchor.constraint(equalTo: icon.trailingAnchor, constant: 1).isActive = true
self.label.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
}

required init?(coder: NSCoder) {
fatalError()
}

/// Returns the font size for the current row height. Defaults to `13.0`
private var fontSize: Double {
switch self.frame.height {
case 20: return 11
case 22: return 13
case 24: return 14
default: return 13
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@ struct OutlineView: NSViewControllerRepresentable {
func updateNSViewController(_ nsViewController: OutlineViewController, context: Context) {
nsViewController.iconColor = prefs.preferences.general.fileIconStyle
nsViewController.updateSelection()
nsViewController.rowHeight = rowHeight
return
}

/// Returns the row height depending on the `projectNavigatorSize` in `AppPreferences`.
///
/// * `small`: 20
/// * `medium`: 22
/// * `large`: 24
private var rowHeight: Double {
switch prefs.preferences.general.projectNavigatorSize {
case .small: return 20
case .medium: return 22
case .large: return 24
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class OutlineViewController: NSViewController {

var iconColor: AppPreferences.FileIconStyle = .color

var rowHeight: Double = 22 {
didSet {
outlineView.rowHeight = rowHeight
outlineView.reloadData()
}
}

/// Setup the ``scrollView`` and ``outlineView``
override func loadView() {
self.scrollView = NSScrollView()
Expand Down Expand Up @@ -136,7 +143,7 @@ extension OutlineViewController: NSOutlineViewDelegate {

guard let tableColumn = tableColumn else { return nil }

let frameRect = NSRect(x: 0, y: 0, width: tableColumn.width, height: 17)
let frameRect = NSRect(x: 0, y: 0, width: tableColumn.width, height: rowHeight)

let view = OutlineTableViewCell(frame: frameRect)

Expand Down Expand Up @@ -166,7 +173,7 @@ extension OutlineViewController: NSOutlineViewDelegate {
}

func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
return 22 // This can be changed to 20 to match Xcodes row height.
return rowHeight // This can be changed to 20 to match Xcodes row height.
}

func outlineViewItemDidExpand(_ notification: Notification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public extension AppPreferences {
/// The reopen behavior of the app
public var reopenBehavior: ReopenBehavior = .welcome

/// The size of the project navigators rows.
public var projectNavigatorSize: ProjectNavigatorSize = .medium

/// Default initializer
public init() {}

Expand All @@ -71,6 +74,8 @@ public extension AppPreferences {
self.fileIconStyle = try container.decodeIfPresent(FileIconStyle.self, forKey: .fileIconStyle) ?? .color
self.reopenBehavior = try container.decodeIfPresent(ReopenBehavior.self,
forKey: .reopenBehavior) ?? .welcome
self.projectNavigatorSize = try container.decodeIfPresent(ProjectNavigatorSize.self,
forKey: .projectNavigatorSize) ?? .medium
}
}

Expand Down Expand Up @@ -116,6 +121,20 @@ public extension AppPreferences {
case newDocument
}

/// The size of the project navigators rows.
///
/// To match Xcode's settings the row height should be:
/// * ``small``: `20pt` (fontSize: `11pt`)
/// * ``medium``: `22pt` (fontSize: `13pt`)
/// * ``small``: `24pt` (fontSize: `14pt`)
///
/// - note: This should be implemented for all lists in a `NavigatorSidebar`
enum ProjectNavigatorSize: String, Codable {
case small
case medium
case large
}

}

public extension AppPreferences {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public struct GeneralPreferencesView: View {
.tag(AppPreferences.ReopenBehavior.newDocument)
}
}
PreferencesSection("Project Navigator Size") {
Picker("Project Navigator Size", selection: $prefs.preferences.general.projectNavigatorSize) {
Text("Small")
.tag(AppPreferences.ProjectNavigatorSize.small)
Text("Medium")
.tag(AppPreferences.ProjectNavigatorSize.medium)
Text("Large")
.tag(AppPreferences.ProjectNavigatorSize.large)
}
}
}
}
}