Skip to content

Commit 3763bc8

Browse files
authored
Merge pull request #24 from dteoh/23-restore-session-preference
Add preference to control document restoration
2 parents 6130c6d + ef47371 commit 3763bc8

File tree

5 files changed

+108
-31
lines changed

5 files changed

+108
-31
lines changed

DevDocs.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
061A0545246E275200CCFC1A /* GeneralPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061A0544246E275200CCFC1A /* GeneralPreferences.swift */; };
1011
06996D2D223DDBEB001507AD /* Summoner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06996D2C223DDBEB001507AD /* Summoner.swift */; };
1112
06996D36223DEDA3001507AD /* MASShortcut.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06996D35223DEDA3001507AD /* MASShortcut.framework */; };
1213
06996D37223DEDA3001507AD /* MASShortcut.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 06996D35223DEDA3001507AD /* MASShortcut.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -59,6 +60,7 @@
5960
/* End PBXCopyFilesBuildPhase section */
6061

6162
/* Begin PBXFileReference section */
63+
061A0544246E275200CCFC1A /* GeneralPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPreferences.swift; sourceTree = "<group>"; };
6264
06996D2C223DDBEB001507AD /* Summoner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Summoner.swift; sourceTree = "<group>"; };
6365
06996D35223DEDA3001507AD /* MASShortcut.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MASShortcut.framework; path = Carthage/Build/Mac/MASShortcut.framework; sourceTree = "<group>"; };
6466
06996D38223DEDC8001507AD /* MASShortcut.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = MASShortcut.framework.dSYM; path = Carthage/Build/Mac/MASShortcut.framework.dSYM; sourceTree = "<group>"; };
@@ -138,7 +140,7 @@
138140
06EAE7FA21D0CD8F00F7C921 /* DocumentationWindow.xib */,
139141
06EAE7FC21D0CE3E00F7C921 /* DocumentationWindowController.swift */,
140142
06B5A73021D354FC007823B2 /* DocumentationWindows.swift */,
141-
06EAE7F321D0CB3E00F7C921 /* Info.plist */,
143+
061A0544246E275200CCFC1A /* GeneralPreferences.swift */,
142144
06EAE7F021D0CB3E00F7C921 /* MainMenu.xib */,
143145
06996D3A223DEF54001507AD /* PreferencesWindowController.swift */,
144146
06996D3B223DEF54001507AD /* PreferencesWindowController.xib */,
@@ -147,6 +149,7 @@
147149
06B5A73A21D36680007823B2 /* Storage.swift */,
148150
06996D2C223DDBEB001507AD /* Summoner.swift */,
149151
06CAA896223E6ACB00B296AC /* URLEventHandler.swift */,
152+
06EAE7F321D0CB3E00F7C921 /* Info.plist */,
150153
06B5A71921D2013D007823B2 /* user-scripts */,
151154
);
152155
path = "devdocs-macos";
@@ -240,6 +243,7 @@
240243
06EAE7ED21D0CB3D00F7C921 /* AppDelegate.swift in Sources */,
241244
06B5A73B21D36680007823B2 /* Storage.swift in Sources */,
242245
06CAA897223E6ACB00B296AC /* URLEventHandler.swift in Sources */,
246+
061A0545246E275200CCFC1A /* GeneralPreferences.swift in Sources */,
243247
);
244248
runOnlyForDeploymentPostprocessing = 0;
245249
};

devdocs-macos/DocumentationWindows.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class DocumentationWindows: NSObject {
4444
}
4545

