diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -636,7 +636,11 @@
// does not care whether the parent-URL has already been
// expanded.
QUrl urlToExpand = m_dirLister->url();
- const QStringList subDirs = url.path().mid(pos).split(QDir::separator());
+
+ // first subdir can be empty, if m_dirLister->url().path() does not end with '/'
+ // this happens if baseUrl is not root but a home directory, see FoldersPanel,
+ // so using QString::SkipEmptyParts
+ const QStringList subDirs = url.path().mid(pos).split(QDir::separator(), QString::SkipEmptyParts);
for (int i = 0; i < subDirs.count() - 1; ++i) {
urlToExpand.setPath(urlToExpand.path() + '/' + subDirs.at(i));
m_urlsToExpand.insert(urlToExpand);
diff --git a/src/panels/folders/dolphin_folderspanelsettings.kcfg b/src/panels/folders/dolphin_folderspanelsettings.kcfg
--- a/src/panels/folders/dolphin_folderspanelsettings.kcfg
+++ b/src/panels/folders/dolphin_folderspanelsettings.kcfg
@@ -10,6 +10,10 @@
false
+
+
+ true
+
true
diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h
--- a/src/panels/folders/folderspanel.h
+++ b/src/panels/folders/folderspanel.h
@@ -43,7 +43,9 @@
virtual ~FoldersPanel();
void setShowHiddenFiles(bool show);
+ void setLimitFoldersPanelToHome(bool enable);
bool showHiddenFiles() const;
+ bool limitFoldersPanelToHome() const;
void setAutoScrolling(bool enable);
bool autoScrolling() const;
@@ -81,14 +83,17 @@
*/
void startFadeInAnimation();
+
private:
/**
* Initializes the base URL of the tree and expands all
* directories until \a url.
* @param url URL of the leaf directory that should get expanded.
*/
void loadTree(const QUrl& url);
+ void reloadTree();
+
/**
* Sets the item with the index \a index as current item, selects
* the item and assures that the item will be visible.
diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp
--- a/src/panels/folders/folderspanel.cpp
+++ b/src/panels/folders/folderspanel.cpp
@@ -50,6 +50,7 @@
#include
#include "dolphindebug.h"
+#include "global.h"
FoldersPanel::FoldersPanel(QWidget* parent) :
Panel(parent),
@@ -82,6 +83,17 @@
return FoldersPanelSettings::hiddenFilesShown();
}
+void FoldersPanel::setLimitFoldersPanelToHome(bool enable)
+{
+ FoldersPanelSettings::setLimitFoldersPanelToHome(enable);
+ reloadTree();
+}
+
+bool FoldersPanel::limitFoldersPanelToHome() const
+{
+ return FoldersPanelSettings::limitFoldersPanelToHome();
+}
+
void FoldersPanel::setAutoScrolling(bool enable)
{
// TODO: Not supported yet in Dolphin 2.0
@@ -122,6 +134,14 @@
return true;
}
+void FoldersPanel::reloadTree()
+{
+ if (m_controller) {
+ loadTree(url());
+ }
+}
+
+
void FoldersPanel::showEvent(QShowEvent* event)
{
if (event->spontaneous()) {
@@ -304,8 +324,13 @@
QUrl baseUrl;
if (url.isLocalFile()) {
- // Use the root directory as base for local URLs (#150941)
- baseUrl = QUrl::fromLocalFile(QDir::rootPath());
+ const bool isInHomeFolder = Dolphin::homeUrl().isParentOf(url) || (Dolphin::homeUrl() == url);
+ if (FoldersPanelSettings::limitFoldersPanelToHome() && isInHomeFolder) {
+ baseUrl = Dolphin::homeUrl();
+ } else {
+ // Use the root directory as base for local URLs (#150941)
+ baseUrl = QUrl::fromLocalFile(QDir::rootPath());
+ }
} else {
// Clear the path for non-local URLs and use it as base
baseUrl = url;
@@ -323,6 +348,13 @@
} else {
m_updateCurrentItem = true;
m_model->expandParentDirectories(url);
+
+ // clear a previous selection, if the home directory is selected
+ // and limitFoldersPanelToHome() active
+ if (FoldersPanelSettings::limitFoldersPanelToHome() && Dolphin::homeUrl() == url) {
+ KItemListSelectionManager* selectionManager = m_controller->selectionManager();
+ selectionManager->clearSelection();
+ }
// slotLoadingCompleted() will be invoked after the model has
// expanded the url
}
diff --git a/src/panels/folders/treeviewcontextmenu.h b/src/panels/folders/treeviewcontextmenu.h
--- a/src/panels/folders/treeviewcontextmenu.h
+++ b/src/panels/folders/treeviewcontextmenu.h
@@ -79,6 +79,12 @@
void setShowHiddenFiles(bool show);
/**
+ * Sets the 'Limit folders panel to home' setting for the
+ * folders panel to \a enable.
+ */
+ void setLimitFoldersPanelToHome(bool enable);
+
+ /**
* Sets the 'Automatic Scrolling' setting for the
* folders panel to \a enable.
*/
diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp
--- a/src/panels/folders/treeviewcontextmenu.cpp
+++ b/src/panels/folders/treeviewcontextmenu.cpp
@@ -124,6 +124,13 @@
popup->addAction(showHiddenFilesAction);
connect(showHiddenFilesAction, &QAction::toggled, this, &TreeViewContextMenu::setShowHiddenFiles);
+ // insert 'Limit to home directory if inside home'
+ QAction* limitFoldersPanelToHomeAction = new QAction(i18nc("@action:inmenu", "Limit to home directory if inside home"), this);
+ limitFoldersPanelToHomeAction->setCheckable(true);
+ limitFoldersPanelToHomeAction->setChecked(m_parent->limitFoldersPanelToHome());
+ popup->addAction(limitFoldersPanelToHomeAction);
+ connect(limitFoldersPanelToHomeAction, &QAction::toggled, this, &TreeViewContextMenu::setLimitFoldersPanelToHome);
+
// insert 'Automatic Scrolling'
QAction* autoScrollingAction = new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this);
autoScrollingAction->setCheckable(true);
@@ -229,6 +236,11 @@
m_parent->setShowHiddenFiles(show);
}
+void TreeViewContextMenu::setLimitFoldersPanelToHome(bool enable)
+{
+ m_parent->setLimitFoldersPanelToHome(enable);
+}
+
void TreeViewContextMenu::setAutoScrolling(bool enable)
{
m_parent->setAutoScrolling(enable);