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:
Le Tan 2018-03-21 19:34:59 +08:00
parent a6c07a6dda
commit 28d359c4bb
5 changed files with 61 additions and 15 deletions

View File

@ -41,7 +41,7 @@ hover_fg=@base_fg
hover_bg=#D0D0D0
selected_fg=@base_fg
selected_bg=#80CBC4
selected_bg=#7BBAB9
active_fg=@selected_fg
active_bg=@selected_bg

View File

@ -1,7 +1,7 @@
#include "vsearch.h"
#include "utils/vutils.h"
#include "vfile.h"
#include "vnotefile.h"
#include "vdirectory.h"
#include "vnotebook.h"
#include "veditarea.h"
@ -16,6 +16,7 @@ VSearch::VSearch(QObject *p_parent)
m_askedToStop(false),
m_engine(NULL)
{
m_slashReg = QRegExp("[\\/]");
}
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)) {
VSearchResultItem *item = searchForOutline(p_file);
if (item) {
@ -190,16 +210,31 @@ void VSearch::searchFirstPhase(VDirectory *p_directory,
return;
}
if (testTarget(VSearchConfig::Folder)
&& testObject(VSearchConfig::Name)) {
QString text = p_directory->getName();
if (matchNonContent(text)) {
VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
VSearchResultItem::LineNumber,
text,
p_directory->fetchPath());
QSharedPointer<VSearchResultItem> pitem(item);
emit resultItemAdded(pitem);
if (testTarget(VSearchConfig::Folder)) {
QString name = p_directory->getName();
QString dirPath = p_directory->fetchPath();
if (testObject(VSearchConfig::Name)) {
if (matchNonContent(name)) {
VSearchResultItem *item = new VSearchResultItem(VSearchResultItem::Folder,
VSearchResultItem::LineNumber,
name,
dirPath);
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);
}
}
}

View File

@ -74,6 +74,8 @@ private:
void searchSecondPhase(const QSharedPointer<VSearchResult> &p_result);
void removeSlashFromPath(QString &p_path);
bool m_askedToStop;
QSharedPointer<VSearchConfig> m_config;
@ -82,6 +84,9 @@ private:
// Wildcard reg to for file name pattern.
QRegExp m_patternReg;
// Remove slashes.
QRegExp m_slashReg;
};
inline bool VSearch::askedToStop() const
@ -129,4 +134,9 @@ inline bool VSearch::matchPattern(const QString &p_name) const
return p_name.contains(m_patternReg);
}
inline void VSearch::removeSlashFromPath(QString &p_path)
{
p_path.remove(m_slashReg);
}
#endif // VSEARCH_H

View File

@ -203,7 +203,8 @@ struct VSearchConfig
Name = 0x1UL,
Content = 0x2UL,
Outline = 0x4UL,
Tag = 0x8UL
Tag = 0x8UL,
Path = 0x10UL
};
enum Target

View File

@ -313,9 +313,9 @@ void VSearcher::handleInputChanged()
readyToSearch = !keyword.isEmpty();
if (readyToSearch) {
// Other targets are only available for Name.
// Other targets are only available for Name and Path.
int obj = m_searchObjectCB->currentData().toInt();
if (obj != VSearchConfig::Name) {
if (obj != VSearchConfig::Name && obj != VSearchConfig::Path) {
int target = m_searchTargetCB->currentData().toInt();
if (!(target & VSearchConfig::Note)) {
readyToSearch = false;