Fixed a bug: the edit dialog fields were not cleared if an
[emufront] / src / dialogs / executableeditdialog.cpp
index 442d6c6..04d1f3e 100644 (file)
@@ -83,23 +83,23 @@ void ExecutableEditDialog::acceptChanges()
     try {
         Setup *su = getSelectedSetup();
         if (!su) {
-            throw new EmuFrontException(tr("Setup not selected"));
+            throw EmuFrontException(tr("Setup not selected"));
         }
         QString name = nameEdit->text().trimmed();
         if (name.isEmpty()){
-            throw new EmuFrontException(tr("Name is not set"));
+            throw EmuFrontException(tr("Name is not set"));
         }
         QString exec = execEdit->text().trimmed();
         if (exec.isEmpty()){
-            throw new EmuFrontException(tr("Executable is not set"));
+            throw EmuFrontException(tr("Executable is not set"));
         }
         QString opts = optEdit->text().trimmed();
         if (opts.isEmpty()) {
-            throw new EmuFrontException(tr("Options not set"));
+            throw EmuFrontException(tr("Options not set"));
         }
         bool change = false;
         Setup *supTmp = ex->getSetup();
-        if (*supTmp != *su) {
+        if (!supTmp || *supTmp != *su) {
             delete supTmp;
             ex->setSetup(su);
             change = true;
@@ -138,6 +138,7 @@ void ExecutableEditDialog::setDataObject(EmuFrontObject *ob)
         qDebug("No executable");
         return;
     }
+    clear();
     if (!ex->getSetup()) {
         qDebug() << "No setup";
         return;
@@ -149,14 +150,26 @@ void ExecutableEditDialog::setDataObject(EmuFrontObject *ob)
     optEdit->setText(ex->getOptions());
 }
 
+void ExecutableEditDialog::clear()
+{
+    nameEdit->clear();
+    execEdit->clear();
+    optEdit->clear();
+    setupComBox->setCurrentIndex(-1);
+}
+
 void ExecutableEditDialog::setSelectedSetup(const Setup *su)
 {
     setupComBox->setSelected(su);
 }
 
-Setup* ExecutableEditDialog::getSelectedSetup() const
+/* Returns a pointer to a Setup object which must be deleted by calling code! */
+Setup* ExecutableEditDialog::getSelectedSetup()
 {
-    EmuFrontObject *o = setupComBox->getSelected();
+    EmuFrontObject *o = 0;
+    try { o = setupComBox->getSelected(); }
+    catch(EmuFrontException &e){ errorMessage->showMessage(e.what()); }
+
     if (!o) return 0;
     Setup *ex = dynamic_cast<Setup*>(o);
     return ex;