add Open File Location in directory tree and file list

This commit is contained in:
Le Tan 2017-05-23 19:59:05 +08:00
parent f7f9ed7157
commit 03c0fdc49d
6 changed files with 48 additions and 5 deletions

View File

@ -72,6 +72,11 @@ void VDirectory::close()
m_opened = false; m_opened = false;
} }
QString VDirectory::retriveBasePath() const
{
return VUtils::basePathFromPath(retrivePath());
}
QString VDirectory::retrivePath(const VDirectory *p_dir) const QString VDirectory::retrivePath(const VDirectory *p_dir) const
{ {
if (!p_dir) { if (!p_dir) {

View File

@ -57,6 +57,7 @@ public:
inline const VNotebook *getNotebook() const; inline const VNotebook *getNotebook() const;
inline const QVector<VFile *> &getFiles() const; inline const QVector<VFile *> &getFiles() const;
inline QString retrivePath() const; inline QString retrivePath() const;
QString retriveBasePath() const;
inline QString retriveRelativePath() const; inline QString retriveRelativePath() const;
inline QString getNotebookName() const; inline QString getNotebookName() const;
inline bool isExpanded() const; inline bool isExpanded() const;

View File

@ -73,6 +73,11 @@ void VDirectoryTree::initActions()
pasteAct->setToolTip(tr("Paste directories under this directory")); pasteAct->setToolTip(tr("Paste directories under this directory"));
connect(pasteAct, &QAction::triggered, connect(pasteAct, &QAction::triggered,
this, &VDirectoryTree::pasteDirectoriesInCurDir); this, &VDirectoryTree::pasteDirectoriesInCurDir);
m_openLocationAct = new QAction(tr("&Open Directory Location"), this);
m_openLocationAct->setToolTip(tr("Open the folder containing this directory in operating system"));
connect(m_openLocationAct, &QAction::triggered,
this, &VDirectoryTree::openDirectoryLocation);
} }
void VDirectoryTree::setNotebook(VNotebook *p_notebook) void VDirectoryTree::setNotebook(VNotebook *p_notebook)
@ -306,6 +311,7 @@ void VDirectoryTree::contextMenuRequested(QPoint pos)
if (item) { if (item) {
menu.addSeparator(); menu.addSeparator();
menu.addAction(m_openLocationAct);
menu.addAction(dirInfoAct); menu.addAction(dirInfoAct);
} }
@ -466,6 +472,14 @@ void VDirectoryTree::editDirectoryInfo()
} while (true); } while (true);
} }
void VDirectoryTree::openDirectoryLocation() const
{
QTreeWidgetItem *curItem = currentItem();
V_ASSERT(curItem);
QUrl url = QUrl::fromLocalFile(getVDirectory(curItem)->retriveBasePath());
QDesktopServices::openUrl(url);
}
void VDirectoryTree::copySelectedDirectories(bool p_cut) void VDirectoryTree::copySelectedDirectories(bool p_cut)
{ {
QList<QTreeWidgetItem *> items = selectedItems(); QList<QTreeWidgetItem *> items = selectedItems();

View File

@ -51,6 +51,7 @@ private slots:
void copySelectedDirectories(bool p_cut = false); void copySelectedDirectories(bool p_cut = false);
void cutSelectedDirectories(); void cutSelectedDirectories();
void pasteDirectoriesInCurDir(); void pasteDirectoriesInCurDir();
void openDirectoryLocation() const;
protected: protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
@ -66,7 +67,7 @@ private:
// Find the corresponding item of @p_dir; // Find the corresponding item of @p_dir;
// Return's NULL if no item is found and it is the root directory if @p_widget is true. // Return's NULL if no item is found and it is the root directory if @p_widget is true.
QTreeWidgetItem *findVDirectory(const VDirectory *p_dir, bool &p_widget); QTreeWidgetItem *findVDirectory(const VDirectory *p_dir, bool &p_widget);
inline QPointer<VDirectory> getVDirectory(QTreeWidgetItem *p_item); inline QPointer<VDirectory> getVDirectory(QTreeWidgetItem *p_item) const;
void copyDirectoryInfoToClipboard(const QJsonArray &p_dirs, bool p_cut); void copyDirectoryInfoToClipboard(const QJsonArray &p_dirs, bool p_cut);
void pasteDirectories(VDirectory *p_destDir); void pasteDirectories(VDirectory *p_destDir);
bool copyDirectory(VDirectory *p_destDir, const QString &p_destName, bool copyDirectory(VDirectory *p_destDir, const QString &p_destName,
@ -96,6 +97,7 @@ private:
QAction *copyAct; QAction *copyAct;
QAction *cutAct; QAction *cutAct;
QAction *pasteAct; QAction *pasteAct;
QAction *m_openLocationAct;
// Navigation Mode. // Navigation Mode.
// Map second key to QTreeWidgetItem. // Map second key to QTreeWidgetItem.
@ -103,7 +105,7 @@ private:
QVector<QLabel *> m_naviLabels; QVector<QLabel *> m_naviLabels;
}; };
inline QPointer<VDirectory> VDirectoryTree::getVDirectory(QTreeWidgetItem *p_item) inline QPointer<VDirectory> VDirectoryTree::getVDirectory(QTreeWidgetItem *p_item) const
{ {
Q_ASSERT(p_item); Q_ASSERT(p_item);
return p_item->data(0, Qt::UserRole).value<VDirectory *>(); return p_item->data(0, Qt::UserRole).value<VDirectory *>();

View File

@ -1,5 +1,6 @@
#include <QtDebug> #include <QtDebug>
#include <QtWidgets> #include <QtWidgets>
#include <QUrl>
#include "vfilelist.h" #include "vfilelist.h"
#include "vconfigmanager.h" #include "vconfigmanager.h"
#include "dialog/vnewfiledialog.h" #include "dialog/vnewfiledialog.h"
@ -79,6 +80,11 @@ void VFileList::initActions()
pasteAct->setToolTip(tr("Paste notes in current directory")); pasteAct->setToolTip(tr("Paste notes in current directory"));
connect(pasteAct, &QAction::triggered, connect(pasteAct, &QAction::triggered,
this, &VFileList::pasteFilesInCurDir); this, &VFileList::pasteFilesInCurDir);
m_openLocationAct = new QAction(tr("&Open Note Location"), this);
m_openLocationAct->setToolTip(tr("Open the folder containing this note in operating system"));
connect(m_openLocationAct, &QAction::triggered,
this, &VFileList::openFileLocation);
} }
void VFileList::setDirectory(VDirectory *p_directory) void VFileList::setDirectory(VDirectory *p_directory)
@ -112,10 +118,18 @@ void VFileList::updateFileList()
void VFileList::fileInfo() void VFileList::fileInfo()
{ {
QListWidgetItem *curItem = fileList->currentItem(); QListWidgetItem *curItem = fileList->currentItem();
Q_ASSERT(curItem); V_ASSERT(curItem);
fileInfo(getVFile(curItem)); fileInfo(getVFile(curItem));
} }
void VFileList::openFileLocation() const
{
QListWidgetItem *curItem = fileList->currentItem();
V_ASSERT(curItem);
QUrl url = QUrl::fromLocalFile(getVFile(curItem)->retriveBasePath());
QDesktopServices::openUrl(url);
}
void VFileList::fileInfo(VFile *p_file) void VFileList::fileInfo(VFile *p_file)
{ {
if (!p_file) { if (!p_file) {
@ -297,10 +311,15 @@ void VFileList::contextMenuRequested(QPoint pos)
menu.addAction(pasteAct); menu.addAction(pasteAct);
} }
if (item && fileList->selectedItems().size() == 1) { if (item) {
menu.addSeparator(); menu.addSeparator();
menu.addAction(m_openLocationAct);
if (fileList->selectedItems().size() == 1) {
menu.addAction(fileInfoAct); menu.addAction(fileInfoAct);
} }
}
menu.exec(fileList->mapToGlobal(pos)); menu.exec(fileList->mapToGlobal(pos));
} }

View File

@ -49,6 +49,7 @@ private slots:
void contextMenuRequested(QPoint pos); void contextMenuRequested(QPoint pos);
void handleItemClicked(QListWidgetItem *currentItem); void handleItemClicked(QListWidgetItem *currentItem);
void fileInfo(); void fileInfo();
void openFileLocation() const;
// m_copiedFiles will keep the files's VFile. // m_copiedFiles will keep the files's VFile.
void copySelectedFiles(bool p_isCut = false); void copySelectedFiles(bool p_isCut = false);
void cutSelectedFiles(); void cutSelectedFiles();
@ -93,6 +94,7 @@ private:
QAction *copyAct; QAction *copyAct;
QAction *cutAct; QAction *cutAct;
QAction *pasteAct; QAction *pasteAct;
QAction *m_openLocationAct;
// Navigation Mode. // Navigation Mode.
// Map second key to QListWidgetItem. // Map second key to QListWidgetItem.