1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-25 18:30:21 +00:00

Fully wired in drag-and-drop for media insertion.

This commit is contained in:
Thomas Harte 2017-08-17 11:00:08 -04:00
parent f68565a33f
commit 378f231499
5 changed files with 40 additions and 3 deletions

View File

@ -165,7 +165,10 @@ class MachineDocument:
}
final func openGLView(_ view: CSOpenGLView, didReceiveFileAt URL: URL) {
// TODO: pass to machine.
let mediaSet = CSMediaSet(fileAt: URL)
if let mediaSet = mediaSet {
mediaSet.apply(to: self.machine)
}
}
// MARK: NSDocument overrides

View File

@ -12,6 +12,7 @@
@interface CSMachine(Target)
- (void)applyTarget:(StaticAnalyser::Target)target;
- (void)applyTarget:(const StaticAnalyser::Target &)target;
- (void)applyMedia:(const StaticAnalyser::Media &)media;
@end

View File

@ -139,7 +139,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
typeRecipient->set_typer_for_string([paste UTF8String]);
}
- (void)applyTarget:(StaticAnalyser::Target)target {
- (void)applyTarget:(const StaticAnalyser::Target &)target {
@synchronized(self) {
ConfigurationTarget::Machine *const configurationTarget =
dynamic_cast<ConfigurationTarget::Machine *>(self.machine);
@ -147,4 +147,12 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
}
}
- (void)applyMedia:(const StaticAnalyser::Media &)media {
@synchronized(self) {
ConfigurationTarget::Machine *const configurationTarget =
dynamic_cast<ConfigurationTarget::Machine *>(self.machine);
if(configurationTarget) configurationTarget->insert_media(media);
}
}
@end

View File

@ -22,3 +22,10 @@
- (void)applyToMachine:(CSMachine *)machine;
@end
@interface CSMediaSet : NSObject
- (instancetype)initWithFileAtURL:(NSURL *)url;
- (void)applyToMachine:(CSMachine *)machine;
@end

View File

@ -69,3 +69,21 @@
}
@end
@implementation CSMediaSet {
StaticAnalyser::Media _media;
}
- (instancetype)initWithFileAtURL:(NSURL *)url {
self = [super init];
if(self) {
_media = StaticAnalyser::GetMedia([url fileSystemRepresentation]);
}
return self;
}
- (void)applyToMachine:(CSMachine *)machine {
[machine applyMedia:_media];
}
@end