mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
UniversalEntry: support searching tags
- z: search tags of notes in all notebooks; - c: search tags of notes in current notebook; - v: search tags of notes in current folder;
This commit is contained in:
parent
ffd653ef55
commit
f94169053e
@ -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);
|
||||
|
@ -183,6 +183,14 @@ void VSearch::searchFirstPhase(VFile *p_file,
|
||||
}
|
||||
}
|
||||
|
||||
if (testObject(VSearchConfig::Tag)) {
|
||||
VSearchResultItem *item = searchForTag(p_file);
|
||||
if (item) {
|
||||
QSharedPointer<VSearchResultItem> 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<const VNoteFile *>(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());
|
||||
|
@ -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<VSearchResult> &p_result);
|
||||
|
@ -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.
|
||||
|
@ -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<VSearchConfig> config(new VSearchConfig(VSearchConfig::AllNotebooks,
|
||||
VSearchConfig::Tag,
|
||||
VSearchConfig::Note,
|
||||
VSearchConfig::Internal,
|
||||
VSearchConfig::NoneOption,
|
||||
p_cmd,
|
||||
QString()));
|
||||
m_search->setConfig(config);
|
||||
QSharedPointer<VSearchResult> 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<VNotebook *> notebooks;
|
||||
notebooks.append(g_mainWin->getNotebookSelector()->currentNotebook());
|
||||
m_search->clear();
|
||||
QSharedPointer<VSearchConfig> config(new VSearchConfig(VSearchConfig::CurrentNotebook,
|
||||
VSearchConfig::Tag,
|
||||
VSearchConfig::Note,
|
||||
VSearchConfig::Internal,
|
||||
VSearchConfig::NoneOption,
|
||||
p_cmd,
|
||||
QString()));
|
||||
m_search->setConfig(config);
|
||||
QSharedPointer<VSearchResult> 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<VSearchConfig> config(new VSearchConfig(VSearchConfig::CurrentFolder,
|
||||
VSearchConfig::Tag,
|
||||
VSearchConfig::Note,
|
||||
VSearchConfig::Internal,
|
||||
VSearchConfig::NoneOption,
|
||||
p_cmd,
|
||||
QString()));
|
||||
m_search->setConfig(config);
|
||||
QSharedPointer<VSearchResult> 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<VSearchResultItem> &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<QSharedPointer<VSearchResultI
|
||||
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:
|
||||
@ -831,8 +924,11 @@ void VSearchUE::selectNextItem(int p_id, bool p_forward)
|
||||
switch (p_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:
|
||||
@ -862,8 +958,11 @@ void VSearchUE::activate(int p_id)
|
||||
switch (p_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:
|
||||
@ -940,8 +1039,11 @@ void VSearchUE::sort(int p_id)
|
||||
switch (p_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:
|
||||
@ -990,8 +1092,11 @@ QString VSearchUE::currentItemFolder(int p_id)
|
||||
switch (p_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:
|
||||
|
@ -29,18 +29,27 @@ public:
|
||||
// Search content of the note in all the notebooks.
|
||||
Content_Note_AllNotebook,
|
||||
|
||||
// Search tag of the note in all the notebooks.
|
||||
Tag_Note_AllNotebook,
|
||||
|
||||
// Search the name of the folder/note in current notebook.
|
||||
Name_FolderNote_CurrentNotebook,
|
||||
|
||||
// Search content of the note in current notebook.
|
||||
Content_Note_CurrentNotebook,
|
||||
|
||||
// Search tag of the note in current notebook.
|
||||
Tag_Note_CurrentNotebook,
|
||||
|
||||
// Search the name of the folder/note in current folder.
|
||||
Name_FolderNote_CurrentFolder,
|
||||
|
||||
// Search content of the note in current folder.
|
||||
Content_Note_CurrentFolder,
|
||||
|
||||
// Search the tag of the note in current folder.
|
||||
Tag_Note_CurrentFolder,
|
||||
|
||||
// List and search the name of opened notes in buffer.
|
||||
Name_Note_Buffer,
|
||||
|
||||
@ -102,6 +111,12 @@ private:
|
||||
|
||||
void searchNameOfFolderNoteInAllNotebooks(const QString &p_cmd);
|
||||
|
||||
void searchTagOfNoteInAllNotebooks(const QString &p_cmd);
|
||||
|
||||
void searchTagOfNoteInCurrentNotebook(const QString &p_cmd);
|
||||
|
||||
void searchTagOfNoteInCurrentFolder(const QString &p_cmd);
|
||||
|
||||
void searchNameOfFolderNoteInCurrentNotebook(const QString &p_cmd);
|
||||
|
||||
void searchNameOfFolderNoteInCurrentFolder(const QString &p_cmd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user