X-Git-Url: http://www.entropy.ch/git/LeanCalc.git/blobdiff_plain/3dfd487304453e1e5546a01add449fdc45de3454..ffa749385a50695ec814776fa667d9f1f267b47c:/Sources/MyDocument.m diff --git a/Sources/MyDocument.m b/Sources/MyDocument.m index 519ffe0..a273168 100644 --- a/Sources/MyDocument.m +++ b/Sources/MyDocument.m @@ -59,27 +59,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; @@ -97,6 +92,23 @@ } +// 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]; +} + + +- (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";