X-Git-Url: http://www.entropy.ch/git/LeanCalc.git/blobdiff_plain/f5fbaceee4c5c117ef600df1362fa90333ed8bc9..c63394a796dd31e2e7ccdc85e2630629e90080c6:/Sources/MyDocument.m diff --git a/Sources/MyDocument.m b/Sources/MyDocument.m index 76f6e6c..514b3ed 100644 --- a/Sources/MyDocument.m +++ b/Sources/MyDocument.m @@ -34,15 +34,14 @@ - (void)awakeFromNib { - if (![self fileName]) { [arrayController add:self]; } - [arrayController setSelectionIndex:[calculations count] - 1]; } + - (IBAction)commit:(id)sender { if (![[sender stringValue] length]) return; @@ -57,27 +56,22 @@ - (BOOL)lastItemIsSelected { - id lastObject = [calculations lastObject]; id selectedObject = [[arrayController selectedObjects] objectAtIndex:0]; - return selectedObject == lastObject; } - (void)addItem { - Calculation *newcalc = [[[Calculation alloc] init] autorelease]; [arrayController addObject:newcalc]; int count = [calculations count]; id secondtolast = [calculations objectAtIndex:count - 2]; [secondtolast setValue:newcalc forKey:@"next"]; - } - (void)insertPrevious:(NSNumber *)sender { - int index = [sender intValue]; if ([calculations count] <= index) return; @@ -95,13 +89,37 @@ } +// enable copy: menu command only when a previous result is selected +- (BOOL)validateMenuItem:(NSMenuItem *)item { + if ([item action] != @selector(copy:)) return YES; + id selectedObject = [[arrayController selectedObjects] objectAtIndex:0]; + return selectedObject && ![self lastItemIsSelected] && ![selectedObject expressionIsEmpty]; +} + +/* +- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector { + NSLog(@"text view by selector %d", aSelector); + return NO; +} +*/ + + +- (IBAction)copy:(id)sender { + NSPasteboard *pboard = [NSPasteboard generalPasteboard]; + [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; + id selectedObject = [[arrayController selectedObjects] objectAtIndex:0]; + [pboard setString:[selectedObject result] forType:NSStringPboardType]; +} + - (NSString *)windowNibName { return @"MyDocument"; } -- (void)windowControllerDidLoadNib:(NSWindowController *) aController { +- (void)windowControllerDidLoadNib:(NSWindowController *)aController { + NSWindow *win = [aController window]; + [win performSelector:@selector(makeFirstResponder:) withObject:expressionField afterDelay:0.0]; [super windowControllerDidLoadNib:aController]; }