From a2670903cf5cdd3d505ec9a1f1cc4f05f45ae075 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Mon, 4 Jun 2018 20:50:50 +0800 Subject: [PATCH] explorer: bug-fix about clicking items when no root entries --- src/vexplorer.cpp | 27 ++++++++++++++++++++++----- src/vexplorer.h | 2 ++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/vexplorer.cpp b/src/vexplorer.cpp index 482808ef..5822b6b9 100644 --- a/src/vexplorer.cpp +++ b/src/vexplorer.cpp @@ -194,6 +194,12 @@ void VExplorer::setupUI() if (!model->isDir(p_index)) { QStringList files; files << model->filePath(p_index); + + // 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])); + } + openFiles(files, g_config->getNoteOpenMode()); } }); @@ -454,11 +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]() { - int idx = addEntry(filePath); - updateDirectoryComboBox(); - if (idx != -1) { - setCurrentEntry(idx); - } + setAsRootDirectory(filePath); }); menu.addAction(setRootAct); @@ -754,3 +756,18 @@ void VExplorer::renameFile(const QString &p_filePath) return; } } + +void VExplorer::setAsRootDirectory(const QString &p_path) +{ + if (p_path.isEmpty()) { + return; + } + + qDebug() << "set new root directory" << p_path; + + int idx = addEntry(p_path); + updateDirectoryComboBox(); + if (idx != -1) { + setCurrentEntry(idx); + } +} diff --git a/src/vexplorer.h b/src/vexplorer.h index b9ff6e91..57af349f 100644 --- a/src/vexplorer.h +++ b/src/vexplorer.h @@ -67,6 +67,8 @@ private: void renameFile(const QString &p_filePath); + void setAsRootDirectory(const QString &p_path); + bool m_initialized; bool m_uiInitialized;