[Gui] PrefPacks - remove "type" parameter

In display, show the "tags" instead.
This commit is contained in:
Chris Hennes
2021-10-11 13:22:28 -05:00
parent abf031d4bf
commit d0b867bdd5
20 changed files with 95 additions and 158 deletions

View File

@@ -36,6 +36,9 @@
</item>
<item>
<widget class="QTreeWidget" name="treeWidget">
<property name="columnCount">
<number>1</number>
</property>
<attribute name="headerMinimumSectionSize">
<number>50</number>
</attribute>
@@ -50,11 +53,6 @@
<string>Property group templates</string>
</property>
</column>
<column>
<property name="text">
<string>Template Type</string>
</property>
</column>
</widget>
</item>
<item>

View File

@@ -81,11 +81,6 @@ void DlgCreateNewPreferencePackImp::setPreferencePackTemplates(const std::vector
QStringList itemColumns;
itemColumns.push_back(QString::fromStdString(t.name));
switch (t.type) {
case Gui::PreferencePack::Type::Appearance: itemColumns.push_back(tr("Appearance")); break;
case Gui::PreferencePack::Type::Behavior: itemColumns.push_back(tr("Behavior")); break;
case Gui::PreferencePack::Type::Combination: itemColumns.push_back(tr("Combination")); break;
}
auto newItem = new QTreeWidgetItem(group, itemColumns);
newItem->setCheckState(0, Qt::Checked);
if (group->checkState(0) != newItem->checkState(0))

View File

@@ -102,10 +102,13 @@ DlgGeneralImp::DlgGeneralImp( QWidget* parent )
auto savedPreferencePacksDirectory = fs::path(App::Application::getUserAppDataDir()) / "SavedPreferencePacks";
// If that directory hasn't been created yet, just send the user to the preferences directory
if (!(fs::exists(savedPreferencePacksDirectory) && fs::is_directory(savedPreferencePacksDirectory)))
if (!(fs::exists(savedPreferencePacksDirectory) && fs::is_directory(savedPreferencePacksDirectory))) {
savedPreferencePacksDirectory = fs::path(App::Application::getUserAppDataDir());
ui->ManagePreferencePacks->hide();
}
QString pathToSavedPacks(QString::fromStdString(savedPreferencePacksDirectory.string()));
ui->ManagePreferencePacks->setToolTip(tr("Open the directory of saved user preference packs"));
connect(ui->ManagePreferencePacks, &QPushButton::clicked, this, [pathToSavedPacks]() { QDesktopServices::openUrl(QUrl::fromLocalFile(pathToSavedPacks)); });
}
@@ -336,56 +339,46 @@ void DlgGeneralImp::recreatePreferencePackMenu()
ui->PreferencePacks->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeMode::ResizeToContents);
QStringList columnHeaders;
columnHeaders << tr("Preference Pack Name")
<< tr("Type", "Whether a preference pack sets appearance, behavior, or both")
<< tr("Tags")
<< QString(); // for the "Load" buttons
ui->PreferencePacks->setHorizontalHeaderLabels(columnHeaders);
// Populate the Preference Packs list
std::map<PreferencePack::Type, std::vector<std::string>> packNames;
packNames[PreferencePack::Type::Appearance] = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Appearance);
packNames[PreferencePack::Type::Behavior] = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Behavior);
packNames[PreferencePack::Type::Combination] = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Combination);
auto packs = Application::Instance->prefPackManager()->preferencePacks();
ui->PreferencePacks->setRowCount(
packNames[PreferencePack::Type::Appearance].size() +
packNames[PreferencePack::Type::Behavior].size() +
packNames[PreferencePack::Type::Combination].size());
ui->PreferencePacks->setRowCount(packs.size());
int row = 0;
QIcon icon = style()->standardIcon(QStyle::SP_DialogApplyButton);
for (const auto& packGroup : packNames) {
for (const auto& pack : packGroup.second) {
auto name = new QTableWidgetItem(QString::fromStdString(pack));
ui->PreferencePacks->setItem(row, 0, name);
QTableWidgetItem* kind;
switch (packGroup.first) {
case PreferencePack::Type::Appearance: kind = new QTableWidgetItem(tr("Appearance")); break;
case PreferencePack::Type::Behavior: kind = new QTableWidgetItem(tr("Behavior")); break;
case PreferencePack::Type::Combination: kind = new QTableWidgetItem(tr("Combination")); break;
default: kind = new QTableWidgetItem(QString::fromUtf8("[ERR: UNKNOWN TYPE]")); break;
}
ui->PreferencePacks->setItem(row, 1, kind);
auto button = new QPushButton(icon, tr("Apply"));
button->setToolTip(tr("Apply the %1 preference pack").arg(QString::fromStdString(pack)));
connect(button, &QPushButton::clicked, this, [this, pack]() { onLoadPreferencePackClicked(pack); });
ui->PreferencePacks->setCellWidget(row, 2, button);
++row;
for (const auto& pack : packs) {
auto name = new QTableWidgetItem(QString::fromStdString(pack.first));
name->setToolTip(QString::fromStdString(pack.second.metadata().description()));
ui->PreferencePacks->setItem(row, 0, name);
auto tags = pack.second.metadata().tag();
QString tagString;
for (const auto& tag : tags) {
if (tagString.isEmpty())
tagString.append(QString::fromStdString(tag));
else
tagString.append(QStringLiteral(", ") + QString::fromStdString(tag));
}
QTableWidgetItem* kind = new QTableWidgetItem(tagString);
ui->PreferencePacks->setItem(row, 1, kind);
auto button = new QPushButton(icon, tr("Apply"));
button->setToolTip(tr("Apply the %1 preference pack").arg(QString::fromStdString(pack.first)));
connect(button, &QPushButton::clicked, this, [this, pack]() { onLoadPreferencePackClicked(pack.first); });
ui->PreferencePacks->setCellWidget(row, 2, button);
++row;
}
}
void DlgGeneralImp::saveAsNewPreferencePack()
{
// Create and run a modal New PreferencePack dialog box
auto appearancePacks = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Appearance);
auto behaviorPacks = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Behavior);
auto combinationPacks = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Combination);
auto allPacks = appearancePacks;
allPacks.insert(allPacks.end(), behaviorPacks.begin(), behaviorPacks.end());
allPacks.insert(allPacks.end(), combinationPacks.begin(), combinationPacks.end());
auto packs = Application::Instance->prefPackManager()->preferencePackNames();
newPreferencePackDialog = std::make_unique<DlgCreateNewPreferencePackImp>(this);
newPreferencePackDialog->setPreferencePackTemplates(Application::Instance->prefPackManager()->templateFiles());
newPreferencePackDialog->setPreferencePackNames(allPacks);
newPreferencePackDialog->setPreferencePackNames(packs);
connect(newPreferencePackDialog.get(), &DlgCreateNewPreferencePackImp::accepted, this, &DlgGeneralImp::newPreferencePackDialogAccepted);
newPreferencePackDialog->open();
}

