Start adding toolbar

This commit is contained in:
Shadowfacts 2020-04-01 19:37:00 -04:00
parent c4425e50e3
commit 3e46c06ba8
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
6 changed files with 197 additions and 10 deletions

View File

@ -40,6 +40,8 @@
D63CDF4123C839010012D658 /* QueryViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D63CDF3F23C839010012D658 /* QueryViewController.xib */; }; D63CDF4123C839010012D658 /* QueryViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D63CDF3F23C839010012D658 /* QueryViewController.xib */; };
D63CDF4423C970C50012D658 /* DatabaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63CDF4223C970C50012D658 /* DatabaseViewController.swift */; }; D63CDF4423C970C50012D658 /* DatabaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63CDF4223C970C50012D658 /* DatabaseViewController.swift */; };
D63CDF4523C970C50012D658 /* DatabaseViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D63CDF4323C970C50012D658 /* DatabaseViewController.xib */; }; D63CDF4523C970C50012D658 /* DatabaseViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D63CDF4323C970C50012D658 /* DatabaseViewController.xib */; };
D6A7D096243541A400B46857 /* WindowStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6A7D095243541A400B46857 /* WindowStatusView.swift */; };
D6A7D09A243546B500B46857 /* WindowStatusView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6A7D099243546B500B46857 /* WindowStatusView.xib */; };
D6D4665323CB730C00F13B1B /* MongoEvaluator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D4665223CB730C00F13B1B /* MongoEvaluator.swift */; }; D6D4665323CB730C00F13B1B /* MongoEvaluator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D4665223CB730C00F13B1B /* MongoEvaluator.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -93,6 +95,8 @@
D63CDF3F23C839010012D658 /* QueryViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = QueryViewController.xib; sourceTree = "<group>"; }; D63CDF3F23C839010012D658 /* QueryViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = QueryViewController.xib; sourceTree = "<group>"; };
D63CDF4223C970C50012D658 /* DatabaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseViewController.swift; sourceTree = "<group>"; }; D63CDF4223C970C50012D658 /* DatabaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseViewController.swift; sourceTree = "<group>"; };
D63CDF4323C970C50012D658 /* DatabaseViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DatabaseViewController.xib; sourceTree = "<group>"; }; D63CDF4323C970C50012D658 /* DatabaseViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DatabaseViewController.xib; sourceTree = "<group>"; };
D6A7D095243541A400B46857 /* WindowStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowStatusView.swift; sourceTree = "<group>"; };
D6A7D099243546B500B46857 /* WindowStatusView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = WindowStatusView.xib; sourceTree = "<group>"; };
D6D4665223CB730C00F13B1B /* MongoEvaluator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MongoEvaluator.swift; sourceTree = "<group>"; }; D6D4665223CB730C00F13B1B /* MongoEvaluator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MongoEvaluator.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -123,6 +127,8 @@
D60C863823CA2DD100C9DB8E /* ServerConnectWindowController.xib */, D60C863823CA2DD100C9DB8E /* ServerConnectWindowController.xib */,
D63CDF3A23C838470012D658 /* DatabaseWindowController.swift */, D63CDF3A23C838470012D658 /* DatabaseWindowController.swift */,
D63CDF3B23C838470012D658 /* DatabaseWindowController.xib */, D63CDF3B23C838470012D658 /* DatabaseWindowController.xib */,
D6A7D095243541A400B46857 /* WindowStatusView.swift */,
D6A7D099243546B500B46857 /* WindowStatusView.xib */,
); );
path = Windows; path = Windows;
sourceTree = "<group>"; sourceTree = "<group>";
@ -253,6 +259,7 @@
D63CDEC023C837DD0012D658 /* Assets.xcassets in Resources */, D63CDEC023C837DD0012D658 /* Assets.xcassets in Resources */,
D60C863A23CA2DD100C9DB8E /* ServerConnectWindowController.xib in Resources */, D60C863A23CA2DD100C9DB8E /* ServerConnectWindowController.xib in Resources */,
D63CDF4523C970C50012D658 /* DatabaseViewController.xib in Resources */, D63CDF4523C970C50012D658 /* DatabaseViewController.xib in Resources */,
D6A7D09A243546B500B46857 /* WindowStatusView.xib in Resources */,
D63CDF3D23C838470012D658 /* DatabaseWindowController.xib in Resources */, D63CDF3D23C838470012D658 /* DatabaseWindowController.xib in Resources */,
D63CDEC323C837DD0012D658 /* MainMenu.xib in Resources */, D63CDEC323C837DD0012D658 /* MainMenu.xib in Resources */,
D63CDF4123C839010012D658 /* QueryViewController.xib in Resources */, D63CDF4123C839010012D658 /* QueryViewController.xib in Resources */,
@ -274,6 +281,7 @@
D60C863F23CA2E2100C9DB8E /* ServerConnectViewController.swift in Sources */, D60C863F23CA2E2100C9DB8E /* ServerConnectViewController.swift in Sources */,
D63CDF4423C970C50012D658 /* DatabaseViewController.swift in Sources */, D63CDF4423C970C50012D658 /* DatabaseViewController.swift in Sources */,
D63CDF3C23C838470012D658 /* DatabaseWindowController.swift in Sources */, D63CDF3C23C838470012D658 /* DatabaseWindowController.swift in Sources */,
D6A7D096243541A400B46857 /* WindowStatusView.swift in Sources */,
D63CDF4023C839010012D658 /* QueryViewController.swift in Sources */, D63CDF4023C839010012D658 /* QueryViewController.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -412,15 +420,15 @@
CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements; CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = HGYVAQA9FW; DEVELOPMENT_TEAM = V4WK9KR9U2;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = MongoView/Info.plist; INFOPLIST_FILE = MongoView/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.MongoView; PRODUCT_BUNDLE_IDENTIFIER = space.vaccor.MongoView;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
}; };
@ -433,15 +441,15 @@
CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements; CODE_SIGN_ENTITLEMENTS = MongoView/MongoView.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = HGYVAQA9FW; DEVELOPMENT_TEAM = V4WK9KR9U2;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = MongoView/Info.plist; INFOPLIST_FILE = MongoView/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.MongoView; PRODUCT_BUNDLE_IDENTIFIER = space.vaccor.MongoView;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
}; };

View File

@ -16,6 +16,13 @@ class MongoController {
var group: EventLoopGroup! var group: EventLoopGroup!
var client: MongoClient! var client: MongoClient!
var status: Status = .connecting {
didSet {
statusDidChange.forEach { $0(status) }
}
}
var statusDidChange = [(Status) -> Void]()
init(connectionString: String) { init(connectionString: String) {
self.connectionString = connectionString self.connectionString = connectionString
@ -31,7 +38,13 @@ class MongoController {
group = MultiThreadedEventLoopGroup(numberOfThreads: 1) group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
client = try! MongoClient(connectionString, using: group) do {
client = try MongoClient(connectionString, using: group)
status = .success
} catch {
status = .failed
print("Failed to connect to Mongo: \(error)")
}
} }
func db(for collection: DatabaseCollection) -> MongoDatabase { func db(for collection: DatabaseCollection) -> MongoDatabase {
@ -43,3 +56,9 @@ class MongoController {
} }
} }
extension MongoController {
enum Status {
case connecting, success, failed
}
}

View File

@ -10,6 +10,10 @@ import Cocoa
class DatabaseWindowController: NSWindowController { class DatabaseWindowController: NSWindowController {
@IBOutlet weak var toolbar: NSToolbar!
weak var statusView: WindowStatusView?
private var titleObservation: NSKeyValueObservation? private var titleObservation: NSKeyValueObservation?
var mongoController: MongoController! var mongoController: MongoController!
@ -28,6 +32,11 @@ class DatabaseWindowController: NSWindowController {
mongoController = MongoController(connectionString: "mongodb://localhost:27017") mongoController = MongoController(connectionString: "mongodb://localhost:27017")
mongoController.setup() mongoController.setup()
} }
mongoController.statusDidChange.append({ [weak self] (status) in
guard let self = self else { return }
self.updateStatusText(status)
})
self.updateStatusText(mongoController.status)
databaseViewController = DatabaseViewController(mongoController: mongoController) databaseViewController = DatabaseViewController(mongoController: mongoController)
contentViewController = databaseViewController contentViewController = databaseViewController
@ -43,6 +52,7 @@ class DatabaseWindowController: NSWindowController {
window!.tabbingMode = .preferred window!.tabbingMode = .preferred
window!.tabbingIdentifier = mongoController.connectionString window!.tabbingIdentifier = mongoController.connectionString
window!.titleVisibility = .hidden
} }
override func newWindowForTab(_ sender: Any?) { override func newWindowForTab(_ sender: Any?) {
@ -52,5 +62,73 @@ class DatabaseWindowController: NSWindowController {
private func updateWindowTitle() { private func updateWindowTitle() {
window?.title = databaseViewController.title ?? "MongoView" window?.title = databaseViewController.title ?? "MongoView"
} }
private func updateStatusText(_ status: MongoController.Status) {
guard let statusView = self.statusView else { return }
switch status {
case .connecting:
statusView.setText("Connecting...")
case .failed:
statusView.setText("Failed to connect")
case .success:
statusView.setText("Connected to \(self.mongoController.connectionString)")
}
}
} }
extension NSToolbarItem.Identifier {
static let mongoStatus = NSToolbarItem.Identifier("MongoView.mongoStatus")
static let refresh = NSToolbarItem.Identifier("MongoView.refresh")
}
extension DatabaseWindowController: NSToolbarDelegate {
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [
.space,
.flexibleSpace,
.mongoStatus,
.refresh,
]
}
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [
.refresh,
.flexibleSpace,
.mongoStatus,
.flexibleSpace,
]
}
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
if itemIdentifier == .mongoStatus {
return createMongoStatusToolbarItem()
} else if itemIdentifier == .refresh {
return createRefreshToolbarItem()
}
return NSToolbarItem(itemIdentifier: itemIdentifier)
}
func createMongoStatusToolbarItem() -> NSToolbarItem {
let item = NSToolbarItem(itemIdentifier: .mongoStatus)
item.label = "Status"
item.paletteLabel = "Status"
let statusView = WindowStatusView.create()
self.statusView = statusView
item.view = statusView
return item
}
func createRefreshToolbarItem() -> NSToolbarItem {
let item = NSToolbarItem(itemIdentifier: .refresh)
item.label = "Refresh"
item.paletteLabel = "Refresh"
item.target = self
let button = NSButton(image: NSImage(named: NSImage.refreshTemplateName)!, target: nil, action: #selector(DatabaseViewController.refresh(_:)))
button.bezelStyle = .texturedRounded
item.view = button
return item
}
}

View File

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

View File

@ -0,0 +1,32 @@
//
// WindowStatusView.swift
// MongoView
//
// Created by Shadowfacts on 4/1/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import Cocoa
class WindowStatusView: NSView {
@IBOutlet weak var button: NSButton!
static func create() -> WindowStatusView {
let nib = NSNib(nibNamed: "WindowStatusView", bundle: .main)
var objects: NSArray? = NSArray()
nib?.instantiate(withOwner: nil, topLevelObjects: &objects)
return objects!.first(where: { $0 is WindowStatusView }) as! WindowStatusView
}
override func awakeFromNib() {
super.awakeFromNib()
(button.cell as! NSButtonCell).imageDimsWhenDisabled = false
}
func setText(_ text: String) {
button.title = text
}
}

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner"/>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="c22-O7-iKe" customClass="WindowStatusView" customModule="MongoView" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="500" height="22"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rXx-fM-BhC">
<rect key="frame" x="0.0" y="-1" width="500" height="23"/>
<constraints>
<constraint firstAttribute="width" constant="500" id="ScX-uS-BYM"/>
</constraints>
<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">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="rXx-fM-BhC" secondAttribute="bottom" id="8WA-ZA-Q0D"/>
<constraint firstItem="rXx-fM-BhC" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="QSy-IQ-7qC"/>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="500" id="TUy-Ci-y94"/>
<constraint firstAttribute="trailing" secondItem="rXx-fM-BhC" secondAttribute="trailing" id="ksp-LZ-zjw"/>
<constraint firstItem="rXx-fM-BhC" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="owa-mM-nje"/>
<constraint firstAttribute="height" constant="22" id="qfB-JT-wOX"/>
</constraints>
<connections>
<outlet property="button" destination="rXx-fM-BhC" id="25d-1p-Awz"/>
</connections>
<point key="canvasLocation" x="140" y="154"/>
</customView>
</objects>
<resources>
<image name="NSAdvanced" width="32" height="32"/>
</resources>
</document>