support search tag in SearchPanel

This commit is contained in:
Le Tan 2021-10-30 08:14:51 +08:00
parent 964dfbb085
commit 8de8b0dda8
5 changed files with 32 additions and 22 deletions

View File

@ -57,6 +57,7 @@ namespace vnotex
ObjectNone = 0,
SearchName = 0x1UL,
SearchContent = 0x2UL,
// SearchOutline is not supported yet.
SearchOutline = 0x4UL,
SearchTag = 0x8UL,
SearchPath = 0x10UL

View File

@ -218,12 +218,10 @@ bool Searcher::firstPhaseSearch(const File *p_file)
}
}
if (testObject(SearchObject::SearchOutline)) {
emit logRequested(tr("Searching outline is not supported yet"));
}
if (testObject(SearchObject::SearchTag)) {
emit logRequested(tr("Searching tag is not supported yet"));
if (searchTag(p_file->getNode())) {
emit resultItemAdded(SearchResultItem::createBufferItem(filePath, relativePath));
}
}
// Make SearchContent always the last one to check.
@ -427,12 +425,10 @@ bool Searcher::firstPhaseSearch(Node *p_node, QVector<SearchSecondPhaseItem> &p_
}
}
if (testObject(SearchObject::SearchOutline)) {
emit logRequested(tr("Searching outline is not supported yet"));
}
if (testObject(SearchObject::SearchTag)) {
emit logRequested(tr("Searching tag is not supported yet"));
if (searchTag(p_node)) {
emit resultItemAdded(SearchResultItem::createBufferItem(filePath, relativePath));
}
}
if (testObject(SearchObject::SearchContent)) {
@ -518,3 +514,20 @@ const SearchToken &Searcher::getToken() const
{
return m_token;
}
bool Searcher::searchTag(const Node *p_node) const
{
if (!p_node) {
return false;
}
Q_ASSERT(p_node->isLoaded());
for (const auto &tag : p_node->getTags()) {
if (isTokenMatched(tag)) {
return true;
}
}
return false;
}

View File

@ -78,6 +78,9 @@ namespace vnotex
bool searchContent(const File *p_file);
// Return true if matched.
bool searchTag(const Node *p_node) const;
void createSearchEngine();
QSharedPointer<SearchOption> m_option;

View File

@ -169,14 +169,11 @@ void SearchPanel::setupSearchObject(QFormLayout *p_layout, QWidget *p_parent)
m_searchObjectContentCheckBox = WidgetsFactory::createCheckBox(tr("Content"), p_parent);
gridLayout->addWidget(m_searchObjectContentCheckBox, 0, 1);
m_searchObjectOutlineCheckBox = WidgetsFactory::createCheckBox(tr("Outline"), p_parent);
gridLayout->addWidget(m_searchObjectOutlineCheckBox, 1, 0);
m_searchObjectTagCheckBox = WidgetsFactory::createCheckBox(tr("Tag"), p_parent);
gridLayout->addWidget(m_searchObjectTagCheckBox, 1, 1);
gridLayout->addWidget(m_searchObjectTagCheckBox, 1, 0);
m_searchObjectPathCheckBox = WidgetsFactory::createCheckBox(tr("Path"), p_parent);
gridLayout->addWidget(m_searchObjectPathCheckBox, 2, 0);
gridLayout->addWidget(m_searchObjectPathCheckBox, 1, 1);
}
void SearchPanel::setupSearchTarget(QFormLayout *p_layout, QWidget *p_parent)
@ -256,7 +253,6 @@ void SearchPanel::restoreFields(const SearchOption &p_option)
{
m_searchObjectNameCheckBox->setChecked(p_option.m_objects & SearchObject::SearchName);
m_searchObjectContentCheckBox->setChecked(p_option.m_objects & SearchObject::SearchContent);
m_searchObjectOutlineCheckBox->setChecked(p_option.m_objects & SearchObject::SearchOutline);
m_searchObjectTagCheckBox->setChecked(p_option.m_objects & SearchObject::SearchTag);
m_searchObjectPathCheckBox->setChecked(p_option.m_objects & SearchObject::SearchPath);
}
@ -379,9 +375,6 @@ void SearchPanel::saveFields(SearchOption &p_option)
if (m_searchObjectContentCheckBox->isChecked()) {
p_option.m_objects |= SearchObject::SearchContent;
}
if (m_searchObjectOutlineCheckBox->isChecked()) {
p_option.m_objects |= SearchObject::SearchOutline;
}
if (m_searchObjectTagCheckBox->isChecked()) {
p_option.m_objects |= SearchObject::SearchTag;
}
@ -566,8 +559,10 @@ void SearchPanel::handleLocationActivated(const Location &p_location)
Q_ASSERT(m_searcher);
if (!m_searchTokenOfSession) {
if (m_option->m_objects & SearchObject::SearchContent) {
m_searchTokenOfSession = QSharedPointer<SearchToken>::create(m_searcher->getToken());
}
}
// TODO: decode the path of location and handle different types of destination.
auto paras = QSharedPointer<FileOpenParameters>::create();

View File

@ -111,8 +111,6 @@ namespace vnotex
QCheckBox *m_searchObjectContentCheckBox = nullptr;
QCheckBox *m_searchObjectOutlineCheckBox = nullptr;
QCheckBox *m_searchObjectTagCheckBox = nullptr;
QCheckBox *m_searchObjectPathCheckBox = nullptr;