From 93cf0b0d3af666f8603a0f6c71f1c2626a5028f2 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Mon, 14 May 2012 14:17:51 -0400 Subject: [PATCH 1/2] Copy and paste backend for cocoa --- cocoa/cocoa_darwin.go | 12 +++++++++++- cocoa/framework/gomacdraw/gmd.h | 5 ++++- cocoa/framework/gomacdraw/gmd.m | 14 ++++++++++++++ wde.go | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/cocoa/cocoa_darwin.go b/cocoa/cocoa_darwin.go index c90607d..fcd1bbd 100644 --- a/cocoa/cocoa_darwin.go +++ b/cocoa/cocoa_darwin.go @@ -42,10 +42,12 @@ func init() { } wde.BackendRun = Run wde.BackendStop = Stop + wde.BackendGetClipboardText = GetClipboardText + wde.BackendSetClipboardText = SetClipboardText + runtime.LockOSThread() C.initMacDraw() SetAppName("go") - } func SetAppName(name string) { @@ -161,6 +163,14 @@ func (w *Window) Close() (err error) { return } +func GetClipboardText() string { + return C.GoString(C.getClipboardText()) +} + +func SetClipboardText(text string) { + C.setClipboardText(C.CString(text)) +} + func Run() { C.NSAppRun() } diff --git a/cocoa/framework/gomacdraw/gmd.h b/cocoa/framework/gomacdraw/gmd.h index 7ae6b25..78f9091 100644 --- a/cocoa/framework/gomacdraw/gmd.h +++ b/cocoa/framework/gomacdraw/gmd.h @@ -60,4 +60,7 @@ void flushWindowScreen(GMDWindow gmdw); void setScreenPixel(GMDImage screen, int x, int y, int r, int g, int b, int a); void getScreenSize(GMDImage screen, int* width, int* height); -void setScreenData(GMDImage screen, void* data); \ No newline at end of file +void setScreenData(GMDImage screen, void* data); + +const char* getClipboardText(); +void setClipboardText(const char* text); diff --git a/cocoa/framework/gomacdraw/gmd.m b/cocoa/framework/gomacdraw/gmd.m index 55061d8..999fea8 100644 --- a/cocoa/framework/gomacdraw/gmd.m +++ b/cocoa/framework/gomacdraw/gmd.m @@ -157,3 +157,17 @@ void getScreenSize(GMDImage screen, int* width, int* height) { *height = size.height; [pool release]; } + +const char* getClipboardText() { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [pool release]; + return [[[NSPasteboard generalPasteboard] stringForType:NSPasteboardTypeString] UTF8String]; +} + +void setClipboardText(const char* text) { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard]; + [pasteBoard clearContents]; + [pasteBoard setString:[[NSString alloc] initWithUTF8String:text] forType:NSPasteboardTypeString]; + [pool release]; +} \ No newline at end of file diff --git a/wde.go b/wde.go index 8a43c40..628885f 100644 --- a/wde.go +++ b/wde.go @@ -103,3 +103,19 @@ func NewWindow(width, height int) (Window, error) { var BackendNewWindow = func(width, height int) (Window, error) { panic("no wde backend imported") } + +func GetClipboardText() string { + return BackendGetClipboardText() +} + +var BackendGetClipboardText = func() string { + panic("no wde backend imported") +} + +func SetClipboardText(text string) { + BackendSetClipboardText(text) +} + +var BackendSetClipboardText = func(text string) { + panic("no wde backend imported") +} From d218e3983cfaffcc0896716ecff33171b8ff04b0 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Wed, 16 May 2012 14:03:18 -0400 Subject: [PATCH 2/2] Setting shortcut Chords for cut, copy, and paste --- cocoa/cocoa_darwin.go | 5 +++++ keys.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/cocoa/cocoa_darwin.go b/cocoa/cocoa_darwin.go index fcd1bbd..b343846 100644 --- a/cocoa/cocoa_darwin.go +++ b/cocoa/cocoa_darwin.go @@ -48,6 +48,11 @@ func init() { runtime.LockOSThread() C.initMacDraw() SetAppName("go") + + // I'll uncomment these once the 'super' key glitch is fixed + // wde.PasteChord = "super+v" + // wde.CopyChord = "super+c" + // wde.CutChord = "super+x" } func SetAppName(name string) { diff --git a/keys.go b/keys.go index 897f1f6..76d0040 100644 --- a/keys.go +++ b/keys.go @@ -130,6 +130,10 @@ const ( KeyCapsLock = "caps" ) +var PasteChord = "control+v" +var CopyChord = "control+c" +var CutChord = "control+x" + var chordPrecedence = []string{ "super", "shift",