v2 / vlib / clipboard / dummy / dummy_clipboard.v
61 lines · 52 sloc · 1.78 KB · 37255767290c243b71f0e78d77c3bd5e875748e6
Raw
1module dummy
2
3// Clipboard represents a system clipboard.
4//
5// System "copy" and "paste" actions utilize the clipboard for temporary storage.
6@[heap]
7pub struct Clipboard {
8mut:
9 text string // text data sent or received
10 got_text bool // used to confirm that we have got the text
11 is_owner bool // to save selection owner state
12}
13
14// new_clipboard returns a new `Clipboard` instance allocated on the heap.
15// The `Clipboard` resources can be released with `free()`
16pub fn new_clipboard() &Clipboard {
17 return &Clipboard{}
18}
19
20// new_primary returns a new X11 `PRIMARY` type `Clipboard` instance allocated on the heap.
21// Please note: new_primary only works on X11 based systems.
22pub fn new_primary() &Clipboard {
23 return &Clipboard{}
24}
25
26// set_text transfers `text` to the system clipboard.
27// This is often associated with a *copy* action (`Ctrl` + `C`).
28pub fn (mut cb Clipboard) set_text(text string) bool {
29 cb.text = text
30 cb.is_owner = true
31 cb.got_text = true
32 return true
33}
34
35// get_text retrieves the contents of the system clipboard.
36// This is often associated with a *paste* action (`Ctrl` + `V`).
37pub fn (mut cb Clipboard) get_text() string {
38 return cb.text
39}
40
41// clear empties the clipboard contents.
42pub fn (mut cb Clipboard) clear() {
43 cb.text = ''
44 cb.is_owner = false
45}
46
47// free releases all memory associated with the clipboard instance.
48pub fn (mut cb Clipboard) free() {
49}
50
51// has_ownership returns true if the contents of the clipboard were created by this clipboard instance.
52pub fn (cb &Clipboard) has_ownership() bool {
53 return cb.is_owner
54}
55
56// check_availability returns true if the clipboard is ready to be used.
57pub fn (cb &Clipboard) check_availability() bool {
58 // This is a dummy clipboard implementation,
59 // which can be always used, although it does not do much...
60 return true
61}
62