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
|
||||
|
||||
selected_fg=@base_fg
|
||||
selected_bg=#80CBC4
|
||||
selected_bg=#7BBAB9
|
||||
|
||||
active_fg=@selected_fg
|
||||
active_bg=@selected_bg
|
||||
|
@ -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,19 +210,34 @@ void VSearch::searchFirstPhase(VDirectory *p_directory,
|
||||
return;
|
||||
}
|
||||
|
||||
if (testTarget(VSearchConfig::Folder)
|
||||
&& testObject(VSearchConfig::Name)) {
|
||||
QString text = p_directory->getName();
|
||||
if (matchNonContent(text)) {
|
||||
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,
|
||||
text,
|
||||
p_directory->fetchPath());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search files.
|
||||
if (testTarget(VSearchConfig::Note)) {
|
||||
for (auto const & file : p_directory->getFiles()) {
|
||||
|
@ -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
|
||||
|
@ -203,7 +203,8 @@ struct VSearchConfig
|
||||
Name = 0x1UL,
|
||||
Content = 0x2UL,
|
||||
Outline = 0x4UL,
|
||||
Tag = 0x8UL
|
||||
Tag = 0x8UL,
|
||||
Path = 0x10UL
|
||||
};
|
||||
|
||||
enum Target
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user