OSDN Git Service

PATCH: [ 1421199 ] Fix plugin menu for when location or diff detail view active
authorPerry Rapp <elsapo@users.sourceforge.net>
Sat, 4 Feb 2006 21:49:36 +0000 (21:49 +0000)
committerPerry Rapp <elsapo@users.sourceforge.net>
Sat, 4 Feb 2006 21:49:36 +0000 (21:49 +0000)
  Src: ChildFrm.cpp ChildFrm.h MainFrm.cpp MainFrm.h MergeDoc.cpp MergeDoc.h

Src/Changes.txt
Src/ChildFrm.cpp
Src/ChildFrm.h
Src/MainFrm.cpp
Src/MainFrm.h
Src/MergeDoc.cpp
Src/MergeDoc.h

index 1b96b69..e8f9fd1 100644 (file)
@@ -11,6 +11,8 @@
   (Also fix French dialog which was left out before.)
   Src: Merge.rc
   Src/Languages: */Merge*.rc
+ PATCH: [ 1421199 ] Fix plugin menu for when location or diff detail view active
+  Src: ChildFrm.cpp ChildFrm.h MainFrm.cpp MainFrm.h MergeDoc.cpp MergeDoc.h
   
 2006-02-03 Perry
  PATCH: [ 1409651 ] fix diffutils handling trailing whitespace
index 7935baa..b7bdd8e 100644 (file)
@@ -104,6 +104,7 @@ CChildFrame::CChildFrame()
 {
        m_bActivated = FALSE;
        m_nLastSplitPos = 0;
+       m_pMergeDoc = 0;
 }
 
 CChildFrame::~CChildFrame()
@@ -194,8 +195,8 @@ BOOL CChildFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
        pLeft->SetStatusInterface(&m_leftStatus);
        pRight->SetStatusInterface(&m_rightStatus);
        // tell merge doc about these views
-       CMergeDoc * pDoc = dynamic_cast<CMergeDoc *>(pContext->m_pCurrentDoc);
-       pDoc->SetMergeViews(pLeft, pRight);
+       m_pMergeDoc = dynamic_cast<CMergeDoc *>(pContext->m_pCurrentDoc);
+       m_pMergeDoc->SetMergeViews(pLeft, pRight);
        pLeft->m_nThisPane = 0;
        pRight->m_nThisPane = 1;
 
@@ -203,7 +204,7 @@ BOOL CChildFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
        CMergeDiffDetailView * pLeftDetail = (CMergeDiffDetailView *)m_wndDetailSplitter.GetPane(0,0);
        CMergeDiffDetailView * pRightDetail = (CMergeDiffDetailView *)m_wndDetailSplitter.GetPane(1,0);
        // tell merge doc about these views
-       pDoc->SetMergeDetailViews(pLeftDetail, pRightDetail);
+       m_pMergeDoc->SetMergeDetailViews(pLeftDetail, pRightDetail);
        pLeftDetail->m_nThisPane = 0;
        pRightDetail->m_nThisPane = 1;
        
index 865857c..c61f1c3 100644 (file)
@@ -35,6 +35,8 @@
 #include "DiffViewBar.h"
 #include "LocationBar.h"
 
+class CMergeDoc;
+
 /** 
  * @brief Frame class for file compare, handles panes, statusbar etc.
  */
@@ -43,8 +45,14 @@ class CChildFrame : public CMDIChildWnd
        DECLARE_DYNCREATE(CChildFrame)
 public:
        CChildFrame();
+
+// Operations
+public:
+       void UpdateResources();
+       void CloseNow();
        IHeaderBar * GetHeaderInterface();
        void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; };
+       CMergeDoc * GetMergeDoc() { return m_pMergeDoc; }
 
 // Attributes
 protected:
@@ -81,13 +89,7 @@ protected:
        MergeStatus m_leftStatus;
        MergeStatus m_rightStatus;
 
-// Operations
-public:
-       void UpdateResources();
-private:
-       BOOL EnsureValidDockState(CDockState& state);
 
-public:
 
 // Overrides
        // ClassWizard generated virtual function overrides
@@ -100,17 +102,19 @@ public:
        //}}AFX_VIRTUAL
 
 // Implementation
-public:
+private:
+       BOOL EnsureValidDockState(CDockState& state);
        void UpdateDiffDockbarHeight(int DiffPanelHeight);
        void SavePosition();
        virtual ~CChildFrame();
-       void CloseNow();
 
 // Generated message map functions
-protected:
+private:
        int m_nLastSplitPos;
        void UpdateHeaderSizes();
        BOOL m_bActivated;
+       CMergeDoc * m_pMergeDoc;
+
        //{{AFX_MSG(CChildFrame)
        afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
        afx_msg void OnClose();
index 118d10e..e5993a8 100644 (file)
@@ -2419,6 +2419,26 @@ void CMainFrame::OnReloadPlugins()
        UpdatePrediffersMenu();
 }
 
