Commit 1f197dc1 authored by Summer Stapleton's avatar Summer Stapleton
Browse files

Adding capacity to recognize that a template has been modified in template...

Adding capacity to recognize that a template has been modified in template edit widget and prompting for template save on widget/project close.
parent 84dc94b8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -738,6 +738,9 @@ namespace Isis {
   */
  void IpceMainWindow::closeEvent(QCloseEvent *event) {

    foreach(TemplateEditorWidget *templateEditor, m_directory->templateEditorViews()) {
      templateEditor->saveOption();
    }
    // The active control is checked here for modification because this was the simplest solution
    // vs changing the project clean state every time the control is modified or saved.
    if (!m_directory->project()->isClean() || (m_directory->project()->activeControl() &&
+32 −6
Original line number Diff line number Diff line
@@ -231,17 +231,18 @@ namespace Isis {
                  "PatternMatch/PatternMatch.html for a description of the "
                  "contents of this file.");
    m_templateComboBox->addItem(m_measureEditor->templateFileName());
    QList <TemplateList *> regTemplates = m_directory->project()->registrationTemplates();
    QList <TemplateList *> regTemplates = m_directory->project()->regTemplates();
    foreach(TemplateList *templateList, regTemplates) {
      foreach(Template *templateFile, *templateList){
        m_templateComboBox->addItem(templateFile->fileName());
        m_templateComboBox->addItem(templateFile->importName() 
                                    + "/" + FileName(templateFile->fileName()).name());
      }
    }
    QFormLayout *templateFileLayout = new QFormLayout();
    templateFileLayout->addRow("Template File:", m_templateComboBox);

    connect(m_templateComboBox, SIGNAL(activated(QString)), 
            m_measureEditor, SLOT(setTemplateFile(QString)));
            this, SLOT(setTemplateFile(QString)));
    connect(m_measureEditor, SIGNAL(setTemplateFailed(QString)), 
            this, SLOT(resetTemplateComboBox(QString)));

@@ -2415,20 +2416,45 @@ namespace Isis {
  void ControlPointEditWidget::addTemplates(TemplateList *templateList) {
    if(templateList->type() == "registrations") {
      for(int i = 0; i < templateList->size(); i++) {
        m_templateComboBox->addItem(templateList->at(i)->fileName());
        m_templateComboBox->addItem(templateList->at(i)->importName()
                                    + "/" + FileName(templateList->at(i)->fileName()).name());
      }
    }
  }
  
  
  /**
  * Reset the selected template in teh template combobox if the template selected by the user does 
  * Appends the filename to the registrations path (unless this is the default template) and calls 
  * setTemplateFile for the control measure
  *
  * @param filename This is the import directory and the filename of the template file selected from
  *                 the QComboBox.
  */
  void ControlPointEditWidget::setTemplateFile(QString filename) {
    QString expandedFileName = filename;
    if(!filename.startsWith("$base")){
      expandedFileName = m_directory->project()->templateRoot() 
                                 + "/registrations/" + filename;
    }
    if (m_measureEditor->setTemplateFile(expandedFileName)) {
      loadTemplateFile(expandedFileName);
    }
  }
  
  
  /**
  * Reset the selected template in the template combobox if the template selected by the user does 
  * not satisfy requirements for the control measure.
  *
  * @param fielName The filename that was previously selected in the template combo box
  */
  void ControlPointEditWidget::resetTemplateComboBox(QString fileName) {
    int index = m_templateComboBox->findText(fileName);
    if(fileName.startsWith("$base")) {
      m_templateComboBox->setCurrentIndex(0);
    }
    QList<QString> components = fileName.split("/");
    int size = components.size();
    int index = m_templateComboBox->findText(components[size - 2] + "/" + components[size - 1]);
    if (index != -1) {
      m_templateComboBox->setCurrentIndex(index);
    }
+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@ namespace Isis {
      void showHideTemplateEditor();
      void saveTemplateFile();
      void saveTemplateFileAs();
      void setTemplateFile(QString);
      void setTemplateModified();
      void writeTemplateFile(QString);
      void resetTemplateComboBox(QString fileName);
+38 −65
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ namespace Isis {
    m_template = currentTemplate;
    m_directory = directory;
    m_fileType = m_template->templateType();
    // m_textChanged = false;
    m_textChanged = false;

    QFile templateFile(m_template->fileName());
    templateFile.open(QFile::ReadOnly | QFile::Text);
@@ -26,34 +26,16 @@ namespace Isis {
    m_ui->templateTextEdit->setText(textStream.readAll());
    templateFile.close();

    // connect(m_ui->templateTextEdit, SIGNAL(textChanged()), this, SLOT(setStateUnclean()));
    connect(m_ui->templateTextEdit, SIGNAL(textChanged()), this, SLOT(textChanged()));
    connect(m_ui->templateTextSave, SIGNAL (released()),this, SLOT (saveText()));
    connect(m_ui->templateTextSaveAs, SIGNAL (released()),this, SLOT (saveAsText()));
    connect(this, SIGNAL(destroyed(QObject *)), this, SLOT(saveOption()));

  }


  TemplateEditorWidget::~TemplateEditorWidget() {
    
    // if (m_textChanged) {
    //   qDebug() << "IN LOOP";
    //   QMessageBox *box = new QMessageBox(QMessageBox::NoIcon, QString("Current Template Has Unsaved Changes"),
    //                          QString("Would you like to save your current template?"),
    //                          NULL, qobject_cast<QWidget *>(parent()), Qt::Dialog);
    //   QPushButton *save = box->addButton("Save", QMessageBox::AcceptRole);
    //   box->addButton("Don't Save", QMessageBox::RejectRole);
    //   QPushButton *cancel = box->addButton("Cancel", QMessageBox::NoRole);
    //   box->exec();
    // 
    //   if (box->clickedButton() == (QAbstractButton*)cancel) {
    //     // event->ignore();
    //     return;
    //   }
    //   else if (box->clickedButton() == (QAbstractButton*)save) {
    //     saveAsText();
    //   }
    // }
    saveOption();
    
    delete m_ui;
  }
@@ -69,7 +51,7 @@ namespace Isis {
      templateFile.close();
    }
    
    // m_textChanged = false;
    m_textChanged = false;
  }

  // Future plans to include Save As button
@@ -116,56 +98,47 @@ namespace Isis {
                           m_fileType, 
                           templateFolder.dirName()));

      // if (compare(m_fileType, "maps") == 0) {
      //   project->addMapTemplates(templateList);
      // }
      // else if (compare(m_fileType, "registrations") == 0) {
      //   project->addRegistrationTemplates(templateList);
      // }
      m_directory->project()->addTemplates(templateList);
      if (m_fileType == "maps") {
        m_directory->project()->addMapTemplates(templateList);
      }
      else if (m_fileType == "registrations") {
        m_directory->project()->addRegTemplates(templateList);
      }
      m_directory->project()->setClean(false);
    }
    else {
      // Throw()
    }

    // m_textChanged = false;
  }
  
  
  // void TemplateEditorWidget::setStateUnclean() {
  //   qDebug() << "CHANGED";
  //   m_textChanged = true;
  // }
  // 
  // 
  // bool TemplateEditorWidget::textChanged() {
  //   return m_textChanged;
  // }
  // 
  // 
  // void TemplateEditorWidget::saveOption() {
  //   qDebug() << "CLOSE";
  // 
  //   // The active control is checked here for modification because this was the simplest solution
  //   // vs changing the project clean state every time the control is modified or saved.
  //   if (m_textChanged) {
  //     qDebug() << "IN LOOP";
  //     QMessageBox *box = new QMessageBox(QMessageBox::NoIcon, QString("Current Template Has Unsaved Changes"),
  //                            QString("Would you like to save your current template?"),
  //                            NULL, qobject_cast<QWidget *>(parent()), Qt::Dialog);
  //     QPushButton *save = box->addButton("Save", QMessageBox::AcceptRole);
  //     box->addButton("Don't Save", QMessageBox::RejectRole);
  //     QPushButton *cancel = box->addButton("Cancel", QMessageBox::NoRole);
  //     box->exec();
  // 
  //     if (box->clickedButton() == (QAbstractButton*)cancel) {
  //       // event->ignore();
  //       return;
  //     }
  //     else if (box->clickedButton() == (QAbstractButton*)save) {
  //       saveAsText();
  //     }
  //   }
  // }
    m_textChanged = false;
  }
  
  
  void TemplateEditorWidget::textChanged() {
    m_textChanged = true;
  }

  
  void TemplateEditorWidget::saveOption() {
    // The active control is checked here for modification because this was the simplest solution
    // vs changing the project clean state every time the control is modified or saved.
    if (m_textChanged) {
      QMessageBox *box = new QMessageBox(QMessageBox::NoIcon, QString("Current Template Has Unsaved Changes"),
                             QString("Would you like to save your current template?"),
                             NULL, qobject_cast<QWidget *>(parent()), Qt::Dialog);
      QPushButton *save = box->addButton("Save", QMessageBox::AcceptRole);
      box->addButton("Don't Save", QMessageBox::RejectRole);
      QPushButton *cancel = box->addButton("Cancel", QMessageBox::NoRole);
      box->exec();
  
      if (box->clickedButton() == (QAbstractButton*)cancel) {
        // event->ignore();
        return;
      }
      else if (box->clickedButton() == (QAbstractButton*)save) {
        saveAsText();
      }
    }
    m_textChanged = false;
  }
}
+3 −5
Original line number Diff line number Diff line
@@ -34,13 +34,11 @@ namespace Isis {

       ~TemplateEditorWidget();

       bool textChanged();

     public slots:
       void saveText();
       void saveAsText();
      //  void setStateUnclean();
      //  void saveOption();
       void saveOption();
       void textChanged();

     private:
       Ui::TemplateEditorWidget *m_ui;
@@ -48,7 +46,7 @@ namespace Isis {
       Directory *m_directory;  // The directory of the open project
       Template *m_template;    // The template being modified
       QString m_fileType;      // The file type of the template ("Maps" or "Registrations")
      //  bool m_textChanged;      // Whether the text in the widget has been changed since last save
       bool m_textChanged;      // Whether the text in the widget has been changed since last save
   };
}