// make an attempt at rescanning any open diff sessions
MergeDocList docs;
GetAllMergeDocs(&docs);
- BOOL savedAll=TRUE;
while (!docs.IsEmpty())
{
CMergeDoc * pMergeDoc = docs.RemoveHead();
pRight->SetInsertTabs(FALSE);
}
- if (pMergeDoc->SaveHelper())
- {
- pMergeDoc->FlushAndRescan(TRUE);
- }
- // mods have been made, so just warn
- else
- {
- savedAll = FALSE;
- }
+ // Allow user to save files or not, cancel is pointless
+ pMergeDoc->SaveHelper(FALSE);
+ pMergeDoc->FlushAndRescan(TRUE);
}
- if (!savedAll)
- AfxMessageBox(IDS_DIFF_OPEN_NO_SET_PROPS,MB_ICONEXCLAMATION);
// Update all dirdoc settings
DirDocList dirDocs;
if ((pLeft && pLeft->IsModified())
|| (pRight && pRight->IsModified()))
{
- if (!pMergeDoc->SaveHelper())
+ // Allow user to cancel closing
+ if (!pMergeDoc->SaveHelper(TRUE))
return;
else
{
CMergeDoc * pMergeDoc = mergedocs.RemoveHead();
// If user cancels, don't open create patch-dialog
- if (!pMergeDoc->SaveHelper())
+ if (!pMergeDoc->SaveHelper(TRUE))
{
bOpenDialog = FALSE;
}
// Check if we got 'ESC pressed' -message
if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_ESCAPE))
{
- // Ask about saving unsaved document
+ // Ask about saving unsaved document, allow to cancel closing
CMergeDoc *pd = GetDocument();
- if (pd->SaveHelper())
+ if (pd->SaveHelper(TRUE))
{
// Set modified status to false so that we are not asking
// about saving again
// other positions are set to (0,0) during ResetView
}
+
BOOL CMergeDoc::CanCloseFrame(CFrameWnd* /*pFrame*/)
{
- if (SaveHelper())
+ // Allow user to cancel closing
+ if (SaveHelper(TRUE))
{
// Set modified status to false so that we are not asking
// about saving again in OnCloseDocument()
}
/**
- * @brief Saves file if file is modified. If file is
+ * @brief Asks and then saves modified files.
+ *
+ * This function saves modified files. User is asked about saving
+ * both files so user can save file(s) one wants to. Optionally
+ * canceling is allowed for following operation, i.e. when closing
+ * documents selecting cancel does not save or close documents.
* opened from directory compare, status there is updated.
+ * @sa [in] bAllowCancel If TRUE "Cancel" button is shown.
+ * @return TRUE if user selected Yes/No so next operation can be
+ * executed. If FALSE user choosed "Cancel".
* @note If filename is empty, we assume scratchpads are saved,
* so instead of filename, description is shown.
* @todo If we have filename and description for file, what should
* we do after saving to different filename? Empty description?
*/
-BOOL CMergeDoc::SaveHelper()
+BOOL CMergeDoc::SaveHelper(BOOL bAllowCancel)
{
BOOL result = TRUE;
CString s;
BOOL bLModified = FALSE;
BOOL bRModified = FALSE;
BOOL bCancel = FALSE;
+ UINT nDialogType = MB_YESNO;
+
+ // Add "Cancel" button to messagebox
+ if (bAllowCancel)
+ nDialogType = MB_YESNOCANCEL;
if (m_ltBuf.IsModified())
{
AfxFormatString1(s, IDS_SAVE_FMT, m_strLeftDesc);
bLModified = TRUE;
- switch(AfxMessageBox(s, MB_YESNOCANCEL|MB_ICONQUESTION))
+ switch (AfxMessageBox(s, nDialogType | MB_ICONQUESTION))
{
case IDYES:
if (!DoSave(m_strLeftFile, bLSaveSuccess, TRUE))
AfxFormatString1(s, IDS_SAVE_FMT, m_strRightDesc);
bRModified = TRUE;
- switch(AfxMessageBox(s, MB_YESNOCANCEL|MB_ICONQUESTION))
+ switch (AfxMessageBox(s, nDialogType | MB_ICONQUESTION))
{
case IDYES:
if (!DoSave(m_strRightFile, bRSaveSuccess, FALSE))
*/
BOOL CMergeDoc::CloseNow()
{
- if (!SaveHelper())
+ // Allow user to cancel closing
+ if (!SaveHelper(TRUE))
return FALSE;
GetParentFrame()->CloseNow();
int nPane = (bLeft) ? 0 : 1;
pf->GetHeaderInterface()->SetActive(nPane, bActivate);
}
+