Skip to content

Commit f8d78b5

Browse files
committed
Add AddTodoViewController
1 parent 7459f82 commit f8d78b5

File tree

6 files changed

+110
-5
lines changed

6 files changed

+110
-5
lines changed

todo-status-bar.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
1E545FD71E0AE62400D19810 /* EditTodosWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E545FD51E0AE62400D19810 /* EditTodosWindowController.xib */; };
1515
1E8FB7541E0BCD5200BF6D20 /* TodoItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E8FB7531E0BCD5200BF6D20 /* TodoItem.swift */; };
1616
1E8FB7561E0BCD6400BF6D20 /* TodoItemsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E8FB7551E0BCD6400BF6D20 /* TodoItemsController.swift */; };
17+
1E8FB75D1E0BF88300BF6D20 /* AddTodoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E8FB75B1E0BF88300BF6D20 /* AddTodoViewController.swift */; };
18+
1E8FB75E1E0BF88300BF6D20 /* AddTodoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E8FB75C1E0BF88300BF6D20 /* AddTodoViewController.xib */; };
1719
/* End PBXBuildFile section */
1820

1921
/* Begin PBXFileReference section */
@@ -26,6 +28,8 @@
2628
1E545FD51E0AE62400D19810 /* EditTodosWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EditTodosWindowController.xib; sourceTree = "<group>"; };
2729
1E8FB7531E0BCD5200BF6D20 /* TodoItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TodoItem.swift; sourceTree = "<group>"; };
2830
1E8FB7551E0BCD6400BF6D20 /* TodoItemsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TodoItemsController.swift; sourceTree = "<group>"; };
31+
1E8FB75B1E0BF88300BF6D20 /* AddTodoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddTodoViewController.swift; sourceTree = "<group>"; };
32+
1E8FB75C1E0BF88300BF6D20 /* AddTodoViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AddTodoViewController.xib; sourceTree = "<group>"; };
2933
/* End PBXFileReference section */
3034

