1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Attempts to support insertion of states into existing windows.

This commit is contained in:
Thomas Harte 2021-04-30 21:37:41 -04:00
parent c906dc3c0a
commit 4758bc8615
7 changed files with 48 additions and 5 deletions

View File

@ -137,6 +137,9 @@ class MachineDocument:
func configureAs(_ analysis: CSStaticAnalyser) {
self.machineDescription = analysis
actionLock.lock()
drawLock.lock()
let missingROMs = NSMutableArray()
if let machine = CSMachine(analyser: analysis, missingROMs: missingROMs) {
self.machine = machine
@ -147,9 +150,11 @@ class MachineDocument:
// Store the selected machine and list of missing ROMs, and
// show the missing ROMs dialogue.
self.missingROMs = missingROMs.map({$0 as! CSMissingROM})
requestRoms()
}
actionLock.unlock()
drawLock.unlock()
}
enum InteractionMode {
@ -280,8 +285,7 @@ class MachineDocument:
/// Delegate message to receive drag and drop files.
final func scanTargetView(_ view: CSScanTargetView, didReceiveFileAt URL: URL) {
let mediaSet = CSMediaSet(fileAt: URL)
mediaSet.apply(to: self.machine)
insertFile(URL)
}
/// Action for the insert menu command; displays an NSOpenPanel and then segues into the same process
@ -292,13 +296,30 @@ class MachineDocument:
openPanel.beginSheetModal(for: self.windowControllers[0].window!) { (response) in
if response == .OK {
for url in openPanel.urls {
let mediaSet = CSMediaSet(fileAt: url)
mediaSet.apply(to: self.machine)
self.insertFile(url)
}
}
}
}
private func insertFile(_ URL: URL) {
// Try to insert media.
let mediaSet = CSMediaSet(fileAt: URL)
if !mediaSet.empty {
mediaSet.apply(to: self.machine)
return
}
// Failing that see whether a new machine is required.
// TODO.
if let newMachine = CSStaticAnalyser(fileAt: URL) {
machine?.stop()
self.interactionMode = .notStarted
self.scanTargetView.willChangeScanTargetOwner()
configureAs(newMachine)
}
}
// MARK: - Input Management.
/// Upon a resign key, immediately releases all ongoing input mechanisms any currently pressed keys,

View File

@ -114,6 +114,8 @@ typedef int Kilobytes;
- (instancetype)initWithFileAtURL:(NSURL *)url;
- (void)applyToMachine:(CSMachine *)machine;
@property(nonatomic, readonly) BOOL empty;
@end
NS_ASSUME_NONNULL_END

View File

@ -309,4 +309,8 @@ static Analyser::Static::ZX8081::Target::MemoryModel ZX8081MemoryModelFromSize(K
[machine applyMedia:_media];
}
- (BOOL)empty {
return _media.empty();
}
@end

View File

@ -22,4 +22,6 @@
- (nonnull NSBitmapImageRep *)imageRepresentation;
- (void)willChangeOwner;
@end

View File

@ -1143,6 +1143,10 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
return &_scanTarget;
}
- (void)willChangeOwner {
_scanTarget.ScanTarget::will_change_owner();
}
- (NSBitmapImageRep *)imageRepresentation {
// Create an NSBitmapRep as somewhere to copy pixel data to.
NSBitmapImageRep *const result =

View File

@ -162,4 +162,10 @@
*/
@property(nonatomic, readonly, nonnull) CSScanTarget *scanTarget;
/*!
Indicates that the enclosed scan target is about to be handed off to a new owner;
exactly identical to calling scanTarget.will_change_owner().
*/
- (void)willChangeScanTargetOwner;
@end

View File

@ -129,6 +129,10 @@ static CVReturn DisplayLinkCallback(__unused CVDisplayLinkRef displayLink, const
return _scanTarget;
}
- (void)willChangeScanTargetOwner {
[_scanTarget willChangeOwner];
}
- (void)updateBacking {
[_scanTarget updateFrameBuffer];
}