Skip to content

Commit

Permalink
Avoid removing items when dropping to a tab fails
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Nov 27, 2024
1 parent 4a77cad commit 40d122b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions src/gui/tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tabbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/gui/tabtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/tabtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> &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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tabwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 40d122b

Please sign in to comment.