From b1c38149729d69a0c2abf916c43bc30db6b89493 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Tue, 18 Nov 2014 16:26:04 +0900 Subject: [PATCH 1/2] 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. --- src/gui/DatabaseWidget.cpp | 16 ++++++++++++++++ src/gui/DatabaseWidget.h | 1 + src/gui/MainWindow.cpp | 15 +++++++++------ src/gui/MainWindow.ui | 7 ++++++- tests/gui/TestGui.cpp | 33 ++++++++++++++++++++++++--------- 5 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index cc9c5fd18..df3214246 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -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()) { diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index cbab175e4..821a21d5b 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -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: diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index dd77989c3..1933ef4db 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -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); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 13c5d6796..838bb5f32 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -177,7 +177,7 @@ - + @@ -304,6 +304,11 @@ + + Find + + + true diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 326c3497b..592f57ecb 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -166,24 +166,39 @@ void TestGui::testAddEntry() void TestGui::testSearch() { - QAction* searchAction = m_mainWindow->findChild("actionSearch"); - QVERIFY(searchAction->isEnabled()); + QAction* toggleSearchAction = m_mainWindow->findChild("actionToggleSearch"); + QVERIFY(toggleSearchAction->isEnabled()); QToolBar* toolBar = m_mainWindow->findChild("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"); QLineEdit* searchEdit = m_dbWidget->findChild("searchEdit"); QToolButton* clearSearch = m_dbWidget->findChild("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); From dd79105baac83c13bb63e990489f6c66e26be308 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Wed, 19 Nov 2014 11:46:38 +0900 Subject: [PATCH 2/2] Complete remove the toggle search action. --- src/gui/DatabaseWidget.cpp | 18 ------------------ src/gui/DatabaseWidget.h | 1 - src/gui/MainWindow.cpp | 8 +------- src/gui/MainWindow.ui | 10 +--------- tests/gui/TestGui.cpp | 18 +++++++++--------- 5 files changed, 11 insertions(+), 44 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index df3214246..dd63b4df2 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -718,24 +718,6 @@ void DatabaseWidget::openSearch() } } -void DatabaseWidget::toggleSearch() -{ - if (isInSearchMode()) { - if (m_searchUi->searchEdit->hasFocus()) { - closeSearch(); - } - else { - m_searchUi->searchEdit->selectAll(); - m_searchUi->searchEdit->setFocus(); - // make sure the search action is checked again - emitCurrentModeChanged(); - } - } - else { - showSearch(); - } -} - void DatabaseWidget::closeSearch() { Q_ASSERT(m_lastGroup); diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 821a21d5b..45de74629 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -118,7 +118,6 @@ public Q_SLOTS: void switchToOpenDatabase(const QString& fileName, const QString& password, const QString& keyFile); void switchToImportKeepass1(const QString& fileName); void openSearch(); - void toggleSearch(); private Q_SLOTS: void entryActivationSignalReceived(Entry* entry, EntryModel::ModelColumn column); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 1933ef4db..d48d09500 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -119,7 +119,7 @@ MainWindow::MainWindow() m_ui->actionAbout->setIcon(filePath()->icon("actions", "help-about")); - m_ui->actionToggleSearch->setIcon(filePath()->icon("actions", "system-search")); + m_ui->actionSearch->setIcon(filePath()->icon("actions", "system-search")); m_actionMultiplexer.connect(SIGNAL(currentModeChanged(DatabaseWidget::Mode)), this, SLOT(setMenuActionState(DatabaseWidget::Mode))); @@ -200,8 +200,6 @@ MainWindow::MainWindow() connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog())); - m_actionMultiplexer.connect(m_ui->actionToggleSearch, SIGNAL(triggered()), - SLOT(toggleSearch())); m_actionMultiplexer.connect(m_ui->actionSearch, SIGNAL(triggered()), SLOT(openSearch())); @@ -299,8 +297,6 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionGroupDelete->setEnabled(groupSelected && dbWidget->canDeleteCurrentGroup()); // TODO: get checked state from db widget 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); @@ -324,7 +320,6 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->menuEntryCopyAttribute->setEnabled(false); m_ui->actionSearch->setEnabled(false); - m_ui->actionToggleSearch->setEnabled(false); m_ui->actionChangeMasterKey->setEnabled(false); m_ui->actionChangeDatabaseSettings->setEnabled(false); m_ui->actionDatabaseSave->setEnabled(false); @@ -351,7 +346,6 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->menuEntryCopyAttribute->setEnabled(false); m_ui->actionSearch->setEnabled(false); - m_ui->actionToggleSearch->setEnabled(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 838bb5f32..09e1c412e 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -177,7 +177,7 @@ - + @@ -304,14 +304,6 @@ - - Find - - - - - true - false diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 592f57ecb..26c8be077 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -166,18 +166,18 @@ void TestGui::testAddEntry() void TestGui::testSearch() { - QAction* toggleSearchAction = m_mainWindow->findChild("actionToggleSearch"); - QVERIFY(toggleSearchAction->isEnabled()); + QAction* searchAction = m_mainWindow->findChild("actionSearch"); + QVERIFY(searchAction->isEnabled()); QToolBar* toolBar = m_mainWindow->findChild("toolBar"); - QWidget* toggleSearchActionWidget = toolBar->widgetForAction(toggleSearchAction); + QWidget* searchActionWidget = toolBar->widgetForAction(searchAction); EntryView* entryView = m_dbWidget->findChild("entryView"); QLineEdit* searchEdit = m_dbWidget->findChild("searchEdit"); QToolButton* clearSearch = m_dbWidget->findChild("clearButton"); QVERIFY(!searchEdit->hasFocus()); - // Toggle - QTest::mouseClick(toggleSearchActionWidget, Qt::LeftButton); + // Enter search + QTest::mouseClick(searchActionWidget, Qt::LeftButton); QTRY_VERIFY(searchEdit->hasFocus()); // Search for "ZZZ" QTest::keyClicks(searchEdit, "ZZZ"); @@ -185,17 +185,17 @@ void TestGui::testSearch() // Escape QTest::keyClick(m_mainWindow, Qt::Key_Escape); QTRY_VERIFY(!searchEdit->hasFocus()); - // Toggle again - QTest::mouseClick(toggleSearchActionWidget, Qt::LeftButton); + // 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("")); - // Ctrl+F should select the current text + // Triggering search should select the existing text QTest::keyClicks(searchEdit, "ZZZ"); - QTest::keyClick(m_mainWindow, Qt::Key_F, Qt::ControlModifier); + QTest::mouseClick(searchActionWidget, Qt::LeftButton); QTRY_VERIFY(searchEdit->hasFocus()); // Search for "some" QTest::keyClicks(searchEdit, "some");