diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 248c962f..552e589b 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -3177,11 +3177,14 @@ void VMainWindow::initUniversalEntry() VSearchUE *searchUE = new VSearchUE(this); m_ue->registerEntry('q', searchUE, VSearchUE::Name_FolderNote_AllNotebook); m_ue->registerEntry('a', searchUE, VSearchUE::Content_Note_AllNotebook); + m_ue->registerEntry('z', searchUE, VSearchUE::Tag_Note_AllNotebook); m_ue->registerEntry('w', searchUE, VSearchUE::Name_Notebook_AllNotebook); m_ue->registerEntry('e', searchUE, VSearchUE::Name_FolderNote_CurrentNotebook); m_ue->registerEntry('d', searchUE, VSearchUE::Content_Note_CurrentNotebook); + m_ue->registerEntry('c', searchUE, VSearchUE::Tag_Note_CurrentNotebook); m_ue->registerEntry('r', searchUE, VSearchUE::Name_FolderNote_CurrentFolder); m_ue->registerEntry('f', searchUE, VSearchUE::Content_Note_CurrentFolder); + m_ue->registerEntry('v', searchUE, VSearchUE::Tag_Note_CurrentFolder); m_ue->registerEntry('t', searchUE, VSearchUE::Name_Note_Buffer); m_ue->registerEntry('g', searchUE, VSearchUE::Content_Note_Buffer); m_ue->registerEntry('b', searchUE, VSearchUE::Outline_Note_Buffer); diff --git a/src/vsearch.cpp b/src/vsearch.cpp index 319ba891..5ca34888 100644 --- a/src/vsearch.cpp +++ b/src/vsearch.cpp @@ -183,6 +183,14 @@ void VSearch::searchFirstPhase(VFile *p_file, } } + if (testObject(VSearchConfig::Tag)) { + VSearchResultItem *item = searchForTag(p_file); + if (item) { + QSharedPointer pitem(item); + emit resultItemAdded(pitem); + } + } + if (testObject(VSearchConfig::Content)) { // Search content in first phase. if (p_searchContent) { @@ -349,6 +357,30 @@ VSearchResultItem *VSearch::searchForOutline(const VFile *p_file) const return item; } +VSearchResultItem *VSearch::searchForTag(const VFile *p_file) const +{ + if (p_file->getType() != FileType::Note) { + return NULL; + } + + const VNoteFile *file = static_cast(p_file); + const QStringList &tags = file->getTags(); + for (auto const & tag: tags) { + if (tag.isEmpty()) { + continue; + } + + if (matchNonContent(tag)) { + return new VSearchResultItem(VSearchResultItem::Note, + VSearchResultItem::LineNumber, + file->getName(), + file->fetchPath()); + } + } + + return NULL; +} + VSearchResultItem *VSearch::searchForContent(const VFile *p_file) const { Q_ASSERT(p_file->isOpened()); diff --git a/src/vsearch.h b/src/vsearch.h index fafed4a4..c71f0e2e 100644 --- a/src/vsearch.h +++ b/src/vsearch.h @@ -72,6 +72,8 @@ private: VSearchResultItem *searchForOutline(const VFile *p_file) const; + VSearchResultItem *searchForTag(const VFile *p_file) const; + VSearchResultItem *searchForContent(const VFile *p_file) const; void searchSecondPhase(const QSharedPointer &p_result); diff --git a/src/vsearcher.cpp b/src/vsearcher.cpp index 3f6135ce..ed09121c 100644 --- a/src/vsearcher.cpp +++ b/src/vsearcher.cpp @@ -248,6 +248,7 @@ void VSearcher::initUIFields() // Object. m_searchObjectCB->addItem(tr("Name"), VSearchConfig::Name); m_searchObjectCB->addItem(tr("Content"), VSearchConfig::Content); + m_searchObjectCB->addItem(tr("Tag"), VSearchConfig::Tag); m_searchObjectCB->setCurrentIndex(m_searchObjectCB->findData(config.m_object)); // Target. diff --git a/src/vsearchue.cpp b/src/vsearchue.cpp index 2d5cee5c..eaea5ef7 100644 --- a/src/vsearchue.cpp +++ b/src/vsearchue.cpp @@ -45,18 +45,27 @@ QString VSearchUE::description(int p_id) const case ID::Content_Note_AllNotebook: return tr("Search the content of notes in all the notebooks"); + case ID::Tag_Note_AllNotebook: + return tr("Search the tags of notes in all the notebooks"); + case ID::Name_FolderNote_CurrentNotebook: return tr("Search the name of folders/notes in current notebook"); case ID::Content_Note_CurrentNotebook: return tr("Search the content of notes in current notebook"); + case ID::Tag_Note_CurrentNotebook: + return tr("Search the tags of notes in current notebook"); + case ID::Name_FolderNote_CurrentFolder: return tr("Search the name of folders/notes in current folder"); case ID::Content_Note_CurrentFolder: return tr("Search the content of notes in current folder"); + case ID::Tag_Note_CurrentFolder: + return tr("Search the tags of notes in current folder"); + case ID::Name_Note_Buffer: return tr("List and search the name of opened notes in buffer"); @@ -124,9 +133,12 @@ QWidget *VSearchUE::widget(int p_id) switch (p_id) { case ID::Name_Notebook_AllNotebook: + case ID::Tag_Note_AllNotebook: case ID::Name_FolderNote_AllNotebook: case ID::Name_FolderNote_CurrentNotebook: + case ID::Tag_Note_CurrentNotebook: case ID::Name_FolderNote_CurrentFolder: + case ID::Tag_Note_CurrentFolder: case ID::Name_Note_Buffer: case ID::Path_FolderNote_AllNotebook: case ID::Path_FolderNote_CurrentNotebook: @@ -165,6 +177,10 @@ void VSearchUE::processCommand(int p_id, const QString &p_cmd) searchNameOfFolderNoteInAllNotebooks(p_cmd); break; + case ID::Tag_Note_AllNotebook: + searchTagOfNoteInAllNotebooks(p_cmd); + break; + case ID::Content_Note_AllNotebook: searchContentOfNoteInAllNotebooks(p_cmd); break; @@ -177,6 +193,10 @@ void VSearchUE::processCommand(int p_id, const QString &p_cmd) searchContentOfNoteInCurrentNotebook(p_cmd); break; + case ID::Tag_Note_CurrentNotebook: + searchTagOfNoteInCurrentNotebook(p_cmd); + break; + case ID::Name_FolderNote_CurrentFolder: searchNameOfFolderNoteInCurrentFolder(p_cmd); break; @@ -185,6 +205,10 @@ void VSearchUE::processCommand(int p_id, const QString &p_cmd) searchContentOfNoteInCurrentFolder(p_cmd); break; + case ID::Tag_Note_CurrentFolder: + searchTagOfNoteInCurrentFolder(p_cmd); + break; + case ID::Name_Note_Buffer: searchNameOfBuffer(p_cmd); break; @@ -282,6 +306,69 @@ void VSearchUE::searchNameOfFolderNoteInAllNotebooks(const QString &p_cmd) } } +void VSearchUE::searchTagOfNoteInAllNotebooks(const QString &p_cmd) +{ + if (p_cmd.isEmpty()) { + m_inSearch = false; + emit stateUpdated(State::Success); + } else { + m_search->clear(); + QSharedPointer config(new VSearchConfig(VSearchConfig::AllNotebooks, + VSearchConfig::Tag, + VSearchConfig::Note, + VSearchConfig::Internal, + VSearchConfig::NoneOption, + p_cmd, + QString())); + m_search->setConfig(config); + QSharedPointer result = m_search->search(g_vnote->getNotebooks()); + handleSearchFinished(result); + } +} + +void VSearchUE::searchTagOfNoteInCurrentNotebook(const QString &p_cmd) +{ + if (p_cmd.isEmpty()) { + m_inSearch = false; + emit stateUpdated(State::Success); + } else { + QVector notebooks; + notebooks.append(g_mainWin->getNotebookSelector()->currentNotebook()); + m_search->clear(); + QSharedPointer config(new VSearchConfig(VSearchConfig::CurrentNotebook, + VSearchConfig::Tag, + VSearchConfig::Note, + VSearchConfig::Internal, + VSearchConfig::NoneOption, + p_cmd, + QString())); + m_search->setConfig(config); + QSharedPointer result = m_search->search(notebooks); + handleSearchFinished(result); + } +} + +void VSearchUE::searchTagOfNoteInCurrentFolder(const QString &p_cmd) +{ + if (p_cmd.isEmpty()) { + m_inSearch = false; + emit stateUpdated(State::Success); + } else { + VDirectory *dir = g_mainWin->getDirectoryTree()->currentDirectory(); + m_search->clear(); + QSharedPointer config(new VSearchConfig(VSearchConfig::CurrentFolder, + VSearchConfig::Tag, + VSearchConfig::Note, + VSearchConfig::Internal, + VSearchConfig::NoneOption, + p_cmd, + QString())); + m_search->setConfig(config); + QSharedPointer result = m_search->search(dir); + handleSearchFinished(result); + } +} + void VSearchUE::searchContentOfNoteInAllNotebooks(const QString &p_cmd) { if (p_cmd.isEmpty()) { @@ -532,8 +619,11 @@ void VSearchUE::handleSearchItemAdded(const QSharedPointer &p switch (m_id) { case ID::Name_Notebook_AllNotebook: case ID::Name_FolderNote_AllNotebook: + case ID::Tag_Note_AllNotebook: case ID::Name_FolderNote_CurrentNotebook: + case ID::Tag_Note_CurrentNotebook: case ID::Name_FolderNote_CurrentFolder: + case ID::Tag_Note_CurrentFolder: case ID::Name_Note_Buffer: case ID::Path_FolderNote_AllNotebook: case ID::Path_FolderNote_CurrentNotebook: @@ -573,8 +663,11 @@ void VSearchUE::handleSearchItemsAdded(const QList