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
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user