Browse Source

Add basic document editing

master
Shadowfacts 2 months ago
parent
commit
c89d6d5f39
Signed by: Shadowfacts <me@shadowfacts.net> GPG Key ID: 94A5AB95422746E5

+ 16
- 0
MongoView.xcodeproj/project.pbxproj View File

@@ -13,6 +13,10 @@
13 13
 		D60C864023CA2E2100C9DB8E /* ServerConnectViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D60C863E23CA2E2100C9DB8E /* ServerConnectViewController.xib */; };
14 14
 		D62408C12438CF550020E09F /* JavaScriptEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D62408C02438CF550020E09F /* JavaScriptEditorView.swift */; };
15 15
 		D624090F243903E90020E09F /* ExtendedJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = D624090E243903E90020E09F /* ExtendedJSON.swift */; };
16
+		D626BF82243BD2EE0075117B /* EditDocumentWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D626BF80243BD2EE0075117B /* EditDocumentWindowController.swift */; };
17
+		D626BF83243BD2EE0075117B /* EditDocumentWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D626BF81243BD2EE0075117B /* EditDocumentWindowController.xib */; };
18
+		D626BF86243BE19A0075117B /* EditDocumentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D626BF84243BE19A0075117B /* EditDocumentViewController.swift */; };
19
+		D626BF87243BE19A0075117B /* EditDocumentViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D626BF85243BE19A0075117B /* EditDocumentViewController.xib */; };
16 20
 		D63CDEBE23C837DC0012D658 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63CDEBD23C837DC0012D658 /* AppDelegate.swift */; };
17 21
 		D63CDEC023C837DD0012D658 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D63CDEBF23C837DD0012D658 /* Assets.xcassets */; };
18 22
 		D63CDEC323C837DD0012D658 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = D63CDEC123C837DD0012D658 /* MainMenu.xib */; };
@@ -88,6 +92,10 @@
88 92
 		D60C863E23CA2E2100C9DB8E /* ServerConnectViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ServerConnectViewController.xib; sourceTree = "<group>"; };
89 93
 		D62408C02438CF550020E09F /* JavaScriptEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JavaScriptEditorView.swift; sourceTree = "<group>"; };
90 94
 		D624090E243903E90020E09F /* ExtendedJSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtendedJSON.swift; sourceTree = "<group>"; };
95
+		D626BF80243BD2EE0075117B /* EditDocumentWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditDocumentWindowController.swift; sourceTree = "<group>"; };
96
+		D626BF81243BD2EE0075117B /* EditDocumentWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = EditDocumentWindowController.xib; sourceTree = "<group>"; };
97
+		D626BF84243BE19A0075117B /* EditDocumentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditDocumentViewController.swift; sourceTree = "<group>"; };
98
+		D626BF85243BE19A0075117B /* EditDocumentViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = EditDocumentViewController.xib; sourceTree = "<group>"; };
91 99
 		D63CDEBA23C837DC0012D658 /* MongoView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MongoView.app; sourceTree = BUILT_PRODUCTS_DIR; };
92 100
 		D63CDEBD23C837DC0012D658 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
93 101
 		D63CDEBF23C837DD0012D658 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -153,6 +161,8 @@
153 161
 				D60C863823CA2DD100C9DB8E /* ServerConnectWindowController.xib */,
154 162
 				D63CDF3A23C838470012D658 /* DatabaseWindowController.swift */,
155 163
 				D63CDF3B23C838470012D658 /* DatabaseWindowController.xib */,
164
+				D626BF80243BD2EE0075117B /* EditDocumentWindowController.swift */,
165
+				D626BF81243BD2EE0075117B /* EditDocumentWindowController.xib */,
156 166
 			);
157 167
 			path = Windows;
158 168
 			sourceTree = "<group>";
@@ -166,6 +176,8 @@
166 176
 				D63CDF4323C970C50012D658 /* DatabaseViewController.xib */,
167 177
 				D63CDF3E23C839010012D658 /* QueryViewController.swift */,
168 178
 				D63CDF3F23C839010012D658 /* QueryViewController.xib */,
179
+				D626BF84243BE19A0075117B /* EditDocumentViewController.swift */,
180
+				D626BF85243BE19A0075117B /* EditDocumentViewController.xib */,
169 181
 			);
170 182
 			path = "View Controllers";
171 183
 			sourceTree = "<group>";
@@ -334,10 +346,12 @@
334 346
 				D60C864023CA2E2100C9DB8E /* ServerConnectViewController.xib in Resources */,
