Merge branch 'knu-untoggle_find'

https://github.com/keepassx/keepassx/pull/66
This commit is contained in:
Felix Geyer 2014-11-30 22:54:23 +01:00
commit 8fd69e084e
5 changed files with 28 additions and 21 deletions

View File

@ -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();
if (!m_searchUi->searchEdit->hasFocus()) {
m_searchUi->searchEdit->setFocus();
// make sure the search action is checked again
emitCurrentModeChanged();

View File

@ -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);

View File

@ -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);

View File

@ -304,9 +304,6 @@
</property>
</action>
<action name="actionSearch">
<property name="checkable">
<bool>true</bool>
</property>
<property name="enabled">
<bool>false</bool>
</property>

View File

@ -170,20 +170,35 @@ void TestGui::testSearch()
QVERIFY(searchAction->isEnabled());
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
QWidget* searchActionWidget = toolBar->widgetForAction(searchAction);
QVERIFY(searchActionWidget->isEnabled());
QTest::mouseClick(searchActionWidget, Qt::LeftButton);
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
QLineEdit* searchEdit = m_dbWidget->findChild<QLineEdit*>("searchEdit");
QToolButton* clearSearch = m_dbWidget->findChild<QToolButton*>("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);