Skip to content

Commit 6586a55

Browse files
committed
#3374 note-selection: adapt multiselect notes context menu
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 7921e81 commit 6586a55

File tree

3 files changed

+76
-9
lines changed

3 files changed

+76
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- **Notes and note folders can now be deleted together** in a single operation when enabling
66
the experimental note tree feature (for [#3374](https://github.com/pbek/QOwnNotes/issues/3374))
77
- When both notes and folders are selected, they will all be deleted after confirmation
8+
- The context menu remove action adapts its text based on selection ("Remove notes", "Remove folders", or "Remove notes and folders")
9+
- The selection label now shows counts for both notes and folders when selected together (e.g., "5 note(s) and 2 folder(s) selected")
810
- The confirmation dialog adapts to show what will be deleted (notes only, folders only, or both)
911
- The current note is now properly reset after deletion to prevent deleted notes from remaining visible
1012
- This avoids having to delete notes and folders separately

src/mainwindow.cpp

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8541,7 +8541,30 @@ void MainWindow::reloadCurrentNoteTags() {
85418541
} else {
85428542
const QVector<Note> notes = selectedNotes();
85438543
tagList = Tag::fetchAllOfNotes(notes);
8544-
const QString notesSelectedText = tr("%n notes selected", "", selectedNotesCount);
8544+
8545+
// Count notes and folders separately
8546+
const auto selectedItems = ui->noteTreeWidget->selectedItems();
8547+
int noteCount = 0;
8548+
int folderCount = 0;
8549+
for (const auto *item : selectedItems) {
8550+
const int itemType = item->data(0, Qt::UserRole + 1).toInt();
8551+
if (itemType == NoteType) {
8552+
noteCount++;
8553+
} else if (itemType == FolderType) {
8554+
folderCount++;
8555+
}
8556+
}
8557+
8558+
// Build selection text based on what's selected
8559+
QString notesSelectedText;
8560+
if (noteCount > 0 && folderCount > 0) {
8561+
notesSelectedText =
8562+
tr("%n note(s) and %1 folder(s) selected", "", noteCount).arg(folderCount);
8563+
} else if (folderCount > 0) {
8564+
notesSelectedText = tr("%n folder(s) selected", "", folderCount);
8565+
} else {
8566+
notesSelectedText = tr("%n notes selected", "", noteCount);
8567+
}
85458568

85468569
ui->selectedTagsToolButton->setText(QString::number(selectedNotesCount));
85478570
ui->selectedTagsToolButton->setToolTip(notesSelectedText);
@@ -9884,20 +9907,53 @@ void MainWindow::on_noteTreeWidget_customContextMenuRequested(const QPoint pos)
98849907
}
98859908

98869909
const QPoint globalPos = ui->noteTreeWidget->mapToGlobal(pos);
9887-
const int type = item->data(0, Qt::UserRole + 1).toInt();
9910+
const auto selectedItems = ui->noteTreeWidget->selectedItems();
9911+
9912+
// Check if we have a mixed selection of notes and folders
9913+
bool hasNotes = false;
9914+
bool hasFolders = false;
9915+
for (const auto *selectedItem : selectedItems) {
9916+
const int itemType = selectedItem->data(0, Qt::UserRole + 1).toInt();
9917+
if (itemType == NoteType) {
9918+
hasNotes = true;
9919+
} else if (itemType == FolderType) {
9920+
hasFolders = true;
9921+
}
9922+
if (hasNotes && hasFolders) {
9923+
break;
9924+
}
9925+
}
98889926

9889-
if (type == FolderType) {
9927+
// If we have a mixed selection or notes, show the notes context menu
9928+
// (which now supports both notes and folders)
9929+
if (hasNotes || (hasNotes && hasFolders)) {
9930+
openNotesContextMenu(globalPos, hasNotes, hasFolders);
9931+
} else if (hasFolders) {
9932+
// Only folders selected, show folder-specific context menu
98909933
std::unique_ptr<QMenu> menu(NoteSubFolderTree::contextMenu(ui->noteTreeWidget));
98919934
menu->exec(globalPos);
9892-
} else if (type == NoteType) {
9893-
openNotesContextMenu(globalPos);
98949935
}
98959936
}
98969937

9897-
void MainWindow::openNotesContextMenu(const QPoint globalPos, bool multiNoteMenuEntriesOnly) {
9938+
void MainWindow::openNotesContextMenu(const QPoint globalPos, bool hasNotes, bool hasFolders) {
98989939
QMenu noteMenu;
98999940
QAction *renameAction = nullptr;
99009941

9942+
// Calculate counts for proper labels
9943+
const auto selectedItems = ui->noteTreeWidget->selectedItems();
9944+
int noteCount = 0;
9945+
int folderCount = 0;
9946+
for (const auto *item : selectedItems) {
9947+
const int itemType = item->data(0, Qt::UserRole + 1).toInt();
9948+
if (itemType == NoteType) {
9949+
noteCount++;
9950+
} else if (itemType == FolderType) {
9951+
folderCount++;
9952+
}
9953+
}
9954+
9955+
bool multiNoteMenuEntriesOnly = (noteCount + folderCount) > 1;
9956+
99019957
if (!multiNoteMenuEntriesOnly) {
99029958
auto *createNoteAction = noteMenu.addAction(tr("New note"));
99039959
connect(createNoteAction, &QAction::triggered, this,
@@ -9909,7 +9965,16 @@ void MainWindow::openNotesContextMenu(const QPoint globalPos, bool multiNoteMenu
99099965
"the note"));
99109966
}
99119967

9912-
auto *removeAction = noteMenu.addAction(tr("&Remove notes"));
9968+
// Set dynamic remove action text based on selection
9969+
QString removeActionText;
9970+
if (hasNotes && hasFolders) {
9971+
removeActionText = tr("&Remove notes and folders");
9972+
} else if (hasFolders) {
9973+
removeActionText = tr("&Remove folders");
9974+
} else {
9975+
removeActionText = tr("&Remove notes");
9976+
}
9977+
auto *removeAction = noteMenu.addAction(removeActionText);
99139978
noteMenu.addSeparator();
99149979

99159980
const QList<NoteFolder> noteFolders = NoteFolder::fetchAll();
@@ -9974,7 +10039,6 @@ void MainWindow::openNotesContextMenu(const QPoint globalPos, bool multiNoteMenu
997410039
}
997510040

997610041
QStringList noteNameList;
9977-
const auto selectedItems = ui->noteTreeWidget->selectedItems();
997810042
for (QTreeWidgetItem *item : selectedItems) {
997910043
// the note names are not unique anymore but the note subfolder
998010044
// path will be taken into account in

src/mainwindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,8 @@ class MainWindow : public QMainWindow {
11341134

11351135
void initFakeVim(QOwnNotesMarkdownTextEdit *noteTextEdit);
11361136

1137-
void openNotesContextMenu(const QPoint globalPos, bool multiNoteMenuEntriesOnly = false);
1137+
void openNotesContextMenu(const QPoint globalPos, bool hasNotes = true,
1138+
bool hasFolders = false);
11381139

11391140
void updateCurrentNoteTextHash();
11401141

0 commit comments

Comments
 (0)