Skip to content

Commit

Permalink
Raw CellML view: make sure that a file is still valid before actually…
Browse files Browse the repository at this point in the history
… reloading it.
  • Loading branch information
agarny committed Jan 25, 2019
1 parent 3a785f1 commit 34331cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
12 changes: 2 additions & 10 deletions src/plugins/editing/RawCellMLView/src/rawcellmlviewplugin.cpp
Expand Up @@ -21,9 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Raw CellML view plugin
//==============================================================================

#include "cellmlfilemanager.h"
#include "cellmlsupportplugin.h"
#include "corecliutils.h"
#include "coreguiutils.h"
#include "filemanager.h"
#include "rawcellmlviewplugin.h"
Expand Down Expand Up @@ -335,16 +333,10 @@ QString RawCellMLViewPlugin::viewDefaultFileExtension() const

QWidget * RawCellMLViewPlugin::viewWidget(const QString &pFileName)
{
// Make sure that we are dealing with either a new file or a CellML 1.0/1.1
// file
// Make sure that we are dealing with a valid file

CellMLSupport::CellmlFile::Version cellmlVersion = CellMLSupport::CellmlFile::fileVersion(pFileName);

if ( !Core::FileManager::instance()->isNew(pFileName)
&& (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_0)
&& (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_1)) {
if (!mViewWidget->isValid(pFileName))
return nullptr;
}

// Update and return our Raw CellML view widget using the given CellML file

Expand Down
19 changes: 17 additions & 2 deletions src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.cpp
Expand Up @@ -102,6 +102,20 @@ void RawCellmlViewWidget::retranslateUi()

//==============================================================================

bool RawCellmlViewWidget::isValid(const QString &pFileName) const
{
// Return whether we are dealing with a new file or a CellML 1.0/1.1 file

CellMLSupport::CellmlFile::Version cellmlVersion = CellMLSupport::CellmlFile::fileVersion(pFileName);

return Core::FileManager::instance()->isNew(pFileName)
|| (cellmlVersion == CellMLSupport::CellmlFile::Cellml_1_0)
|| (cellmlVersion == CellMLSupport::CellmlFile::Cellml_1_1);
}

//==============================================================================


void RawCellmlViewWidget::initialize(const QString &pFileName, bool pUpdate)
{
// Retrieve the editing widget associated with the given file, if any
Expand Down Expand Up @@ -224,14 +238,15 @@ void RawCellmlViewWidget::fileSaved(const QString &pFileName)

void RawCellmlViewWidget::fileReloaded(const QString &pFileName)
{
// The given file has been reloaded, so reload it, should it be managed
// The given file has been reloaded, so reload it, should it be managed and
// still valid
// Note: if the view for the given file is not the active view, then to call
// finalize() and then initialize() would activate the contents of the
// view (but the file tab would still point to the previously active
// file). However, we want to the 'old' file to remain the active one,
// hence the extra argument we pass to initialize()...

if (mEditingWidgets.contains(pFileName)) {
if (mEditingWidgets.contains(pFileName) && isValid(pFileName)) {
bool update = mEditingWidget == mEditingWidgets.value(pFileName);

finalize(pFileName);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.h
Expand Up @@ -67,6 +67,8 @@ class RawCellmlViewWidget : public Core::ViewWidget

void retranslateUi() override;

bool isValid(const QString &pFileName) const;

void initialize(const QString &pFileName, bool pUpdate = true);
void finalize(const QString &pFileName);

Expand Down

0 comments on commit 34331cc

Please sign in to comment.