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 Edit::OnAnnotationAdd(wxCommandEvent& WXUNUSED(event)) { const int line = GetCurrentLine(); wxString ann = AnnotationGetText(line); ann = wxGetTextFromUser ( wxString::Format("Enter annotation for the line %d", line), "Edit annotation", ann, this ); if ( ann.empty() ) return; AnnotationSetText(line, ann); AnnotationSetStyle(line, ANNOTATION_STYLE); // Scintilla doesn't update the scroll width for annotations, even with // scroll width tracking on, so do it manually. const int width = GetScrollWidth(); // NB: The following adjustments are only needed when using // wxSTC_ANNOTATION_BOXED annotations style, but we apply them always // in order to make things simpler and not have to redo the width // calculations when the annotations visibility changes. In a real // program you'd either just stick to a fixed annotations visibility or // update the width when it changes. // Take into account the fact that the annotation is shown indented, with // the same indent as the line it's attached to. int indent = GetLineIndentation(line); // This is just a hack to account for the width of the box, there doesn't // seem to be any way to get it directly from Scintilla. indent += 3; const int widthAnn = TextWidth(ANNOTATION_STYLE, ann + wxString(indent, ' ')); if (widthAnn > width) SetScrollWidth(widthAnn); }
void Edit::OnAnnotationRemove(wxCommandEvent& WXUNUSED(event)) { AnnotationSetText(GetCurrentLine(), wxString()); }