Mercurial > octave
comparison libgui/src/files-dock-widget.cc @ 28130:712cd23aaa4f
Delete multiple files in GUI without multiple dialog boxes (bug #57874).
* files-dock-widget.cc (contextmenu_delete): Count number of files selected.
If multiple files are selected, then use a dialog box just once for the first
iteration over the selected files to determine whether to delete them all.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 21 Feb 2020 12:40:53 -0800 |
parents | ec769a7ab9fb |
children | 0c6dcf803529 |
comparison
equal
deleted
inserted
replaced
28128:c1ca9b6903cd | 28130:712cd23aaa4f |
---|---|
718 void files_dock_widget::contextmenu_delete (bool) | 718 void files_dock_widget::contextmenu_delete (bool) |
719 { | 719 { |
720 QItemSelectionModel *m = m_file_tree_view->selectionModel (); | 720 QItemSelectionModel *m = m_file_tree_view->selectionModel (); |
721 QModelIndexList rows = m->selectedRows (); | 721 QModelIndexList rows = m->selectedRows (); |
722 | 722 |
723 int file_cnt = rows.size (); | |
724 bool multiple_files = (file_cnt > 1); | |
725 | |
723 for (auto it = rows.begin (); it != rows.end (); it++) | 726 for (auto it = rows.begin (); it != rows.end (); it++) |
724 { | 727 { |
725 QModelIndex index = *it; | 728 QModelIndex index = *it; |
726 | 729 |
727 QFileInfo info = m_file_system_model->fileInfo (index); | 730 QFileInfo info = m_file_system_model->fileInfo (index); |
728 | 731 |
729 if (QMessageBox::question (this, tr ("Delete file/directory"), | 732 QMessageBox::StandardButton dlg_answer; |
730 tr ("Are you sure you want to delete\n") | 733 if (multiple_files) |
731 + info.filePath (), | 734 if (it == rows.begin ()) |
732 QMessageBox::Yes | QMessageBox::No) | 735 { |
733 == QMessageBox::Yes) | 736 dlg_answer = QMessageBox::question (this, |
737 tr ("Delete file/directory"), | |
738 tr ("Are you sure you want to delete all %1 selected files?\n").arg (file_cnt), | |
739 QMessageBox::Yes | QMessageBox::No); | |
740 if (dlg_answer != QMessageBox::Yes) | |
741 return; | |
742 } | |
743 else | |
744 dlg_answer = QMessageBox::Yes; | |
745 else | |
746 { | |
747 dlg_answer = QMessageBox::question (this, | |
748 tr ("Delete file/directory"), | |
749 tr ("Are you sure you want to delete\n") | |
750 + info.filePath (), | |
751 QMessageBox::Yes | QMessageBox::No); | |
752 } | |
753 | |
754 if (dlg_answer) | |
734 { | 755 { |
735 if (info.isDir ()) | 756 if (info.isDir ()) |
736 { | 757 { |
737 // see if directory is empty | 758 // see if directory is empty |
738 QDir path (info.absoluteFilePath ()); | 759 QDir path (info.absoluteFilePath ()); |