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/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,15 @@ /* TODO: +-sidepanel not triggering changes in session properly +-"Configure sidebar" > "Add new" has no option to actually add anything there +-create context menu option to "Show Hidden Folders" -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 +60,16 @@ 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)); // optimally, this should be a button toggle or context menu selection + model->openUrl(m_initURL, KDirModel::ShowRoot); @@ -70,6 +79,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 +181,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 +210,7 @@ this, &KonqSideBarTreeModule::slotKDirExpand_setSelection); setSelection(m_lastURL, false); } + slotUpdateColWidth(); } @@ -217,7 +238,7 @@ return resolvedUrl; } -const QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url) +QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url) const { return sorted_model->mapFromSource(model->indexForUrl(url)); }