mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Explorer: support drag&drop a directory to VNote to open it in Explorer
This commit is contained in:
parent
5ebc7b8243
commit
d67ef089b6
@ -15,10 +15,15 @@
|
||||
#include "utils/viconutils.h"
|
||||
#include "vcart.h"
|
||||
#include "vhistorylist.h"
|
||||
#include "vnote.h"
|
||||
#include "vexplorer.h"
|
||||
|
||||
extern VConfigManager *g_config;
|
||||
|
||||
extern VMainWindow *g_mainWin;
|
||||
|
||||
extern VNote *g_vnote;
|
||||
|
||||
#define GET_TAB_FROM_SENDER() static_cast<QAction *>(sender())->data().toInt()
|
||||
|
||||
VEditWindow::VEditWindow(VEditArea *editArea, QWidget *parent)
|
||||
@ -1189,24 +1194,41 @@ void VEditWindow::dropEvent(QDropEvent *p_event)
|
||||
{
|
||||
const QMimeData *mime = p_event->mimeData();
|
||||
if (mime->hasFormat("text/uri-list") && mime->hasUrls()) {
|
||||
// Open external files in this edit window.
|
||||
// Open external files in this edit window or open a direcotry in Explorer.
|
||||
bool isDir = false;
|
||||
QStringList files;
|
||||
QList<QUrl> urls = mime->urls();
|
||||
for (int i = 0; i < urls.size(); ++i) {
|
||||
QString file;
|
||||
if (urls[i].isLocalFile()) {
|
||||
file = urls[i].toLocalFile();
|
||||
QFileInfo fi(file);
|
||||
if (fi.exists() && fi.isFile()) {
|
||||
file = QDir::cleanPath(fi.absoluteFilePath());
|
||||
QFileInfo fi(urls[i].toLocalFile());
|
||||
if (!fi.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString file = QDir::cleanPath(fi.absoluteFilePath());
|
||||
if (fi.isFile()) {
|
||||
files.append(file);
|
||||
} else if (urls.size() == 1) {
|
||||
isDir = true;
|
||||
files.append(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!files.isEmpty()) {
|
||||
focusWindow();
|
||||
g_mainWin->openFiles(files);
|
||||
if (isDir) {
|
||||
VDirectory *dir = g_vnote->getInternalDirectory(files[0]);
|
||||
if (dir) {
|
||||
g_mainWin->locateDirectory(dir);
|
||||
} else {
|
||||
// External directory.
|
||||
g_mainWin->showExplorerPanel(true);
|
||||
g_mainWin->getExplorer()->setRootDirectory(files[0]);
|
||||
}
|
||||
} else {
|
||||
focusWindow();
|
||||
g_mainWin->openFiles(files);
|
||||
}
|
||||
}
|
||||
|
||||
p_event->acceptProposedAction();
|
||||
|
@ -197,7 +197,7 @@ void VExplorer::setupUI()
|
||||
|
||||
// If there is no directory entry currently, new one using the parent dir.
|
||||
if (m_index == -1 || m_entries.isEmpty()) {
|
||||
setAsRootDirectory(VUtils::basePathFromPath(files[0]));
|
||||
setRootDirectory(VUtils::basePathFromPath(files[0]));
|
||||
}
|
||||
|
||||
openFiles(files, g_config->getNoteOpenMode());
|
||||
@ -460,7 +460,7 @@ void VExplorer::handleContextMenuRequested(QPoint p_pos)
|
||||
setRootAct->setToolTip(tr("Set current folder as the root directory to explore"));
|
||||
connect(setRootAct, &QAction::triggered,
|
||||
this, [this, filePath]() {
|
||||
setAsRootDirectory(filePath);
|
||||
setRootDirectory(filePath);
|
||||
});
|
||||
menu.addAction(setRootAct);
|
||||
|
||||
@ -757,12 +757,14 @@ void VExplorer::renameFile(const QString &p_filePath)
|
||||
}
|
||||
}
|
||||
|
||||
void VExplorer::setAsRootDirectory(const QString &p_path)
|
||||
void VExplorer::setRootDirectory(const QString &p_path)
|
||||
{
|
||||
if (p_path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
qDebug() << "set new root directory" << p_path;
|
||||
|
||||
int idx = addEntry(p_path);
|
||||
|
@ -21,6 +21,8 @@ class VExplorer : public QWidget
|
||||
public:
|
||||
explicit VExplorer(QWidget *p_parent = nullptr);
|
||||
|
||||
void setRootDirectory(const QString &p_path);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *p_event) Q_DECL_OVERRIDE;
|
||||
|
||||
@ -67,8 +69,6 @@ private:
|
||||
|
||||
void renameFile(const QString &p_filePath);
|
||||
|
||||
void setAsRootDirectory(const QString &p_path);
|
||||
|
||||
bool m_initialized;
|
||||
|
||||
bool m_uiInitialized;
|
||||
|
@ -68,7 +68,13 @@ extern QFile g_logFile;
|
||||
|
||||
#define COLOR_PIXMAP_ICON_SIZE 64
|
||||
|
||||
#define NAVI_BOX_NOTEBOOKS_IDX 0
|
||||
enum NaviBoxIndex
|
||||
{
|
||||
NotebookPanel = 0,
|
||||
HistoryList,
|
||||
Explorer,
|
||||
TagExplorer
|
||||
};
|
||||
|
||||
|
||||
VMainWindow::VMainWindow(VSingleInstanceGuard *p_guard, QWidget *p_parent)
|
||||
@ -3291,7 +3297,13 @@ void VMainWindow::kickOffStartUpTimer(const QStringList &p_files)
|
||||
void VMainWindow::showNotebookPanel()
|
||||
{
|
||||
changePanelView(PanelViewState::VerticalMode);
|
||||
m_naviBox->setCurrentIndex(NAVI_BOX_NOTEBOOKS_IDX, false);
|
||||
m_naviBox->setCurrentIndex(NaviBoxIndex::NotebookPanel, false);
|
||||
}
|
||||
|
||||
void VMainWindow::showExplorerPanel(bool p_focus)
|
||||
{
|
||||
changePanelView(PanelViewState::VerticalMode);
|
||||
m_naviBox->setCurrentIndex(NaviBoxIndex::Explorer, p_focus);
|
||||
}
|
||||
|
||||
void VMainWindow::stayOnTop(bool p_enabled)
|
||||
|
@ -124,6 +124,10 @@ public:
|
||||
|
||||
void focusEditArea() const;
|
||||
|
||||
void showExplorerPanel(bool p_focus = false);
|
||||
|
||||
VExplorer *getExplorer() const;
|
||||
|
||||
signals:
|
||||
// Emit when editor related configurations were changed by user.
|
||||
void editorConfigUpdated();
|
||||
@ -522,4 +526,9 @@ inline VNotebookSelector *VMainWindow::getNotebookSelector() const
|
||||
{
|
||||
return m_notebookSelector;
|
||||
}
|
||||
|
||||
inline VExplorer *VMainWindow::getExplorer() const
|
||||
{
|
||||
return m_explorer;
|
||||
}
|
||||
#endif // VMAINWINDOW_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user