335 347
 				D63CDEC023C837DD0012D658 /* Assets.xcassets in Resources */,
336 348
 				D60C863A23CA2DD100C9DB8E /* ServerConnectWindowController.xib in Resources */,
349
+				D626BF87243BE19A0075117B /* EditDocumentViewController.xib in Resources */,
337 350
 				D63CDF4523C970C50012D658 /* DatabaseViewController.xib in Resources */,
338 351
 				D6A7D09A243546B500B46857 /* WindowStatusView.xib in Resources */,
339 352
 				D63CDF3D23C838470012D658 /* DatabaseWindowController.xib in Resources */,
340 353
 				D63CDEC323C837DD0012D658 /* MainMenu.xib in Resources */,
354
+				D626BF83243BD2EE0075117B /* EditDocumentWindowController.xib in Resources */,
341 355
 				D63CDF4123C839010012D658 /* QueryViewController.xib in Resources */,
342 356
 			);
343 357
 			runOnlyForDeploymentPostprocessing = 0;
@@ -355,10 +369,12 @@
355 369
 				D63CDF3823C8381A0012D658 /* MongoController.swift in Sources */,
356 370
 				D60C863923CA2DD100C9DB8E /* ServerConnectWindowController.swift in Sources */,
357 371
 				D63CDF3723C8381A0012D658 /* Node.swift in Sources */,
372
+				D626BF86243BE19A0075117B /* EditDocumentViewController.swift in Sources */,
358 373
 				D60C863F23CA2E2100C9DB8E /* ServerConnectViewController.swift in Sources */,
359 374
 				D63CDF4423C970C50012D658 /* DatabaseViewController.swift in Sources */,
360 375
 				D63CDF3C23C838470012D658 /* DatabaseWindowController.swift in Sources */,
361 376
 				D6A7D096243541A400B46857 /* WindowStatusView.swift in Sources */,
377
+				D626BF82243BD2EE0075117B /* EditDocumentWindowController.swift in Sources */,
362 378
 				D6A7D0A42435885B00B46857 /* JavaScriptHighlighter.swift in Sources */,
363 379
 				D62408C12438CF550020E09F /* JavaScriptEditorView.swift in Sources */,
364 380
 				D63CDF4023C839010012D658 /* QueryViewController.swift in Sources */,

+ 24
- 0
MongoView/ExtendedJSON.swift View File

@@ -8,6 +8,7 @@
8 8
 
9 9
 import Foundation
10 10
 import JavaScriptCore
11
+import MongoSwift
11 12
 
12 13
 struct ExtendedJSON {
13 14
     private init() {}
@@ -25,4 +26,27 @@ struct ExtendedJSON {
25 26
         return context.evaluateScript("JSON.stringify(\(string))")?.toString()
26 27
     }
27 28
     
29
+    private static func fromExtJSON(_ string: String) -> Document? {
30
+        do {
31
+            let doc = try Document(fromJSON: string)
32
+            return doc
33
+        } catch {
34
+            print("Unable to create document from extended JSON: \(error)")
35
+            return nil
36
+        }
37
+    }
38
+    
39
+    static func toDocument(_ string: String) -> Document? {
40
+        guard let normalized = normalize(string),
41
+            let doc = fromExtJSON(normalized) else {
42
+                return nil
43
+        }
44
+        return doc
45
+    }
46
+    
47
+    static func prettify(_ string: String) -> String? {
48
+        let command = "JSON.stringify(JSON.parse(`\(string)`), null, 4)"
49
+        return context.evaluateScript(command)?.toString()
50
+    }
51
+    
28 52
 }

+ 70
- 0
MongoView/View Controllers/EditDocumentViewController.swift View File

