Browse Source

Start adding toolbar

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

+ 14
- 6
MongoView.xcodeproj/project.pbxproj View File

@@ -40,6 +40,8 @@
40 40
 		D63CDF4123C839010012D658 /* QueryViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D63CDF3F23C839010012D658 /* QueryViewController.xib */; };
41 41
 		D63CDF4423C970C50012D658 /* DatabaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63CDF4223C970C50012D658 /* DatabaseViewController.swift */; };
42 42
 		D63CDF4523C970C50012D658 /* DatabaseViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D63CDF4323C970C50012D658 /* DatabaseViewController.xib */; };
43
+		D6A7D096243541A400B46857 /* WindowStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6A7D095243541A400B46857 /* WindowStatusView.swift */; };
44
+		D6A7D09A243546B500B46857 /* WindowStatusView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6A7D099243546B500B46857 /* WindowStatusView.xib */; };
43 45
 		D6D4665323CB730C00F13B1B /* MongoEvaluator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D4665223CB730C00F13B1B /* MongoEvaluator.swift */; };
44 46
 /* End PBXBuildFile section */
45 47
 
@@ -93,6 +95,8 @@
93 95
 		D63CDF3F23C839010012D658 /* QueryViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = QueryViewController.xib; sourceTree = "<group>"; };
94 96
 		D63CDF4223C970C50012D658 /* DatabaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseViewController.swift; sourceTree = "<group>"; };
95 97
 		D63CDF4323C970C50012D658 /* DatabaseViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DatabaseViewController.xib; sourceTree = "<group>"; };
98
+		D6A7D095243541A400B46857 /* WindowStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowStatusView.swift; sourceTree = "<group>"; };
99
+		D6A7D099243546B500B46857 /* WindowStatusView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = WindowStatusView.xib; sourceTree = "<group>"; };
96 100
 		D6D4665223CB730C00F13B1B /* MongoEvaluator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MongoEvaluator.swift; sourceTree = "<group>"; };
97 101
 /* End PBXFileReference section */
98 102
 
@@ -123,6 +127,8 @@
123 127
 				D60C863823CA2DD100C9DB8E /* ServerConnectWindowController.xib */,
124 128
 				D63CDF3A23C838470012D658 /* DatabaseWindowController.swift */,
125 129
 				D63CDF3B23C838470012D658 /* DatabaseWindowController.xib */,
130
+				D6A7D095243541A400B46857 /* WindowStatusView.swift */,
131
+				D6A7D099243546B500B46857 /* WindowStatusView.xib */,
126 132
 			);
127 133
 			path = Windows;
128 134
 			sourceTree = "<group>";
@@ -253,6 +259,7 @@
253 259
 				D63CDEC023C837DD0012D658 /* Assets.xcassets in Resources */,
254 260
 				D60C863A23CA2DD100C9DB8E /* ServerConnectWindowController.xib in Resources */,
255 261
 				D63CDF4523C970C50012D658 /* DatabaseViewController.xib in Resources */,
262
+				D6A7D09A243546B500B46857 /* WindowStatusView.xib in Resources */,
256 263
 				D63CDF3D23C838470012D658 /* DatabaseWindowController.xib in Resources */,
257 264
 				D63CDEC323C837DD0012D658 /* MainMenu.xib in Resources */,
258 265
 				D63CDF4123C839010012D658 /* QueryViewController.xib in Resources */,
@@ -274,6 +281,7 @@
274 281
 				D60C863F23CA2E2100C9DB8E /* ServerConnectViewController.swift in Sources */,
275 282
 				D63CDF4423C970C50012D658 /* DatabaseViewController.swift in Sources */,
276 283
 				D63CDF3C23C838470012D658 /* DatabaseWindowController.swift in Sources */,
284
+				D6A7D096243541A400B46857 /* WindowStatusView.swift in Sources */,
277 285
 				D63CDF4023C839010012D658 /* QueryViewController.swift in Sources */,
278 286
 			);
279 287
 			runOnlyForDeploymentPostprocessing = 0;
@@ -412,15 +420,15 @@
412 420
 				CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements;
413 421
 				CODE_SIGN_STYLE = Automatic;
