Skip to content

Commit

Permalink
Raw SED-ML 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 34331cc commit 756c0cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/plugins/editing/RawSEDMLView/src/rawsedmlviewplugin.cpp
Expand Up @@ -21,12 +21,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Raw SED-ML view plugin
//==============================================================================

#include "corecliutils.h"
#include "coreguiutils.h"
#include "filemanager.h"
#include "rawsedmlviewplugin.h"
#include "rawsedmlviewwidget.h"
#include "sedmlfilemanager.h"
#include "sedmlsupportplugin.h"

//==============================================================================
Expand Down Expand Up @@ -337,9 +335,9 @@ QString RawSEDMLViewPlugin::viewDefaultFileExtension() const

QWidget * RawSEDMLViewPlugin::viewWidget(const QString &pFileName)
{
// Make sure that we are dealing with a SED-ML file (be it new or not)
// Make sure that we are dealing with a valid file

if (!SEDMLSupport::SedmlFileManager::instance()->sedmlFile(pFileName))
if (!mViewWidget->isValid(pFileName))
return nullptr;

// Update and return our Raw SED-ML view widget using the given SED-ML file
Expand Down
14 changes: 12 additions & 2 deletions src/plugins/editing/RawSEDMLView/src/rawsedmlviewwidget.cpp
Expand Up @@ -93,6 +93,15 @@ void RawSedmlViewWidget::retranslateUi()

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

bool RawSedmlViewWidget::isValid(const QString &pFileName) const
{
// Return whether we are dealing with a SED-ML file (be it new or not)

return SEDMLSupport::SedmlFileManager::instance()->sedmlFile(pFileName);
}

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

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

void RawSedmlViewWidget::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/RawSEDMLView/src/rawsedmlviewwidget.h
Expand Up @@ -66,6 +66,8 @@ class RawSedmlViewWidget : 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 756c0cf

Please sign in to comment.