From 8bc31b6f717b65ba2eb7bc0eba0100bafd56dd03 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Tue, 26 Nov 2024 15:56:14 +0100 Subject: [PATCH] Avoid removing items when dropping to a tab fails --- src/gui/mainwindow.cpp | 5 +++-- src/gui/mainwindow.h | 2 +- src/gui/tabbar.cpp | 6 ++++-- src/gui/tabbar.h | 2 +- src/gui/tabtree.cpp | 6 ++++-- src/gui/tabtree.h | 2 +- src/gui/tabwidget.h | 2 +- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 73ed049a1d..d80252fef5 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1136,14 +1136,15 @@ void MainWindow::onClipboardCommandActionTriggered(CommandAction *commandAction, action( actionData, command, QModelIndex() ); } -void MainWindow::onTabWidgetDropItems(const QString &tabName, const QMimeData *data) +void MainWindow::onTabWidgetDropItems(const QString &tabName, const QMimeData *data, bool *accepted) { auto browser = tab(tabName); if (browser) { const QVariantMap dataMap = data->hasFormat(mimeItems) ? cloneData(data, QStringList() << mimeItems) : cloneData(data); - browser->addAndSelect(dataMap, 0); + if ( browser->addAndSelect(dataMap, 0) ) + *accepted = true; } } diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 742bc70a63..45c76d61a0 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -486,7 +486,7 @@ class MainWindow final : public QMainWindow void onItemCommandActionTriggered(CommandAction *commandAction, const QString &triggeredShortcut); void onClipboardCommandActionTriggered(CommandAction *commandAction, const QString &triggeredShortcut); - void onTabWidgetDropItems(const QString &tabName, const QMimeData *data); + void onTabWidgetDropItems(const QString &tabName, const QMimeData *data, bool *accepted); void showContextMenuAt(QPoint position); diff --git a/src/gui/tabbar.cpp b/src/gui/tabbar.cpp index 31aaa3b28a..ac98a5ebe6 100644 --- a/src/gui/tabbar.cpp +++ b/src/gui/tabbar.cpp @@ -184,8 +184,10 @@ void TabBar::dropEvent(QDropEvent *event) int tabIndex = dropItemsTabIndex(*event, *this); if ( tabIndex != -1 ) { - acceptDrag(event); - emit dropItems( tabName(tabIndex), event->mimeData() ); + bool accepted = false; + emit dropItems( tabName(tabIndex), event->mimeData(), &accepted ); + if (accepted) + acceptDrag(event); } else { QTabBar::dropEvent(event); } diff --git a/src/gui/tabbar.h b/src/gui/tabbar.h index 5ecfdd5887..e0f08fa8f3 100644 --- a/src/gui/tabbar.h +++ b/src/gui/tabbar.h @@ -49,7 +49,7 @@ class TabBar final : public QTabBar, public TabsWidgetInterface signals: void tabBarMenuRequested(const QPoint &pos, int tab); void tabRenamed(const QString &newName, int index); - void dropItems(const QString &tabName, const QMimeData *data); + void dropItems(const QString &tabName, const QMimeData *data, bool *accepted); protected: void contextMenuEvent(QContextMenuEvent *event) override; diff --git a/src/gui/tabtree.cpp b/src/gui/tabtree.cpp index 17b309eefe..0d98b0d7b5 100644 --- a/src/gui/tabtree.cpp +++ b/src/gui/tabtree.cpp @@ -559,8 +559,10 @@ void TabTree::dropEvent(QDropEvent *event) const auto targetItem = dropItemsTarget(*event, *this); if (targetItem) { - acceptDrag(event); - emit dropItems( getTabPath(targetItem), event->mimeData() ); + bool accepted = false; + emit dropItems( getTabPath(targetItem), event->mimeData(), &accepted ); + if (accepted) + acceptDrag(event); } else if ( itemAt(event->pos()) ) { const QString oldPrefix = getTabPath(current); diff --git a/src/gui/tabtree.h b/src/gui/tabtree.h index 7b5387cc3d..33f7b642f0 100644 --- a/src/gui/tabtree.h +++ b/src/gui/tabtree.h @@ -70,7 +70,7 @@ class TabTree final : public QTreeWidget, public TabsWidgetInterface void currentTabChanged(int index); void tabTreeMenuRequested(const QPoint &pos, const QString &groupPath); void tabsMoved(const QString &oldPrefix, const QString &newPrefix, const QList &indexes); - void dropItems(const QString &tabName, const QMimeData *data); + void dropItems(const QString &tabName, const QMimeData *data, bool *accepted); protected: void contextMenuEvent(QContextMenuEvent *event) override; diff --git a/src/gui/tabwidget.h b/src/gui/tabwidget.h index 6406d12243..3c23ef884d 100644 --- a/src/gui/tabwidget.h +++ b/src/gui/tabwidget.h @@ -90,7 +90,7 @@ class TabWidget final : public QWidget void tabRenamed(const QString &newName, int index); void currentChanged(int tabIndex, int oldTabIndex); void tabCloseRequested(int); - void dropItems(const QString &tabName, const QMimeData *data); + void dropItems(const QString &tabName, const QMimeData *data, bool *accepted); protected: bool eventFilter(QObject *object, QEvent *event) override;