Search in sources :

Example 1 with SearchContext

use of org.fife.ui.rtextarea.SearchContext in project jadx by skylot.

the class SearchBar method search.

private void search(int direction) {
    String searchText = searchField.getText();
    if (searchText == null || searchText.length() == 0 || rTextArea.getText() == null) {
        return;
    }
    boolean forward = direction >= 0;
    boolean matchCase = matchCaseCB.isSelected();
    boolean regex = regexCB.isSelected();
    boolean wholeWord = wholeWordCB.isSelected();
    SearchContext context = new SearchContext();
    context.setSearchFor(searchText);
    context.setMatchCase(matchCase);
    context.setRegularExpression(regex);
    context.setSearchForward(forward);
    context.setWholeWord(wholeWord);
    context.setMarkAll(markAllCB.isSelected());
    // TODO hack: move cursor before previous search for not jump to next occurrence
    if (direction == 0 && !COLOR_BG_ERROR.equals(searchField.getBackground())) {
        try {
            int caretPos = rTextArea.getCaretPosition();
            int lineNum = rTextArea.getLineOfOffset(caretPos) - 1;
            if (lineNum > 1) {
                rTextArea.setCaretPosition(rTextArea.getLineStartOffset(lineNum));
            }
        } catch (BadLocationException e) {
            LOG.error("Caret move error", e);
        }
    }
    SearchResult result = SearchEngine.find(rTextArea, context);
    if (!result.wasFound()) {
        int pos = SearchEngine.getNextMatchPos(searchText, rTextArea.getText(), forward, matchCase, wholeWord);
        if (pos != -1) {
            rTextArea.setCaretPosition(forward ? 0 : rTextArea.getDocument().getLength() - 1);
            search(direction);
            searchField.setBackground(COLOR_BG_WARN);
            return;
        }
        searchField.setBackground(COLOR_BG_ERROR);
    } else {
        searchField.setBackground(COLOR_BG_NORMAL);
    }
}
Also used : SearchContext(org.fife.ui.rtextarea.SearchContext) SearchResult(org.fife.ui.rtextarea.SearchResult) BadLocationException(javax.swing.text.BadLocationException)

Example 2 with SearchContext

use of org.fife.ui.rtextarea.SearchContext in project drmips by brunonova.

the class FrmSimulator method replace.

/**
	 * Replaces the next occurrence of the given string by another string.
	 * @param str The string to find.
	 * @param by The string to replace with.
	 * @param matchCase If the search is case-sensitive.
	 * @param forward Whether to search forwards or backwards.
	 */
protected void replace(String str, String by, boolean matchCase, boolean forward) {
    if (!str.isEmpty()) {
        clearFind();
        SearchContext context = new SearchContext();
        context.setSearchFor(str);
        context.setReplaceWith(by);
        context.setMatchCase(matchCase);
        context.setRegularExpression(false);
        context.setSearchForward(forward);
        context.setWholeWord(false);
        SearchEngine.replace(txtCode, context);
        txtCode.markAll(str, matchCase, false, false);
    }
}
Also used : SearchContext(org.fife.ui.rtextarea.SearchContext)

Example 3 with SearchContext

use of org.fife.ui.rtextarea.SearchContext in project drmips by brunonova.

the class FrmSimulator method replaceAll.

/**
	 * Replaces all occurrence of the given string by another string.
	 * @param str The string to find.
	 * @param by The string to replace with.
	 * @param matchCase If the search is case-sensitive.
	 * @param forward Whether to search forwards or backwards.
	 */
protected void replaceAll(String str, String by, boolean matchCase, boolean forward) {
    if (!str.isEmpty()) {
        clearFind();
        SearchContext context = new SearchContext();
        context.setSearchFor(str);
        context.setReplaceWith(by);
        context.setMatchCase(matchCase);
        context.setRegularExpression(false);
        context.setSearchForward(forward);
        context.setWholeWord(false);
        SearchEngine.replaceAll(txtCode, context);
    }
}
Also used : SearchContext(org.fife.ui.rtextarea.SearchContext)

Example 4 with SearchContext

use of org.fife.ui.rtextarea.SearchContext in project drmips by brunonova.

the class FrmSimulator method find.

/**
	 * Finds the specified string in the code editor.
	 * @param str The string to find.
	 * @param matchCase If the search is case-sensitive.
	 * @param forward Whether to search forwards or backwards.
	 */
protected void find(String str, boolean matchCase, boolean forward) {
    if (!str.isEmpty()) {
        clearFind();
        SearchContext context = new SearchContext();
        context.setSearchFor(str);
        context.setMatchCase(matchCase);
        context.setRegularExpression(false);
        context.setSearchForward(forward);
        context.setWholeWord(false);
        SearchEngine.find(txtCode, context);
        txtCode.markAll(str, matchCase, false, false);
    }
}
Also used : SearchContext(org.fife.ui.rtextarea.SearchContext)

Aggregations

SearchContext (org.fife.ui.rtextarea.SearchContext)4 BadLocationException (javax.swing.text.BadLocationException)1 SearchResult (org.fife.ui.rtextarea.SearchResult)1