414 422
 				COMBINE_HIDPI_IMAGES = YES;
415
-				CURRENT_PROJECT_VERSION = 2;
416
-				DEVELOPMENT_TEAM = HGYVAQA9FW;
423
+				CURRENT_PROJECT_VERSION = 3;
424
+				DEVELOPMENT_TEAM = V4WK9KR9U2;
417 425
 				ENABLE_HARDENED_RUNTIME = YES;
418 426
 				INFOPLIST_FILE = MongoView/Info.plist;
419 427
 				LD_RUNPATH_SEARCH_PATHS = (
420 428
 					"$(inherited)",
421 429
 					"@executable_path/../Frameworks",
422 430
 				);
423
-				PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.MongoView;
431
+				PRODUCT_BUNDLE_IDENTIFIER = space.vaccor.MongoView;
424 432
 				PRODUCT_NAME = "$(TARGET_NAME)";
425 433
 				SWIFT_VERSION = 5.0;
426 434
 			};
@@ -433,15 +441,15 @@
433 441
 				CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements;
434 442
 				CODE_SIGN_STYLE = Automatic;
435 443
 				COMBINE_HIDPI_IMAGES = YES;
436
-				CURRENT_PROJECT_VERSION = 2;
437
-				DEVELOPMENT_TEAM = HGYVAQA9FW;
444
+				CURRENT_PROJECT_VERSION = 3;
445
+				DEVELOPMENT_TEAM = V4WK9KR9U2;
438 446
 				ENABLE_HARDENED_RUNTIME = YES;
439 447
 				INFOPLIST_FILE = MongoView/Info.plist;
440 448
 				LD_RUNPATH_SEARCH_PATHS = (
441 449
 					"$(inherited)",
442 450
 					"@executable_path/../Frameworks",
443 451
 				);
444
-				PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.MongoView;
452
+				PRODUCT_BUNDLE_IDENTIFIER = space.vaccor.MongoView;
445 453
 				PRODUCT_NAME = "$(TARGET_NAME)";
446 454
 				SWIFT_VERSION = 5.0;
447 455
 			};

+ 20
- 1
MongoView/MongoController.swift View File