View File

@@ -113,19 +113,10 @@ bool PreferencePack::apply() const
return true;
}
PreferencePack::Type PreferencePack::type() const
{
auto typeList = _metadata["type"];
if (typeList.empty())
return Type::Combination;
auto typeString = typeList.front().contents;
if (typeString == "appearance")
return Type::Appearance;
else if (typeString == "behavior" || typeString == "behaviour")
return Type::Behavior;
else
return Type::Combination;
App::Metadata Gui::PreferencePack::metadata() const
{
return _metadata;
}
void PreferencePack::applyConfigChanges() const
@@ -191,16 +182,20 @@ void Gui::PreferencePackManager::FindPreferencePacksInPackage(const fs::path& mo
}
}
std::vector<std::string> PreferencePackManager::preferencePackNames(PreferencePack::Type type) const
std::vector<std::string> PreferencePackManager::preferencePackNames() const
{
std::lock_guard<std::mutex> lock(_mutex);
std::vector<std::string> names;
for (const auto& preferencePack : _preferencePacks)
if (preferencePack.second.type() == type)
names.push_back(preferencePack.first);
names.push_back(preferencePack.first);
return names;
}
std::map<std::string, PreferencePack> Gui::PreferencePackManager::preferencePacks() const
{
return _preferencePacks;
}
bool PreferencePackManager::apply(const std::string& preferencePackName) const
{
std::lock_guard<std::mutex> lock(_mutex);
@@ -320,21 +315,6 @@ void PreferencePackManager::save(const std::string& name, const std::vector<Temp
newPreferencePackMetadata.setName(name);
newPreferencePackMetadata.setVersion(1);
auto templateType = templates.front().type;
for (const auto& t : templates) {
if (t.type != templateType) {
templateType = PreferencePack::Type::Combination;
break;
}
}
std::string typeString;
switch (templateType) {
case PreferencePack::Type::Appearance: typeString = "appearance"; break;
case PreferencePack::Type::Behavior: typeString = "behavior"; break;
case PreferencePack::Type::Combination: typeString = "combination"; break;
}
newPreferencePackMetadata.addGenericMetadata("type", App::Meta::GenericMetadata(typeString));
metadata->addContentItem("preferencepack", newPreferencePackMetadata);
metadata->write(savedPreferencePacksDirectory / "package.xml");
@@ -383,28 +363,19 @@ std::vector<PreferencePackManager::TemplateFile> scanForTemplateFiles(const std:
auto templateFolders = scanForTemplateFolders(groupName, entry);
std::vector<PreferencePackManager::TemplateFile> templateFiles;
for (const auto& dir : templateFolders) {
auto templateDirs = std::vector<std::pair<fs::path, PreferencePack::Type>>({
std::make_pair(dir / "Appearance", PreferencePack::Type::Appearance),
std::make_pair(dir / "appearance", PreferencePack::Type::Appearance),
std::make_pair(dir / "Behavior", PreferencePack::Type::Behavior),
std::make_pair(dir / "behavior", PreferencePack::Type::Behavior),
std::make_pair(dir / "Behaviour", PreferencePack::Type::Behavior),
std::make_pair(dir / "behaviour", PreferencePack::Type::Behavior) });
for (const auto& templateDir : templateDirs) {
if (!fs::exists(templateDir.first) || !fs::is_directory(templateDir.first))
continue;
for (const auto& entry : fs::directory_iterator(templateDir.first)) {
if (entry.path().extension() == ".cfg") {
auto name = entry.path().filename().stem().string();
std::replace(name.begin(), name.end(), '_', ' ');
// Make sure we don't insert the same thing twice...
if (std::find_if(templateFiles.begin(), templateFiles.end(), [groupName, name](const auto &rhs)->bool {
return groupName == rhs.group && name == rhs.name;
} ) != templateFiles.end())
continue;
templateFiles.push_back({ groupName, name, entry, templateDir.second });
}
for (const auto& templateDir : templateFolders) {
if (!fs::exists(templateDir) || !fs::is_directory(templateDir))
continue;
for (const auto& entry : fs::directory_iterator(templateDir)) {
if (entry.path().extension() == ".cfg") {
auto name = entry.path().filename().stem().string();
std::replace(name.begin(), name.end(), '_', ' ');
// Make sure we don't insert the same thing twice...
if (std::find_if(templateFiles.begin(), templateFiles.end(), [groupName, name](const auto &rhs)->bool {
return groupName == rhs.group && name == rhs.name;
} ) != templateFiles.end())
continue;
templateFiles.push_back({ groupName, name, entry });
}
}
}

View File

@@ -20,8 +20,8 @@
* *
***************************************************************************/
#ifndef BASE_THEMEMANAGER_H
#define BASE_THEMEMANAGER_H
#ifndef BASE_PREFERENCEPACKMANAGER_H
#define BASE_PREFERENCEPACKMANAGER_H
#include <vector>
#include <string>
@@ -59,16 +59,10 @@ namespace Gui {
*/
bool apply() const;
enum class Type {
Appearance,
Behavior,
Combination
};
/**
* Get the type of PreferencePack (appearance, behavior, or a combination of the two)
* Get the complete metadata object for this preference pack
*/
Type type() const;
App::Metadata metadata() const;
private:
@@ -100,9 +94,14 @@ namespace Gui {
void rescan();
/**
* Get an alphabetical list of names of all installed PreferencePacks of a given type
* Get an alphabetical list of names of all installed PreferencePacks
*/
std::vector<std::string> preferencePackNames(PreferencePack::Type type) const;
std::vector<std::string> preferencePackNames() const;
/**
* Get a map of all installed PreferencePack names and their associated packs
*/
std::map<std::string, PreferencePack> preferencePacks() const;
/**
* Apply the named preferencePack
@@ -142,7 +141,7 @@ namespace Gui {
* templates that only affect appearance, and those that affect behavior.
*
* The base FreeCAD installation includes default templates in:
* $INSTALL_DIR/data/Gui/PreferencePackTemplates/(Appearance|Behavior)/
* $INSTALL_DIR/data/Gui/PreferencePackTemplates/
*
* External add-ons are also searched for any directory called PreferencePackTemplates or
* preference_pack_templates -- either of which is expected to contain appearance and/or
@@ -154,7 +153,6 @@ namespace Gui {
std::string group; // Generally the Add-On/Mod/Package name
std::string name;
boost::filesystem::path path;
PreferencePack::Type type;
};
/**

View File

@@ -1,27 +0,0 @@
SET(PreferencePackTemplates_Files
Arch_Colors.cfg
Console_Colors.cfg
Draft_Colors.cfg
Editor_Colors.cfg
Editor_Font.cfg
Path_Colors.cfg
Sketcher_Colors.cfg
Start_Colors.cfg
TechDraw_Colors.cfg
Window_Colors.cfg
)
ADD_CUSTOM_TARGET(PreferencePackTemplates_data ALL
SOURCES ${PreferencePackTemplates_Files}
)
fc_copy_sources(PreferencePackTemplates_data "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Gui/PreferencePackTemplates/Appearance"
${PreferencePackTemplates_Files})
INSTALL(
FILES
${PreferencePackTemplates_Files}
DESTINATION
${CMAKE_INSTALL_DATADIR}/Gui/PreferencePackTemplates/Appearance
)

View File

@@ -1,18 +0,0 @@
SET(PreferencePackBehaviorTemplates_Files
Main_window_layout.cfg
)
ADD_CUSTOM_TARGET(PreferencePackBehaviorTemplates_data ALL
SOURCES ${PreferencePackBehaviorTemplates_Files}
)
fc_copy_sources(PreferencePackBehaviorTemplates_data "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Gui/PreferencePackTemplates/Behavior"
${PreferencePackBehaviorTemplates_Files})
INSTALL(
FILES
${PreferencePackBehaviorTemplates_Files}
DESTINATION
${CMAKE_INSTALL_DATADIR}/Gui/PreferencePackTemplates/Behavior
)

View File

@@ -1,2 +1,28 @@
add_subdirectory(Appearance)
add_subdirectory(Behavior)
SET(PreferencePackTemplates_Files
Arch_Colors.cfg
Console_Colors.cfg
Draft_Colors.cfg
Editor_Colors.cfg
Editor_Font.cfg
Main_window_layout.cfg
Path_Colors.cfg
Sketcher_Colors.cfg
Start_Colors.cfg
TechDraw_Colors.cfg
Window_Colors.cfg
)
ADD_CUSTOM_TARGET(PreferencePackTemplates_data ALL
SOURCES ${PreferencePackTemplates_Files}
)
fc_copy_sources(PreferencePackTemplates_data "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Gui/PreferencePackTemplates"
${PreferencePackTemplates_Files})
INSTALL(
FILES
${PreferencePackTemplates_Files}
DESTINATION
${CMAKE_INSTALL_DATADIR}/Gui/PreferencePackTemplates
)

View File

@@ -12,7 +12,8 @@
<name>FreeCAD Classic Colors</name>
<description>FreeCAD default colors for core app and included Mods.</description>
<version>1.0.0</version>
<type>appearance</type>
<tag>built-in</tag>
<tag>colors</tag>
</preferencepack>
</content>