Skip to content

Commit

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

#include "cellmleditingviewwidget.h"
#include "cellmlfilemanager.h"
#include "cellmlsupportplugin.h"
#include "cellmltextviewplugin.h"
#include "cellmltextviewwidget.h"
#include "corecliutils.h"
#include "coreguiutils.h"
#include "filemanager.h"

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

Expand Down Expand Up @@ -375,16 +371,10 @@ QString CellMLTextViewPlugin::viewDefaultFileExtension() const

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

CellMLSupport::CellmlFile::Version cellmlVersion = CellMLSupport::CellmlFile::fileVersion(pFileName);
// Make sure that we are dealing with a valid file

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 CellML Text view widget using the given CellML
// file
Expand Down
18 changes: 16 additions & 2 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.cpp
Expand Up @@ -453,6 +453,19 @@ void CellmlTextViewWidget::retranslateUi()

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

bool CellmlTextViewWidget::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 CellmlTextViewWidget::initialize(const QString &pFileName, bool pUpdate)
{
// Retrieve the editing widget associated with the given file, if any
Expand Down Expand Up @@ -667,7 +680,8 @@ void CellmlTextViewWidget::fileSaved(const QString &pFileName)

void CellmlTextViewWidget::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() will activate the contents of the
// view (but the file tab will still point to the previously active
Expand All @@ -676,7 +690,7 @@ void CellmlTextViewWidget::fileReloaded(const QString &pFileName)

CellmlTextViewWidgetData *data = mData.value(pFileName);

if (data) {
if (data && isValid(pFileName)) {
bool update = mEditingWidget == data->editingWidget();

finalize(pFileName);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.h
Expand Up @@ -139,6 +139,8 @@ class CellmlTextViewWidget : 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 3a785f1

Please sign in to comment.