2020-12-25 18:21:42 +01:00
|
|
|
module dummy
|
|
|
|
|
2022-04-05 12:06:32 +02:00
|
|
|
// Clipboard represents a system clipboard.
|
|
|
|
//
|
|
|
|
// System "copy" and "paste" actions utilize the clipboard for temporary storage.
|
2020-12-25 18:21:42 +01:00
|
|
|
pub struct Clipboard {
|
|
|
|
mut:
|
|
|
|
text string // text data sent or received
|
2021-01-21 12:45:59 +01:00
|
|
|
got_text bool // used to confirm that we have got the text
|
|
|
|
is_owner bool // to save selection owner state
|
2020-12-25 18:21:42 +01:00
|
|
|
}
|
|
|
|
|
2021-01-21 12:45:59 +01:00
|
|
|
// new_clipboard returns a new `Clipboard` instance allocated on the heap.
|
|
|
|
// The `Clipboard` resources can be released with `free()`
|
2020-12-25 18:21:42 +01:00
|
|
|
pub fn new_clipboard() &Clipboard {
|
|
|
|
return &Clipboard{}
|
|
|
|
}
|
|
|
|
|
2021-01-21 12:45:59 +01:00
|
|
|
// new_primary returns a new X11 `PRIMARY` type `Clipboard` instance allocated on the heap.
|
|
|
|
// Please note: new_primary only works on X11 based systems.
|
2020-12-25 18:21:42 +01:00
|
|
|
pub fn new_primary() &Clipboard {
|
|
|
|
return &Clipboard{}
|
|
|
|
}
|
|
|
|
|
2022-04-05 12:06:32 +02:00
|
|
|
// set_text transfers `text` to the system clipboard.
|
|
|
|
// This is often associated with a *copy* action (`Ctrl` + `C`).
|
2021-03-04 09:49:40 +01:00
|
|
|
pub fn (mut cb Clipboard) set_text(text string) bool {
|
2020-12-25 18:21:42 +01:00
|
|
|
cb.text = text
|
|
|
|
cb.is_owner = true
|
|
|
|
cb.got_text = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-04-05 12:06:32 +02:00
|
|
|
// get_text retrieves the contents of the system clipboard
|
|
|
|
// as a `string`.
|
|
|
|
// This is often associated with a *paste* action (`Ctrl` + `V`).
|
2021-03-04 09:49:40 +01:00
|
|
|
pub fn (mut cb Clipboard) get_text() string {
|
2020-12-25 18:21:42 +01:00
|
|
|
return cb.text
|
|
|
|
}
|
|
|
|
|
2022-04-05 12:06:32 +02:00
|
|
|
// clear empties the clipboard contents.
|
2021-03-04 09:49:40 +01:00
|
|
|
pub fn (mut cb Clipboard) clear() {
|
2020-12-25 18:21:42 +01:00
|
|
|
cb.text = ''
|
|
|
|
cb.is_owner = false
|
|
|
|
}
|
|
|
|
|
2022-04-05 12:06:32 +02:00
|
|
|
// free releases all memory associated with the clipboard
|
|
|
|
// instance.
|
2021-03-04 09:49:40 +01:00
|
|
|
pub fn (mut cb Clipboard) free() {
|
2020-12-25 18:21:42 +01:00
|
|
|
}
|
|
|
|
|
2022-04-05 12:06:32 +02:00
|
|
|
// has_ownership returns true if the contents of
|
|
|
|
// the clipboard were created by this clipboard instance.
|
2021-03-04 09:49:40 +01:00
|
|
|
pub fn (cb &Clipboard) has_ownership() bool {
|
2020-12-25 18:21:42 +01:00
|
|
|
return cb.is_owner
|
|
|
|
}
|
|
|
|
|
2022-04-05 12:06:32 +02:00
|
|
|
// check_availability returns true if the clipboard is ready to be used.
|
2021-03-04 09:49:40 +01:00
|
|
|
pub fn (cb &Clipboard) check_availability() bool {
|
2020-12-25 18:21:42 +01:00
|
|
|
// This is a dummy clipboard implementation,
|
|
|
|
// which can be always used, although it does not do much...
|
|
|
|
return true
|
|
|
|
}
|