Skip to content

Commit

Permalink
refactor + rehighlight only if we are no doing a reload (issue #406)
Browse files Browse the repository at this point in the history
  • Loading branch information
donbright committed Feb 17, 2014
1 parent e66e169 commit 838e80a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 17 deletions.
10 changes: 8 additions & 2 deletions scripts/builder.sh
Expand Up @@ -85,8 +85,14 @@ get_openscad_source_code()
if [ "`echo $? | grep 0`" ]; then
echo clone of source code is ok
else
echo clone of openscad source code failed. exiting
exit 1
if [ $DOUPLOAD ]; then
if [ ! $DOBUILD ]; then
echo upload only - skipping openscad git clone
fi
else
echo clone of openscad source code failed. exiting
exit 1
fi
fi
cd openscad
git submodule update --init # MCAD
Expand Down
3 changes: 3 additions & 0 deletions src/MainWindow.h
Expand Up @@ -206,6 +206,9 @@ public slots:
class ProgressWidget *progresswidget;
class CGALWorker *cgalworker;
QMutex consolemutex;
signals:
void highlightError(int);
void unhighlightLastError();
};

class GuiLocker
Expand Down
24 changes: 24 additions & 0 deletions src/editor.cc
@@ -1,6 +1,12 @@
#include "editor.h"
#include "Preferences.h"

Editor::Editor(QWidget *parent) : QTextEdit(parent)
{
setAcceptRichText(false);
this->highlighter = new Highlighter(this->document());
}

void Editor::indentSelection()
{
QTextCursor cursor = textCursor();
Expand Down Expand Up @@ -122,3 +128,21 @@ void Editor::setPlainText(const QString &text)
verticalScrollBar()->setSliderPosition(y);
}
}

void Editor::highlightError(int error_pos)
{
highlighter->highlightError( error_pos );
QTextCursor cursor = this->textCursor();
cursor.setPosition( error_pos );
this->setTextCursor( cursor );
}

void Editor::unhighlightLastError()
{
highlighter->unhighlightLastError();
}

Editor::~Editor()
{
delete highlighter;
}
12 changes: 9 additions & 3 deletions src/editor.h
Expand Up @@ -3,14 +3,15 @@
#include <QWidget>
#include <QWheelEvent>
#include <QScrollBar>

#include <QTextEdit>
#include "highlighter.h"

class Editor : public QTextEdit
{
Q_OBJECT
public:
Editor(QWidget *parent) : QTextEdit(parent) { setAcceptRichText(false); }
void setPlainText(const QString &text);
Editor(QWidget *parent);
~Editor();
public slots:
void zoomIn();
void zoomOut();
Expand All @@ -21,6 +22,11 @@ public slots:
void unindentSelection();
void commentSelection();
void uncommentSelection();
void setPlainText(const QString &text);
void highlightError(int error_pos);
void unhighlightLastError();

private:
void wheelEvent ( QWheelEvent * event );
Highlighter *highlighter;
};
6 changes: 4 additions & 2 deletions src/highlighter.h
Expand Up @@ -3,27 +3,29 @@

#include <QSyntaxHighlighter>
#include <QTextFormat>
#include <QTextEdit>
#include <QHash>

class Highlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
enum state_e {NORMAL=-1,QUOTE,COMMENT};
QHash<QString, QTextCharFormat> tokenFormats;
QTextCharFormat errorFormat;
Highlighter(QTextDocument *parent);
void highlightBlock(const QString &text);
void assignFormatsToTokens(const QString &);
void portable_rehighlightBlock( const QTextBlock &text );
void highlightError(int error_pos);
void unhighlightLastError();
void assignFormatsToTokens(const QString &);
private:
QTextBlock lastErrorBlock;
int errorPos;
bool errorState;
QMap<QString,QStringList> tokentypes;
QMap<QString,QTextCharFormat> typeformats;
int lastDocumentPos();
void portable_rehighlightBlock( const QTextBlock &text );
};

#endif
22 changes: 12 additions & 10 deletions src/mainwin.cc
Expand Up @@ -189,7 +189,8 @@ MainWindow::MainWindow(const QString &filename)
fps = 0;
fsteps = 1;

highlighter = new Highlighter(editor->document());
connect(this, SIGNAL(highlightError(int)), editor, SLOT(highlightError(int)));
connect(this, SIGNAL(unhighlightLastError()), editor, SLOT(unhighlightLastError()));
editor->setTabStopWidth(30);
editor->setLineWrapping(true); // Not designable

Expand Down Expand Up @@ -690,6 +691,16 @@ void MainWindow::compile(bool reload, bool forcedone)
return;
}
}

if (!reload && didcompile) {
if (!animate_panel->isVisible()) {
emit unhighlightLastError();
if (!this->root_module) {
emit highlightError( parser_error_pos );
}
}
}

compileDone(didcompile | forcedone);
}

Expand Down Expand Up @@ -1317,15 +1328,6 @@ void MainWindow::compileTopLevelDocument()
QFileInfo(this->fileName).absolutePath().toLocal8Bit(),
false);

if (!animate_panel->isVisible()) {
highlighter->unhighlightLastError();
if (!this->root_module) {
QTextCursor cursor = editor->textCursor();
cursor.setPosition(parser_error_pos);
editor->setTextCursor(cursor);
highlighter->highlightError( parser_error_pos );
}
}
}

void MainWindow::checkAutoReload()
Expand Down

0 comments on commit 838e80a

Please sign in to comment.