@@ -18,6 +18,7 @@ pub struct App {
1818 pub disable_saving : bool , // For testing
1919 pub theme : Theme ,
2020 pub selected_theme_index : usize , // for theme selector view
21+ pub error_message : String ,
2122}
2223
2324// which field is focused in task detail view
@@ -44,6 +45,21 @@ pub enum InputMode {
4445 RenamingColumn ,
4546 ConfirmingDelete ,
4647 SelectingTheme ,
48+ ShowErrorInfo ,
49+ }
50+
51+ impl InputMode {
52+ pub fn has_open_input ( & self ) -> bool {
53+ match self {
54+ Self :: AddingTask
55+ | Self :: AddingTag
56+ | Self :: EditingTitle
57+ | Self :: EditingDescription
58+ | Self :: RenamingColumn
59+ | Self :: AddingProject => true ,
60+ _ => false ,
61+ }
62+ }
4763}
4864
4965impl App {
@@ -77,6 +93,7 @@ impl App {
7793 disable_saving : false ,
7894 theme,
7995 selected_theme_index : 0 ,
96+ error_message : String :: new ( ) ,
8097 }
8198 }
8299
@@ -119,6 +136,7 @@ impl App {
119136 disable_saving : true ,
120137 theme : Theme :: default ( ) ,
121138 selected_theme_index : 0 ,
139+ error_message : String :: new ( ) ,
122140 }
123141 }
124142
@@ -378,6 +396,20 @@ impl App {
378396 self . input_buffer . pop ( ) ;
379397 }
380398
399+ // Open the external editor defined in $EDITOR
400+ pub fn open_external_editor ( & mut self ) {
401+ match edit:: edit ( & self . input_buffer ) {
402+ Ok ( edited) => self . input_buffer = edited,
403+ Err ( e) => self . handle_error ( e. to_string ( ) ) ,
404+ }
405+ }
406+
407+ // handle error by switching to error info mode
408+ fn handle_error ( & mut self , error_message : String ) {
409+ self . error_message = error_message;
410+ self . input_mode = InputMode :: ShowErrorInfo ;
411+ }
412+
381413 // submit input
382414 pub fn submit_input ( & mut self ) {
383415 match self . input_mode {
@@ -472,7 +504,8 @@ impl App {
472504 | InputMode :: ViewingHelp
473505 | InputMode :: ProjectList
474506 | InputMode :: ConfirmingDelete
475- | InputMode :: SelectingTheme => { }
507+ | InputMode :: SelectingTheme
508+ | InputMode :: ShowErrorInfo => { }
476509 }
477510 self . cancel_input ( ) ;
478511 }
@@ -496,6 +529,15 @@ impl App {
496529 } ;
497530 }
498531
532+ // cycle to previous field in task detail view
533+ pub fn previous_field ( & mut self ) {
534+ self . focused_field = match self . focused_field {
535+ TaskField :: Title => TaskField :: Description ,
536+ TaskField :: Description => TaskField :: Tags ,
537+ TaskField :: Tags => TaskField :: Title ,
538+ }
539+ }
540+
499541 // start editing title
500542 pub fn start_editing_title ( & mut self ) {
501543 if let Some ( column) = self . board ( ) . get_column ( self . selected_column ) {
@@ -641,6 +683,12 @@ impl App {
641683 self . input_mode = InputMode :: Normal ;
642684 }
643685
686+ // TODO: This should probably go back to the last mode instead of always Normal
687+ pub fn close_error_info ( & mut self ) {
688+ self . input_mode = InputMode :: Normal ;
689+ self . error_message . clear ( ) ;
690+ }
691+
644692 // show help view
645693 pub fn show_help ( & mut self ) {
646694 self . input_mode = InputMode :: ViewingHelp ;
0 commit comments