Browse Source

Close context menu when content model is reset

Closes #9522.
adaptive-webui-19844
Vladimir Golovnev (Glassez) 6 years ago
parent
commit
5a86c4ac52
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 29
      src/gui/properties/propertieswidget.cpp

29
src/gui/properties/propertieswidget.cpp

@ -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() // The selected torrent might have disappeared during exec()
// from the current view thus leaving invalid indices. // so we just close menu when an appropriate model is reset
const QModelIndex index = *(selectedRows.begin()); connect(m_ui->filesList->model(), &QAbstractItemModel::modelAboutToBeReset
if (!index.isValid() || !act) return; , &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);
} }

Loading…
Cancel
Save