Skip to content

Commit

Permalink
Fix repeated requests of reloading from disk
Browse files Browse the repository at this point in the history
A popuped message appear for the 1st modification from outside of
Notepad++, if users ignore it and save another change outside, the 2nd
popuped message appears. This commit fix this bad behaviour, which could
lead crash.

Closes #3307
  • Loading branch information
Boris authored and donho committed May 27, 2017
1 parent 71ffe87 commit 85216fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 16 additions & 4 deletions PowerEditor/src/ScitillaComponent/Buffer.cpp
Expand Up @@ -250,7 +250,12 @@ bool Buffer::checkFileState() //eturns true if the status has been changed (it c

_currentStatus = DOC_MODIFIED;
_timeStamp = buf.st_mtime;
doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp);

if (_reloadFromDiskRequestGuard.try_lock())
{
doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp);
_reloadFromDiskRequestGuard.unlock();
}
isOK = true;
}
}
Expand All @@ -273,10 +278,17 @@ bool Buffer::checkFileState() //eturns true if the status has been changed (it c

if (mask != 0)
{
doNotify(mask);
isOK = true;
if (_reloadFromDiskRequestGuard.try_lock())
{
doNotify(mask);

_reloadFromDiskRequestGuard.unlock();

return true;
}
}
isOK = false;

return false;
}

if (isWow64Off)
Expand Down
4 changes: 4 additions & 0 deletions PowerEditor/src/ScitillaComponent/Buffer.h
Expand Up @@ -25,6 +25,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#include <mutex>

#include "Utf8_16.h"


Expand Down Expand Up @@ -413,4 +415,6 @@ class Buffer final
bool _hasLangBeenSetFromMenu = false;

MapPosition _mapPosition;

std::mutex _reloadFromDiskRequestGuard;
};

0 comments on commit 85216fe

Please sign in to comment.