@@ -0,0 +1,70 @@
1
+//
2
+//  EditDocumentViewController.swift
3
+//  MongoView
4
+//
5
+//  Created by Shadowfacts on 4/6/20.
6
+//  Copyright © 2020 Shadowfacts. All rights reserved.
7
+//
8
+
9
+import Cocoa
10
+import MongoSwift
11
+
12
+class EditDocumentViewController: NSViewController {
13
+
14
+    private(set) var mongoController: MongoController!
15
+    private(set) var collection: DatabaseCollection!
16
+    private(set) var document: Document!
17
+    
18
+    var documentEdited: (() -> Void)?
19
+    
20
+    @IBOutlet var editorTextView: JavaScriptEditorView!
21
+    @IBOutlet weak var saveButton: NSButton!
22
+    @IBOutlet weak var cancelButton: NSButton!
23
+    @IBOutlet weak var validateButton: NSButton!
24
+    
25
+    init(mongoController: MongoController, collection: DatabaseCollection, document: Document) {
26
+        self.mongoController = mongoController
27
+        self.collection = collection
28
+        self.document = document
29
+        
30
+        super.init(nibName: "EditDocumentViewController", bundle: .main)
31
+    }
32
+    
33
+    required init?(coder: NSCoder) {
34
+        fatalError()
35
+    }
36
+
37
+    override func viewDidLoad() {
38
+        super.viewDidLoad()
39
+        
40
+        editorTextView.string = ExtendedJSON.prettify(document.extendedJSON) ?? document.extendedJSON
41
+        editorTextView.isAutomaticQuoteSubstitutionEnabled = false
42
+    }
43
+    
44
+    @IBAction func savePressed(_ sender: Any) {
45
+        guard let id = document["_id"],
46
+            let newDoc = ExtendedJSON.toDocument(editorTextView.string) else {
47
+                // todo: error
48
+                return
49
+        }
50
+        let collection = mongoController.collection(self.collection)
51
+        collection.replaceOne(filter: ["_id": id], replacement: newDoc).whenComplete { (result) in
52
+            DispatchQueue.main.async {
53
+                switch result {
54
+                case .success(_):
55
+                    self.documentEdited?()
56
+                case let .failure(error):
57
+                    print("Unable to replace document: \(error)")
58
+                }
59
+                self.view.window!.close()
60
+            }
61
+        }
62
+    }
63
+    
64
+    @IBAction func cancelPressed(_ sender: Any) {
65
+        view.window!.close()
66
+    }
67
+    
68
+    @IBAction func validatePressed(_ sender: Any) {
69
+    }
70
+}

+ 110
- 0
MongoView/View Controllers/EditDocumentViewController.xib View File

