Esempio n. 1
0
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 );
   }
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
/**
 * Style needed
 */
void FbEditor::onStyleNeeded(wxStyledTextEvent & event)
{
    // startint position
    auto startPos  = GetEndStyled();
    auto startLine = LineFromPosition(startPos);
    startPos       = PositionFromLine(startLine);
    // end position
    int lastPos    = event.GetPosition();
    int lastLine   = std::max(LineFromPosition(lastPos), std::min(GetLineCount(), GetFirstVisibleLine() + LinesOnScreen()));
    lastPos        = GetLineEndPosition(lastLine);
        
    // get token
    auto token = m_srcCtx->getLine(startLine, lastLine);
    
    // set stylling position
    StartStyling(startPos, INT_MAX);
    
    // clear indicatirs
    SetIndicatorCurrent(ErrorIndicator);
    IndicatorClearRange(startPos, lastPos - startPos);
    
    // no token? just colour to default
    if (!token) {
        style(lastPos - startPos, TokenStyle::Default);
        return;
    }
    
    
    // style the tokens
    int line = startLine;
    int col  = 0;
    while (token && line <= lastLine) {
        // end of the line?
        if (token->getKind() == TokenKind::EndOfLine) {
            token = token->getNext();
            continue;
        }
        
        // token line
        int tline = token->getLine();
        
        // token started before current line
        if (line > tline) {
            int start = PositionFromLine(line);
            int end   = PositionFromLine(token->getEndLine()) + token->getEndCol();
            style(end - start, token);
            
            // end on line and column
            col  = token->getEndCol();
            line = token->getEndLine();
            
            // get next token and continue
            token = token->getNext();
            continue;
        }
        
        // empty lines before next token?
        if (line < tline) {
            int start = PositionFromLine(line) + col;
            int end   = PositionFromLine(tline) + token->getCol();
            style(end - start, TokenStyle::Default);
            
            // end on line and column
            line = token->getLine();
            col = token->getCol();
            continue;
        }
        
        // started on the current line
        if (line == tline) {
            // empty space ?
            if (token->getCol() > col) {
                style(token->getCol() - col, TokenStyle::Default);
            }
            
            // style the token
            style(token->getLength(), token);
            col = token->getEndCol();
            line = token->getEndLine();
            
            // advance to the next one
            token = token->getNext();
            continue;
        }
        
        // some empty space till end of the line
        int length = GetLineLength(line);
        if (col < length) {
            style(length - col, TokenStyle::Default);
        }
        
        // incement line
        line++;
        col = 0;
    }
}
Esempio n. 4
0
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 );
}