@@ -39,20 +39,22 @@ impl App {
3939 let current_dir_path: String = self . get_current_dir_abs_path ( ) ;
4040
4141 let action: & MenuAction = & self . known_menu_actions [ self . action_menu_cursor_y ] ;
42+ self . window_focus = WindowFocus :: Tree ;
43+ self . action_menu_operation = Some ( action. operation . clone ( ) ) ;
4244 match action. operation {
4345 Operation :: ShellCommand { template } => {
44- self . window_focus = WindowFocus :: Tree ;
45- let res = execute_shell_operation ( & abs_path , template ) ;
46- if res . is_err ( ) {
47- self . error_message = Some ( res . err ( ) . unwrap ( ) . to_string ( ) ) ;
46+ let result = execute_shell_operation ( & abs_path , template ) ;
47+ match result {
48+ Err ( err ) => self . show_error ( err . to_string ( ) ) ,
49+ _ => { }
4850 }
4951 }
5052 Operation :: InteractiveShellCommand { template } => {
51- let res = execute_interactive_shell_operation ( & abs_path, template, tui) ;
52- if res. is_err ( ) {
53- self . error_message = Some ( res. err ( ) . unwrap ( ) . to_string ( ) ) ;
53+ let result = execute_interactive_shell_operation ( & abs_path, template, tui) ;
54+ match result {
55+ Err ( err) => self . show_error ( err. to_string ( ) ) ,
56+ _ => { }
5457 }
55- self . window_focus = WindowFocus :: Tree ;
5658 }
5759 Operation :: PickAbsolutePath => {
5860 self . pick_selected_node ( Some ( false ) ) ;
@@ -62,133 +64,130 @@ impl App {
6264 }
6365 Operation :: Rename => {
6466 let filename = abs_path. split ( '/' ) . last ( ) . unwrap ( ) . to_string ( ) ;
65- self . window_focus = WindowFocus :: ActionMenuStep2 ;
66- self . action_menu_operation = Some ( action. operation . clone ( ) ) ;
67- self . action_menu_title = format ! ( "New name for {}" , filename) ;
68- self . action_menu_buffer = filename;
69- self . action_menu_cursor_x = self . action_menu_buffer . chars ( ) . count ( ) ;
67+ self . open_action_menu_step2 ( format ! ( "New name for {}" , filename) , filename) ;
7068 }
7169 Operation :: CreateFile => {
72- self . window_focus = WindowFocus :: ActionMenuStep2 ;
73- self . action_menu_operation = Some ( action. operation . clone ( ) ) ;
74- self . action_menu_title = format ! ( "New file at {}" , current_dir_path) ;
75- self . action_menu_buffer = "" . to_string ( ) ;
76- self . action_menu_cursor_x = self . action_menu_buffer . chars ( ) . count ( ) ;
70+ self . open_action_menu_step2 (
71+ format ! ( "New file at {}" , current_dir_path) ,
72+ String :: new ( ) ,
73+ ) ;
7774 }
7875 Operation :: CreateDir => {
79- self . window_focus = WindowFocus :: ActionMenuStep2 ;
80- self . action_menu_operation = Some ( action. operation . clone ( ) ) ;
81- self . action_menu_title = format ! ( "New directory at {}" , current_dir_path) ;
82- self . action_menu_buffer = "" . to_string ( ) ;
83- self . action_menu_cursor_x = self . action_menu_buffer . chars ( ) . count ( ) ;
76+ self . open_action_menu_step2 (
77+ format ! ( "New directory at {}" , current_dir_path) ,
78+ String :: new ( ) ,
79+ ) ;
80+ }
81+ Operation :: CustomCommand => {
82+ self . open_action_menu_step2 (
83+ format ! ( "Run command at {}" , current_dir_path) ,
84+ format ! ( "\" {}\" " , abs_path) ,
85+ ) ;
86+ }
87+ Operation :: CustomInteractiveCommand => {
88+ self . open_action_menu_step2 (
89+ format ! ( "Run interactive command at {}" , current_dir_path) ,
90+ format ! ( "\" {}\" " , abs_path) ,
91+ ) ;
8492 }
8593 Operation :: Delete => {
86- let res = delete_tree_node ( & tree_node, & abs_path) ;
87- if res. is_err ( ) {
88- self . error_message = Some ( res. err ( ) . unwrap ( ) . to_string ( ) ) ;
94+ let result = delete_tree_node ( & tree_node, & abs_path) ;
95+ match result {
96+ Err ( err) => self . show_error ( err. to_string ( ) ) ,
97+ _ => { }
8998 }
90- self . window_focus = WindowFocus :: Tree ;
9199 }
92100 Operation :: CopyToClipboard { is_relative_path } => {
93- self . window_focus = WindowFocus :: Tree ;
94- let res = match is_relative_path {
101+ let result = match is_relative_path {
95102 true => copy_path_to_clipboard ( & relative_path. unwrap ( ) ) ,
96103 false => copy_path_to_clipboard ( & abs_path) ,
97104 } ;
98- if res. is_err ( ) {
99- self . error_message = Some ( res. err ( ) . unwrap ( ) . to_string ( ) ) ;
105+ match result {
106+ Err ( err) => self . show_error ( err. to_string ( ) ) ,
107+ _ => { }
100108 }
101109 }
102110 Operation :: FileDetails => {
103- self . window_focus = WindowFocus :: Tree ;
104- let res = get_file_details ( & abs_path, is_directory) ;
105- if res. is_err ( ) {
106- self . error_message = Some ( res. err ( ) . unwrap ( ) . to_string ( ) ) ;
107- } else {
108- self . show_info ( res. unwrap ( ) ) ;
111+ let result = get_file_details ( & abs_path, is_directory) ;
112+ match result {
113+ Ok ( info) => self . show_info ( info) ,
114+ Err ( err) => self . show_error ( err. to_string ( ) ) ,
109115 }
110116 }
111- Operation :: CustomCommand => {
112- self . window_focus = WindowFocus :: ActionMenuStep2 ;
113- self . action_menu_operation = Some ( action. operation . clone ( ) ) ;
114- self . action_menu_title = format ! ( "Run command at {}" , current_dir_path) ;
115- self . action_menu_buffer = format ! ( "\" {}\" " , abs_path) ;
116- self . action_menu_cursor_x = self . action_menu_buffer . chars ( ) . count ( ) ;
117- }
118- Operation :: CustomInteractiveCommand => {
119- self . window_focus = WindowFocus :: ActionMenuStep2 ;
120- self . action_menu_operation = Some ( action. operation . clone ( ) ) ;
121- self . action_menu_title = format ! ( "Run interactive command at {}" , current_dir_path) ;
122- self . action_menu_buffer = format ! ( "\" {}\" " , abs_path) ;
123- self . action_menu_cursor_x = self . action_menu_buffer . chars ( ) . count ( ) ;
124- }
125117 Operation :: ViewContent => {
126- self . window_focus = WindowFocus :: Tree ;
127118 if !is_directory {
128- let res = read_file_content ( & abs_path) ;
129- if res. is_err ( ) {
130- self . error_message = Some ( res. err ( ) . unwrap ( ) . to_string ( ) ) ;
131- } else {
132- self . show_info ( res. unwrap ( ) ) ;
119+ let result = read_file_content ( & abs_path) ;
120+ match result {
121+ Ok ( info) => self . show_info ( info) ,
122+ Err ( err) => self . show_error ( err. to_string ( ) ) ,
133123 }
134124 }
135125 }
136126 }
137127 self . populate_current_child_nodes ( ) ;
138128 }
139129
130+ fn open_action_menu_step2 ( & mut self , title : String , buffer : String ) {
131+ self . window_focus = WindowFocus :: ActionMenuStep2 ;
132+ self . action_menu_title = title;
133+ self . action_menu_buffer = buffer;
134+ self . action_menu_cursor_x = self . action_menu_buffer . chars ( ) . count ( ) ;
135+ }
136+
140137 pub fn execute_dialog_action_step2 ( & mut self , tui : & mut Tui ) {
141138 let abs_path: String = match self . get_selected_abs_path ( ) {
142139 Some ( abs_path) => abs_path,
143140 None => return ,
144141 } ;
145142 if self . action_menu_buffer . is_empty ( ) {
146- self . error_message = Some ( "No value given" . to_string ( ) ) ;
143+ self . show_error ( "No value given" . to_string ( ) ) ;
147144 return ;
148145 }
149146 let current_dir_path: String = self . get_current_dir_abs_path ( ) ;
150147
151148 match self . action_menu_operation {
152149 Some ( Operation :: Rename ) => {
153- let res = rename_file ( & abs_path, & self . action_menu_buffer ) ;
154- if res. is_err ( ) {
155- self . error_message = Some ( res. err ( ) . unwrap ( ) . to_string ( ) ) ;
150+ let result = rename_file ( & abs_path, & self . action_menu_buffer ) ;
151+ match result {
152+ Err ( err) => self . show_error ( err. to_string ( ) ) ,
153+ _ => { }
156154 }
157155 }
158156 Some ( Operation :: CreateFile ) => {
159157 let full_path = format ! ( "{}/{}" , current_dir_path, & self . action_menu_buffer) ;
160- let res = create_file ( & full_path) ;
161- if res. is_err ( ) {
162- self . error_message = Some ( res. err ( ) . unwrap ( ) . to_string ( ) ) ;
158+ let result = create_file ( & full_path) ;
159+ match result {
160+ Err ( err) => self . show_error ( err. to_string ( ) ) ,
161+ _ => { }
163162 }
164163 }
165164 Some ( Operation :: CreateDir ) => {
166165 let full_path = format ! ( "{}/{}" , current_dir_path, & self . action_menu_buffer) ;
167- let res = create_directory ( & full_path) ;
168- if res. is_err ( ) {
169- self . error_message = Some ( res. err ( ) . unwrap ( ) . to_string ( ) ) ;
166+ let result = create_directory ( & full_path) ;
167+ match result {
168+ Err ( err) => self . show_error ( err. to_string ( ) ) ,
169+ _ => { }
170170 }
171171 }
172172 Some ( Operation :: CustomCommand ) => {
173173 let current_dir_path = current_dir_path. clone ( ) ;
174174 let action_menu_buffer = self . action_menu_buffer . clone ( ) ;
175- self . info_message =
176- Some ( format ! ( "Running command...\n {}" , & self . action_menu_buffer) ) ;
175+ self . show_info ( format ! ( "Running command...\n {}" , & self . action_menu_buffer) ) ;
177176 let result_tx = self . background_event_channel . tx . clone ( ) ;
178177 std:: thread:: spawn ( move || {
179- let res = run_custom_command ( current_dir_path, & action_menu_buffer) ;
180- match res {
178+ let result = run_custom_command ( current_dir_path, & action_menu_buffer) ;
179+ match result {
181180 Ok ( output) => result_tx. send ( BackgroundEvent :: InfoMessage ( output) ) ,
182181 Err ( err) => result_tx. send ( BackgroundEvent :: ErrorMessage ( err. to_string ( ) ) ) ,
183182 }
184183 } ) ;
185184 }
186185 Some ( Operation :: CustomInteractiveCommand ) => {
187- let res =
186+ let result =
188187 run_custom_interactive_command ( current_dir_path, & self . action_menu_buffer , tui) ;
189- match res {
188+ match result {
190189 Ok ( output) => self . show_info ( output) ,
191- Err ( err) => self . error_message = Some ( err. to_string ( ) ) ,
190+ Err ( err) => self . show_error ( err. to_string ( ) ) ,
192191 }
193192 }
194193 _ => { }
0 commit comments