Closed Sherlock-Holo closed 8 months ago
Hi, thank you for your feedback.
Such a features is not yet implemented for the StandardListView
. What you can do is to copy it from you data source, here an example in Rust
let main_window = MainWindow::new():unwrap();
main_window.set_items(VecModel::from_slice(&[StandardListViewItem { text: "Hello".into(), /* ... more items */}]));
main_window.on_copy({
let window_handle = main_window.as_weak();
| item_index | {
let text_to_copy = main_window.get_items().row_data(item_index()).unwrap().text.to_string();
// copy text to clipboard
}
});
main_window.on_paste({
let window_handle = main_window.as_weak();
|| {
// paste the content of clipboard
}
});
import { StandardListView } from "std-widgets.slint";
export component MainWindow {
callback copy(int);
callback paste();
in property <[StandardListViewItem]> items <=> i-list-view.model;
width: 600px;
height: 400px;
FocusScope {
// handle keyboard events to invoke copy and paste
}
i-list-view := StandardListView {}
}
it looks a little complicated, when does StandardListViewItem
support copy the text?
At the moment there is nothing planned to implement that feature. In most native ui-toolkits it is not common as default behavior to copy the text of a list item element. It's possible in the web, but there can be almost every text be selected and copied. From my experience most time you want to copy a list item, you want to copy the corresponding data of the list item. Often the text is only a visual representation of the item. So to implement text copy on StandardListView
as default behavior would make the other use cases more complicated.
What we want to do is to provide a better way to implement custom items for ListView
so you can easier implement your custom behavior for items in Slint.
With the current implementation what could help you right now to do in Slint
is something like this:
private property <string> copy-text;
FocusScope {
key-released(e) => {
if (e.text == "C" && e.modifiers.control) {
copy(i-list-view.model[i-list-view.current-item.text]);
}
}
}
i-list-view := StandardListView {}
function copy(text: string) {
copy-text = text;
}
I hope that helps you a little bit.
I am using slint with rust, when I try the
StandardListView
withStandardListViewItem
, I found I can't copy the text in theStandardListViewItem
when running the slint gui, no matter the right click or press Ctrl+C directlyI am using the native style