@@ -0,0 +1,110 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
3
+    <dependencies>
4
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/>
5
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6
+    </dependencies>
7
+    <objects>
8
+        <customObject id="-2" userLabel="File's Owner" customClass="EditDocumentViewController" customModule="MongoView" customModuleProvider="target">
9
+            <connections>
10
+                <outlet property="cancelButton" destination="5M7-Eo-LRQ" id="9iE-dG-Rvz"/>
11
+                <outlet property="editorTextView" destination="1aa-Vo-yPS" id="hip-Qi-9BH"/>
12
+                <outlet property="saveButton" destination="3aO-fI-F6G" id="hbc-f1-hAJ"/>
13
+                <outlet property="validateButton" destination="J9n-en-a5p" id="SoQ-HS-byg"/>
14
+                <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
15
+            </connections>
16
+        </customObject>
17
+        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
18
+        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
19
+        <customView id="Hz6-mo-xeY">
20
+            <rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
21
+            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
22
+            <subviews>
23
+                <stackView distribution="fill" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xa0-UE-ywz">
24
+                    <rect key="frame" x="273" y="8" width="199" height="21"/>
25
+                    <subviews>
26
+                        <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5M7-Eo-LRQ">
27
+                            <rect key="frame" x="-6" y="-7" width="82" height="32"/>
28
+                            <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="xeo-Kh-gMm">
29
+                                <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
30
+                                <font key="font" metaFont="system"/>
31
+                                <string key="keyEquivalent" base64-UTF8="YES">
32
+Gw
33
+</string>
34
+                            </buttonCell>
35
+                            <connections>
36
+                                <action selector="cancelPressed:" target="-2" id="bmf-UI-VmZ"/>
37
+                            </connections>
38
+                        </button>
39
+                        <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3aO-fI-F6G">
40
+                            <rect key="frame" x="72" y="-7" width="133" height="32"/>
41
+                            <buttonCell key="cell" type="push" title="Save and Close" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="FgS-jM-BWn">
42
+                                <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
43
+                                <font key="font" metaFont="system"/>
44
+                            </buttonCell>
45
+                            <connections>
46
+                                <action selector="savePressed:" target="-2" id="Blr-6P-WPb"/>
47
+                            </connections>
48
+                        </button>
49
+                    </subviews>
50
+                    <visibilityPriorities>
51
+                        <integer value="1000"/>
52
+                        <integer value="1000"/>
53
+                    </visibilityPriorities>
54
+                    <customSpacing>
55
+                        <real value="3.4028234663852886e+38"/>
56
+                        <real value="3.4028234663852886e+38"/>
57
+                    </customSpacing>
58
+                </stackView>
59
+                <scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MlX-0S-w82">
60
+                    <rect key="frame" x="8" y="37" width="464" height="227"/>
61
+                    <clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="egN-c7-XBK">
62
+                        <rect key="frame" x="0.0" y="0.0" width="449" height="227"/>
63
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
64
+                        <subviews>
65
+                            <textView importsGraphics="NO" richText="NO" verticallyResizable="YES" id="1aa-Vo-yPS" customClass="JavaScriptEditorView" customModule="MongoView" customModuleProvider="target">
66
+                                <rect key="frame" x="0.0" y="0.0" width="449" height="227"/>
67
+                                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
68
+                                <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
69
+                                <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
70
+                                <size key="minSize" width="449" height="227"/>
71
+                                <size key="maxSize" width="465" height="10000000"/>
72
+                                <color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
73
+                            </textView>
74
+                        </subviews>
75
+                    </clipView>
76
+                    <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="IwO-eE-cem">
77
+                        <rect key="frame" x="-100" y="-100" width="225" height="15"/>
78
+                        <autoresizingMask key="autoresizingMask"/>
79
+                    </scroller>
80
+                    <scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="IDr-mZ-kqd">
81
+                        <rect key="frame" x="449" y="0.0" width="15" height="227"/>
82
+                        <autoresizingMask key="autoresizingMask"/>
83
+                    </scroller>
84
+                </scrollView>
85
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="J9n-en-a5p">
86
+                    <rect key="frame" x="2" y="1" width="89" height="32"/>
87
+                    <buttonCell key="cell" type="push" title="Validate" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="J6T-UY-zPK">
88
+                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
89
+                        <font key="font" metaFont="system"/>
90
+                    </buttonCell>
91
+                    <connections>
92
+                        <action selector="validatePressed:" target="-2" id="gVI-wh-rT2"/>
93
+                    </connections>
94
+                </button>
95
+            </subviews>
96
+            <constraints>
97
+                <constraint firstItem="MlX-0S-w82" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="8" id="BdG-le-KXB"/>
98
+                <constraint firstItem="J9n-en-a5p" firstAttribute="top" secondItem="MlX-0S-w82" secondAttribute="bottom" constant="8" id="FvY-Be-Tdx"/>
99
+                <constraint firstItem="J9n-en-a5p" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="8" id="HzC-6Y-gZG"/>
100
+                <constraint firstAttribute="bottom" secondItem="xa0-UE-ywz" secondAttribute="bottom" constant="8" id="Ssc-Oa-bTe"/>
101
+                <constraint firstItem="xa0-UE-ywz" firstAttribute="top" secondItem="MlX-0S-w82" secondAttribute="bottom" constant="8" id="Uga-ZA-1b4"/>
102
+                <constraint firstAttribute="trailing" secondItem="xa0-UE-ywz" secondAttribute="trailing" constant="8" id="i4O-th-zRP"/>
103
+                <constraint firstAttribute="bottom" secondItem="J9n-en-a5p" secondAttribute="bottom" constant="8" id="lZs-Qs-8gq"/>
104
+                <constraint firstItem="MlX-0S-w82" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="8" id="m99-4c-vcx"/>
105
+                <constraint firstAttribute="trailing" secondItem="MlX-0S-w82" secondAttribute="trailing" constant="8" id="rYV-TB-qaV"/>
106
+            </constraints>
107
+            <point key="canvasLocation" x="140" y="154"/>
108
+        </customView>
109
+    </objects>
110
+</document>

+ 15
- 3
MongoView/View Controllers/QueryViewController.swift View File

