1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-15 14:27:29 +00:00

Makes an unsuccessful attempt to show the new machine dialogue as a sheet.

Also corrects the 'open' case versus recent changes.
This commit is contained in:
Thomas Harte
2018-04-02 23:31:36 -04:00
parent 69f520428d
commit cde2faeda6
4 changed files with 96 additions and 42 deletions

View File

@@ -1,10 +1,12 @@
<?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="11201" systemVersion="16A323" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14109"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="Vic20Document" customModule="Clock_Signal" customModuleProvider="target"> <customObject id="-2" userLabel="File's Owner" customClass="MachineDocument" customModule="Clock_Signal" customModuleProvider="target">
<connections> <connections>
<outlet property="openGLView" destination="DEG-fq-cjd" id="Gxs-2u-n7B"/> <outlet property="openGLView" destination="DEG-fq-cjd" id="Gxs-2u-n7B"/>
<outlet property="window" destination="xOd-HO-29H" id="JIz-fz-R2o"/> <outlet property="window" destination="xOd-HO-29H" id="JIz-fz-R2o"/>

View File

@@ -9,20 +9,20 @@
import Cocoa import Cocoa
class DocumentController: NSDocumentController { class DocumentController: NSDocumentController {
override func newDocument(_ sender: Any?) { // override func newDocument(_ sender: Any?) {
// Show the new document window. // // Show the new document window.
Bundle.main.loadNibNamed(NSNib.Name(rawValue: "MachinePicker"), owner: self, topLevelObjects: nil) // Bundle.main.loadNibNamed(NSNib.Name(rawValue: "MachinePicker"), owner: self, topLevelObjects: nil)
} // }
//
@IBOutlet var machinePicker: MachinePicker? // @IBOutlet var machinePicker: MachinePicker?
@IBAction func createMachine(_ sender: NSButton?) { // @IBAction func createMachine(_ sender: NSButton?) {
let machine = machinePicker!.selectedMachine() // let machine = machinePicker!.selectedMachine()
let document: MachineDocument = try! openUntitledDocumentAndDisplay(true) as! MachineDocument // let document: MachineDocument = try! openUntitledDocumentAndDisplay(true) as! MachineDocument
document.configureAs(machine) // document.configureAs(machine)
sender?.window?.close() // sender?.window?.close()
} // }
//
@IBAction func cancelCreateMachine(_ sender: NSButton?) { // @IBAction func cancelCreateMachine(_ sender: NSButton?) {
sender?.window?.close() // sender?.window?.close()
} // }
} }

View File

