Skip to content

Commit

Permalink
#3185 add: deleting of note subfolders with Delete or Backspace key
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek committed Dec 23, 2024
1 parent 5687072 commit baa22d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 24.12.6
- A possible crash when pasting HTML as Markdown or pasting as text file was fixed
(for [#3184](https://github.com/pbek/QOwnNotes/issues/3184))
- It is now possible to allow deleting of subfolders with the `Delete` or `Backspace` key,
like for notes and tags (for [#3185](https://github.com/pbek/QOwnNotes/issues/3185))

## 24.12.5
- Both note links and the link dialog are now supporting also heading 1, not only
Expand Down
16 changes: 15 additions & 1 deletion src/widgets/notesubfoldertree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QHeaderView>
#include <QMenu>
#include <QKeyEvent>
#include <memory>

#include "entities/notefolder.h"
Expand All @@ -17,7 +18,7 @@ NoteSubFolderTree::NoteSubFolderTree(QWidget *parent) : QTreeWidget(parent) {
header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
});
setContextMenuPolicy(Qt::CustomContextMenu);

installEventFilter(this);
initConnections();
}

Expand Down Expand Up @@ -428,3 +429,16 @@ void NoteSubFolderTree::onItemSelectionChanged() {
Q_EMIT multipleSubfoldersSelected();
}
}

bool NoteSubFolderTree::eventFilter(QObject *obj, QEvent *event) {
if (event->type() == QEvent::KeyPress) {
auto *keyEvent = dynamic_cast<QKeyEvent *>(event);

if ((keyEvent->key() == Qt::Key_Delete) || (keyEvent->key() == Qt::Key_Backspace)) {
removeSelectedNoteSubFolders(this);
return true;
}
}

return QTreeWidget::eventFilter(obj, event);
}
3 changes: 3 additions & 0 deletions src/widgets/notesubfoldertree.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ class NoteSubFolderTree : public QTreeWidget {
void initConnections();
QTreeWidgetItem *addNoteSubFolder(QTreeWidgetItem *parentItem,
const NoteSubFolder &noteSubFolder);

protected:
bool eventFilter(QObject *obj, QEvent *event) override;
};

0 comments on commit baa22d7

Please sign in to comment.