will_umount method in Activity

This commit is contained in:
veeso
2021-03-21 17:16:52 +01:00
parent 30c2aa144b
commit f0d87ff8c4
9 changed files with 95 additions and 50 deletions

View File

@@ -35,7 +35,7 @@ extern crate crossterm;
extern crate tui;
// Locals
use super::{Activity, Context};
use super::{Activity, Context, ExitReason};
use crate::ui::layout::view::View;
// Ext
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
@@ -71,7 +71,7 @@ enum ViewLayout {
///
/// Setup activity states holder
pub struct SetupActivity {
pub quit: bool, // Becomes true when user requests the activity to terminate
exit_reason: Option<ExitReason>,
context: Option<Context>, // Context holder
view: View, // View
layout: ViewLayout, // View layout
@@ -86,7 +86,7 @@ impl Default for SetupActivity {
user_input_buffer.push(String::new());
}
SetupActivity {
quit: false,
exit_reason: None,
context: None,
view: View::init(),
layout: ViewLayout::SetupForm,
@@ -142,6 +142,15 @@ impl Activity for SetupActivity {
}
}
/// ### will_umount
///
/// `will_umount` is the method which must be able to report to the activity manager, whether
/// the activity should be terminated or not.
/// If not, the call will return `None`, otherwise return`Some(ExitReason)`
fn will_umount(&self) -> Option<&ExitReason> {
self.exit_reason.as_ref()
}
/// ### on_destroy
///
/// `on_destroy` is the function which cleans up runtime variables and data before terminating the activity.

View File

@@ -112,12 +112,12 @@ impl SetupActivity {
self.mount_error(err.as_str());
}
// Exit
self.quit = true;
self.exit_reason = Some(super::ExitReason::Quit);
None
}
(COMPONENT_RADIO_QUIT, Msg::OnSubmit(Payload::Unsigned(1))) => {
// Quit
self.quit = true;
self.exit_reason = Some(super::ExitReason::Quit);
self.umount_quit();
None
}