diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index cc9c5fd18..dd63b4df2 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -702,14 +702,12 @@ void DatabaseWidget::switchToImportKeepass1(const QString& fileName) setCurrentWidget(m_keepass1OpenWidget); } -void DatabaseWidget::toggleSearch() +void DatabaseWidget::openSearch() { if (isInSearchMode()) { - if (m_searchUi->searchEdit->hasFocus()) { - closeSearch(); - } - else { - m_searchUi->searchEdit->selectAll(); + m_searchUi->searchEdit->selectAll(); + + if (!m_searchUi->searchEdit->hasFocus()) { m_searchUi->searchEdit->setFocus(); // make sure the search action is checked again emitCurrentModeChanged(); diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index cbab175e4..45de74629 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -117,7 +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 toggleSearch(); + void openSearch(); private Q_SLOTS: void entryActivationSignalReceived(Entry* entry, EntryModel::ModelColumn column); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index dd77989c3..d48d09500 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -201,7 +201,7 @@ MainWindow::MainWindow() connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog())); m_actionMultiplexer.connect(m_ui->actionSearch, SIGNAL(triggered()), - SLOT(toggleSearch())); + SLOT(openSearch())); updateTrayIcon(); } @@ -295,9 +295,8 @@ 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->actionChangeMasterKey->setEnabled(true); m_ui->actionChangeDatabaseSettings->setEnabled(true); m_ui->actionDatabaseSave->setEnabled(true); @@ -321,7 +320,6 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->menuEntryCopyAttribute->setEnabled(false); m_ui->actionSearch->setEnabled(false); - m_ui->actionSearch->setChecked(false); m_ui->actionChangeMasterKey->setEnabled(false); m_ui->actionChangeDatabaseSettings->setEnabled(false); m_ui->actionDatabaseSave->setEnabled(false); @@ -348,7 +346,6 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->menuEntryCopyAttribute->setEnabled(false); m_ui->actionSearch->setEnabled(false); - m_ui->actionSearch->setChecked(false); m_ui->actionChangeMasterKey->setEnabled(false); m_ui->actionChangeDatabaseSettings->setEnabled(false); m_ui->actionDatabaseSave->setEnabled(false); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 13c5d6796..09e1c412e 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -304,9 +304,6 @@ - - true - false diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 326c3497b..26c8be077 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -170,20 +170,35 @@ void TestGui::testSearch() QVERIFY(searchAction->isEnabled()); QToolBar* toolBar = m_mainWindow->findChild("toolBar"); QWidget* searchActionWidget = toolBar->widgetForAction(searchAction); - QVERIFY(searchActionWidget->isEnabled()); - QTest::mouseClick(searchActionWidget, Qt::LeftButton); - EntryView* entryView = m_dbWidget->findChild("entryView"); QLineEdit* searchEdit = m_dbWidget->findChild("searchEdit"); QToolButton* clearSearch = m_dbWidget->findChild("clearButton"); + QVERIFY(!searchEdit->hasFocus()); + + // Enter search + QTest::mouseClick(searchActionWidget, 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()); + // Enter search again + QTest::mouseClick(searchActionWidget, 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("")); + // Triggering search should select the existing text + QTest::keyClicks(searchEdit, "ZZZ"); + QTest::mouseClick(searchActionWidget, Qt::LeftButton); + 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);