68 void TemplateEditorWidget::saveAsText() {
73 "Save Template File");
74 QGridLayout *layout =
static_cast<QGridLayout*
>(fileDialog->layout());
75 QCheckBox *checkbox =
new QCheckBox(
this);
76 checkbox->setText(
"Automatically Import Template File on Save");
77 checkbox->setCheckState(Qt::Checked);
78 layout->addWidget( checkbox );
80 fileDialog->setAcceptMode(QFileDialog::AcceptSave);
81 fileDialog->setDirectory(QDir::currentPath());
82 if (m_fileType ==
"maps") {
83 fileDialog->setNameFilter(
"Maps (*.map);;All Files (*)");
85 else if (m_fileType ==
"registrations") {
86 fileDialog->setNameFilter(
"Registrations (*.def);;All Files (*)");
91 if (!fileDialog->result()){
97 QString extension = fileDialog->selectedNameFilter().split(
"(")[1].mid(1, 4);
99 if (QString::compare(extension,
".def") == 0 || QString::compare(extension,
".map") == 0) {
100 fileDialog->setDefaultSuffix(extension);
103 if (m_fileType ==
"maps") {
104 fileDialog->setDefaultSuffix(
".map");
106 else if (m_fileType ==
"registrations") {
107 fileDialog->setDefaultSuffix(
".def");
110 QString templateFileName = fileDialog->selectedFiles().first();
113 QFile templateFile(templateFileName);
114 if (templateFile.open(QFile::WriteOnly | QFile::Text)) {
115 templateFile.resize(0);
116 templateFile.write(m_ui->templateTextEdit->toPlainText().toUtf8());
117 templateFile.close();
121 if (checkbox->checkState()) {
122 if (templateFile.exists()) {
123 QDir templateFolder = m_directory->project()->addTemplateFolder(m_fileType +
"/import");
126 +
"/" + templateFolder.dirName() );
128 QFile::copy(templateFileName, templateFolder.path() +
"/" + templateFileName.split(
"/").last());
129 templateList->append(
new Template(templateFolder.path() +
"/"
130 + templateFileName.split(
"/").last(),
132 templateFolder.dirName()));
134 m_directory->project()->addTemplates(templateList);
135 m_directory->project()->setClean(
false);
139 QString(
"Could not import file [%1]").arg(templateFileName),
143 m_textChanged =
false;
161 void TemplateEditorWidget::saveOption() {
164 QMessageBox *box =
new QMessageBox(QMessageBox::NoIcon, QString(
"Current Template Has Unsaved Changes"),
165 QString(
"Would you like to save your current template?"),
166 QMessageBox::NoButton, qobject_cast<QWidget *>(parent()), Qt::Dialog);
167 QPushButton *save = box->addButton(
"Save", QMessageBox::AcceptRole);
168 box->addButton(
"Don't Save", QMessageBox::RejectRole);
169 QPushButton *cancel = box->addButton(
"Cancel", QMessageBox::NoRole);
172 if (box->clickedButton() == (QAbstractButton*)cancel) {
175 else if (box->clickedButton() == (QAbstractButton*)save) {
179 m_textChanged =
false;