mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Make font size of outline view customizable
This commit is contained in:
parent
0648ad2a33
commit
1507d0eeb8
@ -8,6 +8,7 @@ Change Log
|
||||
### Improvements
|
||||
|
||||
- “Input in unicode hex” now supports multi-cursor editing.
|
||||
- Make font size of outline view customizable.
|
||||
|
||||
|
||||
### Fixes
|
||||
|
@ -164,6 +164,7 @@ extension DefaultKeys {
|
||||
static let recentStyleNames = DefaultKey<[String]>("recentStyleNames")
|
||||
static let showStatusBar = DefaultKey<Bool>("showStatusArea")
|
||||
static let selectedInspectorPaneIndex = DefaultKey<Int>("selectedInspectorPaneIndex")
|
||||
static let outlineViewFontSize = DefaultKey<CGFloat>("outlineViewFontSize")
|
||||
static let selectedMultipleReplacementSettingName = DefaultKey<String>("selectedMultipleReplacementSettingName")
|
||||
static let beginCustomSurroundString = DefaultKey<String>("beginCustomSurroundString")
|
||||
static let endCustomSurroundString = DefaultKey<String>("endCustomSurroundString")
|
||||
|
@ -173,6 +173,7 @@ struct DefaultSettings {
|
||||
.recentStyleNames: [],
|
||||
.showStatusBar: true,
|
||||
.selectedInspectorPaneIndex: 0,
|
||||
.outlineViewFontSize: NSFont.smallSystemFontSize,
|
||||
|
||||
// ------ hidden settings ------
|
||||
.headerFooterDateFormat: "yyyy-MM-dd HH:mm",
|
||||
|
@ -42,6 +42,8 @@ final class OutlineViewController: NSViewController {
|
||||
private var selectionObserver: NSObjectProtocol?
|
||||
private var isOwnSelectionChange = false
|
||||
|
||||
private var fontSizeObserver: UserDefaultsObservation?
|
||||
|
||||
@IBOutlet private weak var outlineView: NSOutlineView?
|
||||
|
||||
|
||||
@ -59,6 +61,8 @@ final class OutlineViewController: NSViewController {
|
||||
if let observer = self.selectionObserver {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
}
|
||||
|
||||
self.fontSizeObserver?.invalidate()
|
||||
}
|
||||
|
||||
|
||||
@ -81,6 +85,11 @@ final class OutlineViewController: NSViewController {
|
||||
self.view.setAccessibilityElement(true)
|
||||
self.view.setAccessibilityRole(.group)
|
||||
self.view.setAccessibilityLabel("outline".localized)
|
||||
|
||||
self.fontSizeObserver?.invalidate()
|
||||
self.fontSizeObserver = UserDefaults.standard.observe(key: .outlineViewFontSize) { [weak self] _ in
|
||||
self?.outlineView?.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -297,7 +306,8 @@ extension OutlineViewController: NSOutlineViewDataSource {
|
||||
|
||||
switch identifier {
|
||||
case .title:
|
||||
let font: NSFont = outlineView.font ?? .systemFont(ofSize: NSFont.smallSystemFontSize)
|
||||
let fontSize = UserDefaults.standard[.outlineViewFontSize]
|
||||
let font = outlineView.font.flatMap { NSFont(name: $0.fontName, size: fontSize) } ?? .systemFont(ofSize: fontSize)
|
||||
|
||||
return outlineItem.attributedTitle(for: font, attributes: [.paragraphStyle: self.itemParagraphStyle])
|
||||
|
||||
@ -307,3 +317,31 @@ extension OutlineViewController: NSOutlineViewDataSource {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
extension OutlineViewController {
|
||||
|
||||
/// Increase outline view's font size.
|
||||
@IBAction func biggerFont(_ sender: Any?) {
|
||||
|
||||
UserDefaults.standard[.outlineViewFontSize] += 1
|
||||
}
|
||||
|
||||
|
||||
/// Decrease outline view's font size.
|
||||
@IBAction func smallerFont(_ sender: Any?) {
|
||||
|
||||
guard UserDefaults.standard[.outlineViewFontSize] > NSFont.smallSystemFontSize else { return }
|
||||
|
||||
UserDefaults.standard[.outlineViewFontSize] -= 1
|
||||
}
|
||||
|
||||
|
||||
/// Restore outline view's font size to default.
|
||||
@IBAction func resetFont(_ sender: Any?) {
|
||||
|
||||
UserDefaults.standard.restore(key: .outlineViewFontSize)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user