From 9941e3a5ebb797de640e87bfec57f1505a96774f Mon Sep 17 00:00:00 2001 From: Sup Yut Sum Date: Sat, 6 Apr 2013 08:12:18 +0800 Subject: [PATCH] If file is readonly, run "Save as" (ask new filename) Especially for left view when edit mode is enabled, because there is no such checking Based on TortoiseSVN revision 24087 Signed-off-by: Sup Yut Sum --- src/TortoiseMerge/BaseView.cpp | 7 ++++++- src/TortoiseMerge/WorkingFile.cpp | 7 ++++++- src/TortoiseMerge/WorkingFile.h | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/TortoiseMerge/BaseView.cpp b/src/TortoiseMerge/BaseView.cpp index 61180930f..9822533f3 100644 --- a/src/TortoiseMerge/BaseView.cpp +++ b/src/TortoiseMerge/BaseView.cpp @@ -5343,11 +5343,16 @@ int CBaseView::SaveFile(int nFlags) break; } } - if (!file.Save(m_pWorkingFile->GetFilename())) + CString filename = m_pWorkingFile->GetFilename(); + if (m_pWorkingFile->IsReadonly()) + if (!CCommonAppUtils::FileOpenSave(filename, NULL, IDS_SAVEASTITLE, IDS_COMMONFILEFILTER, false, m_hWnd)) + return -1; + if (!file.Save(filename)) { ::MessageBox(m_hWnd, file.GetErrorString(), _T("TortoiseGitMerge"), MB_ICONERROR); return -1; } + m_pWorkingFile->SetFileName(filename); m_pWorkingFile->StoreFileAttributes(); // m_dlgFilePatches.SetFileStatusAsPatched(sFilePath); SetModified(FALSE); diff --git a/src/TortoiseMerge/WorkingFile.cpp b/src/TortoiseMerge/WorkingFile.cpp index dbabc50e4..f5b4ce0ae 100644 --- a/src/TortoiseMerge/WorkingFile.cpp +++ b/src/TortoiseMerge/WorkingFile.cpp @@ -1,6 +1,6 @@ // TortoiseGitMerge - a Diff/Patch program -// Copyright (C) 2006-2007, 2011-2012 - TortoiseSVN +// Copyright (C) 2006-2007, 2011-2013 - TortoiseSVN // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -151,3 +151,8 @@ void CWorkingFile::ClearStoredAttributes() static const WIN32_FILE_ATTRIBUTE_DATA attribsEmpty = {0}; m_attribs = attribsEmpty; } + +bool CWorkingFile::IsReadonly() const +{ + return (m_attribs.dwFileAttributes != INVALID_FILE_ATTRIBUTES) && (m_attribs.dwFileAttributes & FILE_ATTRIBUTE_READONLY); +} diff --git a/src/TortoiseMerge/WorkingFile.h b/src/TortoiseMerge/WorkingFile.h index 589a621b0..fafeda97e 100644 --- a/src/TortoiseMerge/WorkingFile.h +++ b/src/TortoiseMerge/WorkingFile.h @@ -44,6 +44,7 @@ public: void SetOutOfUse(); bool HasSourceFileChanged() const; + bool IsReadonly() const; void StoreFileAttributes(); // Move the details of the specified file to the current one, and then mark the specified file -- 2.11.4.GIT