Merge pull request #19948 from furgo16/startpage-option-multiplefolders

Start: enable multiple custom folder paths
This commit is contained in:
Chris Hennes
2025-03-06 13:30:46 +00:00
committed by GitHub
6 changed files with 42 additions and 39 deletions

View File

@@ -28,6 +28,7 @@
#include "CustomFolderModel.h"
#include <App/Application.h>
#include <QStringList>
using namespace Start;
@@ -39,30 +40,46 @@ CustomFolderModel::CustomFolderModel(QObject* parent)
Base::Reference<ParameterGrp> 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();
}

View File

@@ -25,7 +25,7 @@
#define FREECAD_START_CUSTOMFOLDERMODEL_H
#include <QAbstractListModel>
#include <QDir>
#include <QString>
#include <Base/Parameter.h>
#include "DisplayedFilesModel.h"
@@ -45,7 +45,7 @@ public:
void loadCustomFolder();
private:
QDir _customFolderDirectory;
QString _customFolderPathSpec;
bool _showOnlyFCStd; // Show only FreeCAD files
};

View File

@@ -44,11 +44,12 @@
<item row="1" column="1">
<widget class="Gui::PrefFileChooser" name="fileChooserCustomFolder" native="true">
<property name="toolTip">
<string>An optional custom folder to be displayed on the Start page.</string>
<string>An optional custom folder to be displayed on the Start page.
By using &quot;;;&quot; to separate paths, you can add several folders here.</string>
</property>
<property name="mode">
<enum>Gui::FileChooser::Directory</enum>
</property>
</property>
<property name="prefEntry" stdset="0">
<cstring>CustomFolder</cstring>
</property>

View File

@@ -66,6 +66,7 @@
#include <QSpacerItem>
#include <QStackedWidget>
#include <QString>
#include <QStringList>
#include <QStyleHints>
#include <QStyleOptionViewItem>
#include <QTimer>

View File

@@ -53,6 +53,7 @@
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <gsl/pointers>
#include <string>
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

View File

@@ -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