1+ #include < functional>
12#include < iostream>
23#include < sstream>
34#include " commander.h"
@@ -203,32 +204,70 @@ const bool CCommander::keyHold(void)
203204
204205const bool CCommander::openCopyMenu (void ) const
205206{
206- bool l_ret ( false ) ;
207+ std::vector<std::function< bool ()>> handlers ;
207208 int l_dialogRetVal (0 );
208- bool l_rename (false );
209209 // List of selected files
210210 std::vector<std::string> l_list;
211211 m_panelSource->getSelectList (l_list);
212- // The rename option appears only if one item is selected
213- l_rename = (l_list.size () == 1 );
214212 {
215213 bool l_loop (false );
216214 std::ostringstream l_stream;
217215 l_stream << l_list.size () << " selected:" ;
218216 // File operation dialog
219217 CDialog l_dialog (l_stream.str (), 0 , Y_LIST + m_panelSource->getHighlightedIndexRelative () * LINE_HEIGHT);
218+
220219 l_dialog.addOption (m_panelSource == &m_panelLeft ? " Copy >" : " < Copy" );
220+ handlers.push_back ([&]() {
221+ File_utils::copyFile (l_list, m_panelTarget->getCurrentPath ());
222+ return true ;
223+ });
224+
221225 l_dialog.addOption (m_panelSource == &m_panelLeft ? " Move >" : " < Move" );
222- if (l_rename)
226+ handlers.push_back ([&]() {
227+ File_utils::moveFile (l_list, m_panelTarget->getCurrentPath ());
228+ return true ;
229+ });
230+
231+
232+ l_dialog.addOption (m_panelSource == &m_panelLeft ? " Symlink >" : " < Symlink" );
233+ handlers.push_back ([&]() {
234+ File_utils::symlinkFile (l_list, m_panelTarget->getCurrentPath ());
235+ return true ;
236+ });
237+
238+ if (l_list.size () == 1 ) {
239+ // The rename option appears only if one item is selected
223240 l_dialog.addOption (" Rename" );
241+ handlers.push_back ([&]() {
242+ CKeyboard l_keyboard (m_panelSource->getHighlightedItem ());
243+ if (l_keyboard.execute () == 1 && !l_keyboard.getInputText ().empty () && l_keyboard.getInputText () != m_panelSource->getHighlightedItem ())
244+ {
245+ File_utils::renameFile (m_panelSource->getHighlightedItemFull (), m_panelSource->getCurrentPath () + (m_panelSource->getCurrentPath () == " /" ? " " : " /" ) + l_keyboard.getInputText ());
246+ return true ;
247+ }
248+ return false ;
249+ });
250+ }
251+
224252 l_dialog.addOption (" Delete" );
253+ handlers.push_back ([&]() {
254+ File_utils::removeFile (l_list);
255+ return true ;
256+ });
257+ const int delete_option = handlers.size ();
258+
225259 l_dialog.addOption (" Disk used" );
260+ handlers.push_back ([&]() {
261+ File_utils::diskUsed (l_list);
262+ return false ;
263+ });
264+
226265 l_dialog.init ();
227266 do
228267 {
229268 l_loop = false ;
230269 l_dialogRetVal = l_dialog.execute ();
231- if (l_dialogRetVal == 3 + l_rename )
270+ if (l_dialogRetVal == delete_option )
232271 {
233272 CDialog l_dialog2 (" " , l_dialog.getX () + l_dialog.getImage ()->w / screen.ppu_x - DIALOG_BORDER, l_dialog.getY () / screen.ppu_y + DIALOG_BORDER + (l_dialog.getHighlightedIndex () + 1 ) * LINE_HEIGHT);
234273 l_dialog2.addOption (" Yes" );
@@ -241,59 +280,10 @@ const bool CCommander::openCopyMenu(void) const
241280 while (l_loop);
242281 }
243282 // Perform operation
244- switch (l_dialogRetVal)
245- {
246- case 1 :
247- // Copy
248- File_utils::copyFile (l_list, m_panelTarget->getCurrentPath ());
249- l_ret = true ;
250- break ;
251- case 2 :
252- // Move
253- File_utils::moveFile (l_list, m_panelTarget->getCurrentPath ());
254- l_ret = true ;
255- break ;
256- case 3 :
257- if (l_rename)
258- {
259- // Rename
260- CKeyboard l_keyboard (m_panelSource->getHighlightedItem ());
261- if (l_keyboard.execute () == 1 && !l_keyboard.getInputText ().empty () && l_keyboard.getInputText () != m_panelSource->getHighlightedItem ())
262- {
263- File_utils::renameFile (m_panelSource->getHighlightedItemFull (), m_panelSource->getCurrentPath () + (m_panelSource->getCurrentPath () == " /" ? " " : " /" ) + l_keyboard.getInputText ());
264- l_ret = true ;
265- }
266- }
267- else
268- {
269- // Delete
270- printf (" About to remove file" );
271- printf (" %s" , l_list.at (0 ).c_str ());
272- File_utils::removeFile (l_list);
273- printf (" Done removing file." );
274- l_ret = true ;
275- }
276- break ;
277- case 4 :
278- if (l_rename)
279- {
280- // Delete
281- File_utils::removeFile (l_list);
282- l_ret = true ;
283- }
284- else
285- // Disk used
286- File_utils::diskUsed (l_list);
287- break ;
288- case 5 :
289- if (l_rename)
290- // Disk used
291- File_utils::diskUsed (l_list);
292- break ;
293- default :
294- break ;
283+ if (l_dialogRetVal > 0 && l_dialogRetVal <= handlers.size ()) {
284+ return handlers[l_dialogRetVal - 1 ]();
295285 }
296- return l_ret ;
286+ return false ;
297287}
298288
299289const bool CCommander::openSystemMenu (void )
0 commit comments