@@ -16,6 +16,13 @@ class MongoController {
16 16
     var group: EventLoopGroup!
17 17
     
18 18
     var client: MongoClient!
19
+    
20
+    var status: Status = .connecting {
21
+        didSet {
22
+            statusDidChange.forEach { $0(status) }
23
+        }
24
+    }
25
+    var statusDidChange = [(Status) -> Void]()
19 26
 
20 27
     init(connectionString: String) {
21 28
         self.connectionString = connectionString
@@ -31,7 +38,13 @@ class MongoController {
31 38
         
32 39
         group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
33 40
         
34
-        client = try! MongoClient(connectionString, using: group)
41
+        do {
42
+            client = try MongoClient(connectionString, using: group)
43
+            status = .success
44
+        } catch {
45
+            status = .failed
46
+            print("Failed to connect to Mongo: \(error)")
47
+        }
35 48
     }
36 49
     
37 50
     func db(for collection: DatabaseCollection) -> MongoDatabase {
@@ -43,3 +56,9 @@ class MongoController {
43 56
     }
44 57
 
45 58
 }
59
+
60
+extension MongoController {
61
+    enum Status {
62
+        case connecting, success, failed
63
+    }
64
+}

+ 78
- 0
MongoView/Windows/DatabaseWindowController.swift View File

@@ -10,6 +10,10 @@ import Cocoa
10 10
 
11 11
 class DatabaseWindowController: NSWindowController {
12 12
 
13
+    @IBOutlet weak var toolbar: NSToolbar!
14
+    
15
+    weak var statusView: WindowStatusView?
16
+    
13 17
     private var titleObservation: NSKeyValueObservation?
14 18
     
15 19
     var mongoController: MongoController!
@@ -28,6 +32,11 @@ class DatabaseWindowController: NSWindowController {
28 32
             mongoController = MongoController(connectionString: "mongodb://localhost:27017")
29 33
             mongoController.setup()
30 34
         }
35
+        mongoController.statusDidChange.append({ [weak self] (status) in
36
+            guard let self = self else { return }
37
+            self.updateStatusText(status)
38
+        })
39
+        self.updateStatusText(mongoController.status)
31 40
 
32 41
         databaseViewController = DatabaseViewController(mongoController: mongoController)
33 42
         contentViewController = databaseViewController
@@ -43,6 +52,7 @@ class DatabaseWindowController: NSWindowController {
43 52
         
44 53
         window!.tabbingMode = .preferred
45 54
         window!.tabbingIdentifier = mongoController.connectionString
55
+        window!.titleVisibility = .hidden
46 56
     }
47 57
     
48 58
     override func newWindowForTab(_ sender: Any?) {
@@ -52,5 +62,73 @@ class DatabaseWindowController: NSWindowController {
52 62
     private func updateWindowTitle() {
53 63
         window?.title = databaseViewController.title ?? "MongoView"
54 64
     }
65
+    
66
+    private func updateStatusText(_ status: MongoController.Status) {
67
+        guard let statusView = self.statusView else { return }
68
+        switch status {
69
+        case .connecting:
70
+            statusView.setText("Connecting...")
71
+        case .failed:
72
+            statusView.setText("Failed to connect")
73
+        case .success:
74
+            statusView.setText("Connected to \(self.mongoController.connectionString)")
75
+        }
76
+    }
55 77
 
56 78
 }
79
+
80
+extension NSToolbarItem.Identifier {
81
+    static let mongoStatus = NSToolbarItem.Identifier("MongoView.mongoStatus")
82
+    static let refresh = NSToolbarItem.Identifier("MongoView.refresh")
83
+}
84
+
85
+extension DatabaseWindowController: NSToolbarDelegate {
86
+    func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
87
+        return [
88
+            .space,
89
+            .flexibleSpace,
90
+            .mongoStatus,
91
+            .refresh,
92
+        ]
93
+    }
94
+    
95
+    func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
96
+        return [
97
+            .refresh,
98
+            .flexibleSpace,
99
+            .mongoStatus,
100
+            .flexibleSpace,
101
+        ]
102
+    }
103
+    
104
+    func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
105
+        if itemIdentifier == .mongoStatus {
106
+            return createMongoStatusToolbarItem()
107
+        } else if itemIdentifier == .refresh {
108
+            return createRefreshToolbarItem()
109
+        }
110
+        
111
+        return NSToolbarItem(itemIdentifier: itemIdentifier)
112
+    }
113
+    
114
+    func createMongoStatusToolbarItem() -> NSToolbarItem {
115
+        let item = NSToolbarItem(itemIdentifier: .mongoStatus)
116
+        item.label = "Status"
117
+        item.paletteLabel = "Status"
118
+        let statusView = WindowStatusView.create()
119
+        self.statusView = statusView
120
+        item.view = statusView
121
+        return item
122
+    }
123
+    
124
+    func createRefreshToolbarItem() -> NSToolbarItem {
125
+        let item = NSToolbarItem(itemIdentifier: .refresh)
126
+        item.label = "Refresh"
127
+        item.paletteLabel = "Refresh"
128
+        item.target = self
129
+        let button = NSButton(image: NSImage(named: NSImage.refreshTemplateName)!, target: nil, action: #selector(DatabaseViewController.refresh(_:)))
130
+        button.bezelStyle = .texturedRounded
131
+        item.view = button
132
+        return item
133
+    }
134
+}

+ 11
- 3
MongoView/Windows/DatabaseWindowController.xib View File

@@ -1,12 +1,13 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15702" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
3 3
     <dependencies>
4
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15702"/>
4
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/>
5 5
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6 6
     </dependencies>
7 7
     <objects>
8 8
         <customObject id="-2" userLabel="File's Owner" customClass="DatabaseWindowController" customModule="MongoView" customModuleProvider="target">
9 9
             <connections>
10
+                <outlet property="toolbar" destination="zlC-gF-itI" id="Blh-Q7-7Ie"/>
10 11
                 <outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
11 12
             </connections>
12 13
         </customObject>
@@ -19,8 +20,15 @@
19 20
             <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
20 21
             <view key="contentView" id="se5-gp-TjO">
21 22
                 <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
22
-                <autoresizingMask key="autoresizingMask"/>
23
+                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23 24
             </view>
25
+            <toolbar key="toolbar" implicitIdentifier="E8476463-3A21-4F21-99C1-EEBBCC89844B" displayMode="iconOnly" sizeMode="regular" id="zlC-gF-itI">
26
+                <allowedToolbarItems/>
27
+                <defaultToolbarItems/>
28
+                <connections>
29
+                    <outlet property="delegate" destination="-2" id="zRR-2c-mGv"/>
30
+                </connections>
31
+            </toolbar>
24 32
             <contentBorderThickness minY="22"/>
25 33
             <connections>
26 34
                 <outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>

+ 32
- 0
MongoView/Windows/WindowStatusView.swift View File

@@ -0,0 +1,32 @@
1
+//
2
+//  WindowStatusView.swift
3
+//  MongoView
4
+//
5
+//  Created by Shadowfacts on 4/1/20.
6
+//  Copyright © 2020 Shadowfacts. All rights reserved.
7
+//
8
+
9
+import Cocoa
10
+
11
+class WindowStatusView: NSView {
12
+    
13
+    @IBOutlet weak var button: NSButton!
14
+    
15
+    static func create() -> WindowStatusView {
16
+        let nib = NSNib(nibNamed: "WindowStatusView", bundle: .main)
17
+        var objects: NSArray? = NSArray()
18
+        nib?.instantiate(withOwner: nil, topLevelObjects: &objects)
19
+        return objects!.first(where: { $0 is WindowStatusView }) as! WindowStatusView
20
+    }
21
+    
22
+    override func awakeFromNib() {
23
+        super.awakeFromNib()
24
+        
25
+        (button.cell as! NSButtonCell).imageDimsWhenDisabled = false
26
+    }
27
+    
28
+    func setText(_ text: String) {
29
+        button.title = text
30
+    }
31
+
32
+}

+ 42
- 0
MongoView/Windows/WindowStatusView.xib View File

@@ -0,0 +1,42 @@
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"/>
9
+        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
10
+        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
11
+        <customView translatesAutoresizingMaskIntoConstraints="NO" id="c22-O7-iKe" customClass="WindowStatusView" customModule="MongoView" customModuleProvider="target">
12
+            <rect key="frame" x="0.0" y="0.0" width="500" height="22"/>
13
+            <subviews>
14
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rXx-fM-BhC">
15
+                    <rect key="frame" x="0.0" y="-1" width="500" height="23"/>
16
+                    <constraints>
17
+                        <constraint firstAttribute="width" constant="500" id="ScX-uS-BYM"/>
18
+                    </constraints>
19
+                    <buttonCell key="cell" type="roundTextured" title="Textured Rounded" bezelStyle="texturedRounded" image="NSAdvanced" imagePosition="trailing" alignment="left" lineBreakMode="truncatingTail" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="dLk-x4-UWx">
20
+                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
21
+                        <font key="font" metaFont="system"/>
22
+                    </buttonCell>
23
+                </button>
24
+            </subviews>
25
+            <constraints>
26
+                <constraint firstAttribute="bottom" secondItem="rXx-fM-BhC" secondAttribute="bottom" id="8WA-ZA-Q0D"/>
27
+                <constraint firstItem="rXx-fM-BhC" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="QSy-IQ-7qC"/>
28
+                <constraint firstAttribute="width" relation="lessThanOrEqual" constant="500" id="TUy-Ci-y94"/>
29
+                <constraint firstAttribute="trailing" secondItem="rXx-fM-BhC" secondAttribute="trailing" id="ksp-LZ-zjw"/>
30
+                <constraint firstItem="rXx-fM-BhC" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="owa-mM-nje"/>
31
+                <constraint firstAttribute="height" constant="22" id="qfB-JT-wOX"/>
32
+            </constraints>
33
+            <connections>
34
+                <outlet property="button" destination="rXx-fM-BhC" id="25d-1p-Awz"/>
35
+            </connections>
36
+            <point key="canvasLocation" x="140" y="154"/>
37
+        </customView>
38
+    </objects>
39
+    <resources>
40
+        <image name="NSAdvanced" width="32" height="32"/>
41
+    </resources>
42
+</document>

Loading…
Cancel
Save