@@ -79,8 +79,7 @@ class QueryViewController: NSViewController {
79 79
         let filterText = filterTextView.string.trimmingCharacters(in: .whitespacesAndNewlines)
80 80
         let filter: Document
81 81
         if !filterText.isEmpty,
82
-            let normalized = ExtendedJSON.normalize(filterText),
83
-            let doc = try? Document(fromJSON: normalized) {
82
+            let doc = ExtendedJSON.toDocument(filterText) {
84 83
             filter = doc
85 84
         } else {
86 85
             filter = [:]
@@ -162,11 +161,24 @@ class QueryViewController: NSViewController {
162 161
         }
163 162
     }
164 163
     
164
+    @IBAction func editDocument(_ sender: Any) {
165
+        guard let node = outlineView.item(atRow: outlineView.clickedRow) as? Node,
166
+            node.parent == nil,
167
+            case let .document(document) = node.value else {
168
+            return
169
+        }
170
+        
171
+        let wc = EditDocumentWindowController(mongoController: mongoController, collection: collection, document: document)
172
+        wc.documentEdited = {
173
+            self.refresh()
174
+        }
175
+        wc.showWindow(nil)
176
+    }
165 177
 }
166 178
 
167 179
 extension QueryViewController: NSMenuItemValidation {
168 180
     func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
169
-        if menuItem.action == #selector(deleteNode(_:)) {
181
+        if menuItem.action == #selector(deleteNode(_:)) || menuItem.action == #selector(editDocument(_:)) {
170 182
             if outlineView.clickedRow != -1, let node = outlineView.item(atRow: outlineView.clickedRow) as? Node, node.parent == nil {
171 183
                 return true
172 184
             } else {

+ 6
- 0
MongoView/View Controllers/QueryViewController.xib View File

@@ -1139,6 +1139,12 @@
1139 1139
         </customView>
1140 1140
         <menu id="nL5-kg-dty">
1141 1141
             <items>
1142
+                <menuItem title="Edit Document" id="0gS-XH-YDt">
1143
+                    <modifierMask key="keyEquivalentModifierMask"/>
1144
+                    <connections>
1145
+                        <action selector="editDocument:" target="-2" id="DP4-Tq-o5M"/>
1146
+                    </connections>
1147
+                </menuItem>
1142 1148
                 <menuItem title="Delete" id="nn0-ZF-eDZ">
1143 1149
                     <modifierMask key="keyEquivalentModifierMask"/>
1144 1150
                     <connections>

+ 38
- 0
MongoView/Windows/EditDocumentWindowController.swift View File

@@ -0,0 +1,38 @@
1
+//
2
+//  EditDocumentWindowController.swift
3
+//  MongoView
4
+//
5
+//  Created by Shadowfacts on 4/6/20.
6
+//  Copyright © 2020 Shadowfacts. All rights reserved.
7
+//
8
+
9
+import Cocoa
10
+import MongoSwift
11
+
12
+class EditDocumentWindowController: NSWindowController {
13
+    
14
+    private(set) var mongoController: MongoController!
15
+    private(set) var collection: DatabaseCollection!
16
+    private(set) var mongoDocument: Document!
17
+    
18
+    var documentEdited: (() -> Void)?
19
+    
20
+    convenience init(mongoController: MongoController, collection: DatabaseCollection, document: Document) {
21
+        self.init(windowNibName: "EditDocumentWindowController")
22
+
23
+        self.mongoController = mongoController
24
+        self.collection = collection
25
+        self.mongoDocument = document
26
+    }
27
+
28
+    override func windowDidLoad() {
29
+        super.windowDidLoad()
30
+
31
+        window!.title = "Edit \(collection.database).\(collection.name) Document"
32
+        
33
+        let vc = EditDocumentViewController(mongoController: mongoController, collection: collection, document: mongoDocument)
34
+        vc.documentEdited = documentEdited
35
+        contentViewController = vc
36
+    }
37
+    
38
+}

+ 30
- 0
MongoView/Windows/EditDocumentWindowController.xib View File

@@ -0,0 +1,30 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
3
+    <dependencies>
4
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/>
5
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6
+    </dependencies>
7
+    <objects>
8
+        <customObject id="-2" userLabel="File's Owner" customClass="EditDocumentWindowController" customModule="MongoView" customModuleProvider="target">
9
+            <connections>
10
+                <outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
11
+            </connections>
12
+        </customObject>
13
+        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
14
+        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
15
+        <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="documentWindow" id="F0z-JX-Cv5">
16
+            <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
17
+            <rect key="contentRect" x="931" y="526" width="1200" height="900"/>
18
+            <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
19
+            <value key="minSize" type="size" width="900" height="600"/>
20
+            <view key="contentView" id="se5-gp-TjO">
21
+                <rect key="frame" x="0.0" y="0.0" width="1200" height="900"/>
22
+                <autoresizingMask key="autoresizingMask"/>
23
+            </view>
24
+            <connections>
25
+                <outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
26
+            </connections>
27
+            <point key="canvasLocation" x="140" y="147"/>
28
+        </window>
29
+    </objects>
30
+</document>

Loading…
Cancel
Save