From db1e2c1c63adbfd578f42a00d4047db583b3c3f3 Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Sun, 10 Apr 2022 15:21:06 +0200 Subject: [PATCH 1/3] implemented setting for changing `Project Navigator` item size --- CodeEdit/Info.plist | 2 +- .../OutlineView/OutlineTableViewCell.swift | 20 ++++++++++++++----- .../OutlineView/OutlineView.swift | 8 ++++++++ .../OutlineView/OutlineViewController.swift | 11 ++++++++-- .../src/Model/AppPreferences.swift | 10 ++++++++++ .../GeneralPreferencesView.swift | 10 ++++++++++ 6 files changed, 53 insertions(+), 8 deletions(-) diff --git a/CodeEdit/Info.plist b/CodeEdit/Info.plist index 4f0a2d4a69..1d038ddc13 100644 --- a/CodeEdit/Info.plist +++ b/CodeEdit/Info.plist @@ -45,6 +45,6 @@ GitHash - b42fe64b91619183f753183ce52ca9f472509037 + cdaf6b982864a55727edc3b1b3201e689bc2ff6d diff --git a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift index bb2e23b88c..e0fba92d7f 100644 --- a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift +++ b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift @@ -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 @@ -32,21 +32,22 @@ 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) + // .init(textStyle: .callout, 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 } @@ -54,4 +55,13 @@ class OutlineTableViewCell: NSTableCellView { fatalError() } + private var fontSize: Double { + switch self.frame.height { + case 20: return 11 + case 22: return 13 + case 24: return 14 + default: return 13 + } + } + } diff --git a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineView.swift b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineView.swift index 9ce09f583c..807e9e9275 100644 --- a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineView.swift +++ b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineView.swift @@ -31,7 +31,15 @@ struct OutlineView: NSViewControllerRepresentable { func updateNSViewController(_ nsViewController: OutlineViewController, context: Context) { nsViewController.iconColor = prefs.preferences.general.fileIconStyle nsViewController.updateSelection() + nsViewController.rowHeight = rowHeight return } + private var rowHeight: Double { + switch prefs.preferences.general.projectNavigatorSize { + case .small: return 20 + case .medium: return 22 + case .large: return 24 + } + } } diff --git a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineViewController.swift b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineViewController.swift index 7de89efdae..3370e765f0 100644 --- a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineViewController.swift +++ b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineViewController.swift @@ -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() @@ -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) @@ -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) { diff --git a/CodeEditModules/Modules/AppPreferences/src/Model/AppPreferences.swift b/CodeEditModules/Modules/AppPreferences/src/Model/AppPreferences.swift index 01ddb238b4..0981045231 100644 --- a/CodeEditModules/Modules/AppPreferences/src/Model/AppPreferences.swift +++ b/CodeEditModules/Modules/AppPreferences/src/Model/AppPreferences.swift @@ -61,6 +61,8 @@ public extension AppPreferences { /// The reopen behavior of the app public var reopenBehavior: ReopenBehavior = .welcome + public var projectNavigatorSize: ProjectNavigatorSize = .medium + /// Default initializer public init() {} @@ -71,6 +73,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 } } @@ -116,6 +120,12 @@ public extension AppPreferences { case newDocument } + enum ProjectNavigatorSize: String, Codable { + case small + case medium + case large + } + } public extension AppPreferences { diff --git a/CodeEditModules/Modules/AppPreferences/src/Sections/GeneralPreferences/GeneralPreferencesView.swift b/CodeEditModules/Modules/AppPreferences/src/Sections/GeneralPreferences/GeneralPreferencesView.swift index 658c5fa682..9981afd312 100644 --- a/CodeEditModules/Modules/AppPreferences/src/Sections/GeneralPreferences/GeneralPreferencesView.swift +++ b/CodeEditModules/Modules/AppPreferences/src/Sections/GeneralPreferences/GeneralPreferencesView.swift @@ -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) + } + } } } } From f0f085fe018ed220fddc22c4c412c5ddbddc22b4 Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Sun, 10 Apr 2022 15:35:33 +0200 Subject: [PATCH 2/3] added docs --- .../OutlineView/OutlineTableViewCell.swift | 1 + .../ProjectNavigator/OutlineView/OutlineView.swift | 5 +++++ .../AppPreferences/src/Model/AppPreferences.swift | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift index e0fba92d7f..76818f5db8 100644 --- a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift +++ b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift @@ -55,6 +55,7 @@ class OutlineTableViewCell: NSTableCellView { 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 diff --git a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineView.swift b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineView.swift index 807e9e9275..7742c638bf 100644 --- a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineView.swift +++ b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineView.swift @@ -35,6 +35,11 @@ struct OutlineView: NSViewControllerRepresentable { 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 diff --git a/CodeEditModules/Modules/AppPreferences/src/Model/AppPreferences.swift b/CodeEditModules/Modules/AppPreferences/src/Model/AppPreferences.swift index 0981045231..69f16ad94b 100644 --- a/CodeEditModules/Modules/AppPreferences/src/Model/AppPreferences.swift +++ b/CodeEditModules/Modules/AppPreferences/src/Model/AppPreferences.swift @@ -61,6 +61,7 @@ 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 @@ -120,6 +121,14 @@ 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 From b2fc620febd125adb0e2f97ac7652ca3f4c4e1a6 Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Sun, 10 Apr 2022 16:05:03 +0200 Subject: [PATCH 3/3] removed commented code --- .../ProjectNavigator/OutlineView/OutlineTableViewCell.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift index 76818f5db8..9f9b5f90ac 100644 --- a/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift +++ b/CodeEdit/NavigatorSidebar/ProjectNavigator/OutlineView/OutlineTableViewCell.swift @@ -33,7 +33,6 @@ class OutlineTableViewCell: NSTableCellView { self.icon = NSImageView(frame: .zero) self.icon.translatesAutoresizingMaskIntoConstraints = false self.icon.symbolConfiguration = .init(pointSize: fontSize, weight: .regular, scale: .medium) - // .init(textStyle: .callout, scale: .medium) self.addSubview(icon) self.imageView = icon