4646
func restore() {
47+
if !GeneralPreferences.shouldRestoreDocs() {
48+
newWindow()
49+
return
50+
}
4751
if let urls = Storage.getLocations() {
4852
urls.filter { url -> Bool in
4953
if let host = url.host {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
import DefaultsKit
3+
4+
private extension DefaultsKey {
5+
static let restoreDocs = Key<Bool>("restoreDocs")
6+
}
7+
8+
class GeneralPreferences {
9+
10+
private init() {
11+
}
12+
13+
class func restoreDefaults() {
14+
Defaults.shared.set(true, for: .restoreDocs)
15+
}
16+
17+
class func shouldRestoreDocs() -> Bool {
18+
return Defaults.shared.get(for: .restoreDocs) ?? true
19+
}
20+
21+
}

devdocs-macos/PreferencesWindowController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ class PreferencesWindowController: NSWindowController {
2323
if let recorderView = masShortcutRecorderView {
2424
recorderView.shortcutValue = Summoner.defaultShortcut
2525
}
26+
GeneralPreferences.restoreDefaults()
2627
}
2728
}
Lines changed: 77 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
4+
<deployment identifier="macosx"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
56
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
67
</dependencies>
78
<objects>
@@ -16,42 +17,88 @@
1617
<window title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" tabbingMode="disallowed" id="F0z-JX-Cv5">
1718
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
1819
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
19-
<rect key="contentRect" x="196" y="240" width="318" height="102"/>
20-
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
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"/>
22+
<value key="minSize" type="size" width="300" height="150"/>
2123
<view key="contentView" wantsLayer="YES" id="se5-gp-TjO">
22-
<rect key="frame" x="0.0" y="0.0" width="318" height="102"/>
24+
<rect key="frame" x="0.0" y="0.0" width="300" height="150"/>
2325
<autoresizingMask key="autoresizingMask"/>
2426
<subviews>
25-
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8hA-DH-I7Z" customClass="MASShortcutView">
26-
<rect key="frame" x="135" y="61" width="163" height="25"/>
27-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
28-
</customView>
29-
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kUZ-2D-ASu">
30-
<rect key="frame" x="153" y="13" width="151" height="32"/>
31-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
32-
<buttonCell key="cell" type="push" title="Restore defaults..." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="r9Z-qe-Up0">
33-
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
34-
<font key="font" metaFont="system"/>
35-
</buttonCell>
36-
<connections>
37-
<action selector="restoreDefaults:" target="-2" id="bad-yA-Cme"/>
38-
</connections>
39-
</button>
40-
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="SLs-UG-n2b">
41-
<rect key="frame" x="18" y="65" width="111" height="17"/>
42-
<autoresizingMask key="autoresizingMask"/>
43-
<textFieldCell key="cell" lineBreakMode="clipping" alignment="right" title="Global shortcut:" id="U8G-v4-cE9">
44-
<font key="font" usesAppearanceFont="YES"/>
45-
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
46-
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
47-
</textFieldCell>
48-
</textField>
27+
<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"/>
29+
<rows>
30+
<gridRow yPlacement="center" rowAlignment="none" bottomPadding="8" id="oya-rS-Vwn"/>
31+
<gridRow bottomPadding="8" id="eSU-Fq-qHb"/>
32+
<gridRow yPlacement="bottom" height="42" id="Gra-w4-ZpZ"/>
33+
</rows>
34+
<columns>
35+
<gridColumn xPlacement="trailing" id="cgL-ew-iuH"/>
36+
<gridColumn xPlacement="leading" id="3zb-nY-eFJ"/>
37+
</columns>
38+
<gridCells>
39+
<gridCell row="oya-rS-Vwn" column="cgL-ew-iuH" id="5Bh-Cw-A9Z">
40+
<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+
<textFieldCell key="cell" lineBreakMode="clipping" alignment="right" title="Global shortcut:" id="U8G-v4-cE9">
43+
<font key="font" usesAppearanceFont="YES"/>
44+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
45+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
46+
</textFieldCell>
47+
</textField>
48+
</gridCell>
49+
<gridCell row="oya-rS-Vwn" column="3zb-nY-eFJ" id="BpC-vH-U6D">
50+
<customView key="contentView" translatesAutoresizingMaskIntoConstraints="NO" id="8hA-DH-I7Z" customClass="MASShortcutView">
51+
<rect key="frame" x="104" y="86" width="100" height="30"/>
52+
</customView>
53+
</gridCell>
54+
<gridCell row="eSU-Fq-qHb" column="cgL-ew-iuH" id="Ktb-Mk-2mJ">
55+
<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+
<textFieldCell key="cell" lineBreakMode="clipping" title="Startup:" id="7Ml-td-ltB">
58+
<font key="font" metaFont="system"/>
59+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
60+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
61+
</textFieldCell>
62+
</textField>
63+
</gridCell>
64+
<gridCell row="eSU-Fq-qHb" column="3zb-nY-eFJ" id="yIA-9o-EA6">
65+
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UP0-PV-5sP">
66+
<rect key="frame" x="102" y="55" width="140" height="18"/>
67+
<buttonCell key="cell" type="check" title="Restore documents" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="pK0-Ox-QTp">
68+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
69+
<font key="font" metaFont="system"/>
70+
</buttonCell>
71+
<connections>
72+
<binding destination="E4w-VZ-Y12" name="value" keyPath="values.restoreDocs" id="dcM-sC-Yho">
73+
<dictionary key="options">
74+
<integer key="NSNullPlaceholder" value="1"/>
75+
</dictionary>
76+
</binding>
77+
</connections>
78+
</button>
79+
</gridCell>
80+
<gridCell row="Gra-w4-ZpZ" column="cgL-ew-iuH" headOfMergedCell="ktl-eK-akI" id="ktl-eK-akI">
81+
<button key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kUZ-2D-ASu">
82+
<rect key="frame" x="95" y="-7" width="151" height="32"/>
83+
<buttonCell key="cell" type="push" title="Restore defaults..." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="r9Z-qe-Up0">
84+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
85+
<font key="font" metaFont="system"/>
86+
</buttonCell>
87+
<connections>
88+
<action selector="restoreDefaults:" target="-2" id="bad-yA-Cme"/>
89+
</connections>
90+
</button>
91+
</gridCell>
92+
<gridCell row="Gra-w4-ZpZ" column="3zb-nY-eFJ" headOfMergedCell="ktl-eK-akI" id="ENg-Zr-n8t"/>
93+
</gridCells>
94+
</gridView>
4995
</subviews>
5096
</view>
5197
<connections>
5298
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
5399
</connections>
54-
<point key="canvasLocation" x="12" y="-21"/>
100+
<point key="canvasLocation" x="-104" y="-5"/>
55101
</window>
102+
<userDefaultsController representsSharedInstance="YES" id="E4w-VZ-Y12"/>
56103
</objects>
57104
</document>

0 commit comments

Comments
 (0)