+/** @brief Return active merge edit view, if can figure it out/is available */
+CMergeEditView * CMainFrame::GetActiveMergeEditView()
+{
+       // NB: GetActiveDocument does not return the Merge Doc 
+       //     even when the merge edit view is in front
+       // NB: CChildFrame::GetActiveView returns NULL when location view active
+       // So we have this rather complicated logic to try to get a merge edit view
+       // We look at the front child window, which should be a frame
+       // and we can get a MergeEditView from it, if it is a CChildFrame
+       // (DirViews use a different frame type)
+       CChildFrame * pFrame = dynamic_cast<CChildFrame *>(GetActiveFrame());
+       if (!pFrame) return 0;
+       // Try to get the active MergeEditView (ie, left or right)
+       if (pFrame->GetActiveView() && pFrame->GetActiveView()->IsKindOf(RUNTIME_CLASS(CMergeEditView)))
+       {
+               return dynamic_cast<CMergeEditView *>(pFrame->GetActiveView());
+       }
+       return pFrame->GetMergeDoc()->GetActiveMergeView();
+}
+
 void CMainFrame::UpdatePrediffersMenu()
 {
        CMenu* menu = GetMenu();
@@ -2431,7 +2451,7 @@ void CMainFrame::UpdatePrediffersMenu()
        HMENU prediffersSubmenu = GetPrediffersSubmenu(hMainMenu);
        if (prediffersSubmenu != NULL)
        {
-               CMergeEditView * pEditView = dynamic_cast<CMergeEditView*> (GetActiveFrame()->GetActiveView());
+               CMergeEditView * pEditView = GetActiveMergeEditView();
                if (pEditView)
                        pEditView->createPrediffersSubmenu(prediffersSubmenu);
                else
index a6ceada..74310de 100644 (file)
@@ -273,6 +273,7 @@ private:
        void ShowFontChangeMessage();
        void OptionsInit();
        void OpenFileOrUrl(LPCTSTR szFile, LPCTSTR szUrl);
+       CMergeEditView * GetActiveMergeEditView();
 };
 
 CMainFrame * GetMainFrame(); // access to the singleton main frame object
index 38ad21d..215d2fa 100644 (file)
@@ -257,22 +257,39 @@ BOOL CMergeDoc::OnNewDocument()
  * @brief Determines currently active view.
  * @return one of MERGEVIEW_INDEX_TYPE values or -1 in error.
  */
-int CMergeDoc::GetActiveMergeView()
-{
-       CCrystalTextView* curView = dynamic_cast<CCrystalTextView*> (GetParentFrame()->GetActiveView());
-       if (curView == m_pView[0])
+int CMergeDoc::GetActiveMergeViewIndexType() const
+{
+       CMergeDoc * pThis = const_cast<CMergeDoc *>(this);
+       // Get active view pointer
+       CView * pActiveView = pThis->GetParentFrame()->GetActiveView();
+       // Cast it to common base of all our views
+       CCrystalTextView* curView = dynamic_cast<CCrystalTextView*> (pActiveView);
+       // Now test it against all our views to see which it is
+       if (curView == GetLeftView())
                return MERGEVIEW_LEFT;
-       else if (curView == m_pView[1])
+       else if (curView == GetRightView())
                return MERGEVIEW_RIGHT;
-       else if (curView == m_pDetailView[0])
+       else if (curView == GetLeftDetailView())
                return MERGEVIEW_LEFT_DETAIL;
-       else if (curView == m_pDetailView[1])
+       else if (curView == GetRightDetailView())
                return MERGEVIEW_RIGHT_DETAIL;
 
        _RPTF0(_CRT_ERROR, "Invalid view pointer!");
        return -1;
 }
 
+/**
+ * @brief Return active merge edit view (or left one if neither active)
+ */
+CMergeEditView * CMergeDoc::GetActiveMergeView()
+{
+       CView * pActiveView = GetParentFrame()->GetActiveView();
+       CMergeEditView * pMergeEditView = dynamic_cast<CMergeEditView *>(pActiveView);
+       if (!pMergeEditView)
+               pMergeEditView = GetLeftView(); // default to left view (in case some location or detail view active)
+       return pMergeEditView;
+}
+
 void CMergeDoc::SetUnpacker(PackingInfo * infoNewHandler)
 {
        if (infoNewHandler)
@@ -799,13 +816,13 @@ void CMergeDoc::ListCopy(int srcPane, int dstPane, int nDiff /* = -1*/,
                {
                        // Find out diff under cursor
                        CPoint ptCursor;
-                       int nActiveView = GetActiveMergeView();
-                       if (nActiveView == MERGEVIEW_LEFT || nActiveView == MERGEVIEW_RIGHT)
-                               ptCursor = m_pView[nActiveView]->GetCursorPos();
-                       else if (nActiveView == MERGEVIEW_LEFT_DETAIL ||
-                                       nActiveView == MERGEVIEW_RIGHT_DETAIL)
+                       int nActiveViewIndexType = GetActiveMergeViewIndexType();
+                       if (nActiveViewIndexType == MERGEVIEW_LEFT || nActiveViewIndexType == MERGEVIEW_RIGHT)
+                               ptCursor = m_pView[nActiveViewIndexType]->GetCursorPos();
+                       else if (nActiveViewIndexType == MERGEVIEW_LEFT_DETAIL ||
+                                       nActiveViewIndexType == MERGEVIEW_RIGHT_DETAIL)
                        {
-                               ptCursor = m_pView[nActiveView - MERGEVIEW_LEFT_DETAIL]->GetCursorPos();
+                               ptCursor = m_pView[nActiveViewIndexType - MERGEVIEW_LEFT_DETAIL]->GetCursorPos();
                        }
                        nDiff = m_diffList.LineToDiff(ptCursor.y);
                }
@@ -1856,15 +1873,15 @@ void CMergeDoc::FlushAndRescan(BOOL bForced /* =FALSE */)
 
        WaitStatusCursor waitstatus(LoadResString(IDS_STATUS_RESCANNING));
 
-       int nActiveView = GetActiveMergeView();
+       int nActiveViewIndexType = GetActiveMergeViewIndexType();
 
        // store cursors and hide caret
        m_pView[0]->PushCursors();
        m_pView[1]->PushCursors();
        m_pDetailView[0]->PushCursors();
        m_pDetailView[1]->PushCursors();
-       if (nActiveView == MERGEVIEW_LEFT || nActiveView == MERGEVIEW_RIGHT)
-               m_pView[nActiveView]->HideCursor();
+       if (nActiveViewIndexType == MERGEVIEW_LEFT || nActiveViewIndexType == MERGEVIEW_RIGHT)
+               m_pView[nActiveViewIndexType]->HideCursor();
 
        BOOL bBinary = FALSE;
        BOOL bIdentical = FALSE;
@@ -1875,26 +1892,26 @@ void CMergeDoc::FlushAndRescan(BOOL bForced /* =FALSE */)
        m_pView[1]->PopCursors();
        m_pDetailView[0]->PopCursors();
        m_pDetailView[1]->PopCursors();
-       if (nActiveView == MERGEVIEW_LEFT || nActiveView == MERGEVIEW_RIGHT)
-               m_pView[nActiveView]->ShowCursor();
+       if (nActiveViewIndexType == MERGEVIEW_LEFT || nActiveViewIndexType == MERGEVIEW_RIGHT)
+               m_pView[nActiveViewIndexType]->ShowCursor();
 
        // because of ghostlines, m_nTopLine may differ just after Rescan
        // scroll both views to the same top line
        CMergeEditView * fixedView = m_pView[0];
-       if (nActiveView == MERGEVIEW_LEFT || nActiveView == MERGEVIEW_RIGHT)
+       if (nActiveViewIndexType == MERGEVIEW_LEFT || nActiveViewIndexType == MERGEVIEW_RIGHT)
                // only one view needs to scroll so do not scroll the active view
-               fixedView = m_pView[nActiveView];
+               fixedView = m_pView[nActiveViewIndexType];
        fixedView->UpdateSiblingScrollPos(FALSE);
 
        // make sure we see the cursor from the curent view
-       if (nActiveView == MERGEVIEW_LEFT || nActiveView == MERGEVIEW_RIGHT)
-               m_pView[nActiveView]->EnsureVisible(m_pView[nActiveView]->GetCursorPos());
+       if (nActiveViewIndexType == MERGEVIEW_LEFT || nActiveViewIndexType == MERGEVIEW_RIGHT)
+               m_pView[nActiveViewIndexType]->EnsureVisible(m_pView[nActiveViewIndexType]->GetCursorPos());
 
        // scroll both diff views to the same top line
        CMergeDiffDetailView * fixedDetailView = m_pDetailView[0];
-       if (nActiveView == MERGEVIEW_LEFT_DETAIL || nActiveView == MERGEVIEW_RIGHT_DETAIL)
+       if (nActiveViewIndexType == MERGEVIEW_LEFT_DETAIL || nActiveViewIndexType == MERGEVIEW_RIGHT_DETAIL)
                // only one view needs to scroll so do not scroll the active view
-               fixedDetailView = m_pDetailView[nActiveView - MERGEVIEW_LEFT_DETAIL];
+               fixedDetailView = m_pDetailView[nActiveViewIndexType - MERGEVIEW_LEFT_DETAIL];
        fixedDetailView->UpdateSiblingScrollPos(FALSE);
 
        // Refresh display
index 3278c87..52d9f92 100644 (file)
@@ -218,7 +218,8 @@ public:
        /// String of concatenated filenames as text to apply plugins filter to
        CString m_strBothFilenames;
 
-       int GetActiveMergeView();
+       int GetActiveMergeViewIndexType() const;
+       CMergeEditView * GetActiveMergeView();
        void UpdateHeaderPath(int pane);
        void UpdateHeaderActivity(int pane, BOOL bActivate);
        void RefreshOptions();