@@ -28,6 +28,7 @@ class MachineDocument:
return nil return nil
} }
} }
var optionsPanelNibName: String?
func aspectRatio() -> NSSize { func aspectRatio() -> NSSize {
return NSSize(width: 4.0, height: 3.0) return NSSize(width: 4.0, height: 3.0)
@@ -50,6 +51,14 @@ class MachineDocument:
super.windowControllerDidLoadNib(aController) super.windowControllerDidLoadNib(aController)
aController.window?.contentAspectRatio = self.aspectRatio() aController.window?.contentAspectRatio = self.aspectRatio()
setupMachineOutput() setupMachineOutput()
// If there's no machine but the NIB has loaded, show the new machine dialogue
if self.machine == nil {
Bundle.main.loadNibNamed(NSNib.Name(rawValue: "MachinePicker"), owner: self, topLevelObjects: nil)
aController.window?.beginSheet(self.machinePickerPanel!, completionHandler: { (response) in
Swift.print("\(response)")
})
}
} }
fileprivate func setupMachineOutput() { fileprivate func setupMachineOutput() {
@@ -60,6 +69,14 @@ class MachineDocument:
machine.setView(openGLView, aspectRatio: Float(aspectRatio.width / aspectRatio.height)) machine.setView(openGLView, aspectRatio: Float(aspectRatio.width / aspectRatio.height))
}) })
// attach an options panel if one is available
if let optionsPanelNibName = self.optionsPanelNibName {
Bundle.main.loadNibNamed(NSNib.Name(rawValue: optionsPanelNibName), owner: self, topLevelObjects: nil)
self.optionsPanel.machine = machine
self.optionsPanel?.establishStoredOptions()
showOptions(self)
}
machine.delegate = self machine.delegate = self
self.bestEffortUpdater = CSBestEffortUpdater() self.bestEffortUpdater = CSBestEffortUpdater()
@@ -121,14 +138,8 @@ class MachineDocument:
func configureAs(_ analysis: CSStaticAnalyser) { func configureAs(_ analysis: CSStaticAnalyser) {
if let machine = CSMachine(analyser: analysis) { if let machine = CSMachine(analyser: analysis) {
self.machine = machine self.machine = machine
self.optionsPanelNibName = analysis.optionsPanelNibName
setupMachineOutput() setupMachineOutput()
if let optionsPanelNibName = analysis.optionsPanelNibName {
Bundle.main.loadNibNamed(NSNib.Name(rawValue: optionsPanelNibName), owner: self, topLevelObjects: nil)
self.optionsPanel.machine = self.machine
self.optionsPanel?.establishStoredOptions()
showOptions(self)
}
} }
} }
@@ -141,6 +152,11 @@ class MachineDocument:
} }
} }
convenience init(type typeName: String) throws {
self.init()
self.fileType = typeName
}
// MARK: the pasteboard // MARK: the pasteboard
func paste(_ sender: AnyObject!) { func paste(_ sender: AnyObject!) {
let pasteboard = NSPasteboard.general let pasteboard = NSPasteboard.general
@@ -193,21 +209,42 @@ class MachineDocument:
// MARK: Input management // MARK: Input management
func windowDidResignKey(_ notification: Notification) { func windowDidResignKey(_ notification: Notification) {
// self.machine.clearAllKeys() if let machine = self.machine {
machine.clearAllKeys()
}
} }
func keyDown(_ event: NSEvent) { func keyDown(_ event: NSEvent) {
self.machine.setKey(event.keyCode, characters: event.characters, isPressed: true) if let machine = self.machine {
machine.setKey(event.keyCode, characters: event.characters, isPressed: true)
}
} }
func keyUp(_ event: NSEvent) { func keyUp(_ event: NSEvent) {
self.machine.setKey(event.keyCode, characters: event.characters, isPressed: false) if let machine = self.machine {
machine.setKey(event.keyCode, characters: event.characters, isPressed: false)
}
} }
func flagsChanged(_ newModifiers: NSEvent) { func flagsChanged(_ newModifiers: NSEvent) {
self.machine.setKey(VK_Shift, characters: nil, isPressed: newModifiers.modifierFlags.contains(.shift)) if let machine = self.machine {
self.machine.setKey(VK_Control, characters: nil, isPressed: newModifiers.modifierFlags.contains(.control)) machine.setKey(VK_Shift, characters: nil, isPressed: newModifiers.modifierFlags.contains(.shift))
self.machine.setKey(VK_Command, characters: nil, isPressed: newModifiers.modifierFlags.contains(.command)) machine.setKey(VK_Control, characters: nil, isPressed: newModifiers.modifierFlags.contains(.control))
self.machine.setKey(VK_Option, characters: nil, isPressed: newModifiers.modifierFlags.contains(.option)) machine.setKey(VK_Command, characters: nil, isPressed: newModifiers.modifierFlags.contains(.command))
machine.setKey(VK_Option, characters: nil, isPressed: newModifiers.modifierFlags.contains(.option))
}
}
// MARK: New machine creation
@IBOutlet var machinePicker: MachinePicker?
@IBOutlet var machinePickerPanel: NSPanel?
@IBAction func createMachine(_ sender: NSButton?) {
self.configureAs(machinePicker!.selectedMachine())
machinePicker = nil
sender?.window?.close()
}
@IBAction func cancelCreateMachine(_ sender: NSButton?) {
close()
} }
} }

View File

