From 208f2b1158a05b7dcc13b689eefb0bb88c8a72e3 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Mon, 13 Jun 2016 21:07:14 +0200 Subject: [PATCH] ui: Changed full text search character to ? and added shortcut CTRL+SHIFT+F --- .../component/controller/SearchController.cpp | 16 ++++++----- src/lib/component/view/SearchView.h | 3 +++ src/lib/data/search/SearchMatch.h | 2 ++ src/lib/utility/messaging/type/MessageFind.h | 8 ++++-- src/lib_gui/qt/element/QtSearchBar.cpp | 5 ++++ src/lib_gui/qt/element/QtSearchBar.h | 1 + src/lib_gui/qt/element/QtSmartSearchBox.cpp | 27 +++++++++++-------- src/lib_gui/qt/element/QtSmartSearchBox.h | 1 + src/lib_gui/qt/view/QtSearchView.cpp | 12 +++++++++ src/lib_gui/qt/view/QtSearchView.h | 3 +++ src/lib_gui/qt/window/QtMainWindow.cpp | 10 ++++++- src/lib_gui/qt/window/QtMainWindow.h | 1 + 12 files changed, 69 insertions(+), 20 deletions(-) diff --git a/src/lib/component/controller/SearchController.cpp b/src/lib/component/controller/SearchController.cpp index 7095dbd9..1de18c68 100644 --- a/src/lib/component/controller/SearchController.cpp +++ b/src/lib/component/controller/SearchController.cpp @@ -47,7 +47,14 @@ void SearchController::handleMessage(MessageActivateTokens* message) void SearchController::handleMessage(MessageFind* message) { - getView()->setFocus(); + if (message->findFulltext) + { + getView()->findFulltext(); + } + else + { + getView()->setFocus(); + } } void SearchController::handleMessage(MessageSearchAutocomplete* message) @@ -59,11 +66,8 @@ void SearchController::handleMessage(MessageSearchAutocomplete* message) void SearchController::handleMessage(MessageSearchFullText* message) { LOG_INFO("fulltext string: \"" + message->searchTerm + "\""); - std::string prefix = "@"; - if (message->caseSensitive) - { - prefix += "@"; - } + std::string prefix(message->caseSensitive ? 2 : 1, SearchMatch::FULLTEXT_SEARCH_CHARACTER); + SearchMatch match(prefix + message->searchTerm); match.searchType = SearchMatch::SEARCH_FULLTEXT; getView()->setMatches(std::vector(1, match)); diff --git a/src/lib/component/view/SearchView.h b/src/lib/component/view/SearchView.h index 7fbe0103..574c01ab 100644 --- a/src/lib/component/view/SearchView.h +++ b/src/lib/component/view/SearchView.h @@ -16,7 +16,10 @@ public: virtual std::string getName() const; virtual void setMatches(const std::vector& matches) = 0; + virtual void setFocus() = 0; + virtual void findFulltext() = 0; + virtual void setAutocompletionList(const std::vector& autocompletionList) = 0; protected: diff --git a/src/lib/data/search/SearchMatch.h b/src/lib/data/search/SearchMatch.h index dee361ae..a6150b2f 100644 --- a/src/lib/data/search/SearchMatch.h +++ b/src/lib/data/search/SearchMatch.h @@ -34,6 +34,8 @@ struct SearchMatch static SearchMatch createCommand(CommandType type); static std::string getCommandName(CommandType type); + static const char FULLTEXT_SEARCH_CHARACTER = '?'; + SearchMatch(); SearchMatch(const std::string& query); diff --git a/src/lib/utility/messaging/type/MessageFind.h b/src/lib/utility/messaging/type/MessageFind.h index 3d3b2b37..3a542415 100644 --- a/src/lib/utility/messaging/type/MessageFind.h +++ b/src/lib/utility/messaging/type/MessageFind.h @@ -4,10 +4,12 @@ #include "utility/messaging/Message.h" #include "utility/types.h" -class MessageFind: public Message +class MessageFind + : public Message { public: - MessageFind() + MessageFind(bool fulltext = false) + : findFulltext(fulltext) { } @@ -15,6 +17,8 @@ public: { return "MessageFind"; } + + bool findFulltext; }; #endif // MESSAGE_FIND_H diff --git a/src/lib_gui/qt/element/QtSearchBar.cpp b/src/lib_gui/qt/element/QtSearchBar.cpp index a2fef5e0..fbea62e6 100644 --- a/src/lib_gui/qt/element/QtSearchBar.cpp +++ b/src/lib_gui/qt/element/QtSearchBar.cpp @@ -77,6 +77,11 @@ void QtSearchBar::setFocus() m_searchBox->setFocus(); } +void QtSearchBar::findFulltext() +{ + m_searchBox->findFulltext(); +} + void QtSearchBar::setAutocompletionList(const std::vector& autocompletionList) { m_searchBox->setAutocompletionList(autocompletionList); diff --git a/src/lib_gui/qt/element/QtSearchBar.h b/src/lib_gui/qt/element/QtSearchBar.h index e06cb68d..32f66729 100644 --- a/src/lib_gui/qt/element/QtSearchBar.h +++ b/src/lib_gui/qt/element/QtSearchBar.h @@ -24,6 +24,7 @@ public: void setMatches(const std::vector& matches); void setFocus(); + void findFulltext(); void setAutocompletionList(const std::vector& autocompletionList); QAbstractItemView* getCompleterPopup(); diff --git a/src/lib_gui/qt/element/QtSmartSearchBox.cpp b/src/lib_gui/qt/element/QtSmartSearchBox.cpp index 0dc4bd3a..f5ceb895 100644 --- a/src/lib_gui/qt/element/QtSmartSearchBox.cpp +++ b/src/lib_gui/qt/element/QtSmartSearchBox.cpp @@ -37,25 +37,21 @@ void QtSmartSearchBox::search() std::vector matches = utility::toVector(m_matches); - LOG_INFO_STREAM(<< "Search query: " << SearchMatch::searchMatchesToString(matches) << text().toStdString()); - MessageSearch(matches).dispatch(); } void QtSmartSearchBox::fullTextSearch() { std::string term = text().toStdString().substr(1); - if (term.at(0) == '@') + bool caseSensitive = false; + + if (term.at(0) == SearchMatch::FULLTEXT_SEARCH_CHARACTER) { term = term.substr(1); - LOG_INFO_STREAM(<< "FullTextsearch(case sensitive): " << term); - MessageSearchFullText(term, true).dispatch(); - } - else - { - LOG_INFO_STREAM(<< "FullTextsearch: " << term); - MessageSearchFullText(term).dispatch(); + caseSensitive = true; } + + MessageSearchFullText(term, caseSensitive).dispatch(); } QtSmartSearchBox::QtSmartSearchBox(QWidget* parent) @@ -126,6 +122,15 @@ void QtSmartSearchBox::setFocus() layoutElements(); } +void QtSmartSearchBox::findFulltext() +{ + QLineEdit::setFocus(Qt::ShortcutFocusReason); + selectAllElementsWith(true); + deleteSelectedElements(); + + setEditText(QChar(SearchMatch::FULLTEXT_SEARCH_CHARACTER)); +} + bool QtSmartSearchBox::event(QEvent *event) { if (event->type() == QEvent::KeyPress) @@ -160,7 +165,7 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event) if (event->key() == Qt::Key_Return) { - if (text().startsWith('@')) + if (text().startsWith(SearchMatch::FULLTEXT_SEARCH_CHARACTER)) { fullTextSearch(); return; diff --git a/src/lib_gui/qt/element/QtSmartSearchBox.h b/src/lib_gui/qt/element/QtSmartSearchBox.h index d5eb1013..1e2be618 100644 --- a/src/lib_gui/qt/element/QtSmartSearchBox.h +++ b/src/lib_gui/qt/element/QtSmartSearchBox.h @@ -41,6 +41,7 @@ public: void setAutocompletionList(const std::vector& autocompletionList); void setMatches(const std::vector& matches); void setFocus(); + void findFulltext(); protected: virtual bool event(QEvent *event); diff --git a/src/lib_gui/qt/view/QtSearchView.cpp b/src/lib_gui/qt/view/QtSearchView.cpp index c0a8ea4b..5ff1a94f 100644 --- a/src/lib_gui/qt/view/QtSearchView.cpp +++ b/src/lib_gui/qt/view/QtSearchView.cpp @@ -12,6 +12,7 @@ QtSearchView::QtSearchView(ViewLayout* viewLayout) , m_refreshViewFunctor(std::bind(&QtSearchView::doRefreshView, this)) , m_setMatchesFunctor(std::bind(&QtSearchView::doSetMatches, this, std::placeholders::_1)) , m_setFocusFunctor(std::bind(&QtSearchView::doSetFocus, this)) + , m_findFulltextFunctor(std::bind(&QtSearchView::doFindFulltext, this)) , m_setAutocompletionListFunctor(std::bind(&QtSearchView::doSetAutocompletionList, this, std::placeholders::_1)) { m_widget = new QtSearchBar(); @@ -46,6 +47,11 @@ void QtSearchView::setFocus() m_setFocusFunctor(); } +void QtSearchView::findFulltext() +{ + m_findFulltextFunctor(); +} + void QtSearchView::setAutocompletionList(const std::vector& autocompletionList) { m_setAutocompletionListFunctor(autocompletionList); @@ -69,6 +75,12 @@ void QtSearchView::doSetFocus() m_widget->setFocus(); } +void QtSearchView::doFindFulltext() +{ + getViewLayout()->showView(this); + m_widget->findFulltext(); +} + void QtSearchView::doSetAutocompletionList(const std::vector& autocompletionList) { m_widget->setAutocompletionList(autocompletionList); diff --git a/src/lib_gui/qt/view/QtSearchView.h b/src/lib_gui/qt/view/QtSearchView.h index 20482fa5..8085f17c 100644 --- a/src/lib_gui/qt/view/QtSearchView.h +++ b/src/lib_gui/qt/view/QtSearchView.h @@ -21,12 +21,14 @@ public: // SearchView implementation virtual void setMatches(const std::vector& matches); virtual void setFocus(); + virtual void findFulltext(); virtual void setAutocompletionList(const std::vector& autocompletionList); private: void doRefreshView(); void doSetMatches(const std::vector& matches); void doSetFocus(); + void doFindFulltext(); void doSetAutocompletionList(const std::vector& autocompletionList); void setStyleSheet(); @@ -34,6 +36,7 @@ private: QtThreadedFunctor<> m_refreshViewFunctor; QtThreadedFunctor&> m_setMatchesFunctor; QtThreadedFunctor<> m_setFocusFunctor; + QtThreadedFunctor<> m_findFulltextFunctor; QtThreadedFunctor&> m_setAutocompletionListFunctor; QtSearchBar* m_widget; diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index 1e5ef435..6795f885 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -406,6 +406,11 @@ void QtMainWindow::find() MessageFind().dispatch(); } +void QtMainWindow::findFulltext() +{ + MessageFind(true).dispatch(); +} + void QtMainWindow::overview() { MessageSearch(std::vector(1, SearchMatch::createCommand(SearchMatch::COMMAND_ALL))).dispatch(); @@ -600,7 +605,10 @@ void QtMainWindow::setupEditMenu() } } - menu->addAction(tr("&Find"), this, SLOT(find()), QKeySequence::Find); + menu->addSeparator(); + + menu->addAction(tr("&Find Symbol"), this, SLOT(find()), QKeySequence::Find); + menu->addAction(tr("&Find Text"), this, SLOT(findFulltext()), QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_F)); menu->addSeparator(); diff --git a/src/lib_gui/qt/window/QtMainWindow.h b/src/lib_gui/qt/window/QtMainWindow.h index c2ef3a1b..aae64cc4 100644 --- a/src/lib_gui/qt/window/QtMainWindow.h +++ b/src/lib_gui/qt/window/QtMainWindow.h @@ -111,6 +111,7 @@ public slots: void openRecentProject(); void find(); + void findFulltext(); void overview(); void closeWindow();