OSDN Git Service

PATCH: [ 912754 ] Close open MergeDoc before opening new from DirDoc
authorKimmo Varis <kimmov@gmail.com>
Wed, 10 Mar 2004 15:12:05 +0000 (15:12 +0000)
committerKimmo Varis <kimmov@gmail.com>
Wed, 10 Mar 2004 15:12:05 +0000 (15:12 +0000)
Src/DirDoc.cpp
Src/DirDoc.h
Src/DirView.cpp
Src/readme.txt

index 2e0bf66..278b646 100644 (file)
@@ -505,7 +505,9 @@ POSITION CDirDoc::FindItemFromPaths(LPCTSTR pathLeft, LPCTSTR pathRight)
        return NULL;
 }
 
-// stash away our view pointer
+/**
+ * @brief Stash away our view pointer.
+ */
 void CDirDoc::SetDirView(CDirView * newView)
 {
        m_pDirView = newView;
@@ -515,14 +517,18 @@ void CDirDoc::SetDirView(CDirView * newView)
        ASSERT(temp == m_pDirView); // verify that our stashed pointer is the same as MFC's
 }
 
-// a new merge doc has been opened
+/**
+ * @brief A new MergeDoc has been opened.
+ */
 void CDirDoc::AddMergeDoc(CMergeDoc * pMergeDoc)
 {
        ASSERT(pMergeDoc);
        m_MergeDocs.AddTail(pMergeDoc);
 }
 
-// merge doc informs us it is closing
+/**
+ * @brief MergeDoc informs us it is closing.
+ */
 void CDirDoc::MergeDocClosing(CMergeDoc * pMergeDoc)
 {
        ASSERT(pMergeDoc);
@@ -531,19 +537,36 @@ void CDirDoc::MergeDocClosing(CMergeDoc * pMergeDoc)
        m_MergeDocs.RemoveAt(pos);
 }
 
-// Prepare for reuse
-// Close all our merge docs (which gives them chance to save)
-// This may fail if user cancels a Save dialog
-// in which case this aborts and returns FALSE
-BOOL CDirDoc::ReusingDirDoc()
+/**
+ * @brief Close MergeDocs opened from DirDoc.
+ *
+ * Asks confirmation for docs containing unsaved data and then
+ * closes MergeDocs.
+ * @return TRUE if success, FALSE if user canceled or closing failed
+ */
+BOOL CDirDoc::CloseMergeDocs()
 {
-       // Inform all of our merge docs that we're closing
        for (POSITION pos = m_MergeDocs.GetHeadPosition(); pos; )
        {
                CMergeDoc * pMergeDoc = m_MergeDocs.GetNext(pos);
                if (!pMergeDoc->CloseNow())
                        return FALSE;
        }
+       return TRUE;
+}
+
+/**
+ * @brief Prepare for reuse.
+ *
+ * Close all our merge docs (which gives them chance to save)
+ * This may fail if user cancels a Save dialog
+ * in which case this aborts and returns FALSE
+ */
+BOOL CDirDoc::ReusingDirDoc()
+{
+       // Inform all of our merge docs that we're closing
+       if (!CloseMergeDocs())
+               return FALSE;
 
        // clear diff display
        ASSERT(m_pDirView);
@@ -567,8 +590,11 @@ BOOL CDirDoc::ReusingDirDoc()
        return TRUE;
 }
 
-// Obtain a merge doc to display a difference in files
-// pNew is set to TRUE if a new doc is created, and FALSE if an existing one reused
+/**
+ * @brief Obtain a merge doc to display a difference in files.
+ * @param [out] pNew Set to TRUE if a new doc is created,
+ * and FALSE if an existing one reused.
+ */
 CMergeDoc * CDirDoc::GetMergeDocForDiff(BOOL * pNew)
 {
        CMergeDoc * pMergeDoc = 0;
index dc1fb92..3b292b1 100644 (file)
@@ -69,6 +69,7 @@ protected:
 public:
 // Operations
 public:
+       BOOL CloseMergeDocs();
        CDirView * GetMainView();
        CMergeDoc * GetMergeDocForDiff(BOOL * pNew);
        BOOL ReusingDirDoc();
index 6b28356..58d7b04 100644 (file)
@@ -753,6 +753,10 @@ void CDirView::OpenSelection(PackingInfo * infoUnpacker /*= NULL*/)
                        AfxMessageBox(IDS_FILEBINARY, MB_ICONSTOP);
                else
                {
+                       // Close open documents first (ask to save unsaved data)
+                       if (!GetDocument()->CloseMergeDocs())
+                               return;
+                       
                        // Open identical and different files
                        CString left, right;
                        BOOL bLeftRO = GetDocument()->GetReadOnly(TRUE);
index ed7e578..3614398 100644 (file)
@@ -2,6 +2,8 @@
  Fix for OptionsMgr bugs when loading string options from registry
   UNICODE strings were not handled correctly, incorrect buffer lengths
   Src/Common: OptionsMgr.cpp OptionsMgr.h
+ PATCH: [ 912754 ] Close open MergeDoc before opening new from DirDoc
+  Src: DirDoc.cpp DirDoc.h DirView.cpp
 
 2004-03-09 Kimmo
  PATCH: [ 912297 ] Splashscreen and syntax highlight options