Example #1
0
bool QuickFindBar::DoShow(bool s, const wxString& findWhat)
{
    bool res = wxPanel::Show(s);

    if(s && !m_eventsConnected) {
        BindEditEvents(true);

    } else if(m_eventsConnected) {
        BindEditEvents(false);
    }

    if(s && m_sci) {
        // Delete the indicators
        m_sci->SetIndicatorCurrent(1);
        m_sci->IndicatorClearRange(0, m_sci->GetLength());

        if(EditorConfigST::Get()->GetOptions()->GetClearHighlitWordsOnFind()) {
            m_sci->SetIndicatorCurrent(MARKER_WORD_HIGHLIGHT);
            m_sci->IndicatorClearRange(0, m_sci->GetLength());
        }
    }

    if(res) {
        GetParent()->GetSizer()->Layout();
    }

    if(!m_sci) {
        // nothing to do

    } else if(!s) {
        // hiding
        m_sci->SetFocus();

    } else if(!findWhat.IsEmpty()) {

        m_findWhat->ChangeValue(findWhat);
        m_findWhat->SelectAll();
        m_findWhat->SetFocus();
        PostCommandEvent(this, m_findWhat);

    } else {
        if(m_sci->GetSelections() > 1) {
        }
        wxString findWhat = DoGetSelectedText().BeforeFirst(wxT('\n'));
        if(!findWhat.IsEmpty()) {
            m_findWhat->ChangeValue(findWhat);
        }

        m_findWhat->SelectAll();
        m_findWhat->SetFocus();
        PostCommandEvent(this, m_findWhat);
    }
    return res;
}
Example #2
0
void QuickFindBar::OnFindPrevious(wxCommandEvent& e)
{
    CHECK_FOCUS_WIN();

    // Highlighted text takes precedence over the current search string
    wxString selectedText = DoGetSelectedText();
    if(selectedText.IsEmpty() == false) {
        m_findWhat->ChangeValue(selectedText);
        m_findWhat->SelectAll();
    }

    DoSearch(0);
}
Example #3
0
void QuickFindBar::OnFindPreviousCaret(wxCommandEvent& e)
{
    CHECK_FOCUS_WIN();

    wxString selection(DoGetSelectedText());
    if(selection.IsEmpty()) {
        // select the word
        long pos = m_sci->GetCurrentPos();
        long start = m_sci->WordStartPosition(pos, true);
        long end = m_sci->WordEndPosition(pos, true);

        selection = m_sci->GetTextRange(start, end);
        if(selection.IsEmpty() == false) m_sci->SetCurrentPos(start);
    }

    if(selection.IsEmpty()) return;

    m_findWhat->ChangeValue(selection);
    DoSearch(0);
}
Example #4
0
void QuickFindBar::OnReplace(wxCommandEvent& event)
{
    wxUnusedVar(event);
    if(!m_sci)
        return;

    // if there is no selection, invoke search
    int nNumSelections = m_sci->GetSelections();
#ifndef __WXMAC__
    int re_flags = wxRE_ADVANCED;
#else
    int re_flags = wxRE_DEFAULT;
#endif

    bool caseSearch = m_flags & wxSD_MATCHCASE;
    wxString selectionText;
    if(nNumSelections == 1) {
        selectionText = m_sci->GetSelectedText();

    } else if(nNumSelections > 1) {
        selectionText = DoGetSelectedText();
    }

    if(selectionText.IsEmpty())
        return;

    wxString find = m_findWhat->GetValue();
    wxString replaceWith = m_replaceWith->GetValue();

    if(!caseSearch) {
        selectionText.MakeLower();
        find.MakeLower();
    }

    if(find.IsEmpty())
        return;

    if(!replaceWith.IsEmpty()) {
        clConfig::Get().AddQuickFindReplaceItem(replaceWith);
        DoUpdateReplaceHistory();
    }

    int nextSearchOffset = m_sci->GetSelectionStart() + replaceWith.Length();

    // do we got a match?
    if((selectionText != find) && !(m_flags & wxSD_REGULAREXPRESSION)) {
        size_t flags = kSearchForward | kSearchIncremental;
        DoSearch(flags);

    } else if(m_flags & wxSD_REGULAREXPRESSION) {
        // regular expression search
        wxString selectedText = selectionText;

        // handle back references (\1 \2 etc)
        if(m_sci && selectedText.IsEmpty() == false) {

            // search was regular expression search
            // handle any back references
            caseSearch == false ? re_flags |= wxRE_ICASE : re_flags;
            wxRegEx re(find, re_flags);
            if(re.IsValid() && re.Matches(selectedText)) {
                re.Replace(&selectedText, replaceWith);
            }

            m_sci->BeginUndoAction();
            for(int i = 0; i < nNumSelections; ++i) {
                int nStart = m_sci->GetSelectionNStart(i);
                int nEnd = m_sci->GetSelectionNEnd(i);
                if(nEnd > nStart) {
                    m_sci->Replace(nStart, nEnd, selectedText);
                }
            }
            m_sci->EndUndoAction();
            m_sci->ClearSelections();
        }

        // and search again
        if(nNumSelections == 1) {
            size_t flags = kSearchForward | kSearchIncremental;
            DoSearch(flags, nextSearchOffset);
        }

    } else {

        m_sci->BeginUndoAction();
        for(int i = 0; i < nNumSelections; ++i) {
            int nStart = m_sci->GetSelectionNStart(i);
            int nEnd = m_sci->GetSelectionNEnd(i);
            if(nEnd > nStart) {
                m_sci->Replace(nStart, nEnd, replaceWith);
            }
        }
        m_sci->EndUndoAction();
        m_sci->ClearSelections();

        // and search again
        if(nNumSelections == 1) {
            size_t flags = kSearchForward | kSearchIncremental;
            DoSearch(flags, nextSearchOffset);
        }
    }
}