Beispiel #1
0
//--| CEditReplaceDlg::OnEditReplaceAll|--------------------------------------------------
void CEditReplaceDlg::OnEditReplaceAll()
{
    if (! UpdateData())
       return;
    
    if (! m_bFound)
    {
        m_ptFoundAt = m_ptCurrentPos;
        m_bFound = DoHighlightText();
    }
    
    while (m_bFound)
    {
        // We have highlighted text
        VERIFY(m_pBuddy->ReplaceSelection(m_sNewText));
        
        // Manually recalculate points
        if (m_bEnableScopeSelection)
        {
            if (m_ptBlockBegin.y == m_ptFoundAt.y && m_ptBlockBegin.x > m_ptFoundAt.x)
            {
                m_ptBlockBegin.x -= lstrlen(m_sText);
                m_ptBlockBegin.x += lstrlen(m_sNewText);
            }
            if (m_ptBlockEnd.y == m_ptFoundAt.y && m_ptBlockEnd.x > m_ptFoundAt.x)
            {
                m_ptBlockEnd.x -= lstrlen(m_sText);
                m_ptBlockEnd.x += lstrlen(m_sNewText);
            }
        }
        m_ptFoundAt.x += lstrlen(m_sNewText);
        m_bFound = DoHighlightText();
    }
}
Beispiel #2
0
void CEditReplaceDlg::
OnEditSkip ()
{
  if (!UpdateData ())
    return;
  
  m_ctlFindText.SaveState(_T("Files\\ReplaceInFile"));
  m_ctlReplText.SaveState(_T("Files\\ReplaceWithInFile"));
  UpdateLastSearch ();

  CButton *pSkip = (CButton*) GetDlgItem (IDC_EDIT_SKIP);
  CButton *pRepl = (CButton*) GetDlgItem (IDC_EDIT_REPLACE);

  if (!m_bFound)
    {
      m_ptFoundAt = m_ptCurrentPos;
      m_bFound = DoHighlightText ( TRUE );
      if (m_bFound)
        {
          pSkip->SetButtonStyle (pSkip->GetButtonStyle () & ~BS_DEFPUSHBUTTON);
          pRepl->SetButtonStyle (pRepl->GetButtonStyle () | BS_DEFPUSHBUTTON);
          // pRepl->SetFocus ();
        }
      else
        {
          pRepl->SetButtonStyle (pRepl->GetButtonStyle () & ~BS_DEFPUSHBUTTON);
          pSkip->SetButtonStyle (pSkip->GetButtonStyle () | BS_DEFPUSHBUTTON);
          // pSkip->SetFocus ();
        }
      return;
    }

  if (!m_pBuddy->m_nLastFindWhatLen)
    if (m_ptFoundAt.y + 1 < m_pBuddy->GetLineCount ())
      {
        m_ptFoundAt.x = 0;
        m_ptFoundAt.y++;
      }
    else
      {
        m_bFound = FALSE;
        return;
      }
  else
    m_ptFoundAt.x += 1;
  m_bFound = DoHighlightText ( TRUE );
  if (m_bFound)
    {
      pSkip->SetButtonStyle (pSkip->GetButtonStyle () & ~BS_DEFPUSHBUTTON);
      pRepl->SetButtonStyle (pRepl->GetButtonStyle () | BS_DEFPUSHBUTTON);
      // pRepl->SetFocus ();
    }
  else
    {
      pRepl->SetButtonStyle (pRepl->GetButtonStyle () & ~BS_DEFPUSHBUTTON);
      pSkip->SetButtonStyle (pSkip->GetButtonStyle () | BS_DEFPUSHBUTTON);
      // pSkip->SetFocus ();
    }
}
Beispiel #3
0
//--| CEditReplaceDlg::OnEditSkip|--------------------------------------------------------
void CEditReplaceDlg::OnEditSkip()
{
    if (! UpdateData())
       return;
    
    if (! m_bFound)
    {
        m_ptFoundAt = m_ptCurrentPos;
        m_bFound = DoHighlightText();
        return;
    }
    
    m_ptFoundAt.x += 1;
    m_bFound = DoHighlightText();
}
Beispiel #4
0
void CEditReplaceDlg::
OnEditReplaceAll ()
{
  if (!UpdateData ())
    return;

  m_ctlFindText.SaveState(_T("Files\\ReplaceInFile"));
  m_ctlReplText.SaveState(_T("Files\\ReplaceWithInFile"));
  UpdateLastSearch ();

  int nNumReplaced = 0;
  BOOL bWrapped = FALSE;
  CWaitCursor waitCursor;


  if (!m_bFound)
    {
      m_ptFoundAt = m_ptCurrentPos;
      m_bFound = DoHighlightText ( FALSE );
    }

  CPoint m_ptFirstFound = m_ptFoundAt;

  while (m_bFound)
    {
      DWORD dwSearchFlags = 0;
      if (m_bMatchCase)
        dwSearchFlags |= FIND_MATCH_CASE;
      if (m_bWholeWord)
        dwSearchFlags |= FIND_WHOLE_WORD;
      if (m_bRegExp)
        dwSearchFlags |= FIND_REGEXP;
    
      //  We have highlighted text
      VERIFY (m_pBuddy->ReplaceSelection (m_sNewText, m_sNewText.GetLength(), dwSearchFlags));

      //  Manually recalculate points
      if (m_bEnableScopeSelection)
        {
          if (m_ptBlockBegin.y == m_ptFoundAt.y && m_ptBlockBegin.x > m_ptFoundAt.x)
            {
              m_ptBlockBegin.x -= m_pBuddy->m_nLastFindWhatLen;
              m_ptBlockBegin.x += m_pBuddy->m_nLastReplaceLen;
            }
          if (m_ptBlockEnd.y == m_ptFoundAt.y && m_ptBlockEnd.x > m_ptFoundAt.x)
            {
              m_ptBlockEnd.x -= m_pBuddy->m_nLastFindWhatLen;
              m_ptBlockEnd.x += m_pBuddy->m_nLastReplaceLen;
            }
        }
      // recalculate m_ptFirstFound
      if (m_ptFirstFound.y == m_ptFoundAt.y && m_ptFirstFound.x > m_ptFoundAt.x)
        {
          m_ptFirstFound.x -= m_pBuddy->m_nLastFindWhatLen;
          m_ptFirstFound.x += m_pBuddy->m_nLastReplaceLen;
        }

      // calculate the end of the current replacement
      CPoint m_ptCurrentReplacedEnd;
      m_ptCurrentReplacedEnd.y = m_ptFoundAt.y;
      m_ptCurrentReplacedEnd.x = m_ptFoundAt.x + m_pBuddy->m_nLastReplaceLen;

      // m_ptFoundAt.x has two meanings:
      // (1) One is the position of the word that was found.
      // (2) The other is next position to search.
      // The code below calculates the latter.
      if (!m_pBuddy->m_nLastFindWhatLen)
        if (m_ptFoundAt.y + 1 < m_pBuddy->GetLineCount ())
          {
            m_ptFoundAt.x = 0;
            m_ptFoundAt.y++;
          }
        else
          {
            m_bFound = FALSE;
            break;
          }
      else
        {
          m_ptFoundAt.x += m_pBuddy->m_nLastReplaceLen;
          m_ptFoundAt = m_pBuddy->GetCursorPos ();
        }
      nNumReplaced++;

      // find the next instance
      m_bFound = DoHighlightText ( FALSE );

      // detect if we just wrapped at end of file
      if (m_ptFoundAt.y < m_ptCurrentReplacedEnd.y || (m_ptFoundAt.y == m_ptCurrentReplacedEnd.y && m_ptFoundAt.x < m_ptCurrentReplacedEnd.x))
        bWrapped = TRUE;

      // after wrapping, stop at m_ptFirstFound
      // so we don't replace twice when replacement string includes replaced string 
      // (like replace "here" with "there")
      if (bWrapped)
        if (m_ptFoundAt.y > m_ptFirstFound.y || (m_ptFoundAt.y == m_ptFirstFound.y && m_ptFoundAt.x >= m_ptFirstFound.x))
          break;
    }

  // Let user know how many strings were replaced
  CString strMessage;
  CString strNumber;
  strNumber.Format( _T("%d"), nNumReplaced );
  LangFormatString1(strMessage, IDS_NUM_REPLACED, strNumber);

  AfxMessageBox( strMessage, MB_ICONINFORMATION|MB_DONT_DISPLAY_AGAIN, IDS_NUM_REPLACED);
}
Beispiel #5
0
void CEditReplaceDlg::
OnEditReplace ()
{
  if (!UpdateData ())
    return;

  m_ctlFindText.SaveState(_T("Files\\ReplaceInFile"));
  m_ctlReplText.SaveState(_T("Files\\ReplaceWithInFile"));
  UpdateLastSearch ();

  if (!m_bFound)
    {
      m_ptFoundAt = m_ptCurrentPos;
      m_bFound = DoHighlightText ( TRUE );
      CButton *pSkip = (CButton*) GetDlgItem (IDC_EDIT_SKIP);
      CButton *pRepl = (CButton*) GetDlgItem (IDC_EDIT_REPLACE);
      if (m_bFound)
        {
          pSkip->SetButtonStyle (pSkip->GetButtonStyle () & ~BS_DEFPUSHBUTTON);
          pRepl->SetButtonStyle (pRepl->GetButtonStyle () | BS_DEFPUSHBUTTON);
          // pRepl->SetFocus ();
        }
      else
        {
          pRepl->SetButtonStyle (pRepl->GetButtonStyle () & ~BS_DEFPUSHBUTTON);
          pSkip->SetButtonStyle (pSkip->GetButtonStyle () | BS_DEFPUSHBUTTON);
          // pSkip->SetFocus ();
        }
      return;
    }
  DWORD dwSearchFlags = 0;
  if (m_bMatchCase)
    dwSearchFlags |= FIND_MATCH_CASE;
  if (m_bWholeWord)
    dwSearchFlags |= FIND_WHOLE_WORD;
  if (m_bRegExp)
    dwSearchFlags |= FIND_REGEXP;

  //  We have highlighted text
  VERIFY (m_pBuddy->ReplaceSelection (m_sNewText, m_sNewText.GetLength(), dwSearchFlags));

  //  Manually recalculate points
  if (m_bEnableScopeSelection)
    {
      if (m_ptBlockBegin.y == m_ptFoundAt.y && m_ptBlockBegin.x > m_ptFoundAt.x)
        {
          m_ptBlockBegin.x -= m_pBuddy->m_nLastFindWhatLen;
          m_ptBlockBegin.x += m_pBuddy->m_nLastReplaceLen;
        }
      if (m_ptBlockEnd.y == m_ptFoundAt.y && m_ptBlockEnd.x > m_ptFoundAt.x)
        {
          m_ptBlockEnd.x -= m_pBuddy->m_nLastFindWhatLen;
          m_ptBlockEnd.x += m_pBuddy->m_nLastReplaceLen;
        }
    }
  if (!m_pBuddy->m_nLastFindWhatLen)
    if (m_ptFoundAt.y + 1 < m_pBuddy->GetLineCount ())
      {
        m_ptFoundAt.x = 0;
        m_ptFoundAt.y++;
      }
    else
      {
        m_bFound = FALSE;
        return;
      }
  else
    {
      m_ptFoundAt.x += m_pBuddy->m_nLastReplaceLen;
      m_ptFoundAt = m_pBuddy->GetCursorPos ();
    }
  m_bFound = DoHighlightText ( TRUE );
}