Commit d22dee38 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Fixed save button from greying out when a user cancels the save dialog. Fixes #5205.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@8290 41f8697f-d340-4b68-9986-7bafba869bb8
parent 6640013f
Loading
Loading
Loading
Loading
+41 −3
Original line number Diff line number Diff line
@@ -34,6 +34,13 @@

namespace Isis {

  /**
   * Constructor
   *
   * Creates a work order for saving the state of the project.
   *
   * @param Project *project Pointer to the project to save.
   */
  SaveProjectWorkOrder::SaveProjectWorkOrder(Project *project) :
      WorkOrder(project) {
    QAction::setText(tr("&Save Project"));
@@ -43,28 +50,59 @@ namespace Isis {
  }


  /**
   * Copy constrcutor
   *
   * Creates a SaveProjectWorkOrder from another one.
   *
   * @param const SaveProjectWorkOrder &order The work order to copy from.
   */
  SaveProjectWorkOrder::SaveProjectWorkOrder(const SaveProjectWorkOrder &other) :
      WorkOrder(other) {
  }


  /**
   * Destructor
   */
  SaveProjectWorkOrder::~SaveProjectWorkOrder() {

  }


  /**
   * Clones an existing SaveProjectWorkder and gives back a newly allocated copy of the work order.
   *
   * @return SaveProjectWorkOrder* Returns a newly allocated clone of this work order.
   */
  SaveProjectWorkOrder *SaveProjectWorkOrder::clone() const {
    return new SaveProjectWorkOrder(*this);
  }


  /**
   * Sets up the work order.
   *
   * This will check to see if the Project::save() was completed (i.e. checks if the file
   * dialog created for a temp project wasn't cancelled by the user). If the Project::save()
   * was not cancelled, then the project is set to a clean state and this returns true. Otherwise
   * if the Project::save() is cancelled, the project is still not clean and false is returned
   * indicated the setup failed.
   *
   * @see Project::save()
   *
   * @return bool Returns if the setup was successful or not. See description for more details.
   */
  bool SaveProjectWorkOrder::setupExecution() {
    bool success = WorkOrder::setupExecution();

    if (success) {
      project()->save();
      // Check to save if the save dialog (for a temp project) completed 
      // (i.e. it was not cancelled)
      success = project()->save();
      if (success) {
        project()->setClean(true);
      }
    }

    return success;
  }
+3 −0
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@ namespace Isis {
   *
   * @internal
   *   @history 2017-07-25 Cole Neubauer - Added project()->setClean call #4969
   *   @history 2017-11-08 Ian Humphrey - Modified setupExecution() to check to see if the 
   *                           project::save()'s dialog was cancelled or not to properly
   *                           trigger the clean state of the project. Fixes #5205.
   */
  class SaveProjectWorkOrder : public WorkOrder {
      Q_OBJECT
+23 −1
Original line number Diff line number Diff line
@@ -2059,7 +2059,23 @@ namespace Isis {
  }


  void Project::save() {
  /**
   * Generic save method to save the state of the project.
   *
   * This method is used to save the state of the project. If the project is currently a temporary
   * project, this method will create a file dialog to prompt the user for a place/name to save
   * the project as. Otherwise, the existing project state will be saved. This method also informs
   * the caller whether or not the save occurred. It is possible for a save to NOT occur if the
   * project is a temporary project and the user cancels/closes the dialog prompt.
   *
   * @return @b bool Returns true if the save completed. The save is considered incomplete if the
   * project is a temporary project and the user either cancels or closes the file dialog prompt
   * that is created.
   */
  bool Project::save() {
    // Let caller know if the save dialog was cancelled
    bool saveDialogCompleted = true;

    if (m_isTemporaryProject) {
      QString newDestination = QFileDialog::getSaveFileName(NULL,
                                                            QString("Project Location"),
@@ -2073,10 +2089,16 @@ namespace Isis {
        relocateProjectRoot(newDestination);
        m_isTemporaryProject = false;
      }
      // Dialog was cancelled
      else {
        saveDialogCompleted = false;
      }
    }
    else {
      save(m_projectRoot->absolutePath(), false);
    }

    return saveDialogCompleted;
  }


+4 −1
Original line number Diff line number Diff line
@@ -179,6 +179,9 @@ namespace Isis {
   *                           when there is only one control in the project. Fixes #5160.
   *   @history 2017-11-02 Tyler Wilson - Added support for opening Recent Projects from the
   *                           File Menu.  Fixes #4492.
   *   @history 2017-11-08 Ian Humphrey - Changed save() from a void to a bool return value. This
   *                           indicates if the save dialog (for a temp project) is successfully
   *                           saved (i.e. not cancelled). Fixes #5205.
   */
  class Project : public QObject {
    Q_OBJECT
@@ -277,7 +280,7 @@ namespace Isis {

      void removeImages(ImageList &imageList);

      void save();
      bool save();
      void save(FileName newPath, bool verifyPathDoesntExist = true);

      void addToProject(WorkOrder *);