From e76dcd46381697725546b70a9f46c73620cc2e9b Mon Sep 17 00:00:00 2001 From: veeso Date: Sun, 14 Mar 2021 15:44:21 +0100 Subject: [PATCH] Quit popup --- src/ui/activities/auth_activity/mod.rs | 1 + src/ui/activities/auth_activity/update.rs | 20 ++++++++++-- src/ui/activities/auth_activity/view.rs | 37 +++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/ui/activities/auth_activity/mod.rs b/src/ui/activities/auth_activity/mod.rs index c14110b..8645ed5 100644 --- a/src/ui/activities/auth_activity/mod.rs +++ b/src/ui/activities/auth_activity/mod.rs @@ -58,6 +58,7 @@ const COMPONENT_INPUT_USERNAME: &str = "INPUT_USERNAME"; const COMPONENT_INPUT_PASSWORD: &str = "INPUT_PASSWORD"; const COMPONENT_INPUT_BOOKMARK_NAME: &str = "INPUT_BOOKMARK_NAME"; const COMPONENT_RADIO_PROTOCOL: &str = "RADIO_PROTOCOL"; +const COMPONENT_RADIO_QUIT: &str = "RADIO_QUIT"; const COMPONENT_RADIO_BOOKMARK_DEL_BOOKMARK: &str = "RADIO_DELETE_BOOKMARK"; const COMPONENT_RADIO_BOOKMARK_DEL_RECENT: &str = "RADIO_DELETE_RECENT"; const COMPONENT_RADIO_BOOKMARK_SAVE_PWD: &str = "RADIO_SAVE_PASSWORD"; diff --git a/src/ui/activities/auth_activity/update.rs b/src/ui/activities/auth_activity/update.rs index 13a2577..253bde9 100644 --- a/src/ui/activities/auth_activity/update.rs +++ b/src/ui/activities/auth_activity/update.rs @@ -28,8 +28,8 @@ use super::{ AuthActivity, COMPONENT_BOOKMARKS_LIST, COMPONENT_INPUT_ADDR, COMPONENT_INPUT_BOOKMARK_NAME, COMPONENT_INPUT_PASSWORD, COMPONENT_INPUT_PORT, COMPONENT_INPUT_USERNAME, COMPONENT_RADIO_BOOKMARK_DEL_BOOKMARK, COMPONENT_RADIO_BOOKMARK_DEL_RECENT, - COMPONENT_RADIO_BOOKMARK_SAVE_PWD, COMPONENT_RADIO_PROTOCOL, COMPONENT_RECENTS_LIST, - COMPONENT_TEXT_ERROR, COMPONENT_TEXT_HELP, + COMPONENT_RADIO_BOOKMARK_SAVE_PWD, COMPONENT_RADIO_PROTOCOL, COMPONENT_RADIO_QUIT, + COMPONENT_RECENTS_LIST, COMPONENT_TEXT_ERROR, COMPONENT_TEXT_HELP, }; use crate::ui::layout::{props::TextParts, Msg, Payload}; // ext @@ -124,7 +124,7 @@ impl AuthActivity { } (COMPONENT_INPUT_PASSWORD, &MSG_KEY_DOWN) => { // Give focus to port - self.view.active(COMPONENT_INPUT_USERNAME); + self.view.active(COMPONENT_INPUT_ADDR); None } // Focus ( UP ) @@ -375,6 +375,15 @@ impl AuthActivity { self.umount_error(); None } + // Quit dialog + (COMPONENT_RADIO_QUIT, Msg::OnSubmit(Payload::Unsigned(choice))) => { + // If choice is 0, quit termscp + if *choice == 0 { + self.quit = true; + } + self.umount_quit(); + None + } // On submit on any unhandled (connect) (_, Msg::OnSubmit(_)) | (_, &MSG_KEY_ENTER) => { // Match key for all other components @@ -391,6 +400,11 @@ impl AuthActivity { // Return None None } + // => Quit + (_, &MSG_KEY_ESC) => { + self.mount_quit(); + None + } (_, _) => None, // Ignore other events }, } diff --git a/src/ui/activities/auth_activity/view.rs b/src/ui/activities/auth_activity/view.rs index 1e7b0dd..f02d69c 100644 --- a/src/ui/activities/auth_activity/view.rs +++ b/src/ui/activities/auth_activity/view.rs @@ -259,6 +259,16 @@ impl AuthActivity { ); } } + if let Some(mut props) = self.view.get_props(super::COMPONENT_RADIO_QUIT) { + if props.build().visible { + // make popup + self.view.render( + super::COMPONENT_RADIO_QUIT, + f, + draw_area_in(f.size(), 30, 10), + ); + } + } if let Some(mut props) = self .view .get_props(super::COMPONENT_RADIO_BOOKMARK_DEL_BOOKMARK) @@ -362,6 +372,33 @@ impl AuthActivity { self.view.umount(super::COMPONENT_TEXT_ERROR); } + /// ### mount_quit + /// + /// Mount quit popup + pub(super) fn mount_quit(&mut self) { + // Protocol + self.view.mount( + super::COMPONENT_RADIO_QUIT, + Box::new(RadioGroup::new( + PropsBuilder::default() + .with_foreground(Color::Yellow) + .with_texts(TextParts::new( + Some(String::from("Quit TermSCP?")), + Some(vec![TextSpan::from("Yes"), TextSpan::from("No")]), + )) + .build(), + )), + ); + self.view.active(super::COMPONENT_RADIO_QUIT); + } + + /// ### umount_quit + /// + /// Umount quit popup + pub(super) fn umount_quit(&mut self) { + self.view.umount(super::COMPONENT_RADIO_QUIT); + } + /// ### mount_bookmark_del_dialog /// /// Mount bookmark delete dialog