diff options
| author | Méven Car <[email protected]> | 2026-05-03 14:53:01 +0200 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2026-06-13 12:24:37 +0200 |
| commit | 70f34211cb4ad1f3f6170ded062bafff85d66643 (patch) | |
| tree | cdcbce9a16cc6deed31f0550e7867b0335968ea2 | |
| parent | 169332e5691267fd69ac20ac2b1aa06441c588db (diff) | |
Add A restore view properties to defaults button
The button allows to restore to defaults, in case you are using the
per-folder view properties settings.
The button disables or enables itself whether or not it matches the
defaults view settings.
| -rw-r--r-- | src/dolphinmainwindow.cpp | 10 | ||||
| -rw-r--r-- | src/dolphinpart.rc | 3 | ||||
| -rw-r--r-- | src/dolphinui.rc | 5 | ||||
| -rw-r--r-- | src/dolphinuiforphones.rc | 5 | ||||
| -rw-r--r-- | src/tests/viewpropertiestest.cpp | 24 | ||||
| -rw-r--r-- | src/views/dolphinview.cpp | 28 | ||||
| -rw-r--r-- | src/views/dolphinview.h | 9 | ||||
| -rw-r--r-- | src/views/dolphinviewactionhandler.cpp | 13 | ||||
| -rw-r--r-- | src/views/dolphinviewactionhandler.h | 2 | ||||
| -rw-r--r-- | src/views/viewproperties.cpp | 29 | ||||
| -rw-r--r-- | src/views/viewproperties.h | 9 |
11 files changed, 132 insertions, 5 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index c1bbcc5f5..d35575624 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -1677,6 +1677,8 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer *viewContainer) &DolphinViewContainer::selectionModeChanged, actionCollection()->action(QStringLiteral("toggle_selection_mode")), &QAction::setChecked); + + disconnect(oldViewContainer->view(), &DolphinView::viewSettingsChanged, this, nullptr); } connectViewSignals(viewContainer); @@ -2732,6 +2734,9 @@ void DolphinMainWindow::updateViewActions() QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter")); toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); + QAction *restoreViewSettingsToDefault = actionCollection()->action(QStringLiteral("restore_view_settings_default")); + restoreViewSettingsToDefault->setEnabled(!m_activeViewContainer->view()->isViewSettingsDefaults()); + updateSplitActions(); } @@ -2813,6 +2818,11 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer *container) connect(navigator, &KUrlNavigator::tabRequested, this, &DolphinMainWindow::openNewTab); connect(navigator, &KUrlNavigator::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate); connect(navigator, &KUrlNavigator::newWindowRequested, this, &DolphinMainWindow::openNewWindow); + + connect(view, &DolphinView::viewSettingsChanged, this, [this](bool isDefault) { + QAction *restoreViewSettingsToDefault = actionCollection()->action(QStringLiteral("restore_view_settings_default")); + restoreViewSettingsToDefault->setEnabled(!isDefault); + }); } void DolphinMainWindow::updateSplitActions() diff --git a/src/dolphinpart.rc b/src/dolphinpart.rc index b5452c1ea..bd2814233 100644 --- a/src/dolphinpart.rc +++ b/src/dolphinpart.rc @@ -1,6 +1,6 @@ <?xml version="1.0"?> <!DOCTYPE gui SYSTEM "kpartgui.dtd"> -<gui name="dolphinpart" version="19" translationDomain="dolphin"> +<gui name="dolphinpart" version="20" translationDomain="dolphin"> <MenuBar> <Menu name="edit"><text>&Edit</text> <Action name="new_menu"/> @@ -28,6 +28,7 @@ <Action name="show_preview" /> <Action name="show_hidden_files" /> <Separator/> + <Action name="restore_view_settings_default" /> <Action name="view_properties" /> </Menu> <Menu name="go"><text>&Go</text> diff --git a/src/dolphinui.rc b/src/dolphinui.rc index a22e77e89..c82e104f3 100644 --- a/src/dolphinui.rc +++ b/src/dolphinui.rc @@ -48,6 +48,9 @@ <Action name="show_hidden_files" /> <Action name="act_as_admin" /> <Separator/> + <Action name="restore_view_settings_default" /> + <Action name="view_properties" /> + <Separator/> <Action name="split_view_menu" /> <Action name="popout_split_view" /> <Action name="split_stash" /> @@ -60,8 +63,6 @@ <Action name="editable_location" /> <Action name="replace_location" /> </Menu> - <Separator/> - <Action name="view_properties" /> </Menu> <Menu name="go"> <Action name="bookmarks" /> diff --git a/src/dolphinuiforphones.rc b/src/dolphinuiforphones.rc index 06e9e3694..eba2b970a 100644 --- a/src/dolphinuiforphones.rc +++ b/src/dolphinuiforphones.rc @@ -48,6 +48,9 @@ <Action name="show_hidden_files" /> <Action name="act_as_admin" /> <Separator/> + <Action name="restore_view_settings_default" /> + <Action name="view_properties" /> + <Separator/> <Action name="split_view_menu" /> <Action name="popout_split_view" /> <Action name="split_stash" /> @@ -60,8 +63,6 @@ <Action name="editable_location" /> <Action name="replace_location" /> </Menu> - <Separator/> - <Action name="view_properties" /> </Menu> <Menu name="go"> <Action name="bookmarks" /> diff --git a/src/tests/viewpropertiestest.cpp b/src/tests/viewpropertiestest.cpp index 101fff707..f90d57b88 100644 --- a/src/tests/viewpropertiestest.cpp +++ b/src/tests/viewpropertiestest.cpp @@ -38,6 +38,7 @@ private Q_SLOTS: void testUseAsDefaultViewSettings(); void testUseAsCustomDefaultViewSettings(); void testSpecialFolderPropsPreservedWithGlobalViewProps(); + void testRestoreViewProps(); private: bool m_globalViewProps; @@ -579,6 +580,29 @@ void ViewPropertiesTest::testSpecialFolderPropsPreservedWithGlobalViewProps() } } +void ViewPropertiesTest::testRestoreViewProps() +{ + const QUrl testDirUrl = m_testDir->url(); + + // First visit: customize the view mode to DetailsView + { + ViewProperties props(testDirUrl); + QCOMPARE(props.viewMode(), DolphinView::IconsView); // default + props.setViewMode(DolphinView::DetailsView); + } + { + ViewProperties props(testDirUrl); + QCOMPARE(props.viewMode(), DolphinView::DetailsView); + QVERIFY(!props.isDefaults()); + } + { + ViewProperties props(testDirUrl); + props.restoreToDefaults(); + QVERIFY(props.isDefaults()); + QCOMPARE(props.viewMode(), DolphinView::IconsView); + } +} + QTEST_GUILESS_MAIN(ViewPropertiesTest) #include "viewpropertiestest.moc" diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index e14227198..cbeec0910 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -377,6 +377,7 @@ void DolphinView::setPreviewsShown(bool show) if (newZoomLevel != oldZoomLevel) { Q_EMIT zoomLevelChanged(newZoomLevel, oldZoomLevel); } + Q_EMIT viewSettingsChanged(props.isDefaults()); } bool DolphinView::previewsShown() const @@ -399,6 +400,7 @@ void DolphinView::setHiddenFilesShown(bool show) m_model->setShowHiddenFiles(show); Q_EMIT hiddenFilesShownChanged(show); + Q_EMIT viewSettingsChanged(props.isDefaults()); } bool DolphinView::hiddenFilesShown() const @@ -418,6 +420,7 @@ void DolphinView::setGroupedSorting(bool grouped) m_model->setGroupedSorting(grouped); Q_EMIT groupedSortingChanged(grouped); + Q_EMIT viewSettingsChanged(props.isDefaults()); } bool DolphinView::groupedSorting() const @@ -514,7 +517,9 @@ void DolphinView::setZoomLevel(int level) props.setZoomLevel(level == m_defaultZoomLevel ? -1 : level); hideToolTip(); + Q_EMIT zoomLevelChanged(newZoomLevel, oldZoomLevel); + Q_EMIT viewSettingsChanged(props.isDefaults()); } } @@ -540,6 +545,7 @@ void DolphinView::setSortRole(const QByteArray &role) model->setSortRole(role); Q_EMIT sortRoleChanged(role); + Q_EMIT viewSettingsChanged(props.isDefaults()); } } @@ -585,6 +591,7 @@ void DolphinView::setSortOrder(Qt::SortOrder order) m_model->setSortOrder(order); Q_EMIT sortOrderChanged(order); + Q_EMIT viewSettingsChanged(props.isDefaults()); } } @@ -628,6 +635,7 @@ void DolphinView::setVisibleRoles(const QList<QByteArray> &roles) m_view->setVisibleRoles(roles); Q_EMIT visibleRolesChanged(m_visibleRoles, previousRoles); + Q_EMIT viewSettingsChanged(props.isDefaults()); } QList<QByteArray> DolphinView::visibleRoles() const @@ -1695,6 +1703,8 @@ void DolphinView::updateSortFoldersFirst(bool foldersFirst) m_model->setSortDirectoriesFirst(foldersFirst); Q_EMIT sortFoldersFirstChanged(foldersFirst); + + Q_EMIT viewSettingsChanged(props.isDefaults()); } void DolphinView::updateSortHiddenLast(bool hiddenLast) @@ -1705,6 +1715,8 @@ void DolphinView::updateSortHiddenLast(bool hiddenLast) m_model->setSortHiddenLast(hiddenLast); Q_EMIT sortHiddenLastChanged(hiddenLast); + + Q_EMIT viewSettingsChanged(props.isDefaults()); } QPair<bool, QString> DolphinView::pasteInfo() const @@ -2058,6 +2070,20 @@ void DolphinView::updateViewState() updateSelectionState(); } +bool DolphinView::isViewSettingsDefaults() const +{ + ViewProperties props(viewPropertiesUrl()); + return props.isDefaults(); +} + +void DolphinView::restoreViewSettingsToDefaults() +{ + ViewProperties props(viewPropertiesUrl()); + props.restoreToDefaults(); + + applyViewProperties(props); +} + void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior) { if (GeneralSettings::showToolTips()) { @@ -2515,6 +2541,8 @@ void DolphinView::applyViewProperties(const ViewProperties &props) } m_view->endTransaction(); + + Q_EMIT viewSettingsChanged(props.isDefaults()); } void DolphinView::updateDefaultZoomLevel() diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index b0ab6ab6a..19813f0e1 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -509,6 +509,13 @@ public Q_SLOTS: */ void updateViewState(); + /** + * Whether or not the current has the default settings + */ + bool isViewSettingsDefaults() const; + + void restoreViewSettingsToDefaults(); + Q_SIGNALS: /** * Is emitted if the view has been activated by e. g. a mouse click. @@ -751,6 +758,8 @@ Q_SIGNALS: */ void doubleClickViewBackground(Qt::MouseButton button); + void viewSettingsChanged(bool isDefault); + protected: /** Changes the zoom level if Control is pressed during a wheel event. */ void wheelEvent(QWheelEvent *event) override; diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp index 2aed32d8e..25d89ee90 100644 --- a/src/views/dolphinviewactionhandler.cpp +++ b/src/views/dolphinviewactionhandler.cpp @@ -388,6 +388,12 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac "in which all folder view properties can be adjusted.")); connect(adjustViewProps, &QAction::triggered, this, &DolphinViewActionHandler::slotAdjustViewProperties); + QAction *restoreViewSettingsToDefault = actionCollection()->addAction(QStringLiteral("restore_view_settings_default")); + restoreViewSettingsToDefault->setIcon(QIcon::fromTheme(QStringLiteral("view-restore"))); + restoreViewSettingsToDefault->setText(i18nc("@action:inmenu", "Restore to Defaults")); + restoreViewSettingsToDefault->setToolTip(i18nc("info:tooltip", "Restore View Settings to Defaults Value")); + connect(restoreViewSettingsToDefault, &QAction::triggered, this, &DolphinViewActionHandler::restoreViewSettingsToDefaults); + // View settings: the dropdown menu contains various view-related actions KActionMenu *viewSettings = m_actionCollection->add<KActionMenu>(QStringLiteral("view_settings")); viewSettings->setText(i18nc("@action:intoolbar", "View Settings")); @@ -404,6 +410,8 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac viewSettings->addAction(visibleRolesMenu); viewSettings->addAction(showPreview); viewSettings->addAction(showHiddenFiles); + viewSettings->addSeparator(); + viewSettings->addAction(restoreViewSettingsToDefault); viewSettings->addAction(adjustViewProps); viewSettings->setPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup); connect(viewSettings, &KActionMenu::triggered, viewModeActions, &KSelectAction::triggered); @@ -954,4 +962,9 @@ void DolphinViewActionHandler::slotSelectionChanged(const KFileItemList &selecti } } +void DolphinViewActionHandler::restoreViewSettingsToDefaults() +{ + m_currentView->restoreViewSettingsToDefaults(); +} + #include "moc_dolphinviewactionhandler.cpp" diff --git a/src/views/dolphinviewactionhandler.h b/src/views/dolphinviewactionhandler.h index b15a73933..41fc994d1 100644 --- a/src/views/dolphinviewactionhandler.h +++ b/src/views/dolphinviewactionhandler.h @@ -236,6 +236,8 @@ private Q_SLOTS: */ void slotSelectionChanged(const KFileItemList &selection); + void restoreViewSettingsToDefaults(); + private: /** * Create all the actions. diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp index 484047651..94262e651 100644 --- a/src/views/viewproperties.cpp +++ b/src/views/viewproperties.cpp @@ -116,6 +116,35 @@ ViewPropertySettings *ViewProperties::defaultProperties() const return props; } +void ViewProperties::restoreToDefaults() +{ + delete m_node; + m_node = defaultProperties(); + update(); +} + +bool ViewProperties::isDefaults() const +{ + const auto defaultProps = defaultProperties(); + auto cleanup = qScopeGuard([&defaultProps]() { + delete defaultProps; + }); + // clang-format off + return m_node->viewMode() == defaultProps->viewMode() + && m_node->zoomLevel() == defaultProps->zoomLevel() + && m_node->previewsShown() == defaultProps->previewsShown() + && m_node->hiddenFilesShown() == defaultProps->hiddenFilesShown() + && m_node->groupedSorting() == defaultProps->groupedSorting() + && m_node->groupRole() == defaultProps->groupRole() + && m_node->sortRole() == defaultProps->sortRole() + && m_node->sortOrder() == defaultProps->sortOrder() + && m_node->sortFoldersFirst() == defaultProps->sortFoldersFirst() + && m_node->sortHiddenLast() == defaultProps->sortHiddenLast() + && m_node->visibleRoles() == defaultProps->visibleRoles() + && m_node->headerColumnWidths() == defaultProps->headerColumnWidths(); + // clang-format on +} + ViewProperties::ViewProperties(const QUrl &url) : m_changedProps(false) , m_autoSave(true) diff --git a/src/views/viewproperties.h b/src/views/viewproperties.h index 801d33845..c203e2f0c 100644 --- a/src/views/viewproperties.h +++ b/src/views/viewproperties.h @@ -125,6 +125,15 @@ public: */ QString destinationDir(const QString &subDir) const; + /** + * Restore the view settings to the default settings + * Depending on the view type. + * + * Only useful when in per-folder settings + */ + void restoreToDefaults(); + bool isDefaults() const; + private: /** * Returns the view-mode prefix when storing additional properties for |
