示例#1
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 ();
    }
}
示例#2
0
BOOL CEditReplaceDlg::PreTranslateMessage(MSG* pMsg)
{
  if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
    {
      CButton *pSkip = (CButton*) GetDlgItem (IDC_EDIT_SKIP);
      if (pSkip->GetButtonStyle () & BS_DEFPUSHBUTTON)
        {
          OnEditSkip ();
        }
      else
        {
          OnEditReplace ();
        }
      return TRUE;
    }
  return CDialog::PreTranslateMessage(pMsg);
}
示例#3
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 );
}