mirror of https://github.com/vitalif/openscad
#879 Handle document modification signals, make editor interface more abstract
parent
f6b74eb6e0
commit
10f4a52985
44
src/editor.h
44
src/editor.h
|
@ -17,33 +17,35 @@ public:
|
||||||
virtual void setInitialSizeHint(const QSize&) { }
|
virtual void setInitialSizeHint(const QSize&) { }
|
||||||
virtual void wheelEvent (QWheelEvent*) { }
|
virtual void wheelEvent (QWheelEvent*) { }
|
||||||
virtual void setTabStopWidth(int) { }
|
virtual void setTabStopWidth(int) { }
|
||||||
virtual QString toPlainText() { QString s; return s;}
|
virtual QString toPlainText() = 0;
|
||||||
virtual QTextDocument *document(){QTextDocument *t = new QTextDocument; return t;}
|
virtual QTextDocument *document(){QTextDocument *t = new QTextDocument; return t;}
|
||||||
virtual bool find(const QString &, bool findNext = false, bool findBackwards = false) = 0;
|
virtual bool find(const QString &, bool findNext = false, bool findBackwards = false) = 0;
|
||||||
virtual void replaceSelectedText(const QString &) = 0;
|
virtual void replaceSelectedText(const QString &) = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void contentsChanged();
|
||||||
|
void modificationChanged(bool);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void zoomIn(){ }
|
virtual void zoomIn() = 0;
|
||||||
virtual void zoomOut() { }
|
virtual void zoomOut() = 0;
|
||||||
virtual void setLineWrapping(bool) { }
|
virtual void setContentModified(bool) = 0;
|
||||||
virtual void setContentModified(bool){ }
|
virtual bool isContentModified() = 0;
|
||||||
virtual bool isContentModified(){ return 0; }
|
virtual void indentSelection() = 0;
|
||||||
virtual void indentSelection(){ }
|
virtual void unindentSelection() = 0;
|
||||||
virtual void unindentSelection(){ }
|
virtual void commentSelection() = 0;
|
||||||
virtual void commentSelection() {}
|
virtual void uncommentSelection() = 0;
|
||||||
virtual void uncommentSelection(){}
|
virtual void setPlainText(const QString &) = 0;
|
||||||
virtual void setPlainText(const QString &){ }
|
virtual void highlightError(int) = 0;
|
||||||
virtual void highlightError(int) {}
|
virtual void unhighlightLastError() = 0;
|
||||||
virtual void unhighlightLastError() {}
|
virtual void setHighlightScheme(const QString&) = 0;
|
||||||
virtual void setHighlightScheme(const QString&){ }
|
|
||||||
virtual void insert(const QString&) = 0;
|
virtual void insert(const QString&) = 0;
|
||||||
virtual void undo(){ }
|
virtual void undo() = 0;
|
||||||
virtual void redo(){ }
|
virtual void redo() = 0;
|
||||||
virtual void cut(){ }
|
virtual void cut() = 0;
|
||||||
virtual void copy(){ }
|
virtual void copy() = 0;
|
||||||
virtual void paste(){ }
|
virtual void paste() = 0;
|
||||||
virtual void onTextChanged() { }
|
virtual void initFont(const QString&, uint) = 0;
|
||||||
virtual void initFont(const QString&, uint){ }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSize initialSizeHint;
|
QSize initialSizeHint;
|
||||||
|
|
|
@ -11,8 +11,12 @@ LegacyEditor::LegacyEditor(QWidget *parent) : EditorInterface(parent)
|
||||||
// This needed to avoid the editor accepting filename drops as we want
|
// This needed to avoid the editor accepting filename drops as we want
|
||||||
// to handle these ourselves in MainWindow
|
// to handle these ourselves in MainWindow
|
||||||
this->textedit->setAcceptDrops(false);
|
this->textedit->setAcceptDrops(false);
|
||||||
|
this->textedit->setWordWrapMode(QTextOption::WrapAnywhere);
|
||||||
|
|
||||||
this->highlighter = new Highlighter(this->textedit->document());
|
this->highlighter = new Highlighter(this->textedit->document());
|
||||||
|
|
||||||
|
connect(this->textedit, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
|
||||||
|
connect(this->textedit, SIGNAL(modificationChanged(bool)), this, SIGNAL(modificationChanged(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LegacyEditor::indentSelection()
|
void LegacyEditor::indentSelection()
|
||||||
|
|
|
@ -31,7 +31,6 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void zoomIn();
|
void zoomIn();
|
||||||
void zoomOut();
|
void zoomOut();
|
||||||
void setLineWrapping(bool on) { if(on) textedit->setWordWrapMode(QTextOption::WrapAnywhere); }
|
|
||||||
void setContentModified(bool y) { textedit->document()->setModified(y); }
|
void setContentModified(bool y) { textedit->document()->setModified(y); }
|
||||||
bool isContentModified() {return textedit->document()->isModified();}
|
bool isContentModified() {return textedit->document()->isModified();}
|
||||||
void indentSelection();
|
void indentSelection();
|
||||||
|
|
|
@ -241,7 +241,6 @@ MainWindow::MainWindow(const QString &filename)
|
||||||
connect(this, SIGNAL(highlightError(int)), editor, SLOT(highlightError(int)));
|
connect(this, SIGNAL(highlightError(int)), editor, SLOT(highlightError(int)));
|
||||||
connect(this, SIGNAL(unhighlightLastError()), editor, SLOT(unhighlightLastError()));
|
connect(this, SIGNAL(unhighlightLastError()), editor, SLOT(unhighlightLastError()));
|
||||||
editor->setTabStopWidth(30);
|
editor->setTabStopWidth(30);
|
||||||
editor->setLineWrapping(true); // Not designable
|
|
||||||
|
|
||||||
this->qglview->statusLabel = new QLabel(this);
|
this->qglview->statusLabel = new QLabel(this);
|
||||||
statusBar()->addWidget(this->qglview->statusLabel);
|
statusBar()->addWidget(this->qglview->statusLabel);
|
||||||
|
@ -417,8 +416,8 @@ MainWindow::MainWindow(const QString &filename)
|
||||||
}
|
}
|
||||||
updateRecentFileActions();
|
updateRecentFileActions();
|
||||||
|
|
||||||
connect(editor->document(), SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged()));
|
connect(editor, SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged()));
|
||||||
connect(editor->document(), SIGNAL(modificationChanged(bool)), this, SLOT(setWindowModified(bool)));
|
connect(editor, SIGNAL(modificationChanged(bool)), this, SLOT(setWindowModified(bool)));
|
||||||
connect(this->qglview, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate()));
|
connect(this->qglview, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate()));
|
||||||
|
|
||||||
connect(Preferences::inst(), SIGNAL(requestRedraw()), this->qglview, SLOT(updateGL()));
|
connect(Preferences::inst(), SIGNAL(requestRedraw()), this->qglview, SLOT(updateGL()));
|
||||||
|
|
|
@ -24,7 +24,9 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
|
||||||
qsci->setFolding(QsciScintilla::BoxedTreeFoldStyle, 4);
|
qsci->setFolding(QsciScintilla::BoxedTreeFoldStyle, 4);
|
||||||
qsci->setCaretLineVisible(true);
|
qsci->setCaretLineVisible(true);
|
||||||
this->setHighlightScheme(preferenceEditorOption);
|
this->setHighlightScheme(preferenceEditorOption);
|
||||||
|
|
||||||
|
connect(qsci, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
|
||||||
|
connect(qsci, SIGNAL(modificationChanged(bool)), this, SIGNAL(modificationChanged(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScintillaEditor::setPlainText(const QString &text)
|
void ScintillaEditor::setPlainText(const QString &text)
|
||||||
|
@ -37,6 +39,11 @@ QString ScintillaEditor::toPlainText()
|
||||||
return qsci->text();
|
return qsci->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScintillaEditor::setContentModified(bool modified)
|
||||||
|
{
|
||||||
|
qsci->setModified(modified);
|
||||||
|
}
|
||||||
|
|
||||||
bool ScintillaEditor::isContentModified()
|
bool ScintillaEditor::isContentModified()
|
||||||
{
|
{
|
||||||
return qsci->isModified();
|
return qsci->isModified();
|
||||||
|
@ -258,3 +265,22 @@ void ScintillaEditor::replaceSelectedText(const QString &newText)
|
||||||
if (qsci->selectedText() != newText) qsci->replaceSelectedText(newText);
|
if (qsci->selectedText() != newText) qsci->replaceSelectedText(newText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScintillaEditor::indentSelection()
|
||||||
|
{
|
||||||
|
// FIXME: Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScintillaEditor::unindentSelection()
|
||||||
|
{
|
||||||
|
// FIXME: Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScintillaEditor::commentSelection()
|
||||||
|
{
|
||||||
|
// FIXME: Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScintillaEditor::uncommentSelection()
|
||||||
|
{
|
||||||
|
// FIXME: Implement
|
||||||
|
}
|
||||||
|
|
|
@ -30,10 +30,15 @@ public slots:
|
||||||
void zoomIn();
|
void zoomIn();
|
||||||
void zoomOut();
|
void zoomOut();
|
||||||
void setPlainText(const QString&);
|
void setPlainText(const QString&);
|
||||||
|
void setContentModified(bool);
|
||||||
bool isContentModified();
|
bool isContentModified();
|
||||||
void highlightError(int);
|
void highlightError(int);
|
||||||
void unhighlightLastError();
|
void unhighlightLastError();
|
||||||
void setHighlightScheme(const QString&);
|
void setHighlightScheme(const QString&);
|
||||||
|
void indentSelection();
|
||||||
|
void unindentSelection();
|
||||||
|
void commentSelection();
|
||||||
|
void uncommentSelection();
|
||||||
void insert(const QString&);
|
void insert(const QString&);
|
||||||
void undo();
|
void undo();
|
||||||
void redo();
|
void redo();
|
||||||
|
|
Loading…
Reference in New Issue