@@ -98,44 +98,11 @@ impl App {
9898 // @todo this should be moved to ui.rs so that mod.rs is independent of crossterm
9999 pub fn keypress ( & mut self , key : crossterm:: event:: KeyCode ) -> Result < ( ) > {
100100 match key {
101- KeyCode :: Char ( 'h' ) => self . toggle_help ( ) ,
102-
103- // Escape jumps back to filehost selector
104- KeyCode :: Esc => {
105- self . set_current_widget ( AppWidgets :: FileSelector ) ;
106- self . file_action . unselect ( ) ;
107- }
108-
109101 KeyCode :: Enter => {
110102 match self . active_widget {
111- // Enter in file selector triggers an action on the selected file
112- AppWidgets :: FileSelector => {
113- self . active_widget = AppWidgets :: FileAction ;
114- if !self . file_action . is_selected ( ) {
115- self . file_action . state . select ( Some ( 0 ) ) ;
116- }
117- }
118- // Enter in action widget trigges an action on the prg
119- AppWidgets :: FileAction => {
120- self . set_current_widget ( AppWidgets :: FileSelector ) ;
121- match self . file_action . state . selected ( ) {
122- Some ( 0 ) => self . run ( false ) ?, // run
123- Some ( 1 ) => self . run ( true ) ?, // reset, then run
124- Some ( 2 ) => self . activate_cbm_browser ( ) ?,
125- _ => { }
126- } ;
127- self . file_action . unselect ( ) ;
128- }
129- AppWidgets :: CBMBrowser => {
130- match self . cbm_browser . state . selected ( ) {
131- _ => {
132- self . run ( false ) ?;
133- self . busy = false ;
134- self . active_widget = AppWidgets :: FileSelector ;
135- }
136- } ;
137- self . file_action . unselect ( ) ;
138- }
103+ AppWidgets :: FileSelector => self . select_filehost_item ( ) ?,
104+ AppWidgets :: FileAction => self . select_file_action ( ) ?,
105+ AppWidgets :: CBMBrowser => self . select_cbm_item ( ) ?,
139106 _ => { }
140107 }
141108 }
@@ -183,6 +150,49 @@ impl App {
183150 }
184151 }
185152
153+ fn escape_to_filehost_browser ( & mut self ) {
154+ self . set_current_widget ( AppWidgets :: FileSelector ) ;
155+ self . file_action . unselect ( ) ;
156+ }
157+
158+ /// Select currently highlighted file in FileHost browser
159+ fn select_filehost_item ( & mut self ) -> Result < ( ) , anyhow:: Error > {
160+ // when selecting file, go to file action widget
161+ self . active_widget = AppWidgets :: FileAction ;
162+ if !self . file_action . is_selected ( ) {
163+ self . file_action . state . select ( Some ( 0 ) ) ;
164+ } ;
165+ Ok ( ( ) )
166+ }
167+
168+ /// Select currently highlighted action in file action widget
169+ fn select_file_action ( & mut self ) -> Result < ( ) , anyhow:: Error > {
170+ // when done, return to filehost browser
171+ self . set_current_widget ( AppWidgets :: FileSelector ) ;
172+ match self . file_action . state . selected ( ) {
173+ Some ( 0 ) => self . run ( false ) ?, // run
174+ Some ( 1 ) => self . run ( true ) ?, // reset, then run
175+ Some ( 2 ) => self . activate_cbm_browser ( ) ?,
176+ _ => { }
177+ } ;
178+ self . file_action . unselect ( ) ;
179+ Ok ( ( ) )
180+ }
181+
182+ /// Select currently highlighted item in CBM browser
183+ fn select_cbm_item ( & mut self ) -> Result < ( ) , anyhow:: Error > {
184+ match self . cbm_browser . state . selected ( ) {
185+ _ => {
186+ self . run ( false ) ?;
187+ self . busy = false ;
188+ self . active_widget = AppWidgets :: FileSelector ;
189+ }
190+ } ;
191+ self . cbm_browser . unselect ( ) ;
192+ self . file_action . unselect ( ) ;
193+ Ok ( ( ) )
194+ }
195+
186196 /// Toggles the help pop-up
187197 fn toggle_help ( & mut self ) {
188198 if self . active_widget != AppWidgets :: Help {
0 commit comments