OSDN Git Service

PATCH: [ 881602 ] Don't allow canceling saving when its pointless
authorKimmo Varis <kimmov@gmail.com>
Fri, 23 Jan 2004 13:44:41 +0000 (13:44 +0000)
committerKimmo Varis <kimmov@gmail.com>
Fri, 23 Jan 2004 13:44:41 +0000 (13:44 +0000)
Src/MainFrm.cpp
Src/MergeDiffDetailView.cpp
Src/MergeDoc.cpp
Src/MergeDoc.h
Src/MergeEditView.cpp
Src/readme.txt

index dedb825..8133c52 100644 (file)
@@ -1029,7 +1029,6 @@ void CMainFrame::OnOptions()
                // make an attempt at rescanning any open diff sessions
                MergeDocList docs;
                GetAllMergeDocs(&docs);
-               BOOL savedAll=TRUE;
                while (!docs.IsEmpty())
                {
                        CMergeDoc * pMergeDoc = docs.RemoveHead();
@@ -1055,18 +1054,10 @@ void CMainFrame::OnOptions()
                                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;
@@ -1847,7 +1838,8 @@ void CMainFrame::OnClose()
                if ((pLeft && pLeft->IsModified())
                        || (pRight && pRight->IsModified()))
                {
-                       if (!pMergeDoc->SaveHelper())
+                       // Allow user to cancel closing
+                       if (!pMergeDoc->SaveHelper(TRUE))
                                return;
                        else
                        {
@@ -2167,7 +2159,7 @@ void CMainFrame::OnToolsGeneratePatch()
                        CMergeDoc * pMergeDoc = mergedocs.RemoveHead();
 
                        // If user cancels, don't open create patch-dialog
-                       if (!pMergeDoc->SaveHelper())
+                       if (!pMergeDoc->SaveHelper(TRUE))
                        {
                                bOpenDialog = FALSE;
                        }
index 7bdf928..906adcb 100644 (file)
@@ -424,9 +424,9 @@ BOOL CMergeDiffDetailView::PreTranslateMessage(MSG* pMsg)
        // 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
@@ -495,3 +495,4 @@ void CMergeDiffDetailView::PopCursors()
 
        // other positions are set to (0,0) during ResetView
 }
+
index 9f15b63..1779e4c 100644 (file)
@@ -960,7 +960,8 @@ UINT CMergeDoc::CountPrevBlanks(UINT nCurLine, BOOL bLeft)
 
 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()
@@ -2059,14 +2060,22 @@ void CMergeDoc::PrimeTextBuffers()
 }
 
 /**
- * @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;
@@ -2075,6 +2084,11 @@ BOOL CMergeDoc::SaveHelper()
        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())
        {
@@ -2084,7 +2098,7 @@ BOOL CMergeDoc::SaveHelper()
                        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))
@@ -2106,7 +2120,7 @@ BOOL CMergeDoc::SaveHelper()
                        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))
@@ -2206,7 +2220,8 @@ void CMergeDoc::DirDocClosing(CDirDoc * pDirDoc)
  */
 BOOL CMergeDoc::CloseNow()
 {
-       if (!SaveHelper())
+       // Allow user to cancel closing
+       if (!SaveHelper(TRUE))
                return FALSE;
 
        GetParentFrame()->CloseNow();
@@ -2531,3 +2546,4 @@ void CMergeDoc::UpdateHeaderActivity(BOOL bLeft, BOOL bActivate)
        int nPane = (bLeft) ? 0 : 1;
        pf->GetHeaderInterface()->SetActive(nPane, bActivate);
 }
+
index 31a251c..2b19a30 100644 (file)
@@ -269,7 +269,7 @@ private:
 
 // Implementation
 public:
-       BOOL SaveHelper();
+       BOOL SaveHelper(BOOL bAllowCancel);
        std::vector<CMergeEditView*> undoTgt;
        std::vector<CMergeEditView*>::iterator curUndo;
        void FlushAndRescan(BOOL bForced = FALSE);
@@ -327,3 +327,4 @@ private:
 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
 
 #endif // !defined(AFX_MERGEDOC_H__BBCD4F90_34E4_11D1_BAA6_00A024706EDC__INCLUDED_)
+
index 0e43809..20e4f70 100644 (file)
@@ -1357,9 +1357,9 @@ BOOL CMergeEditView::PreTranslateMessage(MSG* pMsg)
        // 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
@@ -1810,3 +1810,4 @@ void CMergeEditView::OnUpdateWMGoto(CCmdUI* pCmdUI)
 {
        pCmdUI->Enable(TRUE);
 }
+
index 9d8e3ea..f3e6f87 100644 (file)
@@ -1,3 +1,7 @@
+2004-01-23 Kimmo
+ PATCH: [ 881602 ] Don't allow canceling saving when its pointless
+  src: MainFrm.cpp MergeDiffDetailView.cpp MergeDoc.cpp MergeDoc.h MergeEditView.cpp
+
 2004-01-23 Perry
  PATCH: [ 880006 ] Code cleanup--old commented out lines in DirView.h
   src: DirView.h