@@ -4779,20 +4779,75 @@ void MainWindow::removeSelectedNotes() {
47794779 if (selectedItemsCount == 0 ) {
47804780 return ;
47814781 }
4782- if (selectedItemsCount == 1 && selItems[0 ]->data (0 , Qt::UserRole + 1 ) == FolderType) {
4783- // If just one folder is selected, remove the folder
4784- NoteSubFolderTree::removeSelectedNoteSubFolders (ui->noteTreeWidget );
4782+
4783+ // Separate notes and folders from selected items
4784+ QVector<QTreeWidgetItem *> noteItems;
4785+ QVector<QTreeWidgetItem *> folderItems;
4786+ QStringList noteSubFolderPathList;
4787+ QVector<NoteSubFolder> noteSubFolderList;
4788+
4789+ for (QTreeWidgetItem *item : selItems) {
4790+ const int itemType = item->data (0 , Qt::UserRole + 1 ).toInt ();
4791+ if (itemType == NoteType) {
4792+ noteItems.append (item);
4793+ } else if (itemType == FolderType) {
4794+ folderItems.append (item);
4795+ const int id = item->data (0 , Qt::UserRole).toInt ();
4796+ const NoteSubFolder noteSubFolder = NoteSubFolder::fetch (id);
4797+ if (noteSubFolder.isFetched ()) {
4798+ noteSubFolderList.append (noteSubFolder);
4799+ noteSubFolderPathList.append (noteSubFolder.fullPath ());
4800+ }
4801+ }
4802+ }
4803+
4804+ const int noteCount = noteItems.count ();
4805+ const int folderCount = noteSubFolderList.count ();
4806+
4807+ if (noteCount == 0 && folderCount == 0 ) {
47854808 return ;
47864809 }
47874810
4788- if (Utils::Gui::question (
4789- this , tr (" Remove selected notes" ),
4790- Utils::Misc::replaceOwnCloudText (tr (" Remove <strong>%n</strong> selected note(s)?\n\n "
4791- " If the trash is enabled on your "
4792- " ownCloud server you should be able to restore "
4793- " them from there." ,
4794- " " , selectedItemsCount)),
4795- QStringLiteral (" remove-notes" )) == QMessageBox::Yes) {
4811+ // Build confirmation message based on what's selected
4812+ QString title;
4813+ QString message;
4814+ QString dialogName;
4815+
4816+ if (noteCount > 0 && folderCount > 0 ) {
4817+ // Both notes and folders selected
4818+ title = tr (" Remove selected notes and folders" );
4819+ message = Utils::Misc::replaceOwnCloudText (
4820+ tr (" Remove <strong>%n</strong> selected note(s) and "
4821+ " <strong>%1</strong> folder(s)?"
4822+ " <ul><li>%2</li></ul>"
4823+ " All files and folders in these folders will be removed as well!\n\n "
4824+ " If the trash is enabled on your ownCloud server you should be able to restore "
4825+ " the notes from there." ,
4826+ " " , noteCount)
4827+ .arg (folderCount)
4828+ .arg (noteSubFolderPathList.join (QStringLiteral (" </li><li>" ))));
4829+ dialogName = QStringLiteral (" remove-notes-and-folders" );
4830+ } else if (folderCount > 0 ) {
4831+ // Only folders selected
4832+ title = tr (" Remove selected folders" );
4833+ message = tr (" Remove <strong>%n</strong> selected folder(s)?"
4834+ " <ul><li>%1</li></ul>"
4835+ " All files and folders in these folders will be removed as well!" ,
4836+ " " , folderCount)
4837+ .arg (noteSubFolderPathList.join (QStringLiteral (" </li><li>" )));
4838+ dialogName = QStringLiteral (" remove-folders" );
4839+ } else {
4840+ // Only notes selected
4841+ title = tr (" Remove selected notes" );
4842+ message = Utils::Misc::replaceOwnCloudText (
4843+ tr (" Remove <strong>%n</strong> selected note(s)?\n\n "
4844+ " If the trash is enabled on your ownCloud server you should be able to restore "
4845+ " them from there." ,
4846+ " " , noteCount));
4847+ dialogName = QStringLiteral (" remove-notes" );
4848+ }
4849+
4850+ if (Utils::Gui::question (this , title, message, dialogName) == QMessageBox::Yes) {
47964851 const QSignalBlocker blocker (this ->noteDirectoryWatcher );
47974852 Q_UNUSED (blocker)
47984853
@@ -4816,11 +4871,8 @@ void MainWindow::removeSelectedNotes() {
48164871 const QSignalBlocker blocker1 (ui->noteTreeWidget );
48174872 Q_UNUSED (blocker1)
48184873
4819- for (QTreeWidgetItem *item : selItems) {
4820- if (item->data (0 , Qt::UserRole + 1 ) != NoteType) {
4821- continue ;
4822- }
4823-
4874+ // Remove notes
4875+ for (QTreeWidgetItem *item : noteItems) {
48244876 const int id = item->data (0 , Qt::UserRole).toInt ();
48254877 Note note = Note::fetch (id);
48264878
@@ -4831,18 +4883,34 @@ void MainWindow::removeSelectedNotes() {
48314883 qDebug () << " Removed note " << note.getName ();
48324884 }
48334885
4834- // clear the text edit so it stays clear after removing the
4835- // last note
4886+ // Remove folders
4887+ for (const auto ¬eSubFolder : Utils::asConst (noteSubFolderList)) {
4888+ // remove the directory recursively from the file system
4889+ if (noteSubFolder.removeFromFileSystem ()) {
4890+ showStatusBarMessage (
4891+ tr (" Removed note subfolder: %1" ).arg (noteSubFolder.fullPath ()),
4892+ QStringLiteral (" 📁" ));
4893+ }
4894+ }
4895+
4896+ // clear the text edit so it stays clear after removing notes
4897+ // (either directly or via folder deletion)
48364898 activeNoteTextEdit ()->clear ();
48374899 }
48384900
4839- // set a new current note
4901+ // set a new current note (needed whether notes or folders were deleted,
4902+ // as folders may contain the currently displayed note)
48404903 resetCurrentNote (false );
48414904
48424905 // we try to fix problems with note subfolders
48434906 // we need to wait some time to turn the watcher on again because
48444907 // something is happening after this method that reloads the note folder
48454908 directoryWatcherWorkaround (false );
4909+
4910+ // Reload note folder if folders were deleted
4911+ if (folderCount > 0 ) {
4912+ reloadNoteFolderAction ()->trigger ();
4913+ }
48464914 }
48474915
48484916 loadNoteDirectoryList ();
0 commit comments