mirror of https://github.com/vitalif/openscad
refactor + rehighlight only if we are no doing a reload (issue #406)
parent
e66e1691a9
commit
838e80ae34
|
@ -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
|
||||
|
|
|
@ -206,6 +206,9 @@ private:
|
|||
class ProgressWidget *progresswidget;
|
||||
class CGALWorker *cgalworker;
|
||||
QMutex consolemutex;
|
||||
signals:
|
||||
void highlightError(int);
|
||||
void unhighlightLastError();
|
||||
};
|
||||
|
||||
class GuiLocker
|
||||
|
|
|
@ -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();
|
||||
|
@ -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
src/editor.h
12
src/editor.h
|
@ -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();
|
||||
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -3,19 +3,22 @@
|
|||
|
||||
#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;
|
||||
|
@ -23,7 +26,6 @@ private:
|
|||
QMap<QString,QStringList> tokentypes;
|
||||
QMap<QString,QTextCharFormat> typeformats;
|
||||
int lastDocumentPos();
|
||||
void portable_rehighlightBlock( const QTextBlock &text );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue