Skip to main content

excel_cli/app/
ui.rs

1use crate::app::AppState;
2use crate::app::InputMode;
3
4impl AppState<'_> {
5    pub fn show_help(&mut self) {
6        self.help_scroll = 0;
7        self.help_text = crate::app::help_reference_text();
8        self.help_total_lines = crate::app::help_reference_line_count();
9
10        self.input_mode = InputMode::Help;
11    }
12
13    pub fn save_and_exit(&mut self) {
14        if !self.workbook.is_modified() {
15            self.add_notification("No changes to save".to_string());
16            self.should_quit = true;
17            return;
18        }
19
20        match self.workbook.save() {
21            Ok(_) => {
22                self.undo_history.clear();
23                self.add_notification("File saved".to_string());
24                self.should_quit = true;
25            }
26            Err(e) => {
27                self.add_notification(format!("Save failed: {e}"));
28                self.input_mode = InputMode::Normal;
29            }
30        }
31    }
32
33    pub fn save(&mut self) -> Result<(), anyhow::Error> {
34        if !self.workbook.is_modified() {
35            self.add_notification("No changes to save".to_string());
36            return Ok(());
37        }
38
39        match self.workbook.save() {
40            Ok(_) => {
41                self.undo_history.clear();
42                self.add_notification("File saved".to_string());
43            }
44            Err(e) => {
45                self.add_notification(format!("Save failed: {e}"));
46            }
47        }
48        Ok(())
49    }
50
51    pub fn exit_without_saving(&mut self) {
52        self.should_quit = true;
53    }
54}