예제 #1
0
String TextBuffer::backwardTopLevelText()
{
  // return all the text from point() back to the start of the nearest
  // top-level form before it
  setCaretVisible(false);
  setScrollToShowCursor(false);
  String line, text = String::empty;
  int here=point();
  int pos=here;
  int bol=pointBOL();
  
  for (int i=0; ; i++)
    {
      line = getTextSubstring(bol, pos);
      if ( i == 0 ) 
	text=line;
      else
	text = line + T("\n") + text;
      if ( syntax->isTopLevel(line) || ! moveLine(-1) )
	break;
      else {
	bol=point();
	pos=pointEOL();
      }
    }
  setPoint(here);
  setCaretVisible(true);
  setScrollToShowCursor(true);
  return text;
}
예제 #2
0
bool TextBuffer::indentToColumn(int col)
{
  // reindent current line so that there are col white spaces before
  // the first non-white char in line
  
  int bol=pointBOL();
  int top=bol+currentIndent();  // current pos of first non-white or eol
  int loc=bol+col;  // goal pos for indentation
  
  setCaretVisible(false);
  setScrollToShowCursor(false);

  if (loc < top)
    {
      //std::cout << "deleting " << top-loc << " spaces.\n";
     setPoint(bol);
     setHighlightedRegion(bol, (top-loc));
     insertTextAtCursor(String::empty);    
    }
  else if (loc > top)
    {
      setPoint(bol);
      String pad=String::empty;
      for (int i=top; i<loc; i++) 
	pad << T(" ");
      //std::cout << "inserting " << pad.length() << " spaces.\n";
      insertTextAtCursor(pad);
    }
  setPoint(loc);
  setCaretVisible(true);
  setScrollToShowCursor(true);
  return (loc!=top);
}
예제 #3
0
int TextBuffer::pointEOL()
{
  int here = getCaretPosition();
  setCaretVisible(false);
  int there=gotoEOL();
  setCaretPosition(here);
  setCaretVisible(true);
  return there;
}
예제 #4
0
int TextBuffer::bufferMax()
{
  // really stupid but its much faster than getText().length() !
  int cp1 = getCaretPosition();
  setCaretVisible(false);
  setCaretPosition(BUFMAX);
  int cp2=getCaretPosition();
  setCaretPosition(cp1);
  setCaretVisible(true);
  return cp2;
}
예제 #5
0
String TextBuffer::forwardTopLevelText()
{
  // return all the text starting at point() up to, but not including,
  // the next top-level line that begins after at least one non-white
  // line has been encountered. in other words, a toplevel line that
  // is preceded only by whitespace will not stop the forward
  // exclusive search (else return text would just be whitespace.)
  setCaretVisible(false);
  setScrollToShowCursor(false);
  String line, text = String::empty;
  int here=point();
  int pos=here;
  int eol=pointEOL();
  bool nonw=false; // non-white line flag
  
  for (int i=0; ; i++)
    {
      if (eol > pos)
	{
	  line = getTextSubstring(pos, eol);
	  if (syntax->isWhiteBetween(line, 0, line.length()))
	    text += line;
	  else if (i == 0)
	    {
	      // collect first line no matter what
	      text += line;
	      nonw=true;
	    }
	  else if (nonw && syntax->isTopLevel(line))
	    break;
	  else 
	    {
	      text += line;
	      nonw=true;
	    }
	}
      text += T("\n");
      if (moveLine(1))
	{
	  pos=point();
	  eol=pointEOL();
	}
      else 
	{
	  break;
	}
    }
  setPoint(here);
  setCaretVisible(true);
  setScrollToShowCursor(true);
  return text;
}
예제 #6
0
    AlertTextComp (const String& message,
                   const Font& font)
    {
        setReadOnly (true);
        setMultiLine (true, true);
        setCaretVisible (false);
        setScrollbarsShown (true);
        lookAndFeelChanged();
        setWantsKeyboardFocus (false);

        setFont (font);
        setText (message, false);

        bestWidth = 2 * (int) std::sqrt (font.getHeight() * font.getStringWidth (message));

        setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
        setColour (TextEditor::outlineColourId, Colours::transparentBlack);
        setColour (TextEditor::shadowColourId, Colours::transparentBlack);
    }
예제 #7
0
void TextBuffer::colorize (int from, int to, bool force)
{
  // JUCE LACAUNEA: (1) recoloring should only happen in the visible
  // region of buffer but i dont see anyway to get this information
  // from the viewpoint. (2) In order to recolor I have to delete and
  // add the text back into the buffer

  // this is needed because coloring changes the text buffer and we
  // dont want the editor's change callback to call the colorizer for
  // these changes.
  //  setFlag(EditFlags::Coloring); 

  String text = getTextSubstring(from, to);
  int len = text.length();
  int here = point(), pos = 0, start, end;
  String expr;
  scanresult typ;
  HiliteID hilite;
  Colour color, normal=syntax->hilites[HiliteIDs::None];
  static KeyPress dkey = KeyPress(KeyPress::deleteKey);
  
  // offset is the starting position of text string in buffer.
  setCaretVisible(false);
  setScrollToShowCursor(false);
  //printf("hiliting %d to %d...\n", from, to);
  while (pos < len)
    {
      typ=parse_sexpr(syntax->syntab, text, -1, len, 1,
		      SCAN_COLOR, &pos, &start, &end);
      hilite=HiliteIDs::None;
      if (typ>0)
	{
	  if (typ==SCAN_TOKEN)
	    {
	      hilite=syntax->getHilite(text, start, end);
	    }
	  else if (typ==SCAN_COMMENT) 
	    {
	      hilite=HiliteIDs::Comment;
	    }
	  else if (typ==SCAN_STRING)
	    {
	      hilite=HiliteIDs::String;
	    }
	  if ((hilite>HiliteIDs::None) || force)
	    {
	      // this is REALLY GROSS!
	      expr=text.substring(start,end);
	      color=syntax->hilites[hilite];
	      setPoint(from+start);
	      setHighlightedRegion(from+start, end-start);
	      TextEditor::keyPressed(dkey);
	      setColour(TextEditor::textColourId, color);
	      insertTextAtCursor(expr);
	      setColour(TextEditor::textColourId, normal);
	      /**
	      color=syntax->hilites[hilite];
	      setColour(TextEditor::textColourId, color);
	      TextEditor::repaintText(from+start, end-start);
	      setColour(TextEditor::textColourId, normal); 
	      **/
	    }
	}
    }
  setPoint(here);
  setCaretVisible(true);
  setScrollToShowCursor(true);
  //  clearFlag(EditFlags::Coloring); 
}