From a854d396ffca2f089ca5c6f4c58b0dab7e995cd1 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 7 Dec 2019 15:22:28 +0300 Subject: [PATCH] clipboard: fix mutability on macOS and Windows --- vlib/clipboard/clipboard.v | 2 +- vlib/clipboard/clipboard_darwin.v | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/vlib/clipboard/clipboard.v b/vlib/clipboard/clipboard.v index 3d7ed991ac..95f3f4cf0a 100644 --- a/vlib/clipboard/clipboard.v +++ b/vlib/clipboard/clipboard.v @@ -18,7 +18,7 @@ pub fn (cb mut Clipboard) paste() string { // clear the clipboard pub fn (cb mut Clipboard) clear_all() { cb.clear() -} +} // destroy the clipboard pub fn (cb mut Clipboard) destroy() { diff --git a/vlib/clipboard/clipboard_darwin.v b/vlib/clipboard/clipboard_darwin.v index 7fc75d510f..64b2448c61 100644 --- a/vlib/clipboard/clipboard_darwin.v +++ b/vlib/clipboard/clipboard_darwin.v @@ -8,10 +8,12 @@ module clipboard struct Clipboard { pb voidptr last_cb_serial i64 +mut: + foo int // TODO remove, for mut hack } fn new_clipboard() &Clipboard{ - mut pb := voidptr(0) + pb := voidptr(0) #pb = [NSPasteboard generalPasteboard]; cb := &Clipboard{ pb: pb @@ -23,11 +25,13 @@ fn (cb &Clipboard) check_availability() bool { return cb.pb != C.NULL } -fn (cb &Clipboard) clear(){ +fn (cb mut Clipboard) clear(){ + cb.foo = 0 #[cb->pb clearContents]; } -fn (cb &Clipboard) free(){ +fn (cb mut Clipboard) free(){ + cb.foo = 0 //nothing to free } @@ -39,9 +43,10 @@ fn (cb &Clipboard) has_ownership() bool { fn C.OSAtomicCompareAndSwapLong() -fn (cb &Clipboard) set_text(text string) bool { +fn (cb mut Clipboard) set_text(text string) bool { + cb.foo = 0 #NSString *ns_clip; - mut ret := false + ret := false #ns_clip = [[ NSString alloc ] initWithBytesNoCopy:text.str length:text.len encoding:NSUTF8StringEncoding freeWhenDone: false]; #[cb->pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; @@ -54,9 +59,10 @@ fn (cb &Clipboard) set_text(text string) bool { return ret } -fn (cb &Clipboard) get_text() string { +fn (cb mut Clipboard) get_text() string { + cb.foo = 0 #NSString *ns_clip; - mut utf8_clip := byteptr(0) + utf8_clip := byteptr(0) #ns_clip = [cb->pb stringForType:NSStringPboardType]; //NSPasteboardTypeString #if (ns_clip == nil) {