void OutputCtrl::ActivateLine( int line, bool openFile ) { // Get the file name and line. bool isError = false; wxString File; long Line; if ( line != -1 ) { wxString Text = GetLine( line ); if ( m_ErrorExpr.Matches( Text ) && m_ErrorExpr.GetMatchCount() > 3 ) { isError = true; File = m_ErrorExpr.GetMatch( Text, 1 ); m_ErrorExpr.GetMatch( Text, 2 ).ToLong( &Line ); } else if ( m_WarnExpr.Matches( Text ) && m_WarnExpr.GetMatchCount() > 3 ) { isError = true; File = m_WarnExpr.GetMatch( Text, 1 ); m_WarnExpr.GetMatch( Text, 2 ).ToLong( &Line ); } } if ( m_Selected != -1 ) { int start = PositionFromLine( m_Selected ); int len = GetLineEndPosition( m_Selected ) - start; // Reverse the style! StartStyling( start, 0xFF ); SetStyling( len, 2 ); } m_Selected = line; if ( !isError ) m_Selected = -1; if ( m_Selected != -1 ) { int start = PositionFromLine( m_Selected ); int len = GetLineEndPosition( m_Selected ) - start; // Reverse the style! StartStyling( start, 0xFF ); SetStyling( len, 1 ); } if ( m_Selected != -1 ) ShowLine( m_Selected ); // Ok read the file name from the list. if ( openFile && !File.IsEmpty() ) { // TODO: Should we launch 3rd party apps here or allow the // file to be opened as text? wxASSERT( tsGetMainFrame() ); tsGetMainFrame()->OpenFile( File, Line-1 ); } }
void LogTextControl::addStyledText(const wxString& message, LogStyle style) { if (message.empty()) return; SetReadOnly(false); // This implements the typical behaviour for log text controls: // When the caret is at the end of the text it will be kept there, keeping // the last logged text visible. // Otherwise the caret position is not altered, so user can navigate // in the already logged text. int lenBefore = GetLength(); bool atEnd = lenBefore == GetCurrentPos(); AppendText(message); int len = GetLength(); StartStyling(lenBefore, 255); SetStyling(len - lenBefore - 1, int(style)); if (atEnd) GotoPos(len); SetReadOnly(true); }
/** * Style text with given style ID */ void FbEditor::style(int length, TokenStyle style) { SetStyling(length, (int)style); }
void OutputCtrl::AppendText( const wxString& text ) { SetReadOnly( false ); bool scrollEnd = false; int pos = GetLength(); if ( GetCurrentPos() == pos && GetAnchor() == pos ) scrollEnd = true; // For each line... const wxChar* ptr = text.c_str(); const wxChar* const end = ptr + text.Length(); const wxChar* next; wxString line; bool isError = false; bool isWarn = false; //wxTextAttr errorStyle( *wxRED, *wxWHITE ); //wxTextAttr warnStyle( *wxRED, *wxWHITE ); //wxColour( 255, 128, 0 ), *wxWHITE ); long lnumb; while( ptr != end ) { wxASSERT( ptr < end ); next = std::find( ptr, end, '\n' ); if ( next != end ) ++next; line.assign( ptr, next ); ptr = next; // Look for error lines and highlight them... // // TODO: I need to optimize the regex here... maybe i // shouldn't use a regex, but use my own logic to spot // errors... could be much faster. // if ( m_ErrorExpr.Matches( line ) && m_ErrorExpr.GetMatchCount() > 3 ) isError = true; else if ( m_WarnExpr.Matches( line ) && m_ErrorExpr.GetMatchCount() > 3 ) isWarn = true; pos = GetLength(); SetTargetStart( pos ); SetTargetEnd( pos ); ReplaceTarget( line ); if ( isError ) { StartStyling( pos, 0xFF ); SetStyling( line.Len(), 2 ); // TODO: SetStyle will screw with the current scroll position. The // trick is to disable ECO_AUTOVSCROLL and ECO_AUTOHSCROLL before // changing the selection to change the style. We need to submit this // fix back to wxWindows. //::SendMessage( GetHwnd(), EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL ); //SetStyle( start, last, errorStyle ); //::SendMessage( GetHwnd(), EM_SETOPTIONS, ECOOP_OR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL ); // Add the error to the debugger state. m_ErrorExpr.GetMatch( line, 2 ).ToLong( &lnumb ); ScriptError* error = new ScriptError; error->file = m_ErrorExpr.GetMatch( line, 1 ); error->line = lnumb; error->start = pos; error->end = pos + line.Len(); error->row = LineFromPosition( pos ); error->error = m_ErrorExpr.GetMatch( line, 3 ); error->error.Trim(); error->warning = false; AddError( error ); isError = false; } else if ( isWarn ) { StartStyling( pos, 0xFF ); SetStyling( line.Len(), 2 ); // TODO: SetStyle will screw with the current scroll position. The // trick is to disable ECO_AUTOVSCROLL and ECO_AUTOHSCROLL before // changing the selection to change the style. We need to submit this // fix back to wxWindows. //::SendMessage( GetHwnd(), EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL ); //SetStyle( start, last, warnStyle ); //::SendMessage( GetHwnd(), EM_SETOPTIONS, ECOOP_OR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL ); // Add the error to the debugger state. m_WarnExpr.GetMatch( line, 2 ).ToLong( &lnumb ); ScriptError* error = new ScriptError; error->file = m_WarnExpr.GetMatch( line, 1 ); error->line = lnumb; error->start = pos; error->end = pos + line.Len(); error->row = LineFromPosition( pos ); error->error = m_WarnExpr.GetMatch( line, 3 ); error->error.Trim(); error->warning = true; AddError( error ); isWarn = false; } } if ( scrollEnd ) { const int endPos = GetLength(); SetAnchor( endPos ); SetCurrentPos( endPos ); ShowLine( LineFromPosition( endPos ) ); } EmptyUndoBuffer(); SetReadOnly( true ); }