Prevent context menu options from disabling with keyboard navigation

* Fixes #2838
* When navigating the entry context menu with up/down arrow the options would disable due to losing focus on the EntryView. This change preserves the "focus" during this event.
This commit is contained in:
Jonathan White 2019-05-30 17:28:47 -04:00
parent 3d5879b8ed
commit 91283e7c76
2 changed files with 14 additions and 2 deletions

View File

@ -253,6 +253,9 @@ MainWindow::MainWindow()
m_ui->actionEntryCopyURL->setShortcutVisibleInContextMenu(true);
#endif
connect(m_ui->menuEntries, SIGNAL(aboutToHide()), SLOT(releaseContextFocusLock()));
connect(m_ui->menuGroups, SIGNAL(aboutToHide()), SLOT(releaseContextFocusLock()));
// Control window state
new QShortcut(Qt::CTRL + Qt::Key_M, this, SLOT(showMinimized()));
new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_M, this, SLOT(hideWindow()));
@ -543,8 +546,8 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
switch (mode) {
case DatabaseWidget::Mode::ViewMode: {
// bool inSearch = dbWidget->isInSearchMode();
bool singleEntrySelected = dbWidget->numberOfSelectedEntries() == 1 && dbWidget->currentEntryHasFocus();
bool entriesSelected = dbWidget->numberOfSelectedEntries() > 0 && dbWidget->currentEntryHasFocus();
bool singleEntrySelected = dbWidget->numberOfSelectedEntries() == 1 && (m_contextMenuFocusLock || dbWidget->currentEntryHasFocus());
bool entriesSelected = dbWidget->numberOfSelectedEntries() > 0 && (m_contextMenuFocusLock || dbWidget->currentEntryHasFocus());
bool groupSelected = dbWidget->isGroupSelected();
bool recycleBinSelected = dbWidget->isRecycleBinSelected();
@ -985,13 +988,20 @@ void MainWindow::updateTrayIcon()
}
}
void MainWindow::releaseContextFocusLock()
{
m_contextMenuFocusLock = false;
}
void MainWindow::showEntryContextMenu(const QPoint& globalPos)
{
m_contextMenuFocusLock = true;
m_ui->menuEntries->popup(globalPos);
}
void MainWindow::showGroupContextMenu(const QPoint& globalPos)
{
m_contextMenuFocusLock = true;
m_ui->menuGroups->popup(globalPos);
}

View File

@ -117,6 +117,7 @@ private slots:
void selectPreviousDatabaseTab();
void togglePasswordsHidden();
void toggleUsernamesHidden();
void releaseContextFocusLock();
private:
static void setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback = 0);
@ -148,6 +149,7 @@ private:
bool m_appExitCalled;
bool m_appExiting;
bool m_contextMenuFocusLock;
uint m_lastFocusOutTime;
QTimer m_trayIconTriggerTimer;
QSystemTrayIcon::ActivationReason m_trayIconTriggerReason;