3135
/* Begin PBXFrameworksBuildPhase section */
@@ -61,6 +65,8 @@
6165
1E545FC71E0AD7E500D19810 /* AppDelegate.swift */,
6266
1E8FB7531E0BCD5200BF6D20 /* TodoItem.swift */,
6367
1E8FB7551E0BCD6400BF6D20 /* TodoItemsController.swift */,
68+
1E8FB75B1E0BF88300BF6D20 /* AddTodoViewController.swift */,
69+
1E8FB75C1E0BF88300BF6D20 /* AddTodoViewController.xib */,
6470
1E545FD41E0AE62400D19810 /* EditTodosWindowController.swift */,
6571
1E545FD51E0AE62400D19810 /* EditTodosWindowController.xib */,
6672
1E545FC91E0AD7E500D19810 /* Assets.xcassets */,
@@ -130,6 +136,7 @@
130136
isa = PBXResourcesBuildPhase;
131137
buildActionMask = 2147483647;
132138
files = (
139+
1E8FB75E1E0BF88300BF6D20 /* AddTodoViewController.xib in Resources */,
133140
1E545FD71E0AE62400D19810 /* EditTodosWindowController.xib in Resources */,
134141
1E545FCA1E0AD7E500D19810 /* Assets.xcassets in Resources */,
135142
1E545FCD1E0AD7E500D19810 /* MainMenu.xib in Resources */,
@@ -146,6 +153,7 @@
146153
1E8FB7561E0BCD6400BF6D20 /* TodoItemsController.swift in Sources */,
147154
1E545FC81E0AD7E500D19810 /* AppDelegate.swift in Sources */,
148155
1E8FB7541E0BCD5200BF6D20 /* TodoItem.swift in Sources */,
156+
1E8FB75D1E0BF88300BF6D20 /* AddTodoViewController.swift in Sources */,
149157
1E545FD61E0AE62400D19810 /* EditTodosWindowController.swift in Sources */,
150158
);
151159
runOnlyForDeploymentPostprocessing = 0;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// AddTodoViewController.swift
3+
// todo-status-bar
4+
//
5+
// Created by derp on 12/22/16.
6+
// Copyright © 2016 Onix-Systems. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
11+
protocol AddTodoViewControllerDelegate: class {
12+
func addTodoViewController(_ controller: AddTodoViewController, didAddTodoWith title: String)
13+
}
14+
15+
class AddTodoViewController: NSViewController, NSControlTextEditingDelegate {
16+
17+
weak var delegate: AddTodoViewControllerDelegate?
18+
19+
func control(_ control: NSControl, textShouldEndEditing fieldEditor: NSText) -> Bool {
20+
guard let string = fieldEditor.string else { return true }
21+
delegate?.addTodoViewController(self, didAddTodoWith: string)
22+
return true
23+
}
24+
25+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
3+
<dependencies>
4+
<deployment identifier="macosx"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<objects>
9+
<customObject id="-2" userLabel="File's Owner" customClass="AddTodoViewController" customModule="todo_status_bar" customModuleProvider="target">
10+
<connections>
11+
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
12+
</connections>
13+
</customObject>
14+
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
15+
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
16+
<customView id="Hz6-mo-xeY">
17+
<rect key="frame" x="0.0" y="0.0" width="223" height="30"/>
18+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
19+
<subviews>
20+
<textField verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VKP-z0-rjH">
21+
<rect key="frame" x="10" y="4" width="205" height="22"/>
22+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="NPy-S5-BjT">
23+
<font key="font" metaFont="system"/>
24+
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
25+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
26+
</textFieldCell>
27+
<connections>
28+
<outlet property="delegate" destination="-2" id="BsV-a9-pNJ"/>
29+
</connections>
30+
</textField>
31+
</subviews>
32+
<constraints>
33+
<constraint firstAttribute="trailing" secondItem="VKP-z0-rjH" secondAttribute="trailing" constant="8" id="Haf-Od-egA"/>
34+
<constraint firstItem="VKP-z0-rjH" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="10" id="NDA-iZ-guA"/>
35+
<constraint firstItem="VKP-z0-rjH" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="4" id="XIA-Q0-mLw"/>
36+
<constraint firstAttribute="bottom" secondItem="VKP-z0-rjH" secondAttribute="bottom" constant="4" id="vaT-r7-3kG"/>
37+
</constraints>
38+
<point key="canvasLocation" x="-127.5" y="123"/>
39+
</customView>
40+
</objects>
41+
</document>

todo-status-bar/AppDelegate.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Cocoa
1010

1111
@NSApplicationMain
12-
class AppDelegate: NSObject, NSApplicationDelegate {
12+
class AppDelegate: NSObject, NSApplicationDelegate, EditTodosWindowControllerDelegate {
1313

1414
@IBOutlet weak var window: NSWindow!
1515

@@ -85,11 +85,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {
8585

8686
@objc private func menuEditItemPressed(_ sender: NSMenuItem) {
8787
NSApp.activate(ignoringOtherApps: true)
88+
editTodosWindowController.delegate = self
8889
editTodosWindowController.todoItemsController = todoItemsController
8990
editTodosWindowController.window?.center()
9091
editTodosWindowController.window?.makeFirstResponder(nil)
9192
editTodosWindowController.window?.makeKeyAndOrderFront(editTodosWindowController)
9293
editTodosWindowController.tableView.reloadData()
9394
}
9495

96+
func editTodosWindowControllerDidUpdateTodoItems(_ controller: EditTodosWindowController) {
97+
setupStatsItemMenu()
98+
}
99+
95100
}

todo-status-bar/EditTodosWindowController.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88

99
import Cocoa
1010

11-
class EditTodosWindowController: NSWindowController, NSTableViewDelegate, NSTableViewDataSource {
11+
protocol EditTodosWindowControllerDelegate: class {
12+
func editTodosWindowControllerDidUpdateTodoItems(_ controller: EditTodosWindowController)
13+
}
14+
15+
class EditTodosWindowController: NSWindowController, NSTableViewDelegate, NSTableViewDataSource, AddTodoViewControllerDelegate {
16+
17+
lazy var addTodoViewController: AddTodoViewController = AddTodoViewController()
18+
var panel: NSPanel?
1219

20+
weak var delegate: EditTodosWindowControllerDelegate?
1321
var todoItemsController: TodoItemsController?
1422
@IBOutlet var tableView: NSTableView!
1523

@@ -51,6 +59,22 @@ class EditTodosWindowController: NSWindowController, NSTableViewDelegate, NSTabl
5159

5260
@IBAction private func addButtonPressed(_ sender: NSButton) {
5361

62+
addTodoViewController.delegate = self
63+
guard let window = window else { return }
64+
let panel = NSPanel(contentViewController: addTodoViewController)
65+
var styleMask = panel.styleMask
66+
styleMask.remove(.resizable)
67+
panel.styleMask = styleMask
68+
self.panel = panel
69+
window.beginSheet(panel)
70+
}
71+
72+
func addTodoViewController(_ controller: AddTodoViewController, didAddTodoWith title: String) {
73+
todoItemsController?.addTodoItem(title: title)
74+
delegate?.editTodosWindowControllerDidUpdateTodoItems(self)
75+
tableView.reloadData()
76+
guard let window = window, let panel = panel else { return }
77+
window.endSheet(panel)
5478
}
5579

5680
@IBAction private func clearAllButtonPressed(_ sender: NSButton) {
@@ -63,6 +87,7 @@ class EditTodosWindowController: NSWindowController, NSTableViewDelegate, NSTabl
6387
if response == NSAlertSecondButtonReturn {
6488
todoItemsController?.deleteAll()
6589
tableView.reloadData()
90+
delegate?.editTodosWindowControllerDidUpdateTodoItems(self)
6691
}
6792
}
6893

todo-status-bar/EditTodosWindowController.xib

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
2222
<view key="contentView" wantsLayer="YES" id="se5-gp-TjO">
2323
<rect key="frame" x="0.0" y="0.0" width="250" height="400"/>
24-
<autoresizingMask key="autoresizingMask"/>
24+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2525
<subviews>
2626
<scrollView wantsLayer="YES" fixedFrame="YES" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jSm-Uz-ETm">
2727
<rect key="frame" x="0.0" y="38" width="250" height="325"/>
@@ -119,7 +119,7 @@
119119
<rect key="frame" x="36" y="10" width="178" height="20"/>
120120
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
121121
<beginningViews>
122-
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2GJ-O1-F8C">
122+
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2GJ-O1-F8C">
123123
<rect key="frame" x="-6" y="-7" width="65" height="31"/>
124124
<buttonCell key="cell" type="push" title="Add" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="PV4-cj-ViH">
125125
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -129,7 +129,7 @@
129129
<action selector="addButtonPressed:" target="-2" id="M6P-EM-cIC"/>
130130
</connections>
131131
</button>
132-
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ydv-Ir-SuB">
132+
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ydv-Ir-SuB">
133133
<rect key="frame" x="93" y="-7" width="91" height="31"/>
134134
<buttonCell key="cell" type="push" title="Clear All" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="F9l-SR-fmr">
135135
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -165,5 +165,6 @@
165165
</connections>
166166
<point key="canvasLocation" x="-34" y="217"/>
167167
</window>
168+
<userDefaultsController representsSharedInstance="YES" id="HDx-49-XBe"/>
168169
</objects>
169170
</document>

0 commit comments

Comments
 (0)