Permalink
Browse files

#38 Closed - completed work on Paste

  • Loading branch information...
0xe1f committed Sep 26, 2016
1 parent 9461dae commit c77abc89a5976c79251939cd3cc1f660a197b62d
Showing with 48 additions and 9 deletions.
  1. +46 −8 Controllers/CMEmulatorController.m
  2. +2 −1 Src/Cocoa/CMCocoaInput.m
@@ -162,12 +162,17 @@ - (void)addRecentMediaItemWithURL:(NSURL *)url
- (void)clearRecentMediaItemsInMenu:(NSMenuItem *)menuItem;
- (void) rebuildRecentItemsMenus;
- (void) syncRecentDocuments;
- (void) pasteFromPasteBoard;
- (BOOL)diskSizeValid:(int)size;
- (NSString *) generateTimestampedFilenameAtPath:(NSString *)parentPath
template:(NSString *)template
extension:(NSString *)ext;
- (void) pasteAlertDidEnd:(NSAlert *) alert
returnCode:(NSInteger) returnCode
contextInfo:(void *) contextInfo;
@end
@implementation CMEmulatorController
@@ -1052,6 +1057,18 @@ - (CMMsxDisplayView *)screen
#pragma mark - Private methods
- (void) pasteFromPasteBoard
{
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
NSString *text = [pasteBoard stringForType:NSPasteboardTypeString];
NSString *runningMachineId = [self runningMachineConfiguration];
NSString *layoutName = [CMMSXKeyboard layoutNameOfMachineWithIdentifier:runningMachineId];
[[self input] pasteText:text
layoutName:layoutName];
}
- (void)zoomWindowBy:(CGFloat)factor
{
[self setScreenSize:NSMakeSize(WIDTH_DEFAULT * factor, HEIGHT_DEFAULT * factor)
@@ -1755,15 +1772,24 @@ - (BOOL)toggleEjectCassetteMenuItemStatus:(NSMenuItem*)menuItem
return NO;
}
- (void)pasteText:(id)sender
- (void) pasteText:(id) sender
{
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
NSString *text = [pasteBoard stringForType:NSPasteboardTypeString];
NSString *runningMachineId = [self runningMachineConfiguration];
NSString *layoutName = [CMMSXKeyboard layoutNameOfMachineWithIdentifier:runningMachineId];
[[self input] pasteText:text layoutName:layoutName];
if (CMGetIntPref(@"emulationSpeedPercentage") != 100) {
NSAlert *alert = [NSAlert alertWithMessageText:CMLoc(@"Due to timing restrictions, Paste is only available when emulating at default speed.", @"")
defaultButton:CMLoc(@"Set to Default", @"Alert dialog button")
alternateButton:CMLoc(@"Cancel", "Alert dialog button")
otherButton:nil
informativeTextWithFormat:@""];
[alert beginSheetModalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(pasteAlertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
return;
}
[self pasteFromPasteBoard];
}
- (void)windowKeyDidChange:(BOOL)isKey
@@ -3047,6 +3073,18 @@ - (void)cassetteRepositionedTo:(NSInteger)position
emulatorResume();
}
#pragma mark - NSAlert
- (void) pasteAlertDidEnd:(NSAlert *) alert
returnCode:(NSInteger) returnCode
contextInfo:(void *) contextInfo
{
if (returnCode == NSAlertDefaultReturn) {
CMSetIntPref(@"emulationSpeedPercentage", 100);
[self pasteFromPasteBoard];
}
}
#pragma mark - NSUserInterfaceValidation
- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
View
@@ -218,7 +218,8 @@ - (BOOL) pasteText:(NSString *) text
return NO; // Invalid key layout
}
// FIXME: stop paste if in process
[self stopPasting];
#ifdef DEBUG
NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate];
#endif

0 comments on commit c77abc8

Please sign in to comment.