Skip to content

Commit

Permalink
While opening a temp file, block checks for outside modifications
Browse files Browse the repository at this point in the history
closes #324
  • Loading branch information
stefankueng committed May 14, 2023
1 parent 75615a8 commit 67c3a21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ CMainWindow::CMainWindow(HINSTANCE hInst, const WNDCLASSEX* wcx /* = nullptr*/)
, m_fileTreeVisible(true)
, m_bPathsToOpenMRU(true)
, m_tabMoveMod(false)
, m_bIgnoreFileChanges(false)
, m_initLine(0)
, m_insertionIndex(-1)
, m_windowRestored(false)
Expand Down Expand Up @@ -3548,14 +3549,17 @@ void CMainWindow::HandleTabChange(const NMHDR& /*nmhdr*/)
}
}

auto ds = m_docManager.HasFileChanged(docID);
if (ds == DocModifiedState::Modified)
if (!m_bIgnoreFileChanges)
{
ReloadTab(curTab, -1, true);
}
else if (ds == DocModifiedState::Removed)
{
HandleOutsideDeletedFile(curTab);
auto ds = m_docManager.HasFileChanged(docID);
if (ds == DocModifiedState::Modified)
{
ReloadTab(curTab, -1, true);
}
else if (ds == DocModifiedState::Removed)
{
HandleOutsideDeletedFile(curTab);
}
}
}

Expand Down Expand Up @@ -3781,7 +3785,8 @@ int CMainWindow::OpenFile(const std::wstring& file, unsigned int openFlags)
bool CMainWindow::OpenFileAs(const std::wstring& tempPath, const std::wstring& realpath, bool bModified)
{
// If we can't open it, not much we can do.
if (OpenFile(tempPath, 0) < 0)
m_bIgnoreFileChanges = true;
OnOutOfScope(m_bIgnoreFileChanges = false;) if (OpenFile(tempPath, 0) < 0)
{
DeleteFile(tempPath.c_str());
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BowPad.
//
// Copyright (C) 2013-2018, 2020-2022 - Stefan Kueng
// Copyright (C) 2013-2018, 2020-2023 - Stefan Kueng
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -234,6 +234,7 @@ class CMainWindow : public CWindow
std::wstring m_tabMoveSavePath;
std::wstring m_tabMoveTitle;
bool m_tabMoveMod;
bool m_bIgnoreFileChanges;
long m_initLine;
int m_insertionIndex;
bool m_windowRestored;
Expand Down

0 comments on commit 67c3a21

Please sign in to comment.