Skip to content

Commit c2e9fcd

Browse files
authored
Merge pull request #52 from dteoh/page-zoom-adjustment
Can set page zoom level of new windows
2 parents da35d0b + 7fb455b commit c2e9fcd

File tree

5 files changed

+111
-23
lines changed

5 files changed

+111
-23
lines changed

devdocs-macos/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1515
func applicationDidFinishLaunching(_ aNotification: Notification) {
1616
Summoner.shared.install()
1717

18-
if GeneralPreferences.shouldRestoreDocs() {
18+
if GeneralPreferences.shouldRestoreDocs {
1919
DocumentationWindows.shared.restore()
2020
}
2121

devdocs-macos/DocumentationViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class DocumentationViewController: NSViewController {
8383
webView.navigationDelegate = self
8484
webView.uiDelegate = self
8585
webView.wantsLayer = true
86+
webView.pageZoom = CGFloat(GeneralPreferences.pageZoom)
8687
// not possible to set "opaque" property, not possible to set backgroundColor...
8788
webView.setValue(false, forKey: "drawsBackground")
8889

devdocs-macos/GeneralPreferences.swift

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,49 @@ import DefaultsKit
33

44
private extension DefaultsKey {
55
static let restoreDocs = Key<Bool>("restoreDocs")
6+
static let pageZoom = Key<Float>("pageZoom")
67
}
78

89
class GeneralPreferences {
9-
1010
private init() {
1111
}
1212

1313
class func restoreDefaults() {
14-
Defaults.shared.set(true, for: .restoreDocs)
14+
self.shouldRestoreDocs = true
15+
self.pageZoom = 1.0
1516
}
1617

17-
class func shouldRestoreDocs() -> Bool {
18-
return Defaults.shared.get(for: .restoreDocs) ?? true
18+
static var shouldRestoreDocs: Bool {
19+
get {
20+
return Defaults.shared.get(for: .restoreDocs) ?? true
21+
}
22+
23+
set {
24+
Defaults.shared.set(newValue, for: .restoreDocs)
25+
}
26+
}
27+
28+
static var pageZoom: Float {
29+
get {
30+
return Defaults.shared.get(for: .pageZoom) ?? 1.0
31+
}
32+
33+
set {
34+
Defaults.shared.set(newValue, for: .pageZoom)
35+
}
1936
}
2037

38+
static let pageZoomOptions: [(String, Float)] = [
39+
("50%", 0.5),
40+
("75%", 0.75),
41+
("100%", 1.0),
42+
("125%", 1.25),
43+
("133%", 1.33),
44+
("150%", 1.5),
45+
("166%", 1.66),
46+
("175%", 1.75),
47+
("200%", 2.0),
48+
("250%", 2.5),
49+
("300%", 3.0),
50+
]
2151
}

devdocs-macos/PreferencesWindowController.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import AppKit
22
import MASShortcut
33

44
class PreferencesWindowController: NSWindowController {
5-
@IBOutlet weak var masShortcutRecorderView: MASShortcutView?;
5+
@IBOutlet weak var masShortcutRecorderView: MASShortcutView?
6+
@IBOutlet weak var pageZoomPopup: NSPopUpButton!
67

78
static let shared = PreferencesWindowController()
89

@@ -13,16 +14,46 @@ class PreferencesWindowController: NSWindowController {
1314
override func windowDidLoad() {
1415
super.windowDidLoad()
1516

17+
let pageZoomMenu = NSMenu()
18+
for option in GeneralPreferences.pageZoomOptions {
19+
let menuItem = NSMenuItem()
20+
menuItem.title = option.0
21+
menuItem.representedObject = option.1
22+
pageZoomMenu.addItem(menuItem)
23+
}
24+
pageZoomPopup.menu = pageZoomMenu
25+
1626
if let recorderView = masShortcutRecorderView {
1727
recorderView.style = .texturedRect
1828
recorderView.associatedUserDefaultsKey = Summoner.prefsKey
1929
}
30+
31+
updateUI()
32+
}
33+
34+
@IBAction func pageZoomPopupDidChangeValue(_ sender: Any) {
35+
if let zoomLevel = pageZoomPopup.selectedItem?.representedObject as? Float {
36+
GeneralPreferences.pageZoom = zoomLevel
37+
}
2038
}
2139

2240
@IBAction func restoreDefaults(_ sender: Any) {
2341
if let recorderView = masShortcutRecorderView {
2442
recorderView.shortcutValue = Summoner.defaultShortcut
2543
}
2644
GeneralPreferences.restoreDefaults()
45+
updateUI()
46+
}
47+
}
48+
49+
private extension PreferencesWindowController {
50+
private func updateUI() {
51+
let pageZoomPreference = GeneralPreferences.pageZoom
52+
for menuItem in pageZoomPopup.menu?.items ?? [] {
53+
if let value = menuItem.representedObject as? Float, value == pageZoomPreference {
54+
pageZoomPopup.select(menuItem)
55+
break
56+
}
57+
}
2758
}
2859
}

devdocs-macos/PreferencesWindowController.xib

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
4-
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
65
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
76
</dependencies>
87
<objects>
98
<customObject id="-2" userLabel="File's Owner" customClass="PreferencesWindowController" customModule="DevDocs" customModuleProvider="target">
109
<connections>
1110
<outlet property="masShortcutRecorderView" destination="8hA-DH-I7Z" id="orq-Ez-K1f"/>
11+
<outlet property="pageZoomPopup" destination="AfN-rU-RiE" id="8m5-iX-OJI"/>
1212
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
1313
</connections>
1414
</customObject>
1515
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
1616
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
1717
<window title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" tabbingMode="disallowed" id="F0z-JX-Cv5">
1818
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
19-
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
20-
<rect key="contentRect" x="196" y="240" width="300" height="150"/>
21-
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
19+
<rect key="contentRect" x="196" y="240" width="300" height="193"/>
20+
<rect key="screenRect" x="0.0" y="0.0" width="3840" height="2135"/>
2221
<value key="minSize" type="size" width="300" height="150"/>
2322
<view key="contentView" wantsLayer="YES" id="se5-gp-TjO">
24-
<rect key="frame" x="0.0" y="0.0" width="300" height="150"/>
23+
<rect key="frame" x="0.0" y="0.0" width="300" height="193"/>
2524
<autoresizingMask key="autoresizingMask"/>
2625
<subviews>
2726
<gridView fixedFrame="YES" xPlacement="none" yPlacement="none" rowAlignment="firstBaseline" translatesAutoresizingMaskIntoConstraints="NO" id="L0m-3Z-iRC">
28-
<rect key="frame" x="30" y="17" width="240" height="116"/>
27+
<rect key="frame" x="30" y="20" width="246" height="156"/>
2928
<rows>
3029
<gridRow yPlacement="center" rowAlignment="none" bottomPadding="8" id="oya-rS-Vwn"/>
3130
<gridRow bottomPadding="8" id="eSU-Fq-qHb"/>
32-
<gridRow yPlacement="bottom" height="42" id="Gra-w4-ZpZ"/>
31+
<gridRow id="OGO-ef-oHz"/>
32+
<gridRow id="2XF-zF-Tdr"/>
33+
<gridRow id="Vd2-4l-trI"/>
3334
</rows>
3435
<columns>
3536
<gridColumn xPlacement="trailing" id="cgL-ew-iuH"/>
@@ -38,7 +39,7 @@
3839
<gridCells>
3940
<gridCell row="oya-rS-Vwn" column="cgL-ew-iuH" id="5Bh-Cw-A9Z">
4041
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SLs-UG-n2b">
41-
<rect key="frame" x="-2" y="93" width="102" height="16"/>
42+
<rect key="frame" x="-2" y="133" width="102" height="16"/>
4243
<textFieldCell key="cell" lineBreakMode="clipping" alignment="right" title="Global shortcut:" id="U8G-v4-cE9">
4344
<font key="font" usesAppearanceFont="YES"/>
4445
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -48,12 +49,12 @@
4849
</gridCell>
4950
<gridCell row="oya-rS-Vwn" column="3zb-nY-eFJ" id="BpC-vH-U6D">
5051
<customView key="contentView" translatesAutoresizingMaskIntoConstraints="NO" id="8hA-DH-I7Z" customClass="MASShortcutView">
51-
<rect key="frame" x="104" y="86" width="100" height="30"/>
52+
<rect key="frame" x="104" y="126" width="100" height="30"/>
5253
</customView>
5354
</gridCell>
5455
<gridCell row="eSU-Fq-qHb" column="cgL-ew-iuH" id="Ktb-Mk-2mJ">
5556
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="v5E-4j-dS4">
56-
<rect key="frame" x="47" y="56" width="53" height="16"/>
57+
<rect key="frame" x="46" y="96" width="54" height="16"/>
5758
<textFieldCell key="cell" lineBreakMode="clipping" title="Startup:" id="7Ml-td-ltB">
5859
<font key="font" metaFont="system"/>
5960
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -63,7 +64,7 @@
6364
</gridCell>
6465
<gridCell row="eSU-Fq-qHb" column="3zb-nY-eFJ" id="yIA-9o-EA6">
6566
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UP0-PV-5sP">
66-
<rect key="frame" x="102" y="55" width="140" height="18"/>
67+
<rect key="frame" x="102" y="95" width="144" height="18"/>
6768
<buttonCell key="cell" type="check" title="Restore documents" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="pK0-Ox-QTp">
6869
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
6970
<font key="font" metaFont="system"/>
@@ -77,9 +78,35 @@
7778
</connections>
7879
</button>
7980
</gridCell>
80-
<gridCell row="Gra-w4-ZpZ" column="cgL-ew-iuH" headOfMergedCell="ktl-eK-akI" id="ktl-eK-akI">
81+
<gridCell row="OGO-ef-oHz" column="cgL-ew-iuH" id="5m9-gS-4xj">
82+
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Oeg-Ip-DAa">
83+
<rect key="frame" x="25" y="65" width="75" height="16"/>
84+
<textFieldCell key="cell" lineBreakMode="clipping" title="Page zoom:" id="Etm-YM-51V">
85+
<font key="font" usesAppearanceFont="YES"/>
86+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
87+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
88+
</textFieldCell>
89+
</textField>
90+
</gridCell>
91+
<gridCell row="OGO-ef-oHz" column="3zb-nY-eFJ" id="0Gc-vb-5Wc">
92+
<popUpButton key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AfN-rU-RiE">
93+
<rect key="frame" x="101" y="58" width="39" height="25"/>
94+
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="Tm7-tn-MO5">
95+
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
96+
<font key="font" metaFont="menu"/>
97+
<menu key="menu" id="MqF-ZB-jc3"/>
98+
</popUpButtonCell>
99+
<connections>
100+
<action selector="pageZoomPopupDidChangeValue:" target="-2" id="3aX-GS-1Eu"/>
101+
</connections>
102+
</popUpButton>
103+
</gridCell>
104+
<gridCell row="2XF-zF-Tdr" column="cgL-ew-iuH" id="8h0-hF-RHo"/>
105+
<gridCell row="2XF-zF-Tdr" column="3zb-nY-eFJ" id="eCQ-l4-o4e"/>
106+
<gridCell row="Vd2-4l-trI" column="cgL-ew-iuH" id="Xo0-Jm-S00"/>
107+
<gridCell row="Vd2-4l-trI" column="3zb-nY-eFJ" id="ke7-Up-4Kh">
81108
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kUZ-2D-ASu">
82-
<rect key="frame" x="95" y="-7" width="151" height="32"/>
109+
<rect key="frame" x="97" y="-7" width="146" height="32"/>
83110
<buttonCell key="cell" type="push" title="Restore defaults..." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="r9Z-qe-Up0">
84111
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
85112
<font key="font" metaFont="system"/>
@@ -89,15 +116,14 @@
89116
</connections>
90117
</button>
91118
</gridCell>
92-
<gridCell row="Gra-w4-ZpZ" column="3zb-nY-eFJ" headOfMergedCell="ktl-eK-akI" id="ENg-Zr-n8t"/>
93119
</gridCells>
94120
</gridView>
95121
</subviews>
96122
</view>
97123
<connections>
98124
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
99125
</connections>
100-
<point key="canvasLocation" x="-104" y="-5"/>
126+
<point key="canvasLocation" x="-926" y="-376.5"/>
101127
</window>
102128
<userDefaultsController representsSharedInstance="YES" id="E4w-VZ-Y12"/>
103129
</objects>

0 commit comments

Comments
 (0)