Skip to content

Commit

Permalink
Raw Text view: make sure that a file is still valid before actually r…
Browse files Browse the repository at this point in the history
…eloading it.
  • Loading branch information
agarny committed Jan 25, 2019
1 parent 756c0cf commit 6abd71d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/plugins/editing/RawTextView/src/rawtextviewplugin.cpp
Expand Up @@ -312,9 +312,9 @@ QString RawTextViewPlugin::viewDefaultFileExtension() const

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

if (!Core::isTextFile(pFileName))
if (!mViewWidget->isValid(pFileName))
return nullptr;

// Update and return our Raw Text view widget using the given file
Expand Down
14 changes: 12 additions & 2 deletions src/plugins/editing/RawTextView/src/rawtextviewwidget.cpp
Expand Up @@ -81,6 +81,15 @@ void RawTextViewWidget::retranslateUi()

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

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

return Core::isTextFile(pFileName);
}

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

void RawTextViewWidget::initialize(const QString &pFileName, bool pUpdate)
{
// Retrieve the editor associated with the given file, if any
Expand Down Expand Up @@ -190,14 +199,15 @@ void RawTextViewWidget::fileSaved(const QString &pFileName)

void RawTextViewWidget::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 (mEditors.contains(pFileName)) {
if (mEditors.contains(pFileName) && isValid(pFileName)) {
bool update = mEditor == mEditors.value(pFileName);

finalize(pFileName);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/editing/RawTextView/src/rawtextviewwidget.h
Expand Up @@ -59,6 +59,8 @@ class RawTextViewWidget : 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 6abd71d

Please sign in to comment.