@@ -6,15 +6,16 @@
<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="DocumentController" customModule="Clock_Signal" customModuleProvider="target"> <customObject id="-2" userLabel="File's Owner" customClass="MachineDocument" customModule="Clock_Signal" customModuleProvider="target">
<connections> <connections>
<outlet property="machinePicker" destination="192-Eb-Rpg" id="7p2-GL-AVt"/> <outlet property="machinePicker" destination="192-Eb-Rpg" id="7p2-GL-AVt"/>
<outlet property="machinePickerPanel" destination="QvC-M9-y7g" id="PMF-8q-M3s"/>
</connections> </connections>
</customObject> </customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/> <customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g"> <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" titleVisibility="hidden" id="QvC-M9-y7g" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> <windowStyleMask key="styleMask" documentModal="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="562" height="203"/> <rect key="contentRect" x="196" y="240" width="562" height="203"/>
<rect key="screenRect" x="0.0" y="0.0" width="1366" height="768"/> <rect key="screenRect" x="0.0" y="0.0" width="1366" height="768"/>
@@ -62,7 +63,7 @@
<rect key="frame" x="10" y="33" width="516" height="92"/> <rect key="frame" x="10" y="33" width="516" height="92"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="00d-sg-Krh"> <popUpButton verticalHuggingPriority="750" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="00d-sg-Krh">
<rect key="frame" x="54" y="65" width="94" height="26"/> <rect key="frame" x="54" y="65" width="94" height="26"/>
<popUpButtonCell key="cell" type="push" title="CPC6128" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" tag="6128" imageScaling="proportionallyDown" inset="2" selectedItem="klh-ZE-Agp" id="hVJ-h6-iea"> <popUpButtonCell key="cell" type="push" title="CPC6128" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" tag="6128" imageScaling="proportionallyDown" inset="2" selectedItem="klh-ZE-Agp" id="hVJ-h6-iea">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
@@ -76,7 +77,7 @@
</menu> </menu>
</popUpButtonCell> </popUpButtonCell>
</popUpButton> </popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="q9q-sl-J0q"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="q9q-sl-J0q">
<rect key="frame" x="8" y="70" width="42" height="17"/> <rect key="frame" x="8" y="70" width="42" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Model" id="Cw3-q5-1bC"> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Model" id="Cw3-q5-1bC">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@@ -84,14 +85,28 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell> </textFieldCell>
</textField> </textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9cx-CH-kPM">
<rect key="frame" x="54" y="65" width="94" height="26"/>
<popUpButtonCell key="cell" type="push" title="CPC6128" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" tag="6128" imageScaling="proportionallyDown" inset="2" selectedItem="hwp-gt-NhT" id="lIW-5k-ov2">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="xIy-eq-osh">
<items>
<menuItem title="CPC464" tag="464" id="R8h-sQ-JeY"/>
<menuItem title="CPC664" tag="664" id="iUo-zD-y6x"/>
<menuItem title="CPC6128" state="on" tag="6128" id="hwp-gt-NhT"/>
</items>
</menu>
</popUpButtonCell>
</popUpButton>
</subviews> </subviews>
<constraints> <constraints>
<constraint firstItem="00d-sg-Krh" firstAttribute="top" secondItem="5zS-Nj-Ynx" secondAttribute="top" constant="3" id="KHk-pr-avq"/> <constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="9cx-CH-kPM" secondAttribute="bottom" constant="17" id="0ut-dE-cZI"/>
<constraint firstItem="00d-sg-Krh" firstAttribute="leading" secondItem="q9q-sl-J0q" secondAttribute="trailing" constant="8" id="Sr4-Xg-lgt"/> <constraint firstItem="9cx-CH-kPM" firstAttribute="leading" secondItem="q9q-sl-J0q" secondAttribute="trailing" constant="8" id="Fum-4i-8f0"/>
<constraint firstItem="q9q-sl-J0q" firstAttribute="leading" secondItem="5zS-Nj-Ynx" secondAttribute="leading" constant="10" id="Wof-5h-gfD"/> <constraint firstItem="q9q-sl-J0q" firstAttribute="leading" secondItem="5zS-Nj-Ynx" secondAttribute="leading" constant="10" id="Wof-5h-gfD"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="00d-sg-Krh" secondAttribute="bottom" constant="17" id="t3s-ba-0dx"/>
<constraint firstItem="q9q-sl-J0q" firstAttribute="centerY" secondItem="00d-sg-Krh" secondAttribute="centerY" id="vA8-IA-Uwf"/> <constraint firstItem="q9q-sl-J0q" firstAttribute="centerY" secondItem="00d-sg-Krh" secondAttribute="centerY" id="vA8-IA-Uwf"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="00d-sg-Krh" secondAttribute="trailing" constant="17" id="y6y-bJ-ECA"/> <constraint firstItem="9cx-CH-kPM" firstAttribute="top" secondItem="5zS-Nj-Ynx" secondAttribute="top" constant="3" id="wuW-it-Nfe"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="9cx-CH-kPM" secondAttribute="trailing" constant="17" id="yrI-ve-pP2"/>
</constraints> </constraints>
</view> </view>
</tabViewItem> </tabViewItem>