Esempio n. 1
0
void CCedtApp::OnSearchFindInFiles() 
{
	// static dialog box to remember last settings...
	static CFindInFilesDialog dlg;

	CMainFrame * pFrame = (CMainFrame *)AfxGetMainWnd(); ASSERT( pFrame );
	if( ! pFrame->CanUseOutputWindow() ) {
		AfxMessageBox(IDS_ERR_OUTPUT_WINDOW_OCCUPIED, MB_OK | MB_ICONSTOP); return;
	}

	CCedtView * pView = (CCedtView *)pFrame->MDIGetActiveView();
	CCedtDoc * pDoc = (pView) ? (CCedtDoc *)pView->GetDocument() : NULL;

	if( pDoc && pView ) {
		dlg.m_szFindString = pView->GetCurrentWord();
		if( pView->IsSelected() && ! pView->GetSelectedLineCount() ) dlg.m_szFindString = pView->GetSelectedString();

		if( ! dlg.m_szFolder.GetLength() ) {
			CString szPathName = pDoc->GetPathName();
			if( szPathName.GetLength() ) dlg.m_szFolder = GetFileDirectory( szPathName );
		}
	} else {
		if( ! dlg.m_szFolder.GetLength() ) {
			TCHAR szTemp[MAX_PATH]; GetCurrentDirectory(MAX_PATH, szTemp);
			dlg.m_szFolder = szTemp;
		}
	}

	if( dlg.DoModal() != IDOK ) return;

	CString szFindString = dlg.m_szFindString;
	CString szFileType = dlg.m_szFileType;
	CString szFolder = dlg.m_szFolder;

	BOOL bLookSubfolders = dlg.m_bLookSubfolders;
	UINT nOptions = COMPOSE_SEARCH_OPTION( dlg.m_bWholeWord, dlg.m_bMatchCase, dlg.m_bRegularExpression);

	CRegExp clsTestRegExp; // compile regular expression for test
	if( HAS_REG_EXP(nOptions) && ! clsTestRegExp.RegComp(szFindString) ) {
		CString szMessage; szMessage.Format(IDS_ERR_REG_COMP_FAILED, szFindString);
		AfxMessageBox(szMessage); return; // test failed
	}

	DoFindInFiles(szFindString, szFileType, szFolder, bLookSubfolders, nOptions); 
}