UniversalEntry: add parent directory name before item name in the result

This commit is contained in:
Le Tan 2018-08-22 20:08:32 +08:00
parent 4b0152c606
commit 5d4b450fab
6 changed files with 41 additions and 4 deletions

View File

@ -1770,3 +1770,12 @@ QUrl VUtils::pathToUrl(const QString &p_path)
return url; return url;
} }
QString VUtils::parentDirName(const QString &p_path)
{
if (p_path.isEmpty()) {
return p_path;
}
return QFileInfo(p_path).dir().dirName();
}

View File

@ -374,6 +374,10 @@ public:
static QUrl pathToUrl(const QString &p_path); static QUrl pathToUrl(const QString &p_path);
// Return the name of the parent directory of @p_path.
// @p_path: file path of file or dir.
static QString parentDirName(const QString &p_path);
// Regular expression for image link. // Regular expression for image link.
// ![image title]( http://github.com/tamlok/vnote.jpg "alt text" =200x100) // ![image title]( http://github.com/tamlok/vnote.jpg "alt text" =200x100)
// Captured texts (need to be trimmed): // Captured texts (need to be trimmed):

View File

@ -16,6 +16,7 @@
#include "vnotebook.h" #include "vnotebook.h"
#include "vuetitlecontentpanel.h" #include "vuetitlecontentpanel.h"
#include "vhistorylist.h" #include "vhistorylist.h"
#include "vuniversalentry.h"
extern VMainWindow *g_mainWin; extern VMainWindow *g_mainWin;
@ -174,7 +175,11 @@ void VListUE::addResultItem(const QSharedPointer<VSearchResultItem> &p_item)
if (p_item->m_text.isEmpty()) { if (p_item->m_text.isEmpty()) {
first = p_item->m_path; first = p_item->m_path;
} else { } else {
first = p_item->m_text; if (p_item->m_type != VSearchResultItem::Notebook) {
first = VUniversalEntry::fileNameWithDir(p_item->m_text, p_item->m_path);
} else {
first = p_item->m_text;
}
second = p_item->m_path; second = p_item->m_path;
} }

View File

@ -17,6 +17,7 @@
#include "vdirectorytree.h" #include "vdirectorytree.h"
#include "veditarea.h" #include "veditarea.h"
#include "vexplorer.h" #include "vexplorer.h"
#include "vuniversalentry.h"
extern VNote *g_vnote; extern VNote *g_vnote;
@ -742,7 +743,11 @@ void VSearchUE::appendItemToList(const QSharedPointer<VSearchResultItem> &p_item
if (p_item->m_text.isEmpty()) { if (p_item->m_text.isEmpty()) {
first = p_item->m_path; first = p_item->m_path;
} else { } else {
first = p_item->m_text; if (p_item->m_type != VSearchResultItem::Notebook) {
first = VUniversalEntry::fileNameWithDir(p_item->m_text, p_item->m_path);
} else {
first = p_item->m_text;
}
second = p_item->m_path; second = p_item->m_path;
} }
@ -782,7 +787,15 @@ void VSearchUE::appendItemToTree(const QSharedPointer<VSearchResultItem> &p_item
QTreeWidgetItem *item = new QTreeWidgetItem(m_treeWidget); QTreeWidgetItem *item = new QTreeWidgetItem(m_treeWidget);
item->setData(0, Qt::UserRole, m_data.size() - 1); item->setData(0, Qt::UserRole, m_data.size() - 1);
item->setText(0, p_item->m_text.isEmpty() ? p_item->m_path : p_item->m_text); QString text;
if (p_item->m_text.isEmpty()) {
text = p_item->m_path;
} else if (p_item->m_type != VSearchResultItem::Notebook) {
text = VUniversalEntry::fileNameWithDir(p_item->m_text, p_item->m_path);
} else {
text = p_item->m_text;
}
item->setText(0, text);
item->setToolTip(0, p_item->m_path); item->setToolTip(0, p_item->m_path);
switch (p_item->m_type) { switch (p_item->m_type) {

View File

@ -14,7 +14,6 @@
#include <QAtomicInt> #include <QAtomicInt>
#include "vmetawordlineedit.h" #include "vmetawordlineedit.h"
#include "utils/vutils.h"
#include "vlistwidget.h" #include "vlistwidget.h"
#include "vpalette.h" #include "vpalette.h"
#include "vlistfolderue.h" #include "vlistfolderue.h"

View File

@ -7,6 +7,7 @@
#include <QAtomicInt> #include <QAtomicInt>
#include "iuniversalentry.h" #include "iuniversalentry.h"
#include "utils/vutils.h"
class VMetaWordLineEdit; class VMetaWordLineEdit;
class QVBoxLayout; class QVBoxLayout;
@ -53,6 +54,8 @@ public:
// @p_id to distinguish. // @p_id to distinguish.
void registerEntry(QChar p_key, IUniversalEntry *p_entry, int p_id = 0); void registerEntry(QChar p_key, IUniversalEntry *p_entry, int p_id = 0);
static QString fileNameWithDir(const QString &p_name, const QString &p_path);
signals: signals:
// Exit Universal Entry. // Exit Universal Entry.
void exited(); void exited();
@ -125,4 +128,8 @@ private:
bool m_pendingCommand; bool m_pendingCommand;
}; };
inline QString VUniversalEntry::fileNameWithDir(const QString &p_name, const QString &p_path)
{
return VUtils::parentDirName(p_path) + " / " + p_name;
}
#endif // VUNIVERSALENTRY_H #endif // VUNIVERSALENTRY_H