Commit cd6364a2 authored by Raphael Rosch's avatar Raphael Rosch Committed by David Faure

Enable option to show hidden folders in sidebar, plus small sidebar code fixes...

Enable option to show hidden folders in sidebar, plus small sidebar code fixes (eg: scrollbar display)

Adds option to use the "ShowHiddenFolders" option in .desktop files for sidebar
buttons, as well as a context menu entry to toggle it when the option is present
in the .desktop file.

Included is a small fix for the width of the column display, which now allows
for the scrollbar to be displayed properly when the tree does not fit the
horizontal area. This is still not perfect though.

Reviewed By: dfaure

Differential Revision: https://phabricator.kde.org/D29871
parent 8aac5b4b
......@@ -2136,6 +2136,11 @@ change the &URL; (path) of the folder viewed in that page.</para></listitem>
<listitem><para>To change the tab icon.</para></listitem>
</varlistentry>
<varlistentry>
<term><guimenuitem>Show Hidden Folders</guimenuitem></term>
<listitem><para>Toggle whether hidden folders (folders with names that start with a dot) should be shown in the treeview.</para></listitem>
</varlistentry>
<varlistentry>
<term><guimenuitem>Remove</guimenuitem></term>
<listitem><para>To remove the tab page from the Sidebar.</para>
......
......@@ -3,6 +3,7 @@ Type=Link
URL=~
Icon=user-home
Open=true
ShowHiddenFolders=false
X-KDE-TreeModule=Directory
X-KDE-KonqSidebarModule=konqsidebar_tree
X-KDE-Weight=10
......
......@@ -4,6 +4,7 @@ URL=file:/
Icon=folder-red
#Icon=folder-orange
Open=true
ShowHiddenFolders=false
X-KDE-TreeModule=Directory
X-KDE-KonqSidebarModule=konqsidebar_tree
X-KDE-Weight=11
......
......@@ -154,6 +154,14 @@ void ModuleManager::setModuleIcon(const QString &fileName, const QString &icon)
ksc.sync();
}
void ModuleManager::setShowHiddenFolders(const QString &fileName, const bool &newState)
{
KConfig desktopFile(m_localPath + fileName, KConfig::SimpleConfig);
KConfigGroup ksc(&desktopFile, "Desktop Entry");
ksc.writeEntry("ShowHiddenFolders", newState);
ksc.sync();
}
void ModuleManager::removeModule(const QString &fileName)
{
// Remove the local file (if it exists)
......
......@@ -61,6 +61,7 @@ public:
void setModuleName(const QString &fileName, const QString &moduleName);
void setModuleUrl(const QString &fileName, const QUrl &url);
void setModuleIcon(const QString &fileName, const QString &icon);
void setShowHiddenFolders(const QString &fileName, const bool &newState);
/// Find a unique filename for a new module, based on a template name
/// like "dirtree%1.desktop".
......
......@@ -328,6 +328,15 @@ void Sidebar_Widget::slotRemove()
}
}
void Sidebar_Widget::slotToggleShowHiddenFolders()
{
Q_ASSERT(currentButtonInfo().canToggleShowHiddenFolders);
bool newToggleState = !currentButtonInfo().showHiddenFolders;
m_moduleManager.setShowHiddenFolders(currentButtonInfo().file, newToggleState);
// TODO: update THAT button only.
QTimer::singleShot(0, this, SLOT(updateButtons()));
}
void Sidebar_Widget::slotMultipleViews()
{
m_singleWidgetMode = !m_singleWidgetMode;
......@@ -402,7 +411,6 @@ void Sidebar_Widget::updateButtons()
delete button.dock;
}
m_buttonBar->removeTab(i);
}
m_buttons.clear();
......@@ -531,6 +539,8 @@ bool Sidebar_Widget::addButton(const QString &desktopFileName, int pos)
m_buttonBar->appendTab(QIcon::fromTheme(icon), lastbtn, name);
ButtonInfo buttonInfo(config, desktopFileName, cleanupURL(url), lib, name, icon);
buttonInfo.configOpen = configGroup.readEntry("Open", false);
buttonInfo.canToggleShowHiddenFolders = (configGroup.readEntry("X-KDE-KonqSidebarModule", QString()) == "konqsidebar_tree");
buttonInfo.showHiddenFolders = configGroup.readEntry("ShowHiddenFolders", false);
m_buttons.insert(lastbtn, buttonInfo);
KMultiTabBarTab *tab = m_buttonBar->tab(lastbtn);
tab->installEventFilter(this);
......@@ -565,6 +575,11 @@ bool Sidebar_Widget::eventFilter(QObject *obj, QEvent *ev)
buttonPopup->addAction(QIcon::fromTheme("edit-rename"), i18n("Set Name..."), this, &Sidebar_Widget::slotSetName); // Item to open a dialog to change the name of the sidebar item (by Pupeno)
buttonPopup->addAction(QIcon::fromTheme("internet-web-browser"), i18n("Set URL..."), this, &Sidebar_Widget::slotSetURL);
buttonPopup->addAction(QIcon::fromTheme("preferences-desktop-icons"), i18n("Set Icon..."), this, &Sidebar_Widget::slotSetIcon);
if (currentButtonInfo().canToggleShowHiddenFolders) {
QAction *toggleShowHiddenFolders = buttonPopup->addAction(i18n("Show Hidden Folders..."), this, &Sidebar_Widget::slotToggleShowHiddenFolders);
toggleShowHiddenFolders->setCheckable(true);
toggleShowHiddenFolders->setChecked(currentButtonInfo().showHiddenFolders);
}
buttonPopup->addSeparator();
buttonPopup->addAction(QIcon::fromTheme("edit-delete"), i18n("Remove"), this, &Sidebar_Widget::slotRemove);
buttonPopup->addSeparator();
......
......@@ -43,7 +43,6 @@ class ButtonInfo
{
public:
ButtonInfo()
: module(NULL), m_plugin(NULL)
{
}
ButtonInfo(const KSharedConfig::Ptr &configFile_,
......@@ -52,10 +51,9 @@ public:
const QString &lib,
const QString &dispName_,
const QString &iconName_)
: configFile(configFile_),
file(file_), dock(NULL),
module(NULL), m_plugin(NULL),
initURL(url_), libName(lib), displayName(dispName_), iconName(iconName_)
: configFile(configFile_), file(file_),
libName(lib), displayName(dispName_),
iconName(iconName_), initURL(url_)
{
}
......@@ -64,14 +62,17 @@ public:
KSharedConfig::Ptr configFile;
QString file;
QPointer<QWidget> dock;
KonqSidebarModule *module;
KonqSidebarPlugin *m_plugin;
KonqSidebarModule *module = nullptr;
KonqSidebarPlugin *m_plugin = nullptr;
QString libName;
QString displayName;
QString iconName;
bool configOpen;
QUrl initURL;
bool configOpen = false;
bool canToggleShowHiddenFolders = false;
bool showHiddenFolders = false;
};
class Sidebar_Widget: public QWidget
......@@ -113,6 +114,7 @@ protected Q_SLOTS:
void slotSetName();
void slotSetURL();
void slotSetIcon();
void slotToggleShowHiddenFolders();
void slotRemove();
void slotUrlsDropped(const QList<QUrl> &urls);
......
......@@ -21,8 +21,14 @@
/*
TODO:
-sidepanel not triggering changes in session properly
-"Configure sidebar" > "Add new" has no option to actually add anything there
-places panel does not respond to view location changes
-detect icon size for places panel
-doubleclick on image (to open kuickview) causes sidebar to deselect
-"View mode" to "sidebar" causes crash and ruins session -- cannot undo
BUGS:
-(konq bug) sftp cannot save file being edited, because: "A file named sftp://hostname/path/to/file already exists."
......@@ -53,14 +59,15 @@ KonqSideBarTreeModule::KonqSideBarTreeModule(QWidget *parent,
m_initURL = cleanupURL(QUrl(configGroup.readPathEntry("URL", QString()))); // because the .desktop file url might be "~"
treeView = new QTreeView(parent);
treeView->setHeaderHidden(true);
treeView->header()->setStretchLastSection(false);
treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
treeView->setTextElideMode(Qt::ElideMiddle);
model = new KDirModel(this);
sorted_model = new KDirSortFilterProxyModel(this);
sorted_model->setSortFoldersFirst(true);
sorted_model->setSourceModel(model);
model->dirLister()->setDirOnlyMode(true);
model->dirLister()->setShowingDotFiles(configGroup.readEntry("ShowHiddenFolders", false));
model->openUrl(m_initURL, KDirModel::ShowRoot);
......@@ -70,6 +77,11 @@ KonqSideBarTreeModule::KonqSideBarTreeModule(QWidget *parent,
treeView->setColumnHidden(i, true);
}
connect(treeView, &QTreeView::expanded,
this, &KonqSideBarTreeModule::slotUpdateColWidth);
connect(treeView, &QTreeView::collapsed,
this, &KonqSideBarTreeModule::slotUpdateColWidth);
model->expandToUrl(m_initURL); // KDirModel is async, we'll just have to wait for slotKDirCompleted()
connect(model, &KDirModel::expand,
this, &KonqSideBarTreeModule::slotKDirExpand_setRootIndex);
......@@ -167,8 +179,14 @@ void KonqSideBarTreeModule::slotSelectionChanged(const QItemSelection &selected,
if (index.isValid() && m_lastURL != urlFromIndex) {
emit openUrlRequest(urlFromIndex);
}
slotUpdateColWidth();
}
// needed because when there is only one column, QTreeView does not trigger resize
void KonqSideBarTreeModule::slotUpdateColWidth()
{
treeView->resizeColumnToContents(0);
}
// needed because KDirModel is async
void KonqSideBarTreeModule::slotKDirExpand_setRootIndex()
......@@ -190,6 +208,7 @@ void KonqSideBarTreeModule::slotKDirExpand_setSelection(const QModelIndex &index
this, &KonqSideBarTreeModule::slotKDirExpand_setSelection);
setSelection(m_lastURL, false);
}
slotUpdateColWidth();
}
......@@ -217,7 +236,7 @@ QUrl KonqSideBarTreeModule::getUrlFromIndex(const QModelIndex &index)
return resolvedUrl;
}
const QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url)
QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url) const
{
return sorted_model->mapFromSource(model->indexForUrl(url));
}
......
......@@ -52,6 +52,7 @@ public:
private slots:
void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void slotUpdateColWidth();
void slotKDirExpand_setRootIndex();
void slotKDirExpand_setSelection(const QModelIndex &index);
void customEvent(QEvent *ev) override;
......@@ -61,7 +62,7 @@ private:
void setSelectionIndex(const QModelIndex &index);
QUrl getUrlFromIndex(const QModelIndex &index);
QModelIndex resolveIndex(const QModelIndex &index);
const QModelIndex getIndexFromUrl(const QUrl &url);
QModelIndex getIndexFromUrl(const QUrl &url) const;
QUrl cleanupURL(const QUrl &url);
QTreeView *treeView;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment