From now on, if you try to leave setup without making any change, you won't be prompted whether to save configuration or not
This commit is contained in:
parent
59c6567ff3
commit
e1109fff15
|
@ -50,6 +50,7 @@ Released on FIXME: ??
|
|||
- Replaced all `...` with `…` in texts
|
||||
- Check if remote host is valid in authentication form
|
||||
- Check if port number is valid in authentication form
|
||||
- From now on, if you try to leave setup without making any change, you won't be prompted whether to save configuration or not
|
||||
- Bugfix:
|
||||
- Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2)
|
||||
- Fixed save bookmark dialog: you could switch out from dialog with `<TAB>`
|
||||
|
|
|
@ -36,12 +36,28 @@ use tuirealm::tui::style::Color;
|
|||
use tuirealm::{Payload, Value};
|
||||
|
||||
impl SetupActivity {
|
||||
/// ### action_on_esc
|
||||
///
|
||||
/// On <ESC>, if there are changes in the configuration, the quit dialog must be shown, otherwise
|
||||
/// we can exit without any problem
|
||||
pub(super) fn action_on_esc(&mut self) {
|
||||
if self.config_changed() {
|
||||
self.mount_quit();
|
||||
} else {
|
||||
self.exit_reason = Some(super::ExitReason::Quit);
|
||||
}
|
||||
}
|
||||
|
||||
/// ### action_save_all
|
||||
///
|
||||
/// Save all configurations. If current tab can load values, they will be loaded, otherwise they'll just be saved
|
||||
/// Save all configurations. If current tab can load values, they will be loaded, otherwise they'll just be saved.
|
||||
/// Once all the configuration has been changed, set config_changed to false
|
||||
pub(super) fn action_save_all(&mut self) -> Result<(), String> {
|
||||
self.action_save_config()?;
|
||||
self.action_save_theme()
|
||||
self.action_save_theme()?;
|
||||
// Set config changed to false
|
||||
self.set_config_changed(false);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ### action_save_config
|
||||
|
|
|
@ -100,6 +100,9 @@ const COMPONENT_COLOR_TRANSFER_STATUS_SORTING: &str = "COMPONENT_COLOR_TRANSFER_
|
|||
const COMPONENT_COLOR_TRANSFER_STATUS_HIDDEN: &str = "COMPONENT_COLOR_TRANSFER_STATUS_HIDDEN";
|
||||
const COMPONENT_COLOR_TRANSFER_STATUS_SYNC: &str = "COMPONENT_COLOR_TRANSFER_STATUS_SYNC";
|
||||
|
||||
// -- store
|
||||
const STORE_CONFIG_CHANGED: &str = "SETUP_CONFIG_CHANGED";
|
||||
|
||||
/// ### ViewLayout
|
||||
///
|
||||
/// Current view layout
|
||||
|
@ -167,6 +170,25 @@ impl SetupActivity {
|
|||
fn theme_provider(&mut self) -> &mut ThemeProvider {
|
||||
self.context_mut().theme_provider_mut()
|
||||
}
|
||||
|
||||
/// ### config_changed
|
||||
///
|
||||
/// Returns whether config has changed
|
||||
fn config_changed(&self) -> bool {
|
||||
self.context()
|
||||
.store()
|
||||
.get_boolean(STORE_CONFIG_CHANGED)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// ### set_config_changed
|
||||
///
|
||||
/// Set value for config changed key into the store
|
||||
fn set_config_changed(&mut self, changed: bool) {
|
||||
self.context_mut()
|
||||
.store_mut()
|
||||
.set_boolean(STORE_CONFIG_CHANGED, changed);
|
||||
}
|
||||
}
|
||||
|
||||
impl Activity for SetupActivity {
|
||||
|
@ -180,6 +202,8 @@ impl Activity for SetupActivity {
|
|||
self.context = Some(context);
|
||||
// Clear terminal
|
||||
self.context.as_mut().unwrap().clear_screen();
|
||||
// Set config changed to false
|
||||
self.set_config_changed(false);
|
||||
// Put raw mode on enabled
|
||||
if let Err(err) = enable_raw_mode() {
|
||||
error!("Failed to enter raw mode: {}", err);
|
||||
|
|
|
@ -182,6 +182,12 @@ impl SetupActivity {
|
|||
None
|
||||
}
|
||||
(COMPONENT_RADIO_SAVE, _) => None,
|
||||
// Detect config changed
|
||||
(_, Msg::OnChange(_)) => {
|
||||
// An input field has changed value; report config changed
|
||||
self.set_config_changed(true);
|
||||
None
|
||||
}
|
||||
// <CTRL+H> Show help
|
||||
(_, &MSG_KEY_CTRL_H) => {
|
||||
// Show help
|
||||
|
@ -211,8 +217,7 @@ impl SetupActivity {
|
|||
}
|
||||
// <ESC>
|
||||
(_, &MSG_KEY_ESC) => {
|
||||
// Mount quit prompt
|
||||
self.mount_quit();
|
||||
self.action_on_esc();
|
||||
None
|
||||
}
|
||||
(_, _) => None, // Nothing to do
|
||||
|
@ -380,8 +385,7 @@ impl SetupActivity {
|
|||
}
|
||||
// <ESC>
|
||||
(_, &MSG_KEY_ESC) => {
|
||||
// Mount quit prompt
|
||||
self.mount_quit();
|
||||
self.action_on_esc();
|
||||
None
|
||||
}
|
||||
(_, _) => None, // Nothing to do
|
||||
|
@ -614,6 +618,8 @@ impl SetupActivity {
|
|||
(component, Msg::OnChange(Payload::One(Value::Str(color)))) => {
|
||||
if let Some(color) = parse_color(color) {
|
||||
self.action_save_color(component, color);
|
||||
// Set unsaved changes to true
|
||||
self.set_config_changed(true);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
@ -698,8 +704,7 @@ impl SetupActivity {
|
|||
}
|
||||
// <ESC>
|
||||
(_, &MSG_KEY_ESC) => {
|
||||
// Mount quit prompt
|
||||
self.mount_quit();
|
||||
self.action_on_esc();
|
||||
None
|
||||
}
|
||||
(_, _) => None, // Nothing to do
|
||||
|
|
|
@ -111,7 +111,9 @@ impl SetupActivity {
|
|||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightRed)
|
||||
.with_options(
|
||||
Some(String::from("Exit setup?")),
|
||||
Some(String::from(
|
||||
"There are unsaved changes! Save changes before leaving?",
|
||||
)),
|
||||
vec![
|
||||
String::from("Save"),
|
||||
String::from("Don't save"),
|
||||
|
|
Loading…
Reference in a new issue