Add export config directory specification feature (#15235)
This commit is contained in:
@@ -32,6 +32,13 @@
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@@ -39,12 +46,12 @@
|
||||
<property name="columnCount">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<attribute name="headerMinimumSectionSize">
|
||||
<number>50</number>
|
||||
</attribute>
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>250</number>
|
||||
</attribute>
|
||||
<attribute name="headerMinimumSectionSize">
|
||||
<number>50</number>
|
||||
</attribute>
|
||||
<attribute name="headerShowSortIndicator" stdset="0">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "DlgCreateNewPreferencePackImp.h"
|
||||
#include "ui_DlgCreateNewPreferencePack.h"
|
||||
|
||||
#include "FileDialog.h"
|
||||
|
||||
using namespace Gui::Dialog;
|
||||
|
||||
@@ -54,6 +55,7 @@ DlgCreateNewPreferencePackImp::DlgCreateNewPreferencePackImp(QWidget* parent)
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
connect(ui->treeWidget, &QTreeWidget::itemChanged, this, &DlgCreateNewPreferencePackImp::onItemChanged);
|
||||
connect(ui->lineEdit, &QLineEdit::textEdited, this, &DlgCreateNewPreferencePackImp::onLineEditTextEdited);
|
||||
connect(ui->pushButton, &QPushButton::clicked, this, &DlgCreateNewPreferencePackImp::onBrowseButtonClicked);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +116,11 @@ std::string DlgCreateNewPreferencePackImp::preferencePackName() const
|
||||
return ui->lineEdit->text().toStdString();
|
||||
}
|
||||
|
||||
std::string Gui::Dialog::DlgCreateNewPreferencePackImp::preferencePackDirectory() const
|
||||
{
|
||||
return _cfgFileDirectory.toStdString();
|
||||
}
|
||||
|
||||
void DlgCreateNewPreferencePackImp::onItemChanged(QTreeWidgetItem* item, int column)
|
||||
{
|
||||
Q_UNUSED(column);
|
||||
@@ -151,6 +158,11 @@ void DlgCreateNewPreferencePackImp::onLineEditTextEdited(const QString& text)
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty());
|
||||
}
|
||||
|
||||
void DlgCreateNewPreferencePackImp::onBrowseButtonClicked()
|
||||
{
|
||||
_cfgFileDirectory = FileDialog::getExistingDirectory(this, tr("Export Config"), _cfgFileDirectory);
|
||||
}
|
||||
|
||||
void Gui::Dialog::DlgCreateNewPreferencePackImp::accept()
|
||||
{
|
||||
// Ensure that the chosen name is either unique, or that the user actually wants to overwrite the old one
|
||||
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
|
||||
std::vector<PreferencePackManager::TemplateFile> selectedTemplates() const;
|
||||
std::string preferencePackName() const;
|
||||
std::string preferencePackDirectory() const;
|
||||
|
||||
protected Q_SLOTS:
|
||||
|
||||
@@ -66,6 +67,8 @@ protected Q_SLOTS:
|
||||
|
||||
void onLineEditTextEdited(const QString &text);
|
||||
|
||||
void onBrowseButtonClicked();
|
||||
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
@@ -74,6 +77,7 @@ private:
|
||||
std::vector<PreferencePackManager::TemplateFile> _templates;
|
||||
QRegularExpressionValidator _nameValidator;
|
||||
std::vector<std::string> _existingPackNames;
|
||||
QString _cfgFileDirectory;
|
||||
};
|
||||
|
||||
} // namespace Dialog
|
||||
|
||||
@@ -504,12 +504,11 @@ static void copyTemplateParameters(/*const*/ ParameterManager& templateParameter
|
||||
}
|
||||
}
|
||||
|
||||
void PreferencePackManager::save(const std::string& name, const std::vector<TemplateFile>& templates)
|
||||
void PreferencePackManager::save(const std::string& name, const std::string& directory, const std::vector<TemplateFile>& templates)
|
||||
{
|
||||
if (templates.empty())
|
||||
return;
|
||||
|
||||
AddPackToMetadata(name);
|
||||
|
||||
// Create the config file
|
||||
auto outputParameterManager = ParameterManager::Create();
|
||||
@@ -519,9 +518,17 @@ void PreferencePackManager::save(const std::string& name, const std::vector<Temp
|
||||
templateParameterManager->LoadDocument(Base::FileInfo::pathToString(t.path).c_str());
|
||||
copyTemplateParameters(*templateParameterManager, *outputParameterManager);
|
||||
}
|
||||
auto savedPreferencePacksDirectory = getSavedPreferencePacksPath();
|
||||
auto cfgFilename = savedPreferencePacksDirectory / name / (name + ".cfg");
|
||||
outputParameterManager->SaveDocument(Base::FileInfo::pathToString(cfgFilename).c_str());
|
||||
|
||||
std::string cfgFilename;
|
||||
if (directory.empty()) {
|
||||
AddPackToMetadata(name);
|
||||
auto savedPreferencePacksDirectory = getSavedPreferencePacksPath();
|
||||
cfgFilename = Base::FileInfo::pathToString(savedPreferencePacksDirectory / name / (name + ".cfg"));
|
||||
}
|
||||
else {
|
||||
cfgFilename = Base::FileInfo::pathToString(fs::path(directory) / (name + ".cfg"));
|
||||
}
|
||||
outputParameterManager->SaveDocument(cfgFilename.c_str());
|
||||
}
|
||||
|
||||
static std::vector<fs::path> scanForTemplateFolders(const std::string& groupName, const fs::path& entry)
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace Gui {
|
||||
*
|
||||
* If the named preferencePack does not exist, this creates it on disk. If it does exist, this overwrites the original.
|
||||
*/
|
||||
void save(const std::string& name, const std::vector<TemplateFile>& templates);
|
||||
void save(const std::string& name, const std::string& directory, const std::vector<TemplateFile>& templates);
|
||||
|
||||
|
||||
std::vector<TemplateFile> templateFiles(bool rescan = false);
|
||||
|
||||
@@ -719,7 +719,8 @@ void DlgSettingsGeneral::newPreferencePackDialogAccepted()
|
||||
return false;
|
||||
});
|
||||
auto preferencePackName = newPreferencePackDialog->preferencePackName();
|
||||
Application::Instance->prefPackManager()->save(preferencePackName, selectedTemplates);
|
||||
auto preferencePackDirectory = newPreferencePackDialog->preferencePackDirectory();
|
||||
Application::Instance->prefPackManager()->save(preferencePackName, preferencePackDirectory, selectedTemplates);
|
||||
recreatePreferencePackMenu();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user