Added copy password button

This commit is contained in:
Cyrmax 2022-07-02 13:45:54 +03:00
parent 2b0cb6afe6
commit 422f4a804f
2 changed files with 11 additions and 1 deletions

View File

@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
native-windows-derive = { version = "1.0.5"}
native-windows-gui = { version = "1.0.12"}
native-windows-gui = { version = "1.0.12", features = ["clipboard"]}
rand = "0.8.5"

View File

@ -51,6 +51,11 @@ pub struct RustPasswordGenerator {
#[nwg_layout_item(layout: grid, col: 1, row: 2, col_span: 5)]
result_text: nwg::TextInput,
#[nwg_control(text: "Copy")]
#[nwg_layout_item(layout: grid, col: 7, row: 2)]
#[nwg_events( OnButtonClick: [ RustPasswordGenerator::copy_password])]
copy_btn: nwg::Button,
#[nwg_control(text: "Generate")]
#[nwg_layout_item(layout: grid, col: 4, row: 3)]
#[nwg_events( OnButtonClick: [ RustPasswordGenerator::generate_password ] )]
@ -87,6 +92,11 @@ impl RustPasswordGenerator {
self.result_text.set_text(&password);
}
fn copy_password(&self) {
let text = self.result_text.text();
nwg::Clipboard::set_data_text(&self.window, &text);
}
fn show_error(&self, message: &str) {
nwg::modal_error_message(&self.window, "error!", message);
}