-
Notifications
You must be signed in to change notification settings - Fork 503
/
Copy pathMainWindowController.swift
78 lines (58 loc) · 2.17 KB
/
MainWindowController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// MainWindowController.swift
// FSNotes
//
// Created by BUDDAx2 on 8/9/17.
// Copyright © 2017 Oleksandr Glushchenko. All rights reserved.
//
import AppKit
class MainWindowController: NSWindowController, NSWindowDelegate {
let notesListUndoManager = UndoManager()
public var lastWindowSize: NSRect? = nil
override func windowDidLoad() {
AppDelegate.mainWindowController = self
self.window?.hidesOnDeactivate = UserDefaultsManagement.hideOnDeactivate
self.window?.titleVisibility = .hidden
self.window?.titlebarAppearsTransparent = true
self.windowFrameAutosaveName = "myMainWindow"
}
func windowDidResize(_ notification: Notification) {
refreshEditArea()
}
func makeNew() {
window?.makeKeyAndOrderFront(self)
NSApp.activate(ignoringOtherApps: true)
refreshEditArea(focusSearch: true)
}
func refreshEditArea(focusSearch: Bool = false) {
guard let vc = ViewController.shared() else { return }
if vc.sidebarOutlineView.isFirstLaunch || focusSearch {
vc.search.window?.makeFirstResponder(vc.search)
} else {
vc.focusEditArea()
}
vc.editor.updateTextContainerInset()
}
func windowWillReturnUndoManager(_ window: NSWindow) -> UndoManager? {
guard let fr = window.firstResponder else {
return notesListUndoManager
}
if fr.isKind(of: NotesTableView.self) {
return notesListUndoManager
}
if fr.isKind(of: EditTextView.self) {
guard let vc = ViewController.shared(), let ev = vc.editor, ev.isEditable else { return notesListUndoManager }
return vc.editorUndoManager
}
return notesListUndoManager
}
public static func shared() -> NSWindow? {
return AppDelegate.mainWindowController?.window
}
func windowDidEnterFullScreen(_ notification: Notification) {
UserDefaultsManagement.fullScreen = true
}
func windowDidExitFullScreen(_ notification: Notification) {
UserDefaultsManagement.fullScreen = false
}
}