core: Add clipboard_content getter
This commit is contained in:
parent
95b0b29310
commit
67d74047a9
|
@ -15,6 +15,9 @@ pub trait UiBackend {
|
|||
/// Changes the mouse cursor image.
|
||||
fn set_mouse_cursor(&mut self, cursor: MouseCursor);
|
||||
|
||||
/// Get the clipboard content
|
||||
fn clipboard_content(&mut self) -> String;
|
||||
|
||||
/// Sets the clipboard to the given content.
|
||||
fn set_clipboard_content(&mut self, content: String);
|
||||
|
||||
|
@ -145,6 +148,10 @@ impl UiBackend for NullUiBackend {
|
|||
|
||||
fn set_mouse_cursor(&mut self, _cursor: MouseCursor) {}
|
||||
|
||||
fn clipboard_content(&mut self) -> String {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn set_clipboard_content(&mut self, _content: String) {}
|
||||
|
||||
fn set_fullscreen(&mut self, _is_full: bool) -> Result<(), FullscreenError> {
|
||||
|
|
|
@ -62,6 +62,12 @@ impl UiBackend for DesktopUiBackend {
|
|||
self.window.set_cursor_icon(icon);
|
||||
}
|
||||
|
||||
fn clipboard_content(&mut self) -> String {
|
||||
self.clipboard
|
||||
.get_text()
|
||||
.unwrap_or_else(|_| "".to_string())
|
||||
}
|
||||
|
||||
fn set_clipboard_content(&mut self, content: String) {
|
||||
if let Err(e) = self.clipboard.set_text(content) {
|
||||
error!("Couldn't set clipboard contents: {:?}", e);
|
||||
|
|
|
@ -65,6 +65,11 @@ impl UiBackend for WebUiBackend {
|
|||
self.update_mouse_cursor();
|
||||
}
|
||||
|
||||
fn clipboard_content(&mut self) -> String {
|
||||
tracing::warn!("get clipboard not implemented");
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn set_clipboard_content(&mut self, content: String) {
|
||||
// We use `document.execCommand("copy")` as `navigator.clipboard.writeText("string")`
|
||||
// is available only in secure contexts (HTTPS).
|
||||
|
|
Loading…
Reference in New Issue