From 5a86c4ac52c519c703a29e0c3b273da17717669f Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 1 Feb 2019 11:44:51 +0300 Subject: [PATCH] Close context menu when content model is reset Closes #9522. --- src/gui/properties/propertieswidget.cpp | 29 +++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index d8c0d6c39..3e78a7b52 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -576,15 +576,15 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &) const QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0); if (selectedRows.empty()) return; - QMenu myFilesLlistMenu; + QMenu myFilesListMenu; QAction *actOpen = nullptr; QAction *actOpenContainingFolder = nullptr; QAction *actRename = nullptr; if (selectedRows.size() == 1) { - actOpen = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("folder-documents"), tr("Open")); - actOpenContainingFolder = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("inode-directory"), tr("Open Containing Folder")); - actRename = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename...")); - myFilesLlistMenu.addSeparator(); + actOpen = myFilesListMenu.addAction(GuiIconProvider::instance()->getIcon("folder-documents"), tr("Open")); + actOpenContainingFolder = myFilesListMenu.addAction(GuiIconProvider::instance()->getIcon("inode-directory"), tr("Open Containing Folder")); + actRename = myFilesListMenu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename...")); + myFilesListMenu.addSeparator(); } QMenu subMenu; if (!m_torrent->isSeed()) { @@ -593,15 +593,22 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &) subMenu.addAction(m_ui->actionNormal); subMenu.addAction(m_ui->actionHigh); subMenu.addAction(m_ui->actionMaximum); - myFilesLlistMenu.addMenu(&subMenu); + myFilesListMenu.addMenu(&subMenu); } - // Call menu - const QAction *act = myFilesLlistMenu.exec(QCursor::pos()); + // The selected torrent might have disappeared during exec() - // from the current view thus leaving invalid indices. - const QModelIndex index = *(selectedRows.begin()); - if (!index.isValid() || !act) return; + // so we just close menu when an appropriate model is reset + connect(m_ui->filesList->model(), &QAbstractItemModel::modelAboutToBeReset + , &myFilesListMenu, [&myFilesListMenu]() + { + myFilesListMenu.setActiveAction(nullptr); + myFilesListMenu.close(); + }); + // Call menu + const QAction *act = myFilesListMenu.exec(QCursor::pos()); + if (!act) return; + const QModelIndex index = selectedRows[0]; if (act == actOpen) { openDoubleClickedFile(index); }