mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support search tag in SearchPanel
This commit is contained in:
parent
964dfbb085
commit
8de8b0dda8
@ -57,6 +57,7 @@ namespace vnotex
|
|||||||
ObjectNone = 0,
|
ObjectNone = 0,
|
||||||
SearchName = 0x1UL,
|
SearchName = 0x1UL,
|
||||||
SearchContent = 0x2UL,
|
SearchContent = 0x2UL,
|
||||||
|
// SearchOutline is not supported yet.
|
||||||
SearchOutline = 0x4UL,
|
SearchOutline = 0x4UL,
|
||||||
SearchTag = 0x8UL,
|
SearchTag = 0x8UL,
|
||||||
SearchPath = 0x10UL
|
SearchPath = 0x10UL
|
||||||
|
@ -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)) {
|
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.
|
// 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)) {
|
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)) {
|
if (testObject(SearchObject::SearchContent)) {
|
||||||
@ -518,3 +514,20 @@ const SearchToken &Searcher::getToken() const
|
|||||||
{
|
{
|
||||||
return m_token;
|
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;
|
||||||
|
}
|
||||||
|
@ -78,6 +78,9 @@ namespace vnotex
|
|||||||
|
|
||||||
bool searchContent(const File *p_file);
|
bool searchContent(const File *p_file);
|
||||||
|
|
||||||
|
// Return true if matched.
|
||||||
|
bool searchTag(const Node *p_node) const;
|
||||||
|
|
||||||
void createSearchEngine();
|
void createSearchEngine();
|
||||||
|
|
||||||
QSharedPointer<SearchOption> m_option;
|
QSharedPointer<SearchOption> m_option;
|
||||||
|
@ -169,14 +169,11 @@ void SearchPanel::setupSearchObject(QFormLayout *p_layout, QWidget *p_parent)
|
|||||||
m_searchObjectContentCheckBox = WidgetsFactory::createCheckBox(tr("Content"), p_parent);
|
m_searchObjectContentCheckBox = WidgetsFactory::createCheckBox(tr("Content"), p_parent);
|
||||||
gridLayout->addWidget(m_searchObjectContentCheckBox, 0, 1);
|
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);
|
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);
|
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)
|
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_searchObjectNameCheckBox->setChecked(p_option.m_objects & SearchObject::SearchName);
|
||||||
m_searchObjectContentCheckBox->setChecked(p_option.m_objects & SearchObject::SearchContent);
|
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_searchObjectTagCheckBox->setChecked(p_option.m_objects & SearchObject::SearchTag);
|
||||||
m_searchObjectPathCheckBox->setChecked(p_option.m_objects & SearchObject::SearchPath);
|
m_searchObjectPathCheckBox->setChecked(p_option.m_objects & SearchObject::SearchPath);
|
||||||
}
|
}
|
||||||
@ -379,9 +375,6 @@ void SearchPanel::saveFields(SearchOption &p_option)
|
|||||||
if (m_searchObjectContentCheckBox->isChecked()) {
|
if (m_searchObjectContentCheckBox->isChecked()) {
|
||||||
p_option.m_objects |= SearchObject::SearchContent;
|
p_option.m_objects |= SearchObject::SearchContent;
|
||||||
}
|
}
|
||||||
if (m_searchObjectOutlineCheckBox->isChecked()) {
|
|
||||||
p_option.m_objects |= SearchObject::SearchOutline;
|
|
||||||
}
|
|
||||||
if (m_searchObjectTagCheckBox->isChecked()) {
|
if (m_searchObjectTagCheckBox->isChecked()) {
|
||||||
p_option.m_objects |= SearchObject::SearchTag;
|
p_option.m_objects |= SearchObject::SearchTag;
|
||||||
}
|
}
|
||||||
@ -566,8 +559,10 @@ void SearchPanel::handleLocationActivated(const Location &p_location)
|
|||||||
Q_ASSERT(m_searcher);
|
Q_ASSERT(m_searcher);
|
||||||
|
|
||||||
if (!m_searchTokenOfSession) {
|
if (!m_searchTokenOfSession) {
|
||||||
|
if (m_option->m_objects & SearchObject::SearchContent) {
|
||||||
m_searchTokenOfSession = QSharedPointer<SearchToken>::create(m_searcher->getToken());
|
m_searchTokenOfSession = QSharedPointer<SearchToken>::create(m_searcher->getToken());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: decode the path of location and handle different types of destination.
|
// TODO: decode the path of location and handle different types of destination.
|
||||||
auto paras = QSharedPointer<FileOpenParameters>::create();
|
auto paras = QSharedPointer<FileOpenParameters>::create();
|
||||||
|
@ -111,8 +111,6 @@ namespace vnotex
|
|||||||
|
|
||||||
QCheckBox *m_searchObjectContentCheckBox = nullptr;
|
QCheckBox *m_searchObjectContentCheckBox = nullptr;
|
||||||
|
|
||||||
QCheckBox *m_searchObjectOutlineCheckBox = nullptr;
|
|
||||||
|
|
||||||
QCheckBox *m_searchObjectTagCheckBox = nullptr;
|
QCheckBox *m_searchObjectTagCheckBox = nullptr;
|
||||||
|
|
||||||
QCheckBox *m_searchObjectPathCheckBox = nullptr;
|
QCheckBox *m_searchObjectPathCheckBox = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user