OSDN Git Service

PATCH: [ 1333600 ] Get rid of global MainFrame pointer (part1)
authorPerry Rapp <elsapo@users.sourceforge.net>
Sun, 15 Jan 2006 18:06:20 +0000 (18:06 +0000)
committerPerry Rapp <elsapo@users.sourceforge.net>
Sun, 15 Jan 2006 18:06:20 +0000 (18:06 +0000)
  Src: DirActions.cpp DirDoc.cpp DirView.cpp FileActionScript.cpp
   MainFrm.cpp MainFrm.h Merge.cpp MergeDoc.cpp MergeEditView.cpp
   OpenDlg.cpp PropRegistry.cpp
  Src\Common: PreferencesDlg.cpp

13 files changed:
Src/Changes.txt
Src/Common/PreferencesDlg.cpp
Src/DirActions.cpp
Src/DirDoc.cpp
Src/DirView.cpp
Src/FileActionScript.cpp
Src/MainFrm.cpp
Src/MainFrm.h
Src/Merge.cpp
Src/MergeDoc.cpp
Src/MergeEditView.cpp
Src/OpenDlg.cpp
Src/PropRegistry.cpp

index e95ca1b..cd1bd41 100644 (file)
@@ -1,3 +1,10 @@
+2006-01-15 Perry
+ PATCH: [ 1333600 ] Get rid of global MainFrame pointer (part1)
+  Src: DirActions.cpp DirDoc.cpp DirView.cpp FileActionScript.cpp
+   MainFrm.cpp MainFrm.h Merge.cpp MergeDoc.cpp MergeEditView.cpp
+   OpenDlg.cpp PropRegistry.cpp
+  Src\Common: PreferencesDlg.cpp
+
 2006-01-14 Perry
  PATCH: [ 1403457 ] Support Unicode file filter files
   Src: FileFilterMgr.cpp
index 50dae6a..805087b 100644 (file)
@@ -120,8 +120,7 @@ void CPreferencesDlg::OnDestroy()
 
 void CPreferencesDlg::OnHelpButton() 
 {
-       CMainFrame *pMf = dynamic_cast<CMainFrame*>(AfxGetMainWnd());
-       pMf->ShowHelp();
+       GetMainFrame()->ShowHelp();
 }
 
 void CPreferencesDlg::AddPage(CPropertyPage* pPage, UINT nResourceID)
index 39e91cb..ba8d78f 100644 (file)
@@ -570,8 +570,8 @@ void CDirView::PerformActionList(FileActionScript & actionScript)
 {
        // Reset suppressing VSS dialog for multiple files.
        // Set in CMainFrame::SaveToVersionControl().
-       mf->m_CheckOutMulti = FALSE;
-       mf->m_bVssSuppressPathCheck = FALSE;
+       GetMainFrame()->m_CheckOutMulti = FALSE;
+       GetMainFrame()->m_bVssSuppressPathCheck = FALSE;
 
        // Check option and enable putting deleted items to Recycle Bin
        if (GetOptionsMgr()->GetBool(OPT_USE_RECYCLE_BIN))
@@ -604,8 +604,8 @@ void CDirView::UpdateAfterFileScript(FileActionScript & actionList)
                switch (act.UIResult)
                {
                case FileActionItem::UI_SYNC:
-                       if (mf->m_bCheckinVCS)
-                               mf->CheckinToClearCase(act.dest);
+                       if (GetMainFrame()->m_bCheckinVCS)
+                               GetMainFrame()->CheckinToClearCase(act.dest);
 
                        // Syncronized item is both-sides item
                        pDoc->SetDiffSide(DIFFCODE::BOTH, act.context);
@@ -945,7 +945,7 @@ void CDirView::DoOpenWithEditor(SIDE_TYPE stype)
        CString file = GetSelectedFileName(stype);
        if (file.IsEmpty()) return;
 
-       mf->OpenFileToExternalEditor(file);
+       GetMainFrame()->OpenFileToExternalEditor(file);
 }
 
 /**
index 9ba45b7..2095cde 100644 (file)
@@ -354,7 +354,7 @@ BOOL CDirDoc::IsShowable(const DIFFITEM & di)
        if (!m_bRecursive && di.isDirectory())
        {
                // result filters
-               if (di.isResultError() && !mf->m_bShowErrors)
+               if (di.isResultError() && !GetMainFrame()->m_bShowErrors)
                        return 0;
 
                // left/right filters
@@ -372,7 +372,7 @@ BOOL CDirDoc::IsShowable(const DIFFITEM & di)
                // result filters
                if (di.isResultSame() && !GetOptionsMgr()->GetBool(OPT_SHOW_IDENTICAL))
                        return 0;
-               if (di.isResultError() && !mf->m_bShowErrors)
+               if (di.isResultError() && !GetMainFrame()->m_bShowErrors)
                        return 0;
                if (di.isResultDiff() && !GetOptionsMgr()->GetBool(OPT_SHOW_DIFFERENT))
                        return 0;
index d4870ac..f9632e6 100644 (file)
@@ -200,8 +200,7 @@ void CDirView::OnInitialUpdate()
        // Load user-selected font
        if (GetOptionsMgr()->GetBool(OPT_FONT_DIRCMP_USECUSTOM))
        {
-               CMainFrame *pMf = dynamic_cast<CMainFrame*>(AfxGetMainWnd());
-               m_font.CreateFontIndirect(&pMf->m_lfDir);
+               m_font.CreateFontIndirect(&GetMainFrame()->m_lfDir);
                SetFont(&m_font, TRUE);
        }
 
@@ -809,7 +808,7 @@ void CDirView::OpenParentDirectory()
                pDoc->m_pTempPathContext = pDoc->m_pTempPathContext->DeleteHead();
                // fall through (no break!)
        case CDirDoc::AllowUpwardDirectory::ParentIsRegularPath:
-               mf->DoFileOpen(leftParent, rightParent,
+               GetMainFrame()->DoFileOpen(leftParent, rightParent,
                        FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
                // fall through (no break!)
        case CDirDoc::AllowUpwardDirectory::No:
@@ -990,12 +989,12 @@ void CDirView::OpenSelection(PackingInfo * infoUnpacker /*= NULL*/)
        {
                // Open subfolders
                // Don't add folders to MRU
-               mf->DoFileOpen(pathLeft, pathRight, FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
+               GetMainFrame()->DoFileOpen(pathLeft, pathRight, FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
        }
        else if (HasZipSupport() && ArchiveGuessFormat(pathLeft) && ArchiveGuessFormat(pathRight))
        {
                // Open archives, not adding paths to MRU
-               mf->DoFileOpen(pathLeft, pathRight, FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
+               GetMainFrame()->DoFileOpen(pathLeft, pathRight, FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
        }
        else
        {
@@ -1029,7 +1028,7 @@ void CDirView::OpenSelection(PackingInfo * infoUnpacker /*= NULL*/)
                filelocRight.unicoding = di2->right.unicoding;
                filelocRight.codepage = di2->right.codepage;
 
-               int rtn = mf->ShowMergeDoc(pDoc, filelocLeft, filelocRight,
+               int rtn = GetMainFrame()->ShowMergeDoc(pDoc, filelocLeft, filelocRight,
                        bLeftRO, bRightRO, infoUnpacker);
                if (rtn == OPENRESULTS_FAILED_BINARY)
                {
@@ -2427,7 +2426,7 @@ void CDirView::OnCopyLeftPathnames()
                        strPaths += _T("\r\n");
                }
        }
-       PutToClipboard(strPaths, mf->GetSafeHwnd());
+       PutToClipboard(strPaths, AfxGetMainWnd()->GetSafeHwnd());
 }
 
 /**
@@ -2451,7 +2450,7 @@ void CDirView::OnCopyRightPathnames()
                        strPaths += _T("\r\n");
                }
        }
-       PutToClipboard(strPaths, mf->GetSafeHwnd());
+       PutToClipboard(strPaths, AfxGetMainWnd()->GetSafeHwnd());
 }
 
 /**
@@ -2484,7 +2483,7 @@ void CDirView::OnCopyBothPathnames()
                        strPaths += _T("\r\n");
                }
        }
-       PutToClipboard(strPaths, mf->GetSafeHwnd());
+       PutToClipboard(strPaths, AfxGetMainWnd()->GetSafeHwnd());
 }
 
 /**
@@ -2504,7 +2503,7 @@ void CDirView::OnCopyFilenames()
                        strPaths += _T("\r\n");
                }
        }
-       PutToClipboard(strPaths, mf->GetSafeHwnd());
+       PutToClipboard(strPaths, AfxGetMainWnd()->GetSafeHwnd());
 }
 
 /**
index 43173fe..abce558 100644 (file)
@@ -83,7 +83,7 @@ int FileActionScript::VCSCheckOut(const CString &path, BOOL &bApplyToAll)
                return retVal;
 
        // TODO: First param is not used!
-       int nRetVal = pMf->SyncFileToVCS(_T(""), path, bApplyToAll, &strErr);
+       int nRetVal = GetMainFrame()->SyncFileToVCS(_T(""), path, bApplyToAll, &strErr);
        if (nRetVal == -1)
        {
                retVal = SCRIPT_FAIL; // So we exit without file operations done
index b3c3072..66d5d59 100644 (file)
@@ -83,7 +83,6 @@ static char THIS_FILE[] = __FILE__;
 #endif
 
 extern CLogFile gLog;
-CMainFrame *mf = NULL;
 
 static BOOL add_regexp PARAMS((struct regexp_list **, char const*, BOOL bShowError));
 /////////////////////////////////////////////////////////////////////////////
@@ -265,8 +264,6 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
        if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
                return -1;
 
-       mf = this;
-       
        // build the initial reg expression list
        RebuildRegExpList(FALSE);
        GetFontProperties();
@@ -589,7 +586,7 @@ CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc,  const FileLocation & ifilelocLeft,
        pMergeDoc->SetUnpacker(infoUnpacker);
 
        // detect codepage
-       BOOL bGuessEncoding = mf->m_options.GetBool(OPT_CP_DETECT);
+       BOOL bGuessEncoding =GetOptionsMgr()->GetBool(OPT_CP_DETECT);
        if (filelocLeft.unicoding == -1)
                filelocLeft.unicoding = ucr::NONE;
        if (filelocLeft.unicoding == ucr::NONE && filelocLeft.codepage == -1)
@@ -2023,27 +2020,27 @@ void CMainFrame::ApplyViewWhitespace()
                CMergeDiffDetailView * pRightDetail = pMergeDoc->GetRightDetailView();
                if (pLeft)
                {
-                       pLeft->SetViewTabs(mf->m_options.GetBool(OPT_VIEW_WHITESPACE));
-                       pLeft->SetViewEols(mf->m_options.GetBool(OPT_VIEW_WHITESPACE),
-                               mf->m_options.GetBool(OPT_ALLOW_MIXED_EOL));
+                       pLeft->SetViewTabs(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE));
+                       pLeft->SetViewEols(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE),
+                               GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL));
                }
                if (pRight)
                {
-                       pRight->SetViewTabs(mf->m_options.GetBool(OPT_VIEW_WHITESPACE));
-                       pRight->SetViewEols(mf->m_options.GetBool(OPT_VIEW_WHITESPACE),
-                               mf->m_options.GetBool(OPT_ALLOW_MIXED_EOL));
+                       pRight->SetViewTabs(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE));
+                       pRight->SetViewEols(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE),
+                               GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL));
                }
                if (pLeftDetail)
                {
-                       pLeftDetail->SetViewTabs(mf->m_options.GetBool(OPT_VIEW_WHITESPACE));
-                       pLeftDetail->SetViewEols(mf->m_options.GetBool(OPT_VIEW_WHITESPACE),
-                               mf->m_options.GetBool(OPT_ALLOW_MIXED_EOL));
+                       pLeftDetail->SetViewTabs(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE));
+                       pLeftDetail->SetViewEols(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE),
+                               GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL));
                }
                if (pRightDetail)
                {
-                       pRightDetail->SetViewTabs(mf->m_options.GetBool(OPT_VIEW_WHITESPACE));
-                       pRightDetail->SetViewEols(mf->m_options.GetBool(OPT_VIEW_WHITESPACE),
-                               mf->m_options.GetBool(OPT_ALLOW_MIXED_EOL));
+                       pRightDetail->SetViewTabs(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE));
+                       pRightDetail->SetViewEols(GetOptionsMgr()->GetBool(OPT_VIEW_WHITESPACE),
+                               GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL));
                }
        }
 }
@@ -3089,5 +3086,17 @@ void CMainFrame::CheckinToClearCase(CString strDestinationPath)
 COptionsMgr *
 GetOptionsMgr() 
 {
-       return mf->GetTheOptionsMgr();
+       return GetMainFrame()->GetTheOptionsMgr();
+}
+
+/**
+ * @brief Access to the singleton main frame (where we have some globals)
+ */
+CMainFrame * GetMainFrame()
+{
+       CWnd * mainwnd = AfxGetMainWnd();
+       ASSERT(mainwnd);
+       CMainFrame *pMainframe = dynamic_cast<CMainFrame*>(mainwnd);
+       ASSERT(pMainframe);
+       return pMainframe;
 }
index 7a2df52..726fa45 100644 (file)
@@ -272,7 +272,7 @@ private:
        void OpenFileOrUrl(LPCTSTR szFile, LPCTSTR szUrl);
 };
 
-extern CMainFrame *mf;
+CMainFrame * GetMainFrame(); // access to the singleton main frame object
 
 /////////////////////////////////////////////////////////////////////////////
 
index 973d467..3228618 100644 (file)
@@ -559,7 +559,7 @@ void CMergeApp::OnViewLanguage()
        {
                //m_lang.ReloadMenu();
                //m_LangDlg.UpdateDocTitle();
-               mf->UpdateResources();
+               GetMainFrame()->UpdateResources();
        }
 }
 
@@ -661,8 +661,7 @@ void CMergeApp::InitializeFileFilters()
 /** @brief Open help from mainframe when user presses F1*/
 void CMergeApp::OnHelp()
 {
-       if (mf)
-               mf->ShowHelp();
+       GetMainFrame()->ShowHelp();
 }
 
 /** @brief Open Contributors.rtf */
@@ -770,4 +769,3 @@ CMergeApp:: ReloadMenu()
 {
        m_pLangDlg->ReloadMenu();
 }
-
index ea73225..7bf6e5a 100644 (file)
@@ -999,27 +999,27 @@ BOOL CMergeDoc::DoSave(LPCTSTR szPath, BOOL &bSaveSuccess, int nBuffer)
        bSaveSuccess = FALSE;
        
        // Check third arg possibly given from command-line
-       if (!mf->m_strSaveAsPath.IsEmpty())
+       if (!GetMainFrame()->m_strSaveAsPath.IsEmpty())
        {
-               if (paths_DoesPathExist(mf->m_strSaveAsPath) == IS_EXISTING_DIR)
+               if (paths_DoesPathExist(GetMainFrame()->m_strSaveAsPath) == IS_EXISTING_DIR)
                {
                        // third arg was a directory, so get append the filename
                        CString sname;
                        SplitFilename(szPath, 0, &sname, 0);
-                       strSavePath = mf->m_strSaveAsPath;
-                       if (mf->m_strSaveAsPath.Right(1) != _T('\\'))
+                       strSavePath = GetMainFrame()->m_strSaveAsPath;
+                       if (GetMainFrame()->m_strSaveAsPath.Right(1) != _T('\\'))
                                strSavePath += _T('\\');
                        strSavePath += sname;
                }
                else
-                       strSavePath = mf->m_strSaveAsPath;      
+                       strSavePath = GetMainFrame()->m_strSaveAsPath;  
        }
 
-       nRetVal = mf->HandleReadonlySave(strSavePath, FALSE, bApplyToAll);
+       nRetVal = GetMainFrame()->HandleReadonlySave(strSavePath, FALSE, bApplyToAll);
        if (nRetVal == IDCANCEL)
                return FALSE;
 
-       if (!mf->CreateBackup(strSavePath))
+       if (!GetMainFrame()->CreateBackup(strSavePath))
                return FALSE;
 
        // FALSE as long as the user is not satisfied
@@ -1173,7 +1173,7 @@ void CMergeDoc::SetDiffViewMode(BOOL bEnable)
 BOOL CMergeDoc::CanCloseFrame(CFrameWnd* /*pFrame*/) 
 {
        // Allow user to cancel closing
-       if (!mf->m_bEscShutdown && SaveHelper(TRUE))
+       if (!GetMainFrame()->m_bEscShutdown && SaveHelper(TRUE))
        {
                // Set modified status to false so that we are not asking
                // about saving again in OnCloseDocument()
@@ -2463,7 +2463,7 @@ int CMergeDoc::LoadFile(CString sFileName, int nBuffer, BOOL & readOnly, int cod
                                IDS_SUGGEST_PRESERVEEOL) == IDYES)
                        {
                                // the user wants to keep the original chars
-                               mf->SetEOLMixed(TRUE);
+                               GetMainFrame()->SetEOLMixed(TRUE);
                                GetOptionsMgr()->SaveOption(OPT_ALLOW_MIXED_EOL, true);
                        }
                }
@@ -2554,13 +2554,13 @@ CMergeDoc::OpenDocs(FileLocation filelocLeft, FileLocation filelocRight,
        int nLeftSuccess = FRESULT_ERROR;
        if (!sLeftFile.IsEmpty())
        {
-               if (mf->m_strLeftDesc.IsEmpty())
+               if (GetMainFrame()->m_strLeftDesc.IsEmpty())
                        m_nBufferType[0] = BUFFER_NORMAL;
                else
                {
                        m_nBufferType[0] = BUFFER_NORMAL_NAMED;
-                       m_strDesc[0] = mf->m_strLeftDesc;
-                       mf->m_strLeftDesc.Empty();
+                       m_strDesc[0] = GetMainFrame()->m_strLeftDesc;
+                       GetMainFrame()->m_strLeftDesc.Empty();
                }
 
                m_pSaveFileInfo[0]->Update(sLeftFile);
@@ -2574,7 +2574,7 @@ CMergeDoc::OpenDocs(FileLocation filelocLeft, FileLocation filelocRight,
                m_nBufferType[0] = BUFFER_UNNAMED;
 
                m_ptBuf[0]->InitNew();
-               m_strDesc[0] = mf->m_strLeftDesc;
+               m_strDesc[0] = GetMainFrame()->m_strLeftDesc;
                nLeftSuccess = FRESULT_OK;
        }
        
@@ -2582,13 +2582,13 @@ CMergeDoc::OpenDocs(FileLocation filelocLeft, FileLocation filelocRight,
        int nRightSuccess = FRESULT_ERROR;
        if (!sRightFile.IsEmpty())
        {
-               if (mf->m_strRightDesc.IsEmpty())
+               if (GetMainFrame()->m_strRightDesc.IsEmpty())
                        m_nBufferType[1] = BUFFER_NORMAL;
                else
                {
                        m_nBufferType[1] = BUFFER_NORMAL_NAMED;
-                       m_strDesc[1] = mf->m_strRightDesc;
-                       mf->m_strRightDesc.Empty();
+                       m_strDesc[1] = GetMainFrame()->m_strRightDesc;
+                       GetMainFrame()->m_strRightDesc.Empty();
                }
 
                m_pSaveFileInfo[1]->Update(sRightFile);
@@ -2601,7 +2601,7 @@ CMergeDoc::OpenDocs(FileLocation filelocLeft, FileLocation filelocRight,
                m_nBufferType[1] = BUFFER_UNNAMED;
 
                m_ptBuf[1]->InitNew();
-               m_strDesc[1] = mf->m_strRightDesc;
+               m_strDesc[1] = GetMainFrame()->m_strRightDesc;
                nRightSuccess = FRESULT_OK;
        }
 
@@ -2627,10 +2627,10 @@ CMergeDoc::OpenDocs(FileLocation filelocLeft, FileLocation filelocRight,
        m_pDetailView[0]->AttachToBuffer();
        m_pDetailView[1]->AttachToBuffer();
 
-       m_pView[0]->SetColorContext(mf->m_pSyntaxColors);
-       m_pView[1]->SetColorContext(mf->m_pSyntaxColors);
-       m_pDetailView[0]->SetColorContext(mf->m_pSyntaxColors);
-       m_pDetailView[1]->SetColorContext(mf->m_pSyntaxColors);
+       m_pView[0]->SetColorContext(GetMainFrame()->m_pSyntaxColors);
+       m_pView[1]->SetColorContext(GetMainFrame()->m_pSyntaxColors);
+       m_pDetailView[0]->SetColorContext(GetMainFrame()->m_pSyntaxColors);
+       m_pDetailView[1]->SetColorContext(GetMainFrame()->m_pSyntaxColors);
 
        // Set read-only statuses
        m_ptBuf[0]->SetReadOnly(bROLeft);
@@ -2666,7 +2666,7 @@ CMergeDoc::OpenDocs(FileLocation filelocLeft, FileLocation filelocRight,
 
        // recreate the sub menu (to fill the "selected prediffers")
        // keep after Rescan (in automatic mode, prediffer is set during the first Rescan)
-       mf->UpdatePrediffersMenu();
+       GetMainFrame()->UpdatePrediffersMenu();
 
        // Open filed if rescan succeed and files are not binaries
        if (nRescanResult == RESCAN_OK && bBinary == FALSE)
index 15709ca..c65f9a0 100644 (file)
@@ -329,7 +329,7 @@ void CMergeEditView::OnActivateView(BOOL bActivate, CView* pActivateView, CView*
 
        CMergeDoc* pDoc = GetDocument();
        pDoc->UpdateHeaderActivity(m_nThisPane, bActivate);
-       mf->UpdatePrediffersMenu();
+       GetMainFrame()->UpdatePrediffersMenu();
 }
 
 int CMergeEditView::GetAdditionalTextBlocks (int nLineIndex, TEXTBLOCK *pBuf)
@@ -2629,7 +2629,7 @@ void CMergeEditView::OnOpenFileWithEditor()
        if (sFileName.IsEmpty())
                return;
 
-       mf->OpenFileToExternalEditor(sFileName);
+       GetMainFrame()->OpenFileToExternalEditor(sFileName);
 }
 
 /**
index 7d3b5cf..625836f 100644 (file)
@@ -537,7 +537,7 @@ void COpenDlg::OnSelectFilter()
        curFilter.TrimLeft();
        curFilter.TrimRight();
 
-       mf->SelectFilter();
+       GetMainFrame()->SelectFilter();
        
        CString FilterNameOrMask = theApp.m_globalFileFilter.GetFilterNameOrMask();
        if (theApp.m_globalFileFilter.IsUsingMask())
index 2842345..3801d1e 100644 (file)
@@ -98,8 +98,7 @@ void CPropRegistry::ReadOptions()
  */
 void CPropRegistry::WriteOptions()
 {
-       CMainFrame *pMf = dynamic_cast<CMainFrame*>(AfxGetMainWnd());
-       CString sDefaultEditor = pMf->GetDefaultEditor();
+       CString sDefaultEditor = GetMainFrame()->GetDefaultEditor();
 
        m_pOptionsMgr->SaveOption(OPT_USE_RECYCLE_BIN, m_bUseRecycleBin == TRUE);
        m_pOptionsMgr->SaveOption(OPT_IGNORE_SMALL_FILETIME, m_bIgnoreSmallTimeDiff == TRUE);