# HG changeset patch # User Chris Cannam # Date 1318858524 -3600 # Node ID a6cbec451508634352f303bed9f6a9d4ce45eb82 # Parent 9d057ed676b6e1b7565a964578673d7cd38a8bb0 Add option to make the newly saved template the default diff -r 9d057ed676b6 -r a6cbec451508 main/MainWindow.cpp --- a/main/MainWindow.cpp Mon Oct 10 16:57:41 2011 +0100 +++ b/main/MainWindow.cpp Mon Oct 17 14:35:24 2011 +0100 @@ -114,6 +114,7 @@ #include #include #include +#include #include #include @@ -2864,27 +2865,50 @@ void MainWindow::saveSessionAsTemplate() { - QString name = QInputDialog::getText - (this, tr("Enter template name"), - tr("Please enter a name for the saved template:")); - if (name == "") return; + QDialog *d = new QDialog; + d->setWindowTitle(tr("Enter template name")); + + QGridLayout *layout = new QGridLayout; + d->setLayout(layout); + + layout->addWidget(new QLabel(tr("Please enter a name for the saved template:")), + 0, 0); + QLineEdit *lineEdit = new QLineEdit; + layout->addWidget(lineEdit, 1, 0); + QCheckBox *makeDefault = new QCheckBox(tr("Set as default template for future audio files")); + layout->addWidget(makeDefault, 2, 0); - name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_"); - - ResourceFinder rf; - QString dir = rf.getResourceSaveDir("templates"); - QString filename = QString("%1/%2.svt").arg(dir).arg(name); - if (QFile(filename).exists()) { - if (QMessageBox::warning(this, - tr("Template file exists"), - tr("Template file exists

The template \"%1\" already exists.
Overwrite it?").arg(name), - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel) != QMessageBox::Ok) { - return; + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + layout->addWidget(bb, 3, 0); + connect(bb, SIGNAL(accepted()), d, SLOT(accept())); + connect(bb, SIGNAL(accepted()), d, SLOT(accept())); + connect(bb, SIGNAL(rejected()), d, SLOT(reject())); + + if (d->exec() == QDialog::Accepted) { + + QString name = lineEdit->text(); + name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_"); + + ResourceFinder rf; + QString dir = rf.getResourceSaveDir("templates"); + QString filename = QString("%1/%2.svt").arg(dir).arg(name); + if (QFile(filename).exists()) { + if (QMessageBox::warning(this, + tr("Template file exists"), + tr("Template file exists

The template \"%1\" already exists.
Overwrite it?").arg(name), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel) != QMessageBox::Ok) { + return; + } + } + + if (saveSessionTemplate(filename)) { + if (makeDefault->isChecked()) { + setDefaultSessionTemplate(name); + } } } - - saveSessionTemplate(filename); } void