mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Make Ctrl+F not toggle the search mode but always enable it.
Switching back from other applications, the previous behavior of Ctrl+F would often bother you in that it would dismiss the search widget if it was already enabled when you meant by the key you wanted to perform a search. Making Ctrl+F always set you in search mode should save user from having to care about the mode which is persistent across application switching and database locking.
This commit is contained in:
parent
57107ea560
commit
b1c3814972
@ -702,6 +702,22 @@ void DatabaseWidget::switchToImportKeepass1(const QString& fileName)
|
||||
setCurrentWidget(m_keepass1OpenWidget);
|
||||
}
|
||||
|
||||
void DatabaseWidget::openSearch()
|
||||
{
|
||||
if (isInSearchMode()) {
|
||||
m_searchUi->searchEdit->selectAll();
|
||||
|
||||
if (!m_searchUi->searchEdit->hasFocus()) {
|
||||
m_searchUi->searchEdit->setFocus();
|
||||
// make sure the search action is checked again
|
||||
emitCurrentModeChanged();
|
||||
}
|
||||
}
|
||||
else {
|
||||
showSearch();
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseWidget::toggleSearch()
|
||||
{
|
||||
if (isInSearchMode()) {
|
||||
|
@ -117,6 +117,7 @@ public Q_SLOTS:
|
||||
void switchToOpenDatabase(const QString& fileName);
|
||||
void switchToOpenDatabase(const QString& fileName, const QString& password, const QString& keyFile);
|
||||
void switchToImportKeepass1(const QString& fileName);
|
||||
void openSearch();
|
||||
void toggleSearch();
|
||||
|
||||
private Q_SLOTS:
|
||||
|
@ -119,7 +119,7 @@ MainWindow::MainWindow()
|
||||
|
||||
m_ui->actionAbout->setIcon(filePath()->icon("actions", "help-about"));
|
||||
|
||||
m_ui->actionSearch->setIcon(filePath()->icon("actions", "system-search"));
|
||||
m_ui->actionToggleSearch->setIcon(filePath()->icon("actions", "system-search"));
|
||||
|
||||
m_actionMultiplexer.connect(SIGNAL(currentModeChanged(DatabaseWidget::Mode)),
|
||||
this, SLOT(setMenuActionState(DatabaseWidget::Mode)));
|
||||
@ -200,8 +200,10 @@ MainWindow::MainWindow()
|
||||
|
||||
connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog()));
|
||||
|
||||
m_actionMultiplexer.connect(m_ui->actionSearch, SIGNAL(triggered()),
|
||||
m_actionMultiplexer.connect(m_ui->actionToggleSearch, SIGNAL(triggered()),
|
||||
SLOT(toggleSearch()));
|
||||
m_actionMultiplexer.connect(m_ui->actionSearch, SIGNAL(triggered()),
|
||||
SLOT(openSearch()));
|
||||
|
||||
updateTrayIcon();
|
||||
}
|
||||
@ -295,9 +297,10 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
|
||||
m_ui->actionGroupNew->setEnabled(groupSelected);
|
||||
m_ui->actionGroupEdit->setEnabled(groupSelected);
|
||||
m_ui->actionGroupDelete->setEnabled(groupSelected && dbWidget->canDeleteCurrentGroup());
|
||||
m_ui->actionSearch->setEnabled(true);
|
||||
// TODO: get checked state from db widget
|
||||
m_ui->actionSearch->setChecked(inSearch);
|
||||
m_ui->actionSearch->setEnabled(true);
|
||||
m_ui->actionToggleSearch->setEnabled(true);
|
||||
m_ui->actionToggleSearch->setChecked(inSearch);
|
||||
m_ui->actionChangeMasterKey->setEnabled(true);
|
||||
m_ui->actionChangeDatabaseSettings->setEnabled(true);
|
||||
m_ui->actionDatabaseSave->setEnabled(true);
|
||||
@ -321,7 +324,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
|
||||
m_ui->menuEntryCopyAttribute->setEnabled(false);
|
||||
|
||||
m_ui->actionSearch->setEnabled(false);
|
||||
m_ui->actionSearch->setChecked(false);
|
||||
m_ui->actionToggleSearch->setEnabled(false);
|
||||
m_ui->actionChangeMasterKey->setEnabled(false);
|
||||
m_ui->actionChangeDatabaseSettings->setEnabled(false);
|
||||
m_ui->actionDatabaseSave->setEnabled(false);
|
||||
@ -348,7 +351,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
|
||||
m_ui->menuEntryCopyAttribute->setEnabled(false);
|
||||
|
||||
m_ui->actionSearch->setEnabled(false);
|
||||
m_ui->actionSearch->setChecked(false);
|
||||
m_ui->actionToggleSearch->setEnabled(false);
|
||||
m_ui->actionChangeMasterKey->setEnabled(false);
|
||||
m_ui->actionChangeDatabaseSettings->setEnabled(false);
|
||||
m_ui->actionDatabaseSave->setEnabled(false);
|
||||
|
@ -177,7 +177,7 @@
|
||||
<addaction name="actionEntryCopyPassword"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionLockDatabases"/>
|
||||
<addaction name="actionSearch"/>
|
||||
<addaction name="actionToggleSearch"/>
|
||||
</widget>
|
||||
<action name="actionQuit">
|
||||
<property name="text">
|
||||
@ -304,6 +304,11 @@
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSearch">
|
||||
<property name="text">
|
||||
<string>Find</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionToggleSearch">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
@ -166,24 +166,39 @@ void TestGui::testAddEntry()
|
||||
|
||||
void TestGui::testSearch()
|
||||
{
|
||||
QAction* searchAction = m_mainWindow->findChild<QAction*>("actionSearch");
|
||||
QVERIFY(searchAction->isEnabled());
|
||||
QAction* toggleSearchAction = m_mainWindow->findChild<QAction*>("actionToggleSearch");
|
||||
QVERIFY(toggleSearchAction->isEnabled());
|
||||
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
||||
QWidget* searchActionWidget = toolBar->widgetForAction(searchAction);
|
||||
QVERIFY(searchActionWidget->isEnabled());
|
||||
QTest::mouseClick(searchActionWidget, Qt::LeftButton);
|
||||
|
||||
QWidget* toggleSearchActionWidget = toolBar->widgetForAction(toggleSearchAction);
|
||||
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
||||
QLineEdit* searchEdit = m_dbWidget->findChild<QLineEdit*>("searchEdit");
|
||||
QToolButton* clearSearch = m_dbWidget->findChild<QToolButton*>("clearButton");
|
||||
|
||||
QVERIFY(!searchEdit->hasFocus());
|
||||
|
||||
// Toggle
|
||||
QTest::mouseClick(toggleSearchActionWidget, Qt::LeftButton);
|
||||
QTRY_VERIFY(searchEdit->hasFocus());
|
||||
// Search for "ZZZ"
|
||||
QTest::keyClicks(searchEdit, "ZZZ");
|
||||
|
||||
QTRY_COMPARE(entryView->model()->rowCount(), 0);
|
||||
|
||||
// Escape
|
||||
QTest::keyClick(m_mainWindow, Qt::Key_Escape);
|
||||
QTRY_VERIFY(!searchEdit->hasFocus());
|
||||
// Toggle again
|
||||
QTest::mouseClick(toggleSearchActionWidget, Qt::LeftButton);
|
||||
QTRY_VERIFY(searchEdit->hasFocus());
|
||||
// Input and clear
|
||||
QTest::keyClicks(searchEdit, "ZZZ");
|
||||
QTRY_COMPARE(searchEdit->text(), QString("ZZZ"));
|
||||
QTest::mouseClick(clearSearch, Qt::LeftButton);
|
||||
QTRY_COMPARE(searchEdit->text(), QString(""));
|
||||
// Ctrl+F should select the current text
|
||||
QTest::keyClicks(searchEdit, "ZZZ");
|
||||
QTest::keyClick(m_mainWindow, Qt::Key_F, Qt::ControlModifier);
|
||||
QTRY_VERIFY(searchEdit->hasFocus());
|
||||
// Search for "some"
|
||||
QTest::keyClicks(searchEdit, "some");
|
||||
|
||||
QTRY_COMPARE(entryView->model()->rowCount(), 4);
|
||||
|
||||
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
|
||||
|
Loading…
Reference in New Issue
Block a user