aboutsummaryrefslogtreecommitdiff
path: root/osx.m
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2005-05-01 12:53:41 +0000
committerSimon Tatham <anakin@pobox.com>2005-05-01 12:53:41 +0000
commit791940b043d500c096a56d57467b4b68ea31ce1f (patch)
treea8168dfaeb265abc278f9b9ff7897ecd0d911bb9 /osx.m
parente72931bfe27e7d7303a22717cce05721551f3e4a (diff)
downloadpuzzles-791940b043d500c096a56d57467b4b68ea31ce1f.zip
puzzles-791940b043d500c096a56d57467b4b68ea31ce1f.tar.gz
puzzles-791940b043d500c096a56d57467b4b68ea31ce1f.tar.bz2
puzzles-791940b043d500c096a56d57467b4b68ea31ce1f.tar.xz
Introduced a new function in every game which formats a game_state
as text. This is used by front ends to implement copy-to-clipboard. Currently the function does nothing (and is disabled) in every game except Solo, but it's a start. [originally from svn r5724]
Diffstat (limited to 'osx.m')
-rw-r--r--osx.m24
1 files changed, 24 insertions, 0 deletions
diff --git a/osx.m b/osx.m
index 1fd689f..28af613 100644
--- a/osx.m
+++ b/osx.m
@@ -571,6 +571,28 @@ struct frontend {
[self processButton:'r'&0x1F x:-1 y:-1];
}
+- (void)copy:(id)sender
+{
+ char *text;
+
+ if ((text = midend_text_format(me)) != NULL) {
+ NSPasteboard *pb = [NSPasteboard generalPasteboard];
+ NSArray *a = [NSArray arrayWithObject:NSStringPboardType];
+ [pb declareTypes:a owner:nil];
+ [pb setString:[NSString stringWithCString:text]
+ forType:NSStringPboardType];
+ } else
+ NSBeep();
+}
+
+- (BOOL)validateMenuItem:(NSMenuItem *)item
+{
+ if ([item action] == @selector(copy:))
+ return (ourgame->can_format_as_text ? YES : NO);
+ else
+ return [super validateMenuItem:item];
+}
+
- (void)clearTypeMenu
{
while ([typemenu numberOfItems] > 1)
@@ -1215,6 +1237,8 @@ int main(int argc, char **argv)
item = newitem(menu, "Undo", "z", NULL, @selector(undoMove:));
item = newitem(menu, "Redo", "S-z", NULL, @selector(redoMove:));
[menu addItem:[NSMenuItem separatorItem]];
+ item = newitem(menu, "Copy", "c", NULL, @selector(copy:));
+ [menu addItem:[NSMenuItem separatorItem]];
item = newitem(menu, "Close", "w", NULL, @selector(performClose:));
menu = newsubmenu([NSApp mainMenu], "Type");