mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-28 03:21:56 +00:00
Limit folder panel to home directory if inside home
Summary: Added the option to limit the displayed folders in the folder panel (F7) to the tree below the user's home directory if the current URL is inside the home directory. This can be configured in the preferences General/Behaviour tab by checking the corresponding check box. Reviewers: #dolphin, elvisangelaccio, emmanuelp Reviewed By: #dolphin, elvisangelaccio, emmanuelp Subscribers: emmanuelp, elvisangelaccio, #konqueror, #dolphin Differential Revision: https://phabricator.kde.org/D7477
This commit is contained in:
parent
652f57d281
commit
94fab8c80e
|
@ -636,7 +636,11 @@ void KFileItemModel::expandParentDirectories(const QUrl &url)
|
||||||
// does not care whether the parent-URL has already been
|
// does not care whether the parent-URL has already been
|
||||||
// expanded.
|
// expanded.
|
||||||
QUrl urlToExpand = m_dirLister->url();
|
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) {
|
for (int i = 0; i < subDirs.count() - 1; ++i) {
|
||||||
urlToExpand.setPath(urlToExpand.path() + '/' + subDirs.at(i));
|
urlToExpand.setPath(urlToExpand.path() + '/' + subDirs.at(i));
|
||||||
m_urlsToExpand.insert(urlToExpand);
|
m_urlsToExpand.insert(urlToExpand);
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
<label>Hidden files shown</label>
|
<label>Hidden files shown</label>
|
||||||
<default>false</default>
|
<default>false</default>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry name="LimitFoldersPanelToHome" type="Bool">
|
||||||
|
<label>Limit folders panel to home directory if inside home</label>
|
||||||
|
<default>true</default>
|
||||||
|
</entry>
|
||||||
<entry name="AutoScrolling" type="Bool">
|
<entry name="AutoScrolling" type="Bool">
|
||||||
<label>Automatic scrolling</label>
|
<label>Automatic scrolling</label>
|
||||||
<default>true</default>
|
<default>true</default>
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include <views/draganddrophelper.h>
|
#include <views/draganddrophelper.h>
|
||||||
|
|
||||||
#include "dolphindebug.h"
|
#include "dolphindebug.h"
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
FoldersPanel::FoldersPanel(QWidget* parent) :
|
FoldersPanel::FoldersPanel(QWidget* parent) :
|
||||||
Panel(parent),
|
Panel(parent),
|
||||||
|
@ -82,6 +83,17 @@ bool FoldersPanel::showHiddenFiles() const
|
||||||
return FoldersPanelSettings::hiddenFilesShown();
|
return FoldersPanelSettings::hiddenFilesShown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FoldersPanel::setLimitFoldersPanelToHome(bool enable)
|
||||||
|
{
|
||||||
|
FoldersPanelSettings::setLimitFoldersPanelToHome(enable);
|
||||||
|
reloadTree();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FoldersPanel::limitFoldersPanelToHome() const
|
||||||
|
{
|
||||||
|
return FoldersPanelSettings::limitFoldersPanelToHome();
|
||||||
|
}
|
||||||
|
|
||||||
void FoldersPanel::setAutoScrolling(bool enable)
|
void FoldersPanel::setAutoScrolling(bool enable)
|
||||||
{
|
{
|
||||||
// TODO: Not supported yet in Dolphin 2.0
|
// TODO: Not supported yet in Dolphin 2.0
|
||||||
|
@ -122,6 +134,14 @@ bool FoldersPanel::urlChanged()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FoldersPanel::reloadTree()
|
||||||
|
{
|
||||||
|
if (m_controller) {
|
||||||
|
loadTree(url());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void FoldersPanel::showEvent(QShowEvent* event)
|
void FoldersPanel::showEvent(QShowEvent* event)
|
||||||
{
|
{
|
||||||
if (event->spontaneous()) {
|
if (event->spontaneous()) {
|
||||||
|
@ -304,8 +324,13 @@ void FoldersPanel::loadTree(const QUrl& url)
|
||||||
|
|
||||||
QUrl baseUrl;
|
QUrl baseUrl;
|
||||||
if (url.isLocalFile()) {
|
if (url.isLocalFile()) {
|
||||||
|
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)
|
// Use the root directory as base for local URLs (#150941)
|
||||||
baseUrl = QUrl::fromLocalFile(QDir::rootPath());
|
baseUrl = QUrl::fromLocalFile(QDir::rootPath());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Clear the path for non-local URLs and use it as base
|
// Clear the path for non-local URLs and use it as base
|
||||||
baseUrl = url;
|
baseUrl = url;
|
||||||
|
@ -320,9 +345,13 @@ void FoldersPanel::loadTree(const QUrl& url)
|
||||||
const int index = m_model->index(url);
|
const int index = m_model->index(url);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
updateCurrentItem(index);
|
updateCurrentItem(index);
|
||||||
|
} else if (url == baseUrl) {
|
||||||
|
// clear the selection when visiting the base url
|
||||||
|
updateCurrentItem(-1);
|
||||||
} else {
|
} else {
|
||||||
m_updateCurrentItem = true;
|
m_updateCurrentItem = true;
|
||||||
m_model->expandParentDirectories(url);
|
m_model->expandParentDirectories(url);
|
||||||
|
|
||||||
// slotLoadingCompleted() will be invoked after the model has
|
// slotLoadingCompleted() will be invoked after the model has
|
||||||
// expanded the url
|
// expanded the url
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,9 @@ public:
|
||||||
virtual ~FoldersPanel();
|
virtual ~FoldersPanel();
|
||||||
|
|
||||||
void setShowHiddenFiles(bool show);
|
void setShowHiddenFiles(bool show);
|
||||||
|
void setLimitFoldersPanelToHome(bool enable);
|
||||||
bool showHiddenFiles() const;
|
bool showHiddenFiles() const;
|
||||||
|
bool limitFoldersPanelToHome() const;
|
||||||
|
|
||||||
void setAutoScrolling(bool enable);
|
void setAutoScrolling(bool enable);
|
||||||
bool autoScrolling() const;
|
bool autoScrolling() const;
|
||||||
|
@ -81,6 +83,7 @@ private slots:
|
||||||
*/
|
*/
|
||||||
void startFadeInAnimation();
|
void startFadeInAnimation();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Initializes the base URL of the tree and expands all
|
* Initializes the base URL of the tree and expands all
|
||||||
|
@ -89,6 +92,8 @@ private:
|
||||||
*/
|
*/
|
||||||
void loadTree(const QUrl& url);
|
void loadTree(const QUrl& url);
|
||||||
|
|
||||||
|
void reloadTree();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the item with the index \a index as current item, selects
|
* Sets the item with the index \a index as current item, selects
|
||||||
* the item and assures that the item will be visible.
|
* the item and assures that the item will be visible.
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
TreeViewContextMenu::TreeViewContextMenu(FoldersPanel* parent,
|
TreeViewContextMenu::TreeViewContextMenu(FoldersPanel* parent,
|
||||||
const KFileItem& fileInfo) :
|
const KFileItem& fileInfo) :
|
||||||
|
@ -124,6 +125,17 @@ void TreeViewContextMenu::open()
|
||||||
popup->addAction(showHiddenFilesAction);
|
popup->addAction(showHiddenFilesAction);
|
||||||
connect(showHiddenFilesAction, &QAction::toggled, this, &TreeViewContextMenu::setShowHiddenFiles);
|
connect(showHiddenFilesAction, &QAction::toggled, this, &TreeViewContextMenu::setShowHiddenFiles);
|
||||||
|
|
||||||
|
// insert 'Limit to Home Directory'
|
||||||
|
const QUrl url = m_fileItem.url();
|
||||||
|
const bool showLimitToHomeDirectory = url.isLocalFile() && (Dolphin::homeUrl().isParentOf(url) || (Dolphin::homeUrl() == url));
|
||||||
|
if (showLimitToHomeDirectory) {
|
||||||
|
QAction* limitFoldersPanelToHomeAction = new QAction(i18nc("@action:inmenu", "Limit to Home Directory"), this);
|
||||||
|
limitFoldersPanelToHomeAction->setCheckable(true);
|
||||||
|
limitFoldersPanelToHomeAction->setChecked(m_parent->limitFoldersPanelToHome());
|
||||||
|
popup->addAction(limitFoldersPanelToHomeAction);
|
||||||
|
connect(limitFoldersPanelToHomeAction, &QAction::toggled, this, &TreeViewContextMenu::setLimitFoldersPanelToHome);
|
||||||
|
}
|
||||||
|
|
||||||
// insert 'Automatic Scrolling'
|
// insert 'Automatic Scrolling'
|
||||||
QAction* autoScrollingAction = new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this);
|
QAction* autoScrollingAction = new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this);
|
||||||
autoScrollingAction->setCheckable(true);
|
autoScrollingAction->setCheckable(true);
|
||||||
|
@ -229,6 +241,11 @@ void TreeViewContextMenu::setShowHiddenFiles(bool show)
|
||||||
m_parent->setShowHiddenFiles(show);
|
m_parent->setShowHiddenFiles(show);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TreeViewContextMenu::setLimitFoldersPanelToHome(bool enable)
|
||||||
|
{
|
||||||
|
m_parent->setLimitFoldersPanelToHome(enable);
|
||||||
|
}
|
||||||
|
|
||||||
void TreeViewContextMenu::setAutoScrolling(bool enable)
|
void TreeViewContextMenu::setAutoScrolling(bool enable)
|
||||||
{
|
{
|
||||||
m_parent->setAutoScrolling(enable);
|
m_parent->setAutoScrolling(enable);
|
||||||
|
|
|
@ -78,6 +78,12 @@ private slots:
|
||||||
*/
|
*/
|
||||||
void setShowHiddenFiles(bool show);
|
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
|
* Sets the 'Automatic Scrolling' setting for the
|
||||||
* folders panel to \a enable.
|
* folders panel to \a enable.
|
||||||
|
|
Loading…
Reference in a new issue