| 1 | module dummy |
| 2 | |
| 3 | // Clipboard represents a system clipboard. |
| 4 | // |
| 5 | // System "copy" and "paste" actions utilize the clipboard for temporary storage. |
| 6 | @[heap] |
| 7 | pub struct Clipboard { |
| 8 | mut: |
| 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()` |
| 16 | pub 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. |
| 22 | pub 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`). |
| 28 | pub 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`). |
| 37 | pub fn (mut cb Clipboard) get_text() string { |
| 38 | return cb.text |
| 39 | } |
| 40 | |
| 41 | // clear empties the clipboard contents. |
| 42 | pub 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. |
| 48 | pub fn (mut cb Clipboard) free() { |
| 49 | } |
| 50 | |
| 51 | // has_ownership returns true if the contents of the clipboard were created by this clipboard instance. |
| 52 | pub 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. |
| 57 | pub 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 | |