Close context menu when content model is reset

Closes #9522.
This commit is contained in:
Vladimir Golovnev (Glassez) 2019-02-01 11:44:51 +03:00
parent 5c00d89d57
commit 5a86c4ac52
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7

View File

@ -576,15 +576,15 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
const QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0); const QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0);
if (selectedRows.empty()) return; if (selectedRows.empty()) return;
QMenu myFilesLlistMenu; QMenu myFilesListMenu;
QAction *actOpen = nullptr; QAction *actOpen = nullptr;
QAction *actOpenContainingFolder = nullptr; QAction *actOpenContainingFolder = nullptr;
QAction *actRename = nullptr; QAction *actRename = nullptr;
if (selectedRows.size() == 1) { if (selectedRows.size() == 1) {
actOpen = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("folder-documents"), tr("Open")); actOpen = myFilesListMenu.addAction(GuiIconProvider::instance()->getIcon("folder-documents"), tr("Open"));
actOpenContainingFolder = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("inode-directory"), tr("Open Containing Folder")); actOpenContainingFolder = myFilesListMenu.addAction(GuiIconProvider::instance()->getIcon("inode-directory"), tr("Open Containing Folder"));
actRename = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename...")); actRename = myFilesListMenu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename..."));
myFilesLlistMenu.addSeparator(); myFilesListMenu.addSeparator();
} }
QMenu subMenu; QMenu subMenu;
if (!m_torrent->isSeed()) { if (!m_torrent->isSeed()) {
@ -593,15 +593,22 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
subMenu.addAction(m_ui->actionNormal); subMenu.addAction(m_ui->actionNormal);
subMenu.addAction(m_ui->actionHigh); subMenu.addAction(m_ui->actionHigh);
subMenu.addAction(m_ui->actionMaximum); 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;
// The selected torrent might have disappeared during exec()
// 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) { if (act == actOpen) {
openDoubleClickedFile(index); openDoubleClickedFile(index);
} }