From 40fe023c266536ff290e9b70c7f8be3f92aeaa4d Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Sun, 2 Mar 2025 19:18:44 +0100 Subject: [PATCH] Start: enable multiple custom folder paths * Update tooltip to indicate support for multiple custom folder paths * Remove migration step that worked around lack of multiple folder support * Remove obsolete migration method * Address linter warnings: build/include_what_you_use * Add QStringList as requested on https://github.com/FreeCAD/FreeCAD/pull/19948/files#r1982267583 --- src/Mod/Start/App/CustomFolderModel.cpp | 47 ++++++++++++++++-------- src/Mod/Start/App/CustomFolderModel.h | 4 +- src/Mod/Start/Gui/DlgStartPreferences.ui | 5 ++- src/Mod/Start/Gui/PreCompiled.h | 1 + src/Mod/Start/Gui/StartView.cpp | 11 +----- src/Mod/Start/StartMigrator.py | 13 +------ 6 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/Mod/Start/App/CustomFolderModel.cpp b/src/Mod/Start/App/CustomFolderModel.cpp index 6225349039..7de6452362 100644 --- a/src/Mod/Start/App/CustomFolderModel.cpp +++ b/src/Mod/Start/App/CustomFolderModel.cpp @@ -28,6 +28,7 @@ #include "CustomFolderModel.h" #include +#include using namespace Start; @@ -39,30 +40,46 @@ CustomFolderModel::CustomFolderModel(QObject* parent) Base::Reference parameterGroup = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/Mod/Start"); - _customFolderDirectory = - QDir(QString::fromStdString(parameterGroup->GetASCII("CustomFolder", ""))); + _customFolderPathSpec = QString::fromStdString(parameterGroup->GetASCII("CustomFolder", "")); _showOnlyFCStd = parameterGroup->GetBool("ShowOnlyFCStd", false); } +/// If the custom folder path contains multiple paths separated by ';;', split them into individual +/// paths. This is used to allow the user to specify multiple paths in the preferences dialog. +/// We use ';;' as a separator because ';' is a valid character in a file path (e.g. NTFS on +/// Windows). void CustomFolderModel::loadCustomFolder() { beginResetModel(); clear(); - if (!_customFolderDirectory.isReadable()) { - Base::Console().Warning( - "BaseApp/Preferences/Mod/Start/CustomFolder: cannot read custom folder %s\n", - _customFolderDirectory.absolutePath().toStdString().c_str()); + auto pathDelimiter = QStringLiteral(";;"); + auto paths = _customFolderPathSpec.split(pathDelimiter, Qt::SkipEmptyParts); + + for (const auto& path : paths) { + QDir customFolderDirectory(path); + if (!customFolderDirectory.exists()) { + Base::Console().Warning( + "BaseApp/Preferences/Mod/Start/CustomFolder: custom folder %s does not exist\n", + customFolderDirectory.absolutePath().toStdString().c_str()); + continue; + } + if (!customFolderDirectory.isReadable()) { + Base::Console().Warning( + "BaseApp/Preferences/Mod/Start/CustomFolder: cannot read custom folder %s\n", + customFolderDirectory.absolutePath().toStdString().c_str()); + continue; + } + if (_showOnlyFCStd) { + customFolderDirectory.setNameFilters(QStringList() << QStringLiteral("*.FCStd")); + } + + auto entries = customFolderDirectory.entryList(QDir::Filter::Files | QDir::Filter::Readable, + QDir::SortFlag::Name); + for (const auto& entry : entries) { + addFile(customFolderDirectory.filePath(entry)); + } } - if (_showOnlyFCStd) { - _customFolderDirectory.setNameFilters(QStringList() << QStringLiteral("*.FCStd")); - } - - auto entries = _customFolderDirectory.entryList(QDir::Filter::Files | QDir::Filter::Readable, - QDir::SortFlag::Name); - for (const auto& entry : entries) { - addFile(_customFolderDirectory.filePath(entry)); - } endResetModel(); } diff --git a/src/Mod/Start/App/CustomFolderModel.h b/src/Mod/Start/App/CustomFolderModel.h index 3901e1e01d..050090967e 100644 --- a/src/Mod/Start/App/CustomFolderModel.h +++ b/src/Mod/Start/App/CustomFolderModel.h @@ -25,7 +25,7 @@ #define FREECAD_START_CUSTOMFOLDERMODEL_H #include -#include +#include #include #include "DisplayedFilesModel.h" @@ -45,7 +45,7 @@ public: void loadCustomFolder(); private: - QDir _customFolderDirectory; + QString _customFolderPathSpec; bool _showOnlyFCStd; // Show only FreeCAD files }; diff --git a/src/Mod/Start/Gui/DlgStartPreferences.ui b/src/Mod/Start/Gui/DlgStartPreferences.ui index 20f0e5bd1a..f48f860d30 100644 --- a/src/Mod/Start/Gui/DlgStartPreferences.ui +++ b/src/Mod/Start/Gui/DlgStartPreferences.ui @@ -44,11 +44,12 @@ - An optional custom folder to be displayed on the Start page. + An optional custom folder to be displayed on the Start page. +By using ";;" to separate paths, you can add several folders here. Gui::FileChooser::Directory - + CustomFolder diff --git a/src/Mod/Start/Gui/PreCompiled.h b/src/Mod/Start/Gui/PreCompiled.h index 73af2c30b8..0afe415960 100644 --- a/src/Mod/Start/Gui/PreCompiled.h +++ b/src/Mod/Start/Gui/PreCompiled.h @@ -66,6 +66,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Mod/Start/Gui/StartView.cpp b/src/Mod/Start/Gui/StartView.cpp index bcc51ba28a..fb331a7d33 100644 --- a/src/Mod/Start/Gui/StartView.cpp +++ b/src/Mod/Start/Gui/StartView.cpp @@ -53,6 +53,7 @@ #include #include #include +#include using namespace StartGui; @@ -198,15 +199,7 @@ StartView::StartView(QWidget* parent) std::string customFolder(hGrp->GetASCII("CustomFolder", "")); bool showCustomFolder = false; if (!customFolder.empty()) { - auto customFolderDirectory = QDir(QString::fromStdString(customFolder)); - if (customFolderDirectory.exists()) { - showCustomFolder = true; - } - else { - Base::Console().Warning( - "BaseApp/Preferences/Mod/Start/CustomFolder: '%s' does not exist\n", - customFolderDirectory.absolutePath().toStdString().c_str()); - } + showCustomFolder = true; } // First start page diff --git a/src/Mod/Start/StartMigrator.py b/src/Mod/Start/StartMigrator.py index 2b5480fe8f..ce9721db46 100644 --- a/src/Mod/Start/StartMigrator.py +++ b/src/Mod/Start/StartMigrator.py @@ -57,7 +57,6 @@ class StartMigrator2024: self._remove_toolbars() self._remove_deprecated_parameters() self._mark_complete() - self._migrate_custom_folder() FreeCAD.Console.PrintMessage("done.\n") # If the old Start workbench was set as the Autoload Module, reconfigure it so the Start command is run at startup, @@ -100,25 +99,17 @@ class StartMigrator2024: if "WebWorkbench" in groups: tux_prefs.RemGroup("WebWorkbench") - # In FreeCAD 1.1, the custom folder parameter was renamed from "ShowCustomFolder" - # to "CustomFolder". The new parameter does not yet support multiple locations. - def _migrate_custom_folder(self): - custom_folder = self.start_prefs.GetString("ShowCustomFolder", "") - - # Note: multiple locations separated by ";;" are not supported at this time - # Use the first listed location and discard the rest - return custom_folder.split(";;")[0] - # Delete old Start preferences def _remove_deprecated_parameters(self): show_on_startup = self.start_prefs.GetBool("ShowOnStartup", True) show_examples = self.start_prefs.GetBool("ShowExamples", True) close_start = self.start_prefs.GetBool("closeStart", False) - custom_folder = self._migrate_custom_folder() + custom_folder = self.start_prefs.GetString("ShowCustomFolder", "") self.start_prefs.Clear() self.start_prefs.SetBool("ShowOnStartup", show_on_startup) self.start_prefs.SetBool("ShowExamples", show_examples) self.start_prefs.SetBool("CloseStart", close_start) + # ShowCustomFolder renamed to CustomFolder in 1.1 self.start_prefs.SetString("CustomFolder", custom_folder) # Indicate that this migration has been run