diff --git a/doc/konqueror/index.docbook b/doc/konqueror/index.docbook --- a/doc/konqueror/index.docbook +++ b/doc/konqueror/index.docbook @@ -2136,6 +2136,11 @@ To change the tab icon. + +Show Hidden Folders +Toggle whether hidden folders (folders with names that start with a dot) should be shown in the treeview. + + Remove To remove the tab page from the Sidebar. diff --git a/sidebar/default_entries/home.desktop b/sidebar/default_entries/home.desktop --- a/sidebar/default_entries/home.desktop +++ b/sidebar/default_entries/home.desktop @@ -3,6 +3,7 @@ URL=~ Icon=user-home Open=true +ShowHiddenFolders=false X-KDE-TreeModule=Directory X-KDE-KonqSidebarModule=konqsidebar_tree X-KDE-Weight=10 diff --git a/sidebar/default_entries/root.desktop b/sidebar/default_entries/root.desktop --- a/sidebar/default_entries/root.desktop +++ b/sidebar/default_entries/root.desktop @@ -4,6 +4,7 @@ Icon=folder-red #Icon=folder-orange Open=true +ShowHiddenFolders=false X-KDE-TreeModule=Directory X-KDE-KonqSidebarModule=konqsidebar_tree X-KDE-Weight=11 diff --git a/sidebar/module_manager.h b/sidebar/module_manager.h --- a/sidebar/module_manager.h +++ b/sidebar/module_manager.h @@ -61,6 +61,7 @@ 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". diff --git a/sidebar/module_manager.cpp b/sidebar/module_manager.cpp --- a/sidebar/module_manager.cpp +++ b/sidebar/module_manager.cpp @@ -149,6 +149,14 @@ 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) diff --git a/sidebar/sidebar_widget.h b/sidebar/sidebar_widget.h --- a/sidebar/sidebar_widget.h +++ b/sidebar/sidebar_widget.h @@ -72,7 +72,8 @@ QString iconName; bool configOpen; QUrl initURL; - + bool canToggleShowHiddenFolders; + bool showHiddenFolders; }; class Sidebar_Widget: public QWidget @@ -114,6 +115,7 @@ void slotSetName(); void slotSetURL(); void slotSetIcon(); + void slotToggleShowHiddenFolders(); void slotRemove(); void slotUrlsDropped(const QList &urls); diff --git a/sidebar/sidebar_widget.cpp b/sidebar/sidebar_widget.cpp --- a/sidebar/sidebar_widget.cpp +++ b/sidebar/sidebar_widget.cpp @@ -333,6 +333,15 @@ } } +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; @@ -407,7 +416,6 @@ delete button.dock; } m_buttonBar->removeTab(i); - } m_buttons.clear(); @@ -530,6 +538,8 @@ m_buttonBar->appendTab(SmallIcon(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); @@ -563,6 +573,11 @@ buttonPopup->addAction(QIcon::fromTheme("edit-rename"), i18n("Set Name..."), this, SLOT(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, SLOT(slotSetURL())); buttonPopup->addAction(QIcon::fromTheme("preferences-desktop-icons"), i18n("Set Icon..."), this, SLOT(slotSetIcon())); + if (currentButtonInfo().canToggleShowHiddenFolders) { + QAction *toggleShowHiddenFolders = buttonPopup->addAction(i18n("Show Hidden Folders..."), this, SLOT(slotToggleShowHiddenFolders())); + toggleShowHiddenFolders->setCheckable(true); + toggleShowHiddenFolders->setChecked(currentButtonInfo().showHiddenFolders); + } buttonPopup->addSeparator(); buttonPopup->addAction(QIcon::fromTheme("edit-delete"), i18n("Remove"), this, SLOT(slotRemove())); buttonPopup->addSeparator(); diff --git a/sidebar/tree_module/tree_module.h b/sidebar/tree_module/tree_module.h --- a/sidebar/tree_module/tree_module.h +++ b/sidebar/tree_module/tree_module.h @@ -52,6 +52,7 @@ 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 @@ 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; diff --git a/sidebar/tree_module/tree_module.cpp b/sidebar/tree_module/tree_module.cpp --- a/sidebar/tree_module/tree_module.cpp +++ b/sidebar/tree_module/tree_module.cpp @@ -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 @@ 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 @@ 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 @@ 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 @@ this, &KonqSideBarTreeModule::slotKDirExpand_setSelection); setSelection(m_lastURL, false); } + slotUpdateColWidth(); } @@ -217,7 +236,7 @@ return resolvedUrl; } -const QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url) +QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url) const { return sorted_model->mapFromSource(model->indexForUrl(url)); }