Kaynağa Gözat

Move to document-based application

master
Matt Baer 6 yıl önce
ebeveyn
işleme
986fc3583d
6 değiştirilmiş dosya ile 134 ekleme ve 5 silme
  1. +8
    -0
      writeas.xcodeproj/project.pbxproj
  2. +4
    -2
      writeas/AppDelegate.swift
  3. +31
    -3
      writeas/Base.lproj/Main.storyboard
  4. +44
    -0
      writeas/Document.swift
  5. +21
    -0
      writeas/Info.plist
  6. +26
    -0
      writeas/WindowController.swift

+ 8
- 0
writeas.xcodeproj/project.pbxproj Dosyayı Görüntüle

@@ -7,7 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
33071005A600B8C542D04637 /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33071BEC2D76387CC2ACE1BD /* WindowController.swift */; };
330711A70F03BFB84FB889AB /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33071648B80C4188CAC44CA1 /* Constants.swift */; };
33071853C7159177EC75175B /* Document.swift in Sources */ = {isa = PBXBuildFile; fileRef = 330715DBB45C2BB18057D4BC /* Document.swift */; };
33071D332D5799D36FBC1DDD /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3307150C0D2CA1C8A71C5E26 /* Preferences.swift */; };
C98EE9AC1F29532F002F646E /* writeas in Resources */ = {isa = PBXBuildFile; fileRef = C98EE9AB1F29532F002F646E /* writeas */; };
C9953E7D1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */; };
@@ -30,7 +32,9 @@

/* Begin PBXFileReference section */
3307150C0D2CA1C8A71C5E26 /* Preferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Preferences.swift; path = writeas/Preferences.swift; sourceTree = "<group>"; };
330715DBB45C2BB18057D4BC /* Document.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Document.swift; path = writeas/Document.swift; sourceTree = "<group>"; };
33071648B80C4188CAC44CA1 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
33071BEC2D76387CC2ACE1BD /* WindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WindowController.swift; path = writeas/WindowController.swift; sourceTree = "<group>"; };
C98EE9AB1F29532F002F646E /* writeas */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = writeas; sourceTree = "<group>"; };
C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf"; sourceTree = "<group>"; };
C9953E7A1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf"; sourceTree = "<group>"; };
@@ -88,6 +92,8 @@
C99B910B1C33841E00A91990 /* writeas */,
C99B910A1C33841E00A91990 /* Products */,
3307150C0D2CA1C8A71C5E26 /* Preferences.swift */,
330715DBB45C2BB18057D4BC /* Document.swift */,
33071BEC2D76387CC2ACE1BD /* WindowController.swift */,
);
sourceTree = "<group>";
};
@@ -204,6 +210,8 @@
C99B910D1C33841E00A91990 /* AppDelegate.swift in Sources */,
33071D332D5799D36FBC1DDD /* Preferences.swift in Sources */,
330711A70F03BFB84FB889AB /* Constants.swift in Sources */,
33071853C7159177EC75175B /* Document.swift in Sources */,
33071005A600B8C542D04637 /* WindowController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};


+ 4
- 2
writeas/AppDelegate.swift Dosyayı Görüntüle

@@ -24,7 +24,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// Set night mode state
nightModeItem.state = Int(UserDefaults.standard.string(forKey: "night_mode_state") ?? String(NSOffState))!
if nightModeItem.state == NSOnState {
vc?.toggle(isNight: true)
let wc = NSApplication.shared().mainWindow!.windowController as? WindowController
wc?.toggle(isNight: true)
}

// Set font
@@ -59,8 +60,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

@IBAction func toggleNightMode(_ sender: NSMenuItem) {
let wc = NSApplication.shared().mainWindow!.windowController as? WindowController
let isOff = sender.state == NSOffState
vc?.toggle(isNight: isOff)
wc?.toggle(isNight: isOff)
sender.state = isOff ? NSOnState : NSOffState
UserDefaults.standard.set(String(sender.state), forKey: "night_mode_state")
}


+ 31
- 3
writeas/Base.lproj/Main.storyboard Dosyayı Görüntüle

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@@ -60,11 +59,40 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="File" id="bib-Uj-vzu">
<items>
<menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
<connections>
<action selector="newDocument:" target="Ady-hI-5gd" id="4Si-XN-c54"/>
</connections>
</menuItem>
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
<connections>
<action selector="fileOpen:" target="Voe-Tx-rLC" id="X9q-tg-tjq"/>
</connections>
</menuItem>
<menuItem title="Open Recent" id="tXI-mr-wws">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
<items>
<menuItem title="Clear Menu" id="vNY-rz-j42">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="clearRecentDocuments:" target="Ady-hI-5gd" id="Daa-9d-B3U"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
<menuItem title="Save" keyEquivalent="s" id="pxx-59-PXV">
<connections>
<action selector="saveDocument:" target="Voe-Tx-rLC" id="6F3-Jk-bXC"/>
</connections>
</menuItem>
<menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
<connections>
<action selector="saveDocumentAs:" target="Ady-hI-5gd" id="mDf-zr-I0C"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
<menuItem title="Publish" id="Vdf-ed-k4A">
<string key="keyEquivalent" base64-UTF8="YES">
@@ -382,7 +410,7 @@ DQ
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
<windowController storyboardIdentifier="DocumentWindow" id="B8D-0N-5wS" customClass="WindowController" customModule="Write_as" customModuleProvider="target" sceneMemberID="viewController">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" topStrut="YES"/>


+ 44
- 0
writeas/Document.swift Dosyayı Görüntüle

@@ -0,0 +1,44 @@
//
// Created by Matt Baer on 8/2/17.
// Copyright (c) 2017 A Bunch Tell. All rights reserved.
//

import Foundation
import Cocoa

class Document: NSDocument {

override init() {
super.init()
// Add your subclass-specific initialization here.
}

override class func autosavesInPlace() -> Bool {
return false
}

override func makeWindowControllers() {
// Returns the Storyboard that contains your Document window.
let storyboard = NSStoryboard(name: "Main", bundle: nil)
let windowController = storyboard.instantiateController(withIdentifier: "DocumentWindow") as! NSWindowController
self.addWindowController(windowController)
}

override func data(ofType typeName: String) throws -> Data {
// Insert code here to write your document to data of the specified type. If outError != nil, ensure that you create and set an appropriate error when returning nil.
// You can also choose to override fileWrapperOfType:error:, writeToURL:ofType:error:, or writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}

override func read(from data: Data, ofType typeName: String) throws {
// Insert code here to read your document from the given data of the specified type. If outError != nil, ensure that you create and set an appropriate error when returning false.
// You can also choose to override readFromFileWrapper:ofType:error: or readFromURL:ofType:error: instead.
// If you override either of these, you should also override -isEntireFileLoaded to return false if the contents are lazily loaded.
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}

override var isDocumentEdited: Bool {
// Never prompt user to save on exit
return false
}
}

+ 21
- 0
writeas/Info.plist Dosyayı Görüntüle

@@ -4,6 +4,27 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>was</string>
</array>
<key>CFBundleTypeIconFile</key>
<string></string>
<key>CFBundleTypeName</key>
<string>DocumentType</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>????</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>NSDocumentClass</key>
<string>$(PRODUCT_MODULE_NAME).Document</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>


+ 26
- 0
writeas/WindowController.swift Dosyayı Görüntüle

@@ -0,0 +1,26 @@
//
// Created by Matt Baer on 8/2/17.
// Copyright (c) 2017 A Bunch Tell. All rights reserved.
//

import Foundation
import AppKit

class WindowController: NSWindowController {
var vc: ViewController?

required init?(coder: NSCoder) {
super.init(coder: coder)
shouldCascadeWindows = true
}

override func windowDidLoad() {
super.windowDidLoad()

vc = (self.window?.contentViewController)! as! ViewController
}

func toggle(isNight: Bool) {
vc?.toggle(isNight: isNight)
}
}

Yükleniyor…
İptal
Kaydet