From 2ae742cc075df80313c0fa596c02b94c52845c6f Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 18 Jul 2018 20:05:27 +0800 Subject: [PATCH] UniversalEntry: U to search the content of notes in Explorer root directory --- src/vmainwindow.cpp | 1 + src/vsearchue.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/vsearchue.h | 7 ++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 6ced84a1..ff6009a4 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -3222,6 +3222,7 @@ void VMainWindow::initUniversalEntry() 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); + m_ue->registerEntry('u', searchUE, VSearchUE::Content_Note_ExplorerDirectory); m_ue->registerEntry('y', new VOutlineUE(this), 0); m_ue->registerEntry('h', searchUE, VSearchUE::Path_FolderNote_AllNotebook); m_ue->registerEntry('n', searchUE, VSearchUE::Path_FolderNote_CurrentNotebook); diff --git a/src/vsearchue.cpp b/src/vsearchue.cpp index eaea5ef7..f1324476 100644 --- a/src/vsearchue.cpp +++ b/src/vsearchue.cpp @@ -16,6 +16,7 @@ #include "vdirectory.h" #include "vdirectorytree.h" #include "veditarea.h" +#include "vexplorer.h" extern VNote *g_vnote; @@ -81,6 +82,9 @@ QString VSearchUE::description(int p_id) const case ID::Path_FolderNote_CurrentNotebook: return tr("Search the path of folders/notes in current notebook"); + case ID::Content_Note_ExplorerDirectory: + return tr("Search the content of notes in Explorer root directory"); + default: Q_ASSERT(false); return tr("Invalid ID %1").arg(p_id); @@ -147,6 +151,7 @@ QWidget *VSearchUE::widget(int p_id) case ID::Content_Note_AllNotebook: case ID::Content_Note_CurrentNotebook: case ID::Content_Note_CurrentFolder: + case ID::Content_Note_ExplorerDirectory: case ID::Content_Note_Buffer: case ID::Outline_Note_Buffer: return m_treeWidget; @@ -205,6 +210,10 @@ void VSearchUE::processCommand(int p_id, const QString &p_cmd) searchContentOfNoteInCurrentFolder(p_cmd); break; + case ID::Content_Note_ExplorerDirectory: + searchContentOfNoteInExplorerDirectory(p_cmd); + break; + case ID::Tag_Note_CurrentFolder: searchTagOfNoteInCurrentFolder(p_cmd); break; @@ -475,6 +484,27 @@ void VSearchUE::searchContentOfNoteInCurrentFolder(const QString &p_cmd) } } +void VSearchUE::searchContentOfNoteInExplorerDirectory(const QString &p_cmd) +{ + if (p_cmd.isEmpty()) { + m_inSearch = false; + emit stateUpdated(State::Success); + } else { + QString rootDirectory = g_mainWin->getExplorer()->getRootDirectory(); + m_search->clear(); + QSharedPointer config(new VSearchConfig(VSearchConfig::ExplorerDirectory, + VSearchConfig::Content, + VSearchConfig::Note, + VSearchConfig::Internal, + VSearchConfig::NoneOption, + p_cmd, + QString())); + m_search->setConfig(config); + QSharedPointer result = m_search->search(rootDirectory); + handleSearchFinished(result); + } +} + QVector getFilesInBuffer() { QVector tabs = g_mainWin->getEditArea()->getAllTabsInfo(); @@ -639,6 +669,7 @@ void VSearchUE::handleSearchItemAdded(const QSharedPointer &p case ID::Content_Note_AllNotebook: case ID::Content_Note_CurrentNotebook: case ID::Content_Note_CurrentFolder: + case ID::Content_Note_ExplorerDirectory: case ID::Content_Note_Buffer: case ID::Outline_Note_Buffer: appendItemToTree(p_item); @@ -684,6 +715,7 @@ void VSearchUE::handleSearchItemsAdded(const QListselectParentItem(); @@ -1016,6 +1051,7 @@ void VSearchUE::toggleItemExpanded(int p_id) case ID::Content_Note_AllNotebook: case ID::Content_Note_CurrentNotebook: case ID::Content_Note_CurrentFolder: + case ID::Content_Note_ExplorerDirectory: case ID::Content_Note_Buffer: case ID::Outline_Note_Buffer: { @@ -1112,6 +1148,7 @@ QString VSearchUE::currentItemFolder(int p_id) case ID::Content_Note_AllNotebook: case ID::Content_Note_CurrentNotebook: case ID::Content_Note_CurrentFolder: + case ID::Content_Note_ExplorerDirectory: case ID::Content_Note_Buffer: case ID::Outline_Note_Buffer: { diff --git a/src/vsearchue.h b/src/vsearchue.h index 7678456f..8a49e348 100644 --- a/src/vsearchue.h +++ b/src/vsearchue.h @@ -63,7 +63,10 @@ public: Path_FolderNote_AllNotebook, // Search path of folder/note in current notebook. - Path_FolderNote_CurrentNotebook + Path_FolderNote_CurrentNotebook, + + // Search content of the note in Explorer root directory. + Content_Note_ExplorerDirectory }; explicit VSearchUE(QObject *p_parent = nullptr); @@ -127,6 +130,8 @@ private: void searchContentOfNoteInCurrentFolder(const QString &p_cmd); + void searchContentOfNoteInExplorerDirectory(const QString &p_cmd); + void searchNameOfBuffer(const QString &p_cmd); void searchContentOfBuffer(const QString &p_cmd);