changeset 13413:82196fa2a103

Refactored and remove old code from CodeEdit.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Tue, 12 Apr 2011 14:52:58 +0200
parents 6579e4c2769a
children d47362945576
files gui//src/CodeEdit.cpp gui//src/CodeEdit.h gui//src/SyntaxHighlighter.cpp gui//src/SyntaxHighlighter.h
diffstat 4 files changed, 285 insertions(+), 506 deletions(-) [+]
line wrap: on
line diff
--- a/gui//src/CodeEdit.cpp
+++ b/gui//src/CodeEdit.cpp
@@ -19,416 +19,301 @@
 #include <QContextMenuEvent>
 #include "CodeEdit.h"
 
-CodeEdit::CodeEdit(QWidget *parent, QString syntaxF): QTextEdit(parent)
-, contextMenu(this)
-{
-  syntax=new Syntax(document());
-  if(!syntaxF.isEmpty())
-    syntax->load(syntaxF);
+CodeEdit::CodeEdit(QWidget *parent)
+    : QTextEdit(parent),
+      contextMenu(this) {
+
+    m_syntaxHighlighter=new SyntaxHighlighter(document());
 
-  setUndoRedoEnabled(true);
-  setTabStopWidth(32);
-  setFrameStyle(QFrame::NoFrame);
+    setUndoRedoEnabled(true);
+    setTabStopWidth(32);
+    setFrameStyle(QFrame::NoFrame);
 
-  autocompletion_ok=true;//(get_config("autoCompletion")!="false");
-  brakets_match_ok=true;//(get_config("bracketsMatch")!="false");
+    autocompletion_ok=true;//(get_config("autoCompletion")!="false");
 
-  // ContextMenu
+    // ContextMenu
 
-  connect(contextMenu.addAction(tr("Undo")), SIGNAL(triggered()),
-	  this, SLOT(undo()));
-  connect(contextMenu.addAction(tr("Redo")), SIGNAL(triggered()),
-	  this, SLOT(redo()));
+    connect(contextMenu.addAction(tr("Undo")), SIGNAL(triggered()),
+          this, SLOT(undo()));
+    connect(contextMenu.addAction(tr("Redo")), SIGNAL(triggered()),
+          this, SLOT(redo()));
 
-  contextMenu.addSeparator();
+    contextMenu.addSeparator();
 
-  connect(contextMenu.addAction(tr("Cut")), SIGNAL(triggered()),
-	  this, SLOT(cut()));
-  connect(contextMenu.addAction(tr("Copy")), SIGNAL(triggered()),
-	  this, SLOT(copy()));
-  connect(contextMenu.addAction(tr("Paste")), SIGNAL(triggered()),
-	  this, SLOT(paste()));
-  connect(contextMenu.addAction(tr("Delete")), SIGNAL(triggered()),
-	  this, SLOT(deleteSelection()));
+    connect(contextMenu.addAction(tr("Cut")), SIGNAL(triggered()),
+          this, SLOT(cut()));
+    connect(contextMenu.addAction(tr("Copy")), SIGNAL(triggered()),
+          this, SLOT(copy()));
+    connect(contextMenu.addAction(tr("Paste")), SIGNAL(triggered()),
+          this, SLOT(paste()));
+    connect(contextMenu.addAction(tr("Delete")), SIGNAL(triggered()),
+          this, SLOT(deleteSelection()));
 
-  contextMenu.addSeparator();
+    contextMenu.addSeparator();
 
-  connect(contextMenu.addAction(tr("Select all")), SIGNAL(triggered()),
-	  this, SLOT(selectAll()));
+    connect(contextMenu.addAction(tr("Select all")), SIGNAL(triggered()),
+          this, SLOT(selectAll()));
 
-  contextMenu.addSeparator();
+    contextMenu.addSeparator();
 
-  connect(contextMenu.addAction(tr("Toggle breakpoint")), SIGNAL(triggered()),
-	  this, SLOT(toggleBreakpoint()));
-	  
-  //connect(this->document(), SIGNAL( contentsChange ( int , int , int  )), this, SLOT(buildUndoRedoStack(int , int , int)) );
-	  
-  if(autocompletion_ok)
-  {
-	connect(this->document(), SIGNAL( contentsChange ( int , int , int  )), this, SLOT(buildAutoCompletionList(int , int , int)) );
-	connect(&completion, SIGNAL(activated ( const QModelIndex &)), this, SLOT(doCompletion(const QModelIndex &)) );
-  }
+    connect(contextMenu.addAction(tr("Toggle breakpoint")), SIGNAL(triggered()),
+          this, SLOT(toggleBreakpoint()));
+
+    //connect(this->document(), SIGNAL( contentsChange ( int , int , int  )), this, SLOT(buildUndoRedoStack(int , int , int)) );
 
-  if(brakets_match_ok)
-  {
-  	connect(&braketsTimer, SIGNAL(timeout ()), this, SLOT(braketsMatch()));
-  }
-  braketsTimer.setSingleShot(true);
-  braketsTimer.setInterval(50);
+    if(autocompletion_ok)
+    {
+        connect(this->document(), SIGNAL( contentsChange ( int , int , int  )), this, SLOT(buildAutoCompletionList(int , int , int)) );
+        connect(&completion, SIGNAL(activated ( const QModelIndex &)), this, SLOT(doCompletion(const QModelIndex &)) );
+    }
+
+
+    octaveCommandTimer.setSingleShot(true);
+    octaveCommandTimer.setInterval(2000);
+
+    connect(&octaveCommandTimer, SIGNAL(timeout ()), this, SLOT(octaveCommandCompletion()));
+
+    completionTimer.setSingleShot(true);
+    completionTimer.setInterval(200);
 
-  octaveCommandTimer.setSingleShot(true);
-  octaveCommandTimer.setInterval(2000);
-  
-  connect(&octaveCommandTimer, SIGNAL(timeout ()), this, SLOT(octaveCommandCompletion()));
-  
-  completionTimer.setSingleShot(true);
-  completionTimer.setInterval(200);
+    connect(&completionTimer, SIGNAL(timeout ()), this, SLOT(buildAutoCompletionList()));
 
-  connect(&completionTimer, SIGNAL(timeout ()), this, SLOT(buildAutoCompletionList()));
-
-   connect(this, SIGNAL( cursorPositionChanged() ), this, SLOT( cursorChanged_cb() ) );
+    connect(this, SIGNAL( cursorPositionChanged() ), this, SLOT( cursorChanged_cb() ) );
 
-  auto_indent=true;
-  setAcceptDrops(false);
-  if(autocompletion_ok)
-  {
-	completion.setWidget(this);
-	completion_model=new QStringListModel(&completion);
-	completion.setModel(completion_model);
-	completion.setCompletionMode(QCompleter::UnfilteredPopupCompletion);
-  }
+    auto_indent=true;
+    setAcceptDrops(false);
+    if(autocompletion_ok)
+    {
+        completion.setWidget(this);
+        completion_model=new QStringListModel(&completion);
+        completion.setModel(completion_model);
+        completion.setCompletionMode(QCompleter::UnfilteredPopupCompletion);
+    }
 
-  text_modified_stop_ok=context_changed_ok=false;
+    text_modified_stop_ok=context_changed_ok=false;
 
-  connect(document(), SIGNAL(modificationChanged (bool)), this, SLOT(textModified_cb(bool)));
+    connect(document(), SIGNAL(modificationChanged (bool)), this, SLOT(textModified_cb(bool)));
 
-  auto_indent=true;//("false"!=get_config("autoindent"));
-  automatic_indention_statement_ok=true;//(get_config("autoindent_statements")=="true");
+    auto_indent=true;//("false"!=get_config("autoindent"));
+    automatic_indention_statement_ok=true;//(get_config("autoindent_statements")=="true");
 }
 
-CodeEdit::~CodeEdit()
-{
-	//printf("Borrando la sintaxis\n");
-	delete syntax;
-	//printf("CodeEdit destruido\n");
+CodeEdit::~CodeEdit() {
+    delete m_syntaxHighlighter;
+}
+
+void CodeEdit::contextMenuEvent(QContextMenuEvent *contextMenuEvent) {
+    contextMenu.exec(contextMenuEvent->globalPos());
+}
+
+void CodeEdit::undo() {
+    document()->undo();
+}
+
+void CodeEdit::redo() {
+    document()->redo();
+}
+
+void CodeEdit::deleteSelection() {
+    textCursor().removeSelectedText();
+}
+
+void CodeEdit::toggleBreakpoint() {
+    int line = 1;
+    for(QTextBlock tb = document()->begin(); tb.isValid(); line++, tb = tb.next()) {
+        if(tb == textCursor().block()) {
+            emit toggleBreakpoint(line);
+            return;
+        }
+    }
 }
 
-void CodeEdit::contextMenuEvent(QContextMenuEvent *e)
-{
-  //setTextCursor(cursorForPosition(e->pos()));
-  contextMenu.exec(e->globalPos());
-}
+bool CodeEdit::event(QEvent * event) {
+    if(QEvent::KeyPress==event->type())
+    {
+        QKeyEvent *k=(QKeyEvent *)event;
+        if(autocompletion_ok && (Qt::Key_Left==k->key() || Qt::Key_Right==k->key())) {
+            completion.popup()->hide();
+        } else if(Qt::Key_Return==k->key() ||  Qt::Key_Enter==k->key()) {
+            if(autocompletion_ok && !completion.popup()->isHidden()) {
+                doCompletion(completion.popup()->currentIndex());
+            } else if(auto_indent) {
+                QTextCursor cursor=textCursor();
+                int pos=cursor.position();
+                cursor.movePosition(QTextCursor::StartOfBlock,QTextCursor::KeepAnchor);
+                QString line=cursor.selectedText();
+                QString start_blank;
+                start_blank.append('\n');
+                for(int i=0;i<line.length() && (line.at(i)==' ' || line.at(i)=='\t');i++)
+                    start_blank.append(line.at(i));
+                if( automatic_indention_statement_ok ) {
+                    QRegExp re("^while[ |(].*|^if[ |(].*|^for .*|^switch[ |(].*|^do$|^try|^else|^elseif$");
+                    if(re.exactMatch( line.trimmed() ) )
+                            start_blank.append("\t");
+                }
 
-void CodeEdit::undo()
-{
-	document()->undo();
-}
-
-void CodeEdit::redo()
-{
-  document()->redo();
+                cursor.setPosition(pos);
+                cursor.insertText(start_blank);
+                setTextCursor(cursor);
+            } else {
+                return QTextEdit::event(event);
+            }
+            return true;
+        }
+    }
+    return QTextEdit::event(event);
 }
 
-void CodeEdit::deleteSelection()
-{
-  textCursor().removeSelectedText();
-}
+void CodeEdit::buildAutoCompletionList(int pos, int charsRemoved, int charsAdded) {
+    octaveCommandTimer.stop();
+    document()->setModified(true);
+    context_changed_ok=true;
 
-void CodeEdit::toggleBreakpoint()
-{
-  int line = 1;
-  for(QTextBlock tb = document()->begin();
-      tb.isValid();
-      line++, tb = tb.next())
-  {
-    if(tb == textCursor().block())
-    {
-      emit toggleBreakpoint(line);
-      return;
-    }
-  }
+    completionPosition=pos;
+    completionTimer.start();
+    completion.popup()->hide();
 }
 
-bool CodeEdit::event( QEvent * e )
-{
+void CodeEdit::buildAutoCompletionList() {
+    QTextCursor cursor=textCursor();
+    int pos=cursor.position()-1;
+    //printf("[CodeEdit::buildAutoCompletionList] pos=%d completionPosition=%d\n", pos, completionPosition);
+    if(pos!=completionPosition)
+            return;
+
+    QTextBlock block=document()->findBlock(pos);
+
+    pos-=block.position();
+    int i=pos;
+    QString text=block.text();
+    QRegExp re("([^a-zA-Z_0-9]+)");
+    i=re.lastIndexIn(text, i);
+    //printf("pos=%d i=%d len=%d\n", pos, i, re.matchedLength());
+    if( i==pos ) {completion.popup()->hide();return;}
+    QString word_to_complete=text.mid(i+1,pos-i);
+    //printf("i=%d word=>%s<\n",i, word_to_complete.toLocal8Bit().data());
+    QString actual_word;
+    re.setPattern("([a-zA-Z_0-9]+)");
+    i=re.indexIn(text, pos);
+    if( i==pos ) actual_word=word_to_complete+text.mid(pos+1,re.matchedLength()-1);
+    //printf("i=%d word=>%s<\n",i, actual_word.toLocal8Bit().data());
+
+    if(word_to_complete.length()==2) {
+        completion_model->setStringList(m_syntaxHighlighter->octave_comands);
+        completion.setCompletionPrefix(word_to_complete);
+        completion.popup()->hide();
 
-	if(QEvent::KeyPress==e->type() )
-	{
-		QKeyEvent *k=(QKeyEvent *)e;
-		if( autocompletion_ok && ( Qt::Key_Left==k->key() || Qt::Key_Right==k->key() ) )
-		{
-			completion.popup()->hide();
-		}
-		else if( Qt::Key_Return==k->key() ||  Qt::Key_Enter==k->key())
-		{
-			if(autocompletion_ok && !completion.popup()->isHidden())
-			{
-				doCompletion(completion.popup()->currentIndex());
-			}
-			else if( auto_indent )
-			{
-				QTextCursor cursor=textCursor();
-				int pos=cursor.position();
-				cursor.movePosition(QTextCursor::StartOfBlock,QTextCursor::KeepAnchor);
-				QString line=cursor.selectedText();
-				QString start_blank;
-				start_blank.append('\n');
-				for(int i=0;i<line.length() && (line.at(i)==' ' || line.at(i)=='\t');i++)
-					start_blank.append(line.at(i));
-				if( automatic_indention_statement_ok )
-				{
-					QRegExp re("^while[ |(].*|^if[ |(].*|^for .*|^switch[ |(].*|^do$|^try|^else|^elseif$");
-					if(re.exactMatch( line.trimmed() ) )
-						start_blank.append("\t");
-				}
+        octaveCommandTimer.start();
+        return;
+    }
+    else if(word_to_complete.length()<3) {completion.popup()->hide();return;}
+
+    emit dynamicHelpRequired(word_to_complete);
+
+    //Se construye la lista de palabras a completar
+
+    QTextBlock blockInit, blockEnd;
+    blockInit=document()->firstBlock();
+    blockEnd =document()->lastBlock();
+    completion_list.clear();
+    buildAutoCompletionListSlide(completion_list, blockInit, blockEnd, word_to_complete, actual_word);
 
-				cursor.setPosition(pos);
-				cursor.insertText(start_blank);
-				setTextCursor( cursor );
-			}
-			else
-			{
-                                return QTextEdit::event(e);
-			}
-			return true;
-		}
-	}
-        return QTextEdit::event(e);
+    if(completion_list.isEmpty()) {completion.popup()->hide();return;}
+
+    completion_model->setStringList(completion_list);
+
+
+    QRect _position=cursorRect();
+
+    //printf("x=%d y=%d width=%d height=%d\n", _position.x(), _position.y(), _position.width(), _position.height() );
+
+    //_position.moveTo(_position.bottomRight() );
+    ////_position.setWidth(100);
+    _position.setWidth(width()/3);
+
+    completion.setCompletionPrefix(word_to_complete);
+    completion.complete(_position);
+    completion.popup()->show();
+    completion.popup()->setFocus(Qt::TabFocusReason);
 }
 
-void CodeEdit::setAutoindent(bool ai_ok)
-{
-	auto_indent=ai_ok;
+void CodeEdit::buildAutoCompletionListSlide(QStringList &list, QTextBlock blockInit, QTextBlock blockEnd, QString word_to_complete, QString actual_word) {
+    //QStringList list;
+
+    //printf("Buscando lista\n");
+    //block=document()->findBlock(0);
+
+    QTextBlock block=blockInit;
+
+    //QString match;
+    QRegExp rx("([a-zA-Z_0-9]+)");
+
+    while( block.isValid() )
+    {
+            QString text=block.text();
+            int i = 0;
+
+            while ((i = rx.indexIn(text, i)) != -1) {
+                    QString word=rx.cap(1);
+                    if( word.startsWith(word_to_complete) && !list.contains(word) && word!=actual_word )
+                    {
+                            list << word;
+                            //printf("i=%d word=>%s< actual_word=>%s<\n",i, word.toLocal8Bit().data(), actual_word.toLocal8Bit().data());
+                    }
+                    i += rx.matchedLength();
+            }
+
+            if(block!=blockEnd) block=block.next();
+            else break;
+    }
 }
 
-bool CodeEdit::getAutoindent() {return auto_indent;}
-
+void CodeEdit::octaveCommandCompletion() {
+    QRect _position=cursorRect();
 
-void CodeEdit::cursorChanged_cb()
-{
-	if(brakets_match_ok)
-	{
-		if(!context_changed_ok) braketsTimer.start();
-		else
-		{
-			context_changed_ok=false;
-			//braketsTimer.stop();
-		}
-	}
+    _position.setWidth(width());
+
+    completion.complete(_position);
+    completion.popup()->show();
+    completion.popup()->setFocus(Qt::TabFocusReason);
 }
 
 
-void CodeEdit::braketsMatch(bool rehigh)
-{
-	bool text_modified_ok=document()->isModified();
-	text_modified_stop_ok=true;
-	//if(autocompletion_ok) disconnect(this->document(), SIGNAL( contentsChange ( int , int , int  )), this, SLOT(buildAutoCompletionList(int , int , int)) );
-	int pos=textCursor().position();
-	int start=-1, end=-1;
-	if(pos>=0) syntax->braketsMacth(pos, start, end, rehigh);
-	QList<QTextEdit::ExtraSelection> selection_list;
-	if(start>=0 && end >=0)
-	{
-		QTextEdit::ExtraSelection selection;
-		selection.cursor=textCursor();
-		selection.cursor.setPosition(start);
-		selection.cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
-		selection.format=selection.cursor.blockCharFormat();
-		QBrush brush(Qt::yellow);
-		selection.format.setBackground (brush);
-		selection_list.append(selection);
-		selection.cursor=textCursor();
-		selection.cursor.setPosition(end);
-		selection.cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
-		selection_list.append(selection);
-	}
-	setExtraSelections(selection_list);
-	//if(autocompletion_ok) connect(this->document(), SIGNAL( contentsChange ( int , int , int  )), this, SLOT(buildAutoCompletionList(int , int , int)) );
-	document()->setModified(text_modified_ok);
-	text_modified_stop_ok=false;
+void CodeEdit::doCompletion(const QModelIndex &index) {
+    QString word=index.data().toString();
+    QString prefix=completion.completionPrefix();
+
+    QString suffix=word.mid(prefix.length());
+
+    QTextCursor cursor=textCursor();
+    cursor.insertText(suffix);
+
+    completion.popup()->hide();
 }
 
-void CodeEdit::buildAutoCompletionList(int pos, int charsRemoved, int charsAdded )
-{
-	octaveCommandTimer.stop();
-
-	if(brakets_match_ok)
-	{
-		braketsTimer.start();
-		//braketsMatch(true);
-	}
-	document()->setModified(true);
-	context_changed_ok=true;
-	
-	completionPosition=pos;
-	completionTimer.start();
-	completion.popup()->hide();
+void CodeEdit::textModified_cb(bool ok) {
+    //printf("[CodeEdit::textModified_cb] Entered\n");
+    if(text_modified_stop_ok) return;
+    emit textModified(ok);
+    //printf("[CodeEdit::textModified_cb] text_modified emit\n");
 }
 
-void CodeEdit::buildAutoCompletionList()
-{
-	QTextCursor cursor=textCursor();
-	int pos=cursor.position()-1;
-	//printf("[CodeEdit::buildAutoCompletionList] pos=%d completionPosition=%d\n", pos, completionPosition);
-	if(pos!=completionPosition)
-		return;
-	
-	//QTextBlock block=document()->findBlock(0);
-	//Cleans brakets match information
-
-	//while( block.isValid() )
-	//{
-		//block.setUserData(NULL);
-		//block=block.next();
-	//}
-	//Buscando palabra a completar
-	QTextBlock block=document()->findBlock(pos);
-	//int _pos=pos;
-	pos-=block.position();
-	int i=pos;
-	QString text=block.text();
-	QRegExp re("([^a-zA-Z_0-9]+)");
-	i=re.lastIndexIn(text, i);
-	//printf("pos=%d i=%d len=%d\n", pos, i, re.matchedLength());
-	if( i==pos ) {completion.popup()->hide();return;}
-	QString word_to_complete=text.mid(i+1,pos-i);
-	//printf("i=%d word=>%s<\n",i, word_to_complete.toLocal8Bit().data());
-	QString actual_word;
-	re.setPattern("([a-zA-Z_0-9]+)");
-	i=re.indexIn(text, pos);
-	if( i==pos ) actual_word=word_to_complete+text.mid(pos+1,re.matchedLength()-1);
-	//printf("i=%d word=>%s<\n",i, actual_word.toLocal8Bit().data());
-
-	if(word_to_complete.length()==2)
-	{
-		completion_model->setStringList(syntax->octave_comands);
-		completion.setCompletionPrefix(word_to_complete);
-		completion.popup()->hide();
-
-		octaveCommandTimer.start();
-
-		return;
-	}
-	else if(word_to_complete.length()<3) {completion.popup()->hide();return;}
-
-	//Searchs help for command
-	//printf("%s\n", word_to_complete.toLocal8Bit().data());
-	emit dynamic_help_required(word_to_complete);
-
-	//Se construye la lista de palabras a completar
-	
-	QTextBlock blockInit, blockEnd;
-	blockInit=document()->firstBlock();
-	blockEnd =document()->lastBlock();
-	completion_list.clear();
-	buildAutoCompletionListSlide(completion_list, blockInit, blockEnd, word_to_complete, actual_word);
-
-	if(completion_list.isEmpty()) {completion.popup()->hide();return;}
-
-	completion_model->setStringList(completion_list);
-
-
-	QRect _position=cursorRect();
-
-	//printf("x=%d y=%d width=%d height=%d\n", _position.x(), _position.y(), _position.width(), _position.height() );
-
-	//_position.moveTo(_position.bottomRight() );
-	////_position.setWidth(100);
-	_position.setWidth(width()/3);
-
-	completion.setCompletionPrefix(word_to_complete);
-	completion.complete(_position);
-	completion.popup()->show();
-	completion.popup()->setFocus(Qt::TabFocusReason);
-}
-
-void CodeEdit::buildAutoCompletionListSlide(QStringList &list, QTextBlock blockInit, QTextBlock blockEnd, QString word_to_complete, QString actual_word)
-{
-	//QStringList list;
-
-	//printf("Buscando lista\n");
-	//block=document()->findBlock(0);
+void CodeEdit::publicBlockBoundingRectList(QVector<qreal> &list, int &first_line){
+    /*
+    qreal pageBottom = viewport()->height();
+    QPointF offset=contentOffset();
+    QTextBlock block=firstVisibleBlock();
+    first_line=block.blockNumber()+1;
+    qreal first_position=blockBoundingGeometry(block).topLeft().y();
 
-	QTextBlock block=blockInit;
-
-	//QString match;
-	QRegExp rx("([a-zA-Z_0-9]+)");
-
-	while( block.isValid() )
-	{
-		QString text=block.text();
-		int i = 0;
-
-		while ((i = rx.indexIn(text, i)) != -1) {
-			QString word=rx.cap(1);
-			if( word.startsWith(word_to_complete) && !list.contains(word) && word!=actual_word )
-			{
-				list << word;
-				//printf("i=%d word=>%s< actual_word=>%s<\n",i, word.toLocal8Bit().data(), actual_word.toLocal8Bit().data());
-			}
-			i += rx.matchedLength();
-		}
-
-		if(block!=blockEnd) block=block.next();
-		else break;
-	}
-}
-
-void CodeEdit::octaveCommandCompletion()
-{
-	QRect _position=cursorRect();
-
-	_position.setWidth(width());
-
-	completion.complete(_position);
-	completion.popup()->show();
-	completion.popup()->setFocus(Qt::TabFocusReason);
-}
-
-
-void CodeEdit::doCompletion(const QModelIndex &index)
-{
-	QString word=index.data().toString();
-	QString prefix=completion.completionPrefix();
+    for ( ; block.isValid(); block = block.next() )
+    {
+            QRectF position=blockBoundingGeometry(block);
+            qreal y=position.topLeft().y()+offset.y()-first_position;
 
-	QString suffix=word.mid(prefix.length());
-
-	QTextCursor cursor=textCursor();
-	cursor.insertText(suffix);
-
-	completion.popup()->hide();
-}
-
-bool CodeEdit::getbraketsMatchOk()
-{
-	return syntax->getIsActiveBraketsMacth();
-}
-
-void CodeEdit::textModified_cb(bool ok)
-{
-	//printf("[CodeEdit::textModified_cb] Entered\n");
-	if(text_modified_stop_ok) return;
-	emit text_modified(ok);
-	//printf("[CodeEdit::textModified_cb] text_modified emit\n");
-}
+            if(y>pageBottom) break;
 
-void CodeEdit::publicBlockBoundingRectList(QVector<qreal> &list, int &first_line)
-{/*
-        qreal pageBottom = viewport()->height();
-	QPointF offset=contentOffset();
-	QTextBlock block=firstVisibleBlock();
-	first_line=block.blockNumber()+1;
-	qreal first_position=blockBoundingGeometry(block).topLeft().y();
-	
-	for ( ; block.isValid(); block = block.next() )
-	{
-		QRectF position=blockBoundingGeometry(block);
-		qreal y=position.topLeft().y()+offset.y()-first_position;
-		
-		if(y>pageBottom) break;
-		
-		list.append(y);
-	}
-        */
+            list.append(y);
+    }
+    */
 }
-
--- a/gui//src/CodeEdit.h
+++ b/gui//src/CodeEdit.h
@@ -16,8 +16,8 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef __CODEEDIT_H__
-#define __CODEEDIT_H__
+#ifndef CODEEDIT_H
+#define CODEEDIT_H
 
 #include <QTextEdit>
 #include <QMenu>
@@ -39,12 +39,9 @@
 class CodeEdit: public QTextEdit {
     Q_OBJECT
 public:
-    CodeEdit(QWidget *parent = 0, QString syntaxF = QString());
+    CodeEdit(QWidget *parent = 0);
     ~CodeEdit();
-    void setAutoindent(bool ai_ok);
-    bool getAutoindent();
-    bool getbraketsMatchOk();
- 
+
     /**List of y top left positions of bounding rects of each visible block of text.
     * @param list List of top left positions.
     * @param first_line First visible block in TextEdit.
@@ -56,8 +53,6 @@
     void redo();
     void deleteSelection();
     void toggleBreakpoint();
-    void braketsMatch(bool rehigh=true);
-    void cursorChanged_cb();
     void buildAutoCompletionList(int pos, int charsRemoved, int charsAdded );
     void buildAutoCompletionList();
     void doCompletion(const QModelIndex &index);
@@ -67,16 +62,15 @@
 signals:
     void toggleBreakpoint(int lineno);
 
-    /**Dinamic help required.*/
-    void dynamic_help_required(const QString &text);
+    /** Dynamic help required. */
+    void dynamicHelpRequired(const QString &text);
 
-    /**Text modified.*/
-    void text_modified(bool ok);
+    /** Text modified. */
+    void textModified(bool ok);
 
 protected:
-    Syntax *syntax;
-    QMenu  contextMenu;
-
+    SyntaxHighlighter *m_syntaxHighlighter;
+    QMenu contextMenu;
     void contextMenuEvent(QContextMenuEvent *e);
     bool event( QEvent * e );
 
@@ -88,19 +82,16 @@
     QStringList completion_list;
     int completionPosition;
 
-    /**Builds auto completion list from block blockInit to blockEnd.*/
+    /** Builds auto completion list from block blockInit to blockEnd. */
     void buildAutoCompletionListSlide(QStringList &list, QTextBlock blockInit, QTextBlock blockEnd, QString word_to_complete, QString actual_word);
 
     bool text_modified_stop_ok; //Stops emit of text_modified signal
     bool context_changed_ok;
 
-    //Editor properties
-
-    /**Automatic indention for while, if, for, switch, do and try statements.*/
+    /** Automatic indention for while, if, for, switch, do and try statements. */
     bool automatic_indention_statement_ok;
-    /**Auto completion*/
+    /** Auto completion. */
     bool autocompletion_ok;
-    /**Brackets Macth*/
-    bool brakets_match_ok;
 };
-#endif
+
+#endif // CODEEDIT_H
--- a/gui//src/SyntaxHighlighter.cpp
+++ b/gui//src/SyntaxHighlighter.cpp
@@ -24,14 +24,14 @@
 #include <QHash>
 #include <QDir>
 
-QList<Syntax::Rule*> Syntax::rules;
-QStringList Syntax::octave_comands;
+QList<SyntaxHighlighter::Rule*> SyntaxHighlighter::rules;
+QStringList SyntaxHighlighter::octave_comands;
 
 /*** Xml Handler ***/
 class SyntaxXmlHandler:public QXmlDefaultHandler
 {
 private:
-  Syntax *syntax;
+  SyntaxHighlighter *syntax;
   QString type_name, text;
   struct Tag
   {
@@ -44,7 +44,7 @@
   QStringList *octave_comands;
 public:
   	// Constructor
-  	SyntaxXmlHandler(Syntax *s, QStringList *octave_comands): QXmlDefaultHandler(), syntax(s)
+  	SyntaxXmlHandler(SyntaxHighlighter *s, QStringList *octave_comands): QXmlDefaultHandler(), syntax(s)
   	{
   		this->octave_comands=octave_comands;
   	}
@@ -141,7 +141,7 @@
 
 /*** Syntax ***/
 
-Syntax::Syntax(QTextDocument *parent): QSyntaxHighlighter(parent)
+SyntaxHighlighter::SyntaxHighlighter(QTextDocument *parent): QSyntaxHighlighter(parent)
 {
   QTextCharFormat f;
 
@@ -203,7 +203,7 @@
 }
 
 
-Syntax::~Syntax()
+SyntaxHighlighter::~SyntaxHighlighter()
 {
 	//foreach(Rule *value, rules_map)
 	//{
@@ -214,7 +214,7 @@
 	setDocument(NULL);
 }
 
-void Syntax::load(const QString &path)
+void SyntaxHighlighter::load(const QString &path)
 {
 	if(octave_comands.isEmpty())
 	{
@@ -287,7 +287,7 @@
 //   }
 // }
 
-void Syntax::setItem(const QString &item, const QString &type, const QString parent)
+void SyntaxHighlighter::setItem(const QString &item, const QString &type, const QString parent)
 {
 	Rule *r;
 	if(!item.isEmpty())
@@ -304,7 +304,7 @@
 	}
 }
 
-void Syntax::setComment(const QString &start, const QString &end, const QString &type)
+void SyntaxHighlighter::setComment(const QString &start, const QString &end, const QString &type)
 {
 	Rule *r;
 	if(!type.isEmpty())
@@ -318,12 +318,12 @@
 	}
 }
 
-void Syntax::setType(const QString &type, const QTextCharFormat &f)
+void SyntaxHighlighter::setType(const QString &type, const QTextCharFormat &f)
 {
   _format[type] = f;
 }
 
-void Syntax::highlightBlock(const QString &str)
+void SyntaxHighlighter::highlightBlock(const QString &str)
 {
   //Para aumentar el rendimiento se hace una tabla i_aux con la posición de lo
   //que ha encontrado cada expresión regular rules.at(n)->pattern.
@@ -442,7 +442,7 @@
 }
 
 
-int Syntax::forward_search(QTextBlock & block, int pos, char bracket_start, char bracket_end)
+int SyntaxHighlighter::forward_search(QTextBlock & block, int pos, char bracket_start, char bracket_end)
 {
 	int i=pos,  open=0;
 
@@ -499,7 +499,7 @@
 	return -1;
 }
 
-int Syntax::backward_search(QTextBlock & block, int pos, char bracket_start, char bracket_end)
+int SyntaxHighlighter::backward_search(QTextBlock & block, int pos, char bracket_start, char bracket_end)
 {
 	int i=pos,  open=0;
 
@@ -604,101 +604,7 @@
 	}
 }
 
-void Syntax::braketsMacth(int pos, int &start, int &end, bool rehigh)
-{
-	QTextDocument *doc=document();
-
-	if(!rehigh)
-	{
-		clear_block_data(doc, true);
-		return;
-	}
-
-	QTextBlock block0=doc->findBlock(pos), block1;
-	if(!block0.isValid() || block0.text().length()<=0)
-	{
-		return;
-	}
-
-
-	pos=pos-block0.position();
-	if (block0.text().size()<=pos) pos=block0.text().size()-1;
-	if(pos<0) pos=0;
-
-	QChar ch=block0.text().at(pos);
-
-	BlockData *dat=(BlockData *)block0.userData();
-	if(dat!=NULL)
-	{
-		if( !dat->bracket.contains(pos) ) ch=' ';
-	}
-
-
-	block1=block0;
-
-	int i=-1;
-	if(ch=='(')
-	{
-		i=forward_search(block1,pos,'(', ')');
-	}
-	else if(ch==')')
-	{
-		i=backward_search(block1,pos,'(', ')');
-	}
-	else if(ch=='[')
-	{
-		i=forward_search(block1,pos,'[', ']');
-	}
-	else if(ch==']')
-	{
-		i=backward_search(block1,pos,'[', ']');
-	}
-	else if(ch=='{')
-	{
-		i=forward_search(block1,pos,'{', '}');
-	}
-	else if(ch=='}')
-	{
-		i=backward_search(block1,pos,'{', '}');
-	}
-	else
-	{
-		if( braketsMacth_ok )
-		{
-			clear_block_data(doc, rehigh);
-			braketsMacth_ok=false;
-		}
-
-		return;
-	}
-
-	if(i>=0)
-	{
-		clear_block_data(doc, true);
-		//set_block_data(block0, block1, pos, i);
-		start=pos+block0.position();
-		end=i+block1.position();
-		//braketsMacth_ok=true;
-		//if(rehigh) rehighlight();
-		
-		/*
-		QTextCursor cursor(doc);
-
-		cursor.beginEditBlock();
-		cursor.setPosition(block0.position()+pos);
-		cursor.setBlockFormat(block0.blockFormat());
-		if(block1!=block0)
-		{
-			cursor.setPosition(block1.position()+i);
-			cursor.setBlockFormat(block1.blockFormat());
-		}
-		cursor.endEditBlock();
-		*/
-	}
-}
-
-
-void Syntax::setActive(bool active)
+void SyntaxHighlighter::setActive(bool active)
 {
 	active_ok=active;
 }
--- a/gui//src/SyntaxHighlighter.h
+++ b/gui//src/SyntaxHighlighter.h
@@ -26,12 +26,12 @@
 #include "config.h"
 
 /**SyntaxHighlighter for Octave code.*/
-class Syntax: public QSyntaxHighlighter
+class SyntaxHighlighter: public QSyntaxHighlighter
 {
  Q_OBJECT
  public:
-  Syntax(QTextDocument *parent);
-  ~Syntax();
+  SyntaxHighlighter(QTextDocument *parent);
+  ~SyntaxHighlighter();
   void highlightBlock(const QString &str);
   void load(const QString &file);
 
@@ -46,9 +46,6 @@
   static QStringList octave_comands;
   
  public slots:
- 
- void braketsMacth(int pos, int &start, int &end, bool rehigh=true);
- 
  /**Return true or false if brackets are been macthed*/
  inline bool getIsActiveBraketsMacth() {return braketsMacth_ok;}