mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
clipboard: add doc strings to all implementations (#13932)
This commit is contained in:
parent
f5e4d17cf3
commit
0b046c14a8
@ -2,6 +2,9 @@ module clipboard
|
|||||||
|
|
||||||
import clipboard.dummy
|
import clipboard.dummy
|
||||||
|
|
||||||
|
// Clipboard represents a system clipboard.
|
||||||
|
//
|
||||||
|
// System "copy" and "paste" actions utilize the clipboard for temporary storage.
|
||||||
pub type Clipboard = dummy.Clipboard
|
pub type Clipboard = dummy.Clipboard
|
||||||
|
|
||||||
fn new_clipboard() &Clipboard {
|
fn new_clipboard() &Clipboard {
|
||||||
|
@ -5,6 +5,9 @@ module clipboard
|
|||||||
#flag -framework Cocoa
|
#flag -framework Cocoa
|
||||||
#include "@VEXEROOT/vlib/clipboard/clipboard_darwin.m"
|
#include "@VEXEROOT/vlib/clipboard/clipboard_darwin.m"
|
||||||
|
|
||||||
|
// Clipboard represents a system clipboard.
|
||||||
|
//
|
||||||
|
// System "copy" and "paste" actions utilize the clipboard for temporary storage.
|
||||||
pub struct Clipboard {
|
pub struct Clipboard {
|
||||||
pb voidptr
|
pb voidptr
|
||||||
last_cb_serial i64
|
last_cb_serial i64
|
||||||
@ -25,21 +28,27 @@ fn new_clipboard() &Clipboard {
|
|||||||
return cb
|
return cb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check_availability returns true if the clipboard is ready to be used.
|
||||||
pub fn (cb &Clipboard) check_availability() bool {
|
pub fn (cb &Clipboard) check_availability() bool {
|
||||||
return cb.pb != C.NULL
|
return cb.pb != C.NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear empties the clipboard contents.
|
||||||
pub fn (mut cb Clipboard) clear() {
|
pub fn (mut cb Clipboard) clear() {
|
||||||
cb.foo = 0
|
cb.foo = 0
|
||||||
cb.set_text('')
|
cb.set_text('')
|
||||||
//#[cb->pb clearContents];
|
//#[cb->pb clearContents];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// free releases all memory associated with the clipboard
|
||||||
|
// instance.
|
||||||
pub fn (mut cb Clipboard) free() {
|
pub fn (mut cb Clipboard) free() {
|
||||||
cb.foo = 0
|
cb.foo = 0
|
||||||
// nothing to free
|
// nothing to free
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// has_ownership returns true if the contents of
|
||||||
|
// the clipboard were created by this clipboard instance.
|
||||||
pub fn (cb &Clipboard) has_ownership() bool {
|
pub fn (cb &Clipboard) has_ownership() bool {
|
||||||
if cb.last_cb_serial == 0 {
|
if cb.last_cb_serial == 0 {
|
||||||
return false
|
return false
|
||||||
@ -50,10 +59,15 @@ pub fn (cb &Clipboard) has_ownership() bool {
|
|||||||
|
|
||||||
fn C.OSAtomicCompareAndSwapLong()
|
fn C.OSAtomicCompareAndSwapLong()
|
||||||
|
|
||||||
|
// set_text transfers `text` to the system clipboard.
|
||||||
|
// This is often associated with a *copy* action (`Cmd` + `C`).
|
||||||
pub fn (mut cb Clipboard) set_text(text string) bool {
|
pub fn (mut cb Clipboard) set_text(text string) bool {
|
||||||
return C.darwin_set_pasteboard_text(cb.pb, text)
|
return C.darwin_set_pasteboard_text(cb.pb, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get_text retrieves the contents of the system clipboard
|
||||||
|
// as a `string`.
|
||||||
|
// This is often associated with a *paste* action (`Cmd` + `V`).
|
||||||
pub fn (mut cb Clipboard) get_text() string {
|
pub fn (mut cb Clipboard) get_text() string {
|
||||||
cb.foo = 0
|
cb.foo = 0
|
||||||
if isnil(cb.pb) {
|
if isnil(cb.pb) {
|
||||||
|
@ -2,6 +2,9 @@ module clipboard
|
|||||||
|
|
||||||
import clipboard.x11
|
import clipboard.x11
|
||||||
|
|
||||||
|
// Clipboard represents a system clipboard.
|
||||||
|
//
|
||||||
|
// System "copy" and "paste" actions utilize the clipboard for temporary storage.
|
||||||
pub type Clipboard = x11.Clipboard
|
pub type Clipboard = x11.Clipboard
|
||||||
|
|
||||||
fn new_clipboard() &Clipboard {
|
fn new_clipboard() &Clipboard {
|
||||||
|
@ -2,6 +2,9 @@ module clipboard
|
|||||||
|
|
||||||
import clipboard.dummy
|
import clipboard.dummy
|
||||||
|
|
||||||
|
// Clipboard represents a system clipboard.
|
||||||
|
//
|
||||||
|
// System "copy" and "paste" actions utilize the clipboard for temporary storage.
|
||||||
pub type Clipboard = dummy.Clipboard
|
pub type Clipboard = dummy.Clipboard
|
||||||
|
|
||||||
fn new_clipboard() &Clipboard {
|
fn new_clipboard() &Clipboard {
|
||||||
|
@ -51,6 +51,9 @@ fn C.OpenClipboard(hwnd C.HWND) int
|
|||||||
|
|
||||||
fn C.DestroyWindow(hwnd C.HWND)
|
fn C.DestroyWindow(hwnd C.HWND)
|
||||||
|
|
||||||
|
// Clipboard represents a system clipboard.
|
||||||
|
//
|
||||||
|
// System "copy" and "paste" actions utilize the clipboard for temporary storage.
|
||||||
struct Clipboard {
|
struct Clipboard {
|
||||||
max_retries int
|
max_retries int
|
||||||
retry_delay int
|
retry_delay int
|
||||||
@ -104,14 +107,18 @@ fn new_clipboard() &Clipboard {
|
|||||||
return cb
|
return cb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check_availability returns true if the clipboard is ready to be used.
|
||||||
pub fn (cb &Clipboard) check_availability() bool {
|
pub fn (cb &Clipboard) check_availability() bool {
|
||||||
return cb.hwnd != C.HWND(C.NULL)
|
return cb.hwnd != C.HWND(C.NULL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// has_ownership returns true if the contents of
|
||||||
|
// the clipboard were created by this clipboard instance.
|
||||||
pub fn (cb &Clipboard) has_ownership() bool {
|
pub fn (cb &Clipboard) has_ownership() bool {
|
||||||
return C.GetClipboardOwner() == cb.hwnd
|
return C.GetClipboardOwner() == cb.hwnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear empties the clipboard contents.
|
||||||
pub fn (mut cb Clipboard) clear() {
|
pub fn (mut cb Clipboard) clear() {
|
||||||
if !cb.get_clipboard_lock() {
|
if !cb.get_clipboard_lock() {
|
||||||
return
|
return
|
||||||
@ -121,6 +128,8 @@ pub fn (mut cb Clipboard) clear() {
|
|||||||
cb.foo = 0
|
cb.foo = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// free releases all memory associated with the clipboard
|
||||||
|
// instance.
|
||||||
pub fn (mut cb Clipboard) free() {
|
pub fn (mut cb Clipboard) free() {
|
||||||
C.DestroyWindow(cb.hwnd)
|
C.DestroyWindow(cb.hwnd)
|
||||||
cb.foo = 0
|
cb.foo = 0
|
||||||
@ -143,6 +152,8 @@ fn to_wide(text string) C.HGLOBAL {
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set_text transfers `text` to the system clipboard.
|
||||||
|
// This is often associated with a *copy* action (`Ctrl` + `C`).
|
||||||
pub fn (mut cb Clipboard) set_text(text string) bool {
|
pub fn (mut cb Clipboard) set_text(text string) bool {
|
||||||
cb.foo = 0
|
cb.foo = 0
|
||||||
buf := to_wide(text)
|
buf := to_wide(text)
|
||||||
@ -164,6 +175,9 @@ pub fn (mut cb Clipboard) set_text(text string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get_text retrieves the contents of the system clipboard
|
||||||
|
// as a `string`.
|
||||||
|
// This is often associated with a *paste* action (`Ctrl` + `V`).
|
||||||
pub fn (mut cb Clipboard) get_text() string {
|
pub fn (mut cb Clipboard) get_text() string {
|
||||||
cb.foo = 0
|
cb.foo = 0
|
||||||
if !cb.get_clipboard_lock() {
|
if !cb.get_clipboard_lock() {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
module dummy
|
module dummy
|
||||||
|
|
||||||
|
// Clipboard represents a system clipboard.
|
||||||
|
//
|
||||||
|
// System "copy" and "paste" actions utilize the clipboard for temporary storage.
|
||||||
pub struct Clipboard {
|
pub struct Clipboard {
|
||||||
mut:
|
mut:
|
||||||
text string // text data sent or received
|
text string // text data sent or received
|
||||||
@ -19,6 +22,8 @@ pub fn new_primary() &Clipboard {
|
|||||||
return &Clipboard{}
|
return &Clipboard{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set_text transfers `text` to the system clipboard.
|
||||||
|
// This is often associated with a *copy* action (`Ctrl` + `C`).
|
||||||
pub fn (mut cb Clipboard) set_text(text string) bool {
|
pub fn (mut cb Clipboard) set_text(text string) bool {
|
||||||
cb.text = text
|
cb.text = text
|
||||||
cb.is_owner = true
|
cb.is_owner = true
|
||||||
@ -26,22 +31,31 @@ pub fn (mut cb Clipboard) set_text(text string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get_text retrieves the contents of the system clipboard
|
||||||
|
// as a `string`.
|
||||||
|
// This is often associated with a *paste* action (`Ctrl` + `V`).
|
||||||
pub fn (mut cb Clipboard) get_text() string {
|
pub fn (mut cb Clipboard) get_text() string {
|
||||||
return cb.text
|
return cb.text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear empties the clipboard contents.
|
||||||
pub fn (mut cb Clipboard) clear() {
|
pub fn (mut cb Clipboard) clear() {
|
||||||
cb.text = ''
|
cb.text = ''
|
||||||
cb.is_owner = false
|
cb.is_owner = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// free releases all memory associated with the clipboard
|
||||||
|
// instance.
|
||||||
pub fn (mut cb Clipboard) free() {
|
pub fn (mut cb Clipboard) free() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// has_ownership returns true if the contents of
|
||||||
|
// the clipboard were created by this clipboard instance.
|
||||||
pub fn (cb &Clipboard) has_ownership() bool {
|
pub fn (cb &Clipboard) has_ownership() bool {
|
||||||
return cb.is_owner
|
return cb.is_owner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check_availability returns true if the clipboard is ready to be used.
|
||||||
pub fn (cb &Clipboard) check_availability() bool {
|
pub fn (cb &Clipboard) check_availability() bool {
|
||||||
// This is a dummy clipboard implementation,
|
// This is a dummy clipboard implementation,
|
||||||
// which can be always used, although it does not do much...
|
// which can be always used, although it does not do much...
|
||||||
|
Loading…
Reference in New Issue
Block a user