From 422f4a804f3e55efad92d47b1be53e116f8bfb32 Mon Sep 17 00:00:00 2001 From: Cyrmax Date: Sat, 2 Jul 2022 13:45:54 +0300 Subject: [PATCH] Added copy password button --- Cargo.toml | 2 +- src/main.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c27b0c8..df4dc95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/main.rs b/src/main.rs index 6a9e4e4..2f9421e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); }