Skip to content

Commit ca44d19

Browse files
authored
Merge pull request #418 from lukepistrol/feat/sidebar-size
`Project Navigator`: Implemented Setting for changing Item Size
2 parents d6dd5ca + 941546e commit ca44d19

File tree

6 files changed

+67
-8
lines changed

6 files changed

+67
-8
lines changed

CodeEdit/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
</dict>
4646
</array>
4747
<key>GitHash</key>
48-
<string>f757c49a7b8bb16b2a531a8c7e7a6a77435484c4</string>
48+
<string>cdaf6b982864a55727edc3b1b3201e689bc2ff6d</string>
4949
</dict>
5050
</plist>

CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class OutlineTableViewCell: NSTableCellView {
2323
self.label.drawsBackground = false
2424
self.label.isBordered = false
2525
self.label.isEditable = false
26-
self.label.font = .preferredFont(forTextStyle: .subheadline)
26+
self.label.font = .labelFont(ofSize: fontSize)
2727

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

3333
self.icon = NSImageView(frame: .zero)
3434
self.icon.translatesAutoresizingMaskIntoConstraints = false
35-
self.icon.symbolConfiguration = .init(textStyle: .callout, scale: .medium)
35+
self.icon.symbolConfiguration = .init(pointSize: fontSize, weight: .regular, scale: .medium)
3636

3737
self.addSubview(icon)
3838
self.imageView = icon
3939

4040
// Icon constraints
4141

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

4747
// Label constraints
4848

49-
self.label.leadingAnchor.constraint(equalTo: icon.trailingAnchor, constant: 2).isActive = true
49+
self.label.leadingAnchor.constraint(equalTo: icon.trailingAnchor, constant: 1).isActive = true
5050
self.label.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
5151
}
5252

5353
required init?(coder: NSCoder) {
5454
fatalError()
5555
}
5656

57+
/// Returns the font size for the current row height. Defaults to `13.0`
58+
private var fontSize: Double {
59+
switch self.frame.height {
60+
case 20: return 11
61+
case 22: return 13
62+
case 24: return 14
63+
default: return 13
64+
}
65+
}
66+
5767
}

CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineView.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ struct OutlineView: NSViewControllerRepresentable {
3131
func updateNSViewController(_ nsViewController: OutlineViewController, context: Context) {
3232
nsViewController.iconColor = prefs.preferences.general.fileIconStyle
3333
nsViewController.updateSelection()
34+
nsViewController.rowHeight = rowHeight
3435
return
3536
}
3637

38+
/// Returns the row height depending on the `projectNavigatorSize` in `AppPreferences`.
39+
///
40+
/// * `small`: 20
41+
/// * `medium`: 22
42+
/// * `large`: 24
43+
private var rowHeight: Double {
44+
switch prefs.preferences.general.projectNavigatorSize {
45+
case .small: return 20
46+
case .medium: return 22
47+
case .large: return 24
48+
}
49+
}
3750
}

CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineViewController.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ class OutlineViewController: NSViewController {
3535

3636
var iconColor: AppPreferences.FileIconStyle = .color
3737

38+
var rowHeight: Double = 22 {
39+
didSet {
40+
outlineView.rowHeight = rowHeight
41+
outlineView.reloadData()
42+
}
43+
}
44+
3845
/// Setup the ``scrollView`` and ``outlineView``
3946
override func loadView() {
4047
self.scrollView = NSScrollView()
@@ -136,7 +143,7 @@ extension OutlineViewController: NSOutlineViewDelegate {
136143

137144
guard let tableColumn = tableColumn else { return nil }
138145

139-
let frameRect = NSRect(x: 0, y: 0, width: tableColumn.width, height: 17)
146+
let frameRect = NSRect(x: 0, y: 0, width: tableColumn.width, height: rowHeight)
140147

141148
let view = OutlineTableViewCell(frame: frameRect)
142149

@@ -166,7 +173,7 @@ extension OutlineViewController: NSOutlineViewDelegate {
166173
}
167174

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

172179
func outlineViewItemDidExpand(_ notification: Notification) {

CodeEditModules/Modules/AppPreferences/src/Model/AppPreferences.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public extension AppPreferences {
6161
/// The reopen behavior of the app
6262
public var reopenBehavior: ReopenBehavior = .welcome
6363

64+
/// The size of the project navigators rows.
65+
public var projectNavigatorSize: ProjectNavigatorSize = .medium
66+
6467
/// Default initializer
6568
public init() {}
6669

@@ -71,6 +74,8 @@ public extension AppPreferences {
7174
self.fileIconStyle = try container.decodeIfPresent(FileIconStyle.self, forKey: .fileIconStyle) ?? .color
7275
self.reopenBehavior = try container.decodeIfPresent(ReopenBehavior.self,
7376
forKey: .reopenBehavior) ?? .welcome
77+
self.projectNavigatorSize = try container.decodeIfPresent(ProjectNavigatorSize.self,
78+
forKey: .projectNavigatorSize) ?? .medium
7479
}
7580
}
7681

@@ -116,6 +121,20 @@ public extension AppPreferences {
116121
case newDocument
117122
}
118123

124+
/// The size of the project navigators rows.
125+
///
126+
/// To match Xcode's settings the row height should be:
127+
/// * ``small``: `20pt` (fontSize: `11pt`)
128+
/// * ``medium``: `22pt` (fontSize: `13pt`)
129+
/// * ``small``: `24pt` (fontSize: `14pt`)
130+
///
131+
/// - note: This should be implemented for all lists in a `NavigatorSidebar`
132+
enum ProjectNavigatorSize: String, Codable {
133+
case small
134+
case medium
135+
case large
136+
}
137+
119138
}
120139

121140
public extension AppPreferences {

CodeEditModules/Modules/AppPreferences/src/Sections/GeneralPreferences/GeneralPreferencesView.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ public struct GeneralPreferencesView: View {
5151
.tag(AppPreferences.ReopenBehavior.newDocument)
5252
}
5353
}
54+
PreferencesSection("Project Navigator Size") {
55+
Picker("Project Navigator Size", selection: $prefs.preferences.general.projectNavigatorSize) {
56+
Text("Small")
57+
.tag(AppPreferences.ProjectNavigatorSize.small)
58+
Text("Medium")
59+
.tag(AppPreferences.ProjectNavigatorSize.medium)
60+
Text("Large")
61+
.tag(AppPreferences.ProjectNavigatorSize.large)
62+
}
63+
}
5464
}
5565
}
5666
}

0 commit comments

Comments
 (0)