示例#1
0
/**
 * Style text based on the token for the length given
 */
void FbEditor::style(int length, TokenPtr token)
{
    if (token->getKind() == TokenKind::Invalid || !token->isValid()) {
        SetIndicatorCurrent(ErrorIndicator);
        IndicatorFillRange(GetEndStyled(), length);
    }
    style(length, _tokenStyles[(int)token->getKind()]);
}
示例#2
0
/* TextEditor::onUpdateUI
 * Called when anything is modified in the text editor (cursor
 * position, styling, text, etc)
 *******************************************************************/
void TextEditor::onUpdateUI(wxStyledTextEvent& e)
{
	// Check for brace match
	if (txed_brace_match)
		checkBraceMatch();

	// If a calltip is open, update it
	if (call_tip->IsShown())
		updateCalltip();

	// Do word matching if appropriate
	if (txed_match_cursor_word && language)
	{
		int word_start = WordStartPosition(GetCurrentPos(), true);
		int word_end = WordEndPosition(GetCurrentPos(), true);
		string current_word = GetTextRange(word_start, word_end);
		if (!current_word.IsEmpty() && HasFocus())
		{
			if (current_word != prev_word_match)
			{
				prev_word_match = current_word;

				SetIndicatorCurrent(8);
				IndicatorClearRange(0, GetTextLength());
				SetTargetStart(0);
				SetTargetEnd(GetTextLength());
				SetSearchFlags(0);
				while (SearchInTarget(current_word) != -1)
				{
					IndicatorFillRange(GetTargetStart(), GetTargetEnd() - GetTargetStart());
					SetTargetStart(GetTargetEnd());
					SetTargetEnd(GetTextLength());
				}
			}
		}
		else
		{
			SetIndicatorCurrent(8);
			IndicatorClearRange(0, GetTextLength());
			prev_word_match = "";
		}
	}

	// Hilight current line
	MarkerDeleteAll(1);
	MarkerDeleteAll(2);
	if (txed_hilight_current_line > 0 && HasFocus())
	{
		int line = LineFromPosition(GetCurrentPos());
		MarkerAdd(line, 1);
		if (txed_hilight_current_line > 1)
			MarkerAdd(line, 2);
	}

	e.Skip();
}
void LuaScriptEditorView::CheckSyntax()
{
   CStringA text;
   GetText(text);

   int indicatorNumber = INDIC_CONTAINER;

   AnnotationClearAll();

   Lua::State state;
   std::vector<CString> errorMessages;
   if (state.CheckSyntax(CString(text), errorMessages))
   {
      IndicSetStyle(indicatorNumber, INDIC_HIDDEN);
      AnnotationSetVisible(ANNOTATION_HIDDEN);
      return;
   }

   IndicSetStyle(indicatorNumber, INDIC_SQUIGGLE);
   IndicSetFore(indicatorNumber, RGB(255, 0, 0)); // red

   SetIndicatorCurrent(indicatorNumber);

   for (size_t index = 0, maxIndex = errorMessages.size(); index < maxIndex; index++)
   {
      CString errorMessage = errorMessages[0];

      int pos = errorMessage.Find(_T("]:"));
      int pos2 = errorMessage.Find(_T(':'), pos + 2);

      int lineNumber = _ttoi(errorMessage.Mid(pos + 2, pos2 - (pos + 2)));
      CString error = errorMessage.Mid(pos2 + 1).Trim();

      SetIndicatorValue(index);

      int textStart = static_cast<int>(PositionFromLine(lineNumber - 1));
      int textEnd = GetLineEndPosition(lineNumber - 1);

      IndicatorFillRange(textStart, textEnd - textStart);

      AnnotationSetText(lineNumber - 1, CStringA(error).GetString());
      AnnotationSetVisible(ANNOTATION_BOXED);
   }
}
void cbStyledTextCtrl::HighlightRightBrace()
{
    if (m_bracePosition == wxSCI_INVALID_POSITION)
        return;

    int pos = GetCurrentPos();
    if (pos == wxSCI_INVALID_POSITION)
        return;

    const static wxColour caretForeground = GetCaretForeground();
    const static int caretWidth = GetCaretWidth();
    const int curLine = GetCurrentLine();
    const int len = GetLength();

    if (m_tabSmartJump && (curLine == LineFromPosition(m_bracePosition)))
    {
        SetIndicatorCurrent(s_indicHighlight);
        const int indPos = GetLineIndentPosition(curLine);
        IndicatorClearRange(indPos, GetLineEndPosition(curLine)-indPos);
        do
        {
            if (pos >= len)
                break;

            wxString cur((wxChar)GetCharAt(pos));
            if (cur == _T("\n"))
                break;

            int style = GetStyleAt(pos);
            if (IsComment(style))
                continue;

            if (IsString(style) || IsCharacter(style))
            {
                const int nextOne = (pos == len) ? GetStyleAt(pos) : GetStyleAt(pos + 1);
                if (IsCharacter(nextOne) || IsString(nextOne))
                    continue;
            }

            if (s_rightBrace.Contains(cur))
            {
                SetCaretForeground(wxColour(255, 0, 0));
                SetCaretWidth(caretWidth + 1);

                IndicatorSetForeground(s_indicHighlight, wxColour(80, 236, 120));
                IndicatorSetStyle(s_indicHighlight, wxSCI_INDIC_HIGHLIGHT);
#ifndef wxHAVE_RAW_BITMAP
                IndicatorSetUnder(s_indicHighlight, true);
#endif
                SetIndicatorCurrent(s_indicHighlight);
                IndicatorFillRange(pos, 1);
                m_bracePosition = pos + 1;
                return;
            }
        }
        while (++pos);
    }

    m_bracePosition = wxSCI_INVALID_POSITION;
    m_lastPosition = wxSCI_INVALID_POSITION;
    m_tabSmartJump = false;
    SetIndicatorCurrent(s_indicHighlight);
    IndicatorClearRange(0, len);

    SetCaretForeground(caretForeground);
    SetCaretWidth(caretWidth);
}