Commit 9c16aebf authored by Tyler Wilson's avatar Tyler Wilson
Browse files

Merged OpenProjectWorkOrder into OpenRecentProjectWorkOrder. Fixes #5220.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@8294 41f8697f-d340-4b68-9986-7bafba869bb8
parent e14958cd
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -76,7 +76,6 @@
#include "MosaicControlNetTool.h"
#include "MosaicSceneWidget.h"
#include "OpenProjectWorkOrder.h"
#include "OpenRecentProjectWorkOrder.h"
#include "Project.h"
#include "ProjectItem.h"
#include "ProjectItemModel.h"
@@ -165,7 +164,6 @@ namespace Isis {
      m_openProjectWorkOrder = createWorkOrder<OpenProjectWorkOrder>();
      m_saveProjectWorkOrder = createWorkOrder<SaveProjectWorkOrder>();
      m_saveProjectAsWorkOrder = createWorkOrder<SaveProjectAsWorkOrder>();      
      m_openRecentProjectWorkOrder = createWorkOrder<OpenRecentProjectWorkOrder>();
      m_runJigsawWorkOrder = createWorkOrder<JigsawWorkOrder>();
      m_closeProjectWorkOrder = createWorkOrder<CloseProjectWorkOrder>();
      m_renameProjectWorkOrder = createWorkOrder<RenameProjectWorkOrder>();
@@ -324,12 +322,13 @@ namespace Isis {
      if (!projectFileName.fileExists() )
        continue;

      QAction *openRecentProjectAction = m_openRecentProjectWorkOrder->clone();
      QAction *openRecentProjectAction = m_openProjectWorkOrder->clone();

      if ( !( (OpenRecentProjectWorkOrder*)openRecentProjectAction )
           ->isExecutable(m_recentProjects.at(i) ) )
      if ( !( (OpenProjectWorkOrder*)openRecentProjectAction )
           ->isExecutable(m_recentProjects.at(i),true ) )
        continue;


      QString projName = m_recentProjects.at(i).split("/").last();      
      openRecentProjectAction->setText(m_recentProjects.at(i).split("/").last() );
      openRecentProjectAction->setToolTip(m_recentProjects.at(i));
+2 −0
Original line number Diff line number Diff line
@@ -190,6 +190,8 @@ namespace Isis {
   *   @history 2017-11-02 Tyler Wilson - Added the updateRecentProjects() function which
   *                           updates the Recent Projects file menu with recently loaded projects.
   *                           Fixes #4492.
   *   @history 2017-11-09 Tyler Wilson - Made changes to updateRecentProjects() to handle deleting
   *                           the OpenRecentProjectWorkOrder.  Fixes #5220.
   */
  class Directory : public QObject {
    Q_OBJECT
+38 −8
Original line number Diff line number Diff line
@@ -26,14 +26,17 @@
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#include <QStringList>
#include <QtConcurrentMap>

#include "Cube.h"
#include "CubeAttribute.h"
#include "FileName.h"
#include "SaveProjectWorkOrder.h"
#include "ProgressBar.h"
#include "Project.h"


namespace Isis {

  /**
@@ -46,8 +49,8 @@ namespace Isis {

    // This workorder is not undoable
    m_isUndoable = false;   

    QAction::setText(tr("&Open Project"));

    QUndoCommand::setText(tr("Open Project"));
    setCreatesCleanState(true);

@@ -62,6 +65,7 @@ namespace Isis {
  }



  /**
   * @brief Copy constructor
   *
@@ -90,6 +94,22 @@ namespace Isis {
  }



  /**
   * @brief This function determines if the given project file name can be opened.
   * @param projectFileName  The path to the project file.
   * @return @b bool True if the file exists, False otherwise.
   */
  bool OpenProjectWorkOrder::isExecutable(QString projectFileName, bool recentProject) {

    m_recentProject = recentProject;
    FileName fname = projectFileName;
    if (!fname.fileExists() )
      return false;

    return true;
  }

  /**
   * @brief Setup this WorkOrder for execution, deleting the progress bar, determine if there
   *              is a current project and if it has been modified and prompting for project
@@ -126,16 +146,26 @@ namespace Isis {
    }

    if (success) {
      m_projectName = QFileDialog::getExistingDirectory(qobject_cast<QWidget *>(parent()),
      if ("Open Project" == toolTip()) {
        m_projectPath = QFileDialog::getExistingDirectory(qobject_cast<QWidget *>(parent()),
                                                              tr("Select Project Directory"));
        if (!m_projectPath.isEmpty()) {
          QUndoCommand::setText(tr("Open Project [%1]").arg(m_projectPath));
        }
      }
        else {

           m_projectPath =toolTip();

          //We are dealing with a recent project

            }

      if (!m_projectName.isEmpty()) {
        QUndoCommand::setText(tr("Open Project [%1]").arg(m_projectName));
      }
      else {
        success = false;
      }
    }


    return success;
  }
@@ -151,7 +181,7 @@ namespace Isis {
      project()->open(args.last());
    }
    else {     
      project()->open(m_projectName);
      project()->open(m_projectPath);
    }

    project()->setClean(true);
+8 −1
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ namespace Isis {
   *                           project while there is a project currently open. Fixes #4969
   *   @history 2017-09-06 Cole Neubauer - Changed execute so it can be used to open a project
   *                           from the command line Fixes #5174
   *   @history 2017-11-09 Tyler Wilson - Made changes to isExecutable() to import functionality
   *                           needed in OpenRecentProjectWorkOrder into OpenProjectWorkOrder
   *                           since OpenRecentProjectWorker is being deleted.  Fixes #5220.
   */
  class OpenProjectWorkOrder : public WorkOrder {
      Q_OBJECT
@@ -57,17 +60,21 @@ namespace Isis {

      virtual OpenProjectWorkOrder *clone() const;


      bool isExecutable(QString projectFileName, bool recentProject=false);
      bool setupExecution();
      void execute();
      void setRecent(bool isRecent);

    signals:
      void openProjectFromCommandLine(QString);

    private:
      OpenProjectWorkOrder &operator=(const OpenProjectWorkOrder &rhs);
      bool m_recentProject;

      bool m_startingState;
      QString m_projectName;
      QString m_projectPath;
  };
}

+0 −151
Original line number Diff line number Diff line
/**
 * @file
 * $Revision: 1.19 $
 * $Date: 2010/03/22 19:44:53 $
 *
 *   Unless noted otherwise, the portions of Isis written by the USGS are
 *   public domain. See individual third-party library and package descriptions
 *   for intellectual property information, user agreements, and related
 *   information.
 *
 *   Although Isis has been used by the USGS, no warranty, expressed or
 *   implied, is made by the USGS as to the accuracy and functioning of such
 *   software and related material nor shall the fact of distribution
 *   constitute any such warranty, and no responsibility is assumed by the
 *   USGS in connection therewith.
 *
 *   For additional information, launch
 *   $ISISROOT/doc//documents/Disclaimers/Disclaimers.html
 *   in a browser or see the Privacy &amp; Disclaimers page on the Isis website,
 *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
 *   http://www.usgs.gov/privacy.html.
 */
#include "OpenRecentProjectWorkOrder.h"
#include "SaveProjectWorkOrder.h"

#include <QCoreApplication>
#include <QDebug>
#include <QMessageBox>
#include <QStringList>

#include "FileName.h"
#include "ProgressBar.h"
#include "Project.h"

namespace Isis {

/**
 * @brief Constructor which creates a WorkOrder that will open a recent project.
 * @param project The Project that this work order should be interacting with
 *
 */
  OpenRecentProjectWorkOrder::OpenRecentProjectWorkOrder(Project *project) :
  WorkOrder(project) {
    // Opening a project is currently not undoable.
    m_isUndoable = false;
    m_projectPath ="";
    QAction::setText(tr("Open &Recent Project") );
    setCreatesCleanState(true);
  }


  /**
   * @brief Copies the OpenRecentProjectWorkOrder 'other' into this new instance.
   * @param other The WorkOrder being copied.
   *
   */
  OpenRecentProjectWorkOrder::OpenRecentProjectWorkOrder(const OpenRecentProjectWorkOrder &other) :
      WorkOrder(other) {
  }


  /**
   * @brief The Destructor.
   */
  OpenRecentProjectWorkOrder::~OpenRecentProjectWorkOrder() {

  }


  /**
   * @brief Returns a copy of this OpenRecentProjectWorkOrder instance.
   * @return @b ( OpenRecentWorkOrder *) A pointer to a copy of this object.
   */
  OpenRecentProjectWorkOrder *OpenRecentProjectWorkOrder::clone() const {
    return new OpenRecentProjectWorkOrder(*this);
  }



  /**
   * @brief This function determines if the given project file name can be opened.
   * @param projectFileName  The path to the project file.
   * @return @b bool True if the file exists, False otherwise.
   */
  bool OpenRecentProjectWorkOrder::isExecutable(QString projectFileName) {

    FileName fname = projectFileName;
    if (!fname.fileExists() )
      return false;

    return true;
  }


  /**
   * @brief Open the project the user select in the recent projects menu
   * @return  @b bool True if a project selected, false if aborted.
   */
  bool OpenRecentProjectWorkOrder::setupExecution() {
    bool success = WorkOrder::setupExecution();
    delete progressBar();
    if (!success) return false;

    //success && !project()->isClean() && project()->isOpen()
    // If more than this work order is in the history, don't allow this operation
    //if (project()->workOrderHistory().count() ) {
    //  QMessageBox::critical(NULL, tr("Unable To Open a Project"),
    //                        tr("If you have modified your current project, you cannot open a new "
    //                           "project because this is not yet implemented"));
    //  return false;
    //}


    if (success && !project()->isClean() && project()->isOpen() ) {
      QMessageBox *box = new QMessageBox(QMessageBox::NoIcon, QString("Current Project Has Unsaved Changes"),
                             QString("Would you like to save your current project?"),
                             NULL, qobject_cast<QWidget *>(parent()), Qt::Dialog);
      QPushButton *save = box->addButton("Save", QMessageBox::AcceptRole);
      QPushButton *dontsave = box->addButton("Don't Save", QMessageBox::RejectRole);
      QPushButton *cancel = box->addButton("Cancel", QMessageBox::NoRole);
      box->exec();

      if (box->clickedButton() == (QAbstractButton*)cancel) {
        success = false;
      }
      else if (box->clickedButton() == (QAbstractButton*)dontsave) {
        success = true;
      }
      else if (box->clickedButton() == (QAbstractButton*)save) {
        SaveProjectWorkOrder *workOrder = new SaveProjectWorkOrder(project());
        project()->addToProject(workOrder);
      }
    }


    m_projectPath =toolTip();
    // Will this ever occur?
    if (m_projectPath.isEmpty()) return false;
    
    QUndoCommand::setText(tr("Open Recent Project [%1]").arg(m_projectPath));
    return true;
  }

  /**
  * @brief Open the project specified in the workorder.
  */
  void OpenRecentProjectWorkOrder::execute() {
    project()->open(m_projectPath);
    project()->setClean(true);
  }
}
Loading