mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
search: add search Object Path
1. For internal file and folder, search the relative path; 2. For orphan file, search the complete path;
This commit is contained in:
parent
a6c07a6dda
commit
28d359c4bb
@ -41,7 +41,7 @@ hover_fg=@base_fg
|
|||||||
hover_bg=#D0D0D0
|
hover_bg=#D0D0D0
|
||||||
|
|
||||||
selected_fg=@base_fg
|
selected_fg=@base_fg
|
||||||
selected_bg=#80CBC4
|
selected_bg=#7BBAB9
|
||||||
|
|
||||||
active_fg=@selected_fg
|
active_fg=@selected_fg
|
||||||
active_bg=@selected_bg
|
active_bg=@selected_bg
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "vsearch.h"
|
#include "vsearch.h"
|
||||||
|
|
||||||
#include "utils/vutils.h"
|
#include "utils/vutils.h"
|
||||||
#include "vfile.h"
|
#include "vnotefile.h"
|
||||||
#include "vdirectory.h"
|
#include "vdirectory.h"
|
||||||
#include "vnotebook.h"
|
#include "vnotebook.h"
|
||||||
#include "veditarea.h"
|
#include "veditarea.h"
|
||||||
@ -16,6 +16,7 @@ VSearch::VSearch(QObject *p_parent)
|
|||||||
m_askedToStop(false),
|
m_askedToStop(false),
|
||||||
m_engine(NULL)
|
m_engine(NULL)
|
||||||
{
|
{
|
||||||
|
m_slashReg = QRegExp("[\\/]");
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<VSearchResult> VSearch::search(const QVector<VFile *> &p_files)
|
QSharedPointer<VSearchResult> VSearch::search(const QVector<VFile *> &p_files)
|
||||||
@ -152,6 +153,25 @@ void VSearch::searchFirstPhase(VFile *p_file,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (testObject(VSearchConfig::Path)) {
|
||||||
|
QString normFilePath;
|
||||||
|
if (p_file->getType() == FileType::Note) {
|
||||||
|
normFilePath = static_cast<VNoteFile *>(p_file)->fetchRelativePath();
|
||||||
|
} else {
|
||||||
|
normFilePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeSlashFromPath(normFilePath);
|
||||||
|
if (matchNonContent(normFilePath)) {
|
||||||
|
VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Note,
|
||||||
|
VSearchResultItem::LineNumber,
|
||||||
|
name,
|
||||||
|
filePath);
|
||||||
|
QSharedPointer<VSearchResultItem> pitem(item);
|
||||||
|
emit resultItemAdded(pitem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (testObject(VSearchConfig::Outline)) {
|
if (testObject(VSearchConfig::Outline)) {
|
||||||
VSearchResultItem *item = searchForOutline(p_file);
|
VSearchResultItem *item = searchForOutline(p_file);
|
||||||
if (item) {
|
if (item) {
|
||||||
@ -190,16 +210,31 @@ void VSearch::searchFirstPhase(VDirectory *p_directory,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (testTarget(VSearchConfig::Folder)
|
if (testTarget(VSearchConfig::Folder)) {
|
||||||
&& testObject(VSearchConfig::Name)) {
|
QString name = p_directory->getName();
|
||||||
QString text = p_directory->getName();
|
QString dirPath = p_directory->fetchPath();
|
||||||
if (matchNonContent(text)) {
|
if (testObject(VSearchConfig::Name)) {
|
||||||
VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
|
if (matchNonContent(name)) {
|
||||||
VSearchResultItem::LineNumber,
|
VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
|
||||||
text,
|
VSearchResultItem::LineNumber,
|
||||||
p_directory->fetchPath());
|
name,
|
||||||
QSharedPointer<VSearchResultItem> pitem(item);
|
dirPath);
|
||||||
emit resultItemAdded(pitem);
|
QSharedPointer<VSearchResultItem> pitem(item);
|
||||||
|
emit resultItemAdded(pitem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (testObject(VSearchConfig::Path)) {
|
||||||
|
QString normPath(p_directory->fetchRelativePath());
|
||||||
|
removeSlashFromPath(normPath);
|
||||||
|
if (matchNonContent(normPath)) {
|
||||||
|
VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
|
||||||
|
VSearchResultItem::LineNumber,
|
||||||
|
name,
|
||||||
|
dirPath);
|
||||||
|
QSharedPointer<VSearchResultItem> pitem(item);
|
||||||
|
emit resultItemAdded(pitem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +74,8 @@ private:
|
|||||||
|
|
||||||
void searchSecondPhase(const QSharedPointer<VSearchResult> &p_result);
|
void searchSecondPhase(const QSharedPointer<VSearchResult> &p_result);
|
||||||
|
|
||||||
|
void removeSlashFromPath(QString &p_path);
|
||||||
|
|
||||||
bool m_askedToStop;
|
bool m_askedToStop;
|
||||||
|
|
||||||
QSharedPointer<VSearchConfig> m_config;
|
QSharedPointer<VSearchConfig> m_config;
|
||||||
@ -82,6 +84,9 @@ private:
|
|||||||
|
|
||||||
// Wildcard reg to for file name pattern.
|
// Wildcard reg to for file name pattern.
|
||||||
QRegExp m_patternReg;
|
QRegExp m_patternReg;
|
||||||
|
|
||||||
|
// Remove slashes.
|
||||||
|
QRegExp m_slashReg;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool VSearch::askedToStop() const
|
inline bool VSearch::askedToStop() const
|
||||||
@ -129,4 +134,9 @@ inline bool VSearch::matchPattern(const QString &p_name) const
|
|||||||
|
|
||||||
return p_name.contains(m_patternReg);
|
return p_name.contains(m_patternReg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void VSearch::removeSlashFromPath(QString &p_path)
|
||||||
|
{
|
||||||
|
p_path.remove(m_slashReg);
|
||||||
|
}
|
||||||
#endif // VSEARCH_H
|
#endif // VSEARCH_H
|
||||||
|
@ -203,7 +203,8 @@ struct VSearchConfig
|
|||||||
Name = 0x1UL,
|
Name = 0x1UL,
|
||||||
Content = 0x2UL,
|
Content = 0x2UL,
|
||||||
Outline = 0x4UL,
|
Outline = 0x4UL,
|
||||||
Tag = 0x8UL
|
Tag = 0x8UL,
|
||||||
|
Path = 0x10UL
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Target
|
enum Target
|
||||||
|
@ -313,9 +313,9 @@ void VSearcher::handleInputChanged()
|
|||||||
readyToSearch = !keyword.isEmpty();
|
readyToSearch = !keyword.isEmpty();
|
||||||
|
|
||||||
if (readyToSearch) {
|
if (readyToSearch) {
|
||||||
// Other targets are only available for Name.
|
// Other targets are only available for Name and Path.
|
||||||
int obj = m_searchObjectCB->currentData().toInt();
|
int obj = m_searchObjectCB->currentData().toInt();
|
||||||
if (obj != VSearchConfig::Name) {
|
if (obj != VSearchConfig::Name && obj != VSearchConfig::Path) {
|
||||||
int target = m_searchTargetCB->currentData().toInt();
|
int target = m_searchTargetCB->currentData().toInt();
|
||||||
if (!(target & VSearchConfig::Note)) {
|
if (!(target & VSearchConfig::Note)) {
|
||||||
readyToSearch = false;
|
readyToSearch = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user