Printing: show warning message when editing bundled templates

When editing a bundled template show warning message.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Gehad elrobey 2015-09-16 20:44:58 -03:00 committed by Dirk Hohndel
parent 27bec9bc7b
commit d3c75f2c72

View file

@ -123,14 +123,24 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
void TemplateEdit::saveSettings() void TemplateEdit::saveSettings()
{ {
QStringList bundledTemplates;
bundledTemplates << "Flowlayout.html" << "One Dive.html" << "Six Dives.html" << "Table.html" << "Two Dives.html";
if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) { if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText("Do you want to save your changes?"); QString message = "Do you want to save your changes?";
bool templateChanged = false;
if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
if (bundledTemplates.contains(printOptions->p_template)) {
message = "You are about to modify a template bundled with Subsurface. Do you want to save your changes?";
}
templateChanged = true;
}
msgBox.setText(message);
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Cancel);
if (msgBox.exec() == QMessageBox::Save) { if (msgBox.exec() == QMessageBox::Save) {
memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options));
if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { if (templateChanged) {
TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText()); TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText());
} }
if (templateOptions->color_palette_index == CUSTOM) { if (templateOptions->color_palette_index == CUSTOM) {