+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
void CPreferencesDlg::OnHelpButton()
{
- CMainFrame *pMf = dynamic_cast<CMainFrame*>(AfxGetMainWnd());
- pMf->ShowHelp();
+ GetMainFrame()->ShowHelp();
}
void CPreferencesDlg::AddPage(CPropertyPage* pPage, UINT nResourceID)
{
// 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))
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);
CString file = GetSelectedFileName(stype);
if (file.IsEmpty()) return;
- mf->OpenFileToExternalEditor(file);
+ GetMainFrame()->OpenFileToExternalEditor(file);
}
/**
if (!m_bRecursive && di.isDirectory())
{
// result filters
- if (di.isResultError() && !mf->m_bShowErrors)
+ if (di.isResultError() && !GetMainFrame()->m_bShowErrors)
return 0;
// left/right filters
// 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;
// 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);
}
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:
{
// 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
{
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)
{
strPaths += _T("\r\n");
}
}
- PutToClipboard(strPaths, mf->GetSafeHwnd());
+ PutToClipboard(strPaths, AfxGetMainWnd()->GetSafeHwnd());
}
/**
strPaths += _T("\r\n");
}
}
- PutToClipboard(strPaths, mf->GetSafeHwnd());
+ PutToClipboard(strPaths, AfxGetMainWnd()->GetSafeHwnd());
}
/**
strPaths += _T("\r\n");
}
}
- PutToClipboard(strPaths, mf->GetSafeHwnd());
+ PutToClipboard(strPaths, AfxGetMainWnd()->GetSafeHwnd());
}
/**
strPaths += _T("\r\n");
}
}
- PutToClipboard(strPaths, mf->GetSafeHwnd());
+ PutToClipboard(strPaths, AfxGetMainWnd()->GetSafeHwnd());
}
/**
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
#endif
extern CLogFile gLog;
-CMainFrame *mf = NULL;
static BOOL add_regexp PARAMS((struct regexp_list **, char const*, BOOL bShowError));
/////////////////////////////////////////////////////////////////////////////
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
- mf = this;
-
// build the initial reg expression list
RebuildRegExpList(FALSE);
GetFontProperties();
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)
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));
}
}
}
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;
}
void OpenFileOrUrl(LPCTSTR szFile, LPCTSTR szUrl);
};
-extern CMainFrame *mf;
+CMainFrame * GetMainFrame(); // access to the singleton main frame object
/////////////////////////////////////////////////////////////////////////////
{
//m_lang.ReloadMenu();
//m_LangDlg.UpdateDocTitle();
- mf->UpdateResources();
+ GetMainFrame()->UpdateResources();
}
}
/** @brief Open help from mainframe when user presses F1*/
void CMergeApp::OnHelp()
{
- if (mf)
- mf->ShowHelp();
+ GetMainFrame()->ShowHelp();
}
/** @brief Open Contributors.rtf */
{
m_pLangDlg->ReloadMenu();
}
-
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
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()
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);
}
}
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);
m_nBufferType[0] = BUFFER_UNNAMED;
m_ptBuf[0]->InitNew();
- m_strDesc[0] = mf->m_strLeftDesc;
+ m_strDesc[0] = GetMainFrame()->m_strLeftDesc;
nLeftSuccess = FRESULT_OK;
}
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);
m_nBufferType[1] = BUFFER_UNNAMED;
m_ptBuf[1]->InitNew();
- m_strDesc[1] = mf->m_strRightDesc;
+ m_strDesc[1] = GetMainFrame()->m_strRightDesc;
nRightSuccess = FRESULT_OK;
}
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);
// 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)
CMergeDoc* pDoc = GetDocument();
pDoc->UpdateHeaderActivity(m_nThisPane, bActivate);
- mf->UpdatePrediffersMenu();
+ GetMainFrame()->UpdatePrediffersMenu();
}
int CMergeEditView::GetAdditionalTextBlocks (int nLineIndex, TEXTBLOCK *pBuf)
if (sFileName.IsEmpty())
return;
- mf->OpenFileToExternalEditor(sFileName);
+ GetMainFrame()->OpenFileToExternalEditor(sFileName);
}
/**
curFilter.TrimLeft();
curFilter.TrimRight();
- mf->SelectFilter();
+ GetMainFrame()->SelectFilter();
CString FilterNameOrMask = theApp.m_globalFileFilter.GetFilterNameOrMask();
if (theApp.m_globalFileFilter.IsUsingMask())
*/
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);