forked from qt-creator/qt-creator
TextEditor: Fix snippet editor crash introduced in d85a4f615
The SnippetEditorWidget setup is unusual as it doesn't have an associated SnippetEditorFactory/SnippetEditor creation chain and requires manual intervention. This was lost in the conversion to the new construction scheme. Change-Id: I0919295603432e525c2abd0da762acc8207f996c Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -62,7 +62,7 @@ QString CppSnippetProvider::displayName() const
|
|||||||
|
|
||||||
void CppSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const
|
void CppSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const
|
||||||
{
|
{
|
||||||
editor->setSyntaxHighlighter(new CppHighlighter);
|
editor->textDocument()->setSyntaxHighlighter(new CppHighlighter);
|
||||||
editor->textDocument()->setIndenter(new CppTools::CppQtStyleIndenter);
|
editor->textDocument()->setIndenter(new CppTools::CppQtStyleIndenter);
|
||||||
editor->setAutoCompleter(new CppAutoCompleter);
|
editor->setAutoCompleter(new CppAutoCompleter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ EnvironmentItemsWidget::EnvironmentItemsWidget(QWidget *parent) :
|
|||||||
QWidget(parent), d(new EnvironmentItemsWidgetPrivate)
|
QWidget(parent), d(new EnvironmentItemsWidgetPrivate)
|
||||||
{
|
{
|
||||||
d->m_editor = new TextEditor::SnippetEditorWidget(this);
|
d->m_editor = new TextEditor::SnippetEditorWidget(this);
|
||||||
d->m_editor->textDocument()->setFontSettings(TextEditor::TextEditorSettings::fontSettings());
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
layout->addWidget(d->m_editor);
|
layout->addWidget(d->m_editor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ QString QmlJSSnippetProvider::displayName() const
|
|||||||
|
|
||||||
void QmlJSSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const
|
void QmlJSSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const
|
||||||
{
|
{
|
||||||
editor->setSyntaxHighlighter(new Highlighter);
|
editor->textDocument()->setSyntaxHighlighter(new Highlighter);
|
||||||
editor->textDocument()->setIndenter(new Indenter);
|
editor->textDocument()->setIndenter(new Indenter);
|
||||||
editor->setAutoCompleter(new AutoCompleter);
|
editor->setAutoCompleter(new AutoCompleter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,6 +185,47 @@ private:
|
|||||||
QSizeF m_size;
|
QSizeF m_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TextEditExtraArea : public QWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextEditExtraArea(BaseTextEditorWidget *edit)
|
||||||
|
: QWidget(edit)
|
||||||
|
{
|
||||||
|
textEdit = edit;
|
||||||
|
setAutoFillBackground(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QSize sizeHint() const {
|
||||||
|
return QSize(textEdit->extraAreaWidth(), 0);
|
||||||
|
}
|
||||||
|
void paintEvent(QPaintEvent *event) {
|
||||||
|
textEdit->extraAreaPaintEvent(event);
|
||||||
|
}
|
||||||
|
void mousePressEvent(QMouseEvent *event) {
|
||||||
|
textEdit->extraAreaMouseEvent(event);
|
||||||
|
}
|
||||||
|
void mouseMoveEvent(QMouseEvent *event) {
|
||||||
|
textEdit->extraAreaMouseEvent(event);
|
||||||
|
}
|
||||||
|
void mouseReleaseEvent(QMouseEvent *event) {
|
||||||
|
textEdit->extraAreaMouseEvent(event);
|
||||||
|
}
|
||||||
|
void leaveEvent(QEvent *event) {
|
||||||
|
textEdit->extraAreaLeaveEvent(event);
|
||||||
|
}
|
||||||
|
void contextMenuEvent(QContextMenuEvent *event) {
|
||||||
|
textEdit->extraAreaContextMenuEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wheelEvent(QWheelEvent *event) {
|
||||||
|
QCoreApplication::sendEvent(textEdit->viewport(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
BaseTextEditorWidget *textEdit;
|
||||||
|
};
|
||||||
|
|
||||||
class BaseTextEditorPrivate
|
class BaseTextEditorPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -460,6 +501,9 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *p
|
|||||||
aggregate->add(baseTextFind);
|
aggregate->add(baseTextFind);
|
||||||
aggregate->add(q);
|
aggregate->add(q);
|
||||||
|
|
||||||
|
m_extraArea = new TextEditExtraArea(q);
|
||||||
|
m_extraArea->setMouseTracking(true);
|
||||||
|
|
||||||
m_stretchWidget = new QWidget;
|
m_stretchWidget = new QWidget;
|
||||||
m_stretchWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
m_stretchWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
m_toolBar = new QToolBar;
|
m_toolBar = new QToolBar;
|
||||||
@@ -485,47 +529,6 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *p
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class TextEditExtraArea : public QWidget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TextEditExtraArea(BaseTextEditorWidget *edit)
|
|
||||||
: QWidget(edit)
|
|
||||||
{
|
|
||||||
textEdit = edit;
|
|
||||||
setAutoFillBackground(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
QSize sizeHint() const {
|
|
||||||
return QSize(textEdit->extraAreaWidth(), 0);
|
|
||||||
}
|
|
||||||
void paintEvent(QPaintEvent *event) {
|
|
||||||
textEdit->extraAreaPaintEvent(event);
|
|
||||||
}
|
|
||||||
void mousePressEvent(QMouseEvent *event) {
|
|
||||||
textEdit->extraAreaMouseEvent(event);
|
|
||||||
}
|
|
||||||
void mouseMoveEvent(QMouseEvent *event) {
|
|
||||||
textEdit->extraAreaMouseEvent(event);
|
|
||||||
}
|
|
||||||
void mouseReleaseEvent(QMouseEvent *event) {
|
|
||||||
textEdit->extraAreaMouseEvent(event);
|
|
||||||
}
|
|
||||||
void leaveEvent(QEvent *event) {
|
|
||||||
textEdit->extraAreaLeaveEvent(event);
|
|
||||||
}
|
|
||||||
void contextMenuEvent(QContextMenuEvent *event) {
|
|
||||||
textEdit->extraAreaContextMenuEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wheelEvent(QWheelEvent *event) {
|
|
||||||
QCoreApplication::sendEvent(textEdit->viewport(), event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
BaseTextEditorWidget *textEdit;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
@@ -566,6 +569,9 @@ static const char kTextBlockMimeType[] = "application/vnd.qtcreator.blocktext";
|
|||||||
BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent)
|
BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent)
|
||||||
: QPlainTextEdit(parent)
|
: QPlainTextEdit(parent)
|
||||||
{
|
{
|
||||||
|
// "Needed", as the creation below triggers ChildEvents that are
|
||||||
|
// passed to this object's event() which uses 'd'.
|
||||||
|
d = 0;
|
||||||
d = new BaseTextEditorWidgetPrivate(this);
|
d = new BaseTextEditorWidgetPrivate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,8 +582,6 @@ void BaseTextEditorWidget::setTextDocument(const QSharedPointer<BaseTextDocument
|
|||||||
|
|
||||||
void BaseTextEditorWidgetPrivate::ctor(const QSharedPointer<BaseTextDocument> &doc)
|
void BaseTextEditorWidgetPrivate::ctor(const QSharedPointer<BaseTextDocument> &doc)
|
||||||
{
|
{
|
||||||
m_extraArea = new TextEditExtraArea(q);
|
|
||||||
m_extraArea->setMouseTracking(true);
|
|
||||||
q->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
q->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
|
|
||||||
m_overlay = new TextEditorOverlay(q);
|
m_overlay = new TextEditorOverlay(q);
|
||||||
@@ -2482,12 +2486,9 @@ void BaseTextEditorWidget::convertPosition(int pos, int *line, int *column) cons
|
|||||||
|
|
||||||
bool BaseTextEditorWidget::event(QEvent *e)
|
bool BaseTextEditorWidget::event(QEvent *e)
|
||||||
{
|
{
|
||||||
#if QT_VERSION >= 0x050000
|
// FIXME: That's far too heavy, and triggers e.g for ChildEvent
|
||||||
if (e->type() != QEvent::InputMethodQuery)
|
if (d && e->type() != QEvent::InputMethodQuery)
|
||||||
d->m_contentsChanged = false;
|
d->m_contentsChanged = false;
|
||||||
#else
|
|
||||||
d->m_contentsChanged = false;
|
|
||||||
#endif
|
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::ShortcutOverride:
|
case QEvent::ShortcutOverride:
|
||||||
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape && d->m_snippetOverlay->isVisible()) {
|
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape && d->m_snippetOverlay->isVisible()) {
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ CodeStyleEditor::CodeStyleEditor(ICodeStylePreferencesFactory *factory,
|
|||||||
CodeStyleSelectorWidget *selector = new CodeStyleSelectorWidget(factory, this);
|
CodeStyleSelectorWidget *selector = new CodeStyleSelectorWidget(factory, this);
|
||||||
selector->setCodeStyle(codeStyle);
|
selector->setCodeStyle(codeStyle);
|
||||||
m_preview = new SnippetEditorWidget(this);
|
m_preview = new SnippetEditorWidget(this);
|
||||||
m_preview->textDocument()->setFontSettings(TextEditorSettings::fontSettings());
|
|
||||||
DisplaySettings displaySettings = m_preview->displaySettings();
|
DisplaySettings displaySettings = m_preview->displaySettings();
|
||||||
displaySettings.m_visualizeWhitespace = true;
|
displaySettings.m_visualizeWhitespace = true;
|
||||||
m_preview->setDisplaySettings(displaySettings);
|
m_preview->setDisplaySettings(displaySettings);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include <texteditor/basetextdocument.h>
|
#include <texteditor/basetextdocument.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QFocusEvent>
|
#include <QFocusEvent>
|
||||||
@@ -44,28 +45,25 @@ namespace TextEditor {
|
|||||||
\ingroup Snippets
|
\ingroup Snippets
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SnippetEditor::SnippetEditor()
|
|
||||||
{
|
|
||||||
addContext(Constants::SNIPPET_EDITOR_ID);
|
|
||||||
setEditorCreator([]() { return new SnippetEditor; });
|
|
||||||
setWidgetCreator([]() { return new SnippetEditorWidget; });
|
|
||||||
setDocumentCreator([]() { return new BaseTextDocument(Constants::SNIPPET_EDITOR_ID); });
|
|
||||||
}
|
|
||||||
|
|
||||||
SnippetEditorWidget::SnippetEditorWidget(QWidget *parent)
|
SnippetEditorWidget::SnippetEditorWidget(QWidget *parent)
|
||||||
: BaseTextEditorWidget(parent)
|
: BaseTextEditorWidget(parent)
|
||||||
{
|
{
|
||||||
|
setSimpleTextDocument(TextEditor::Constants::SNIPPET_EDITOR_ID);
|
||||||
|
textDocument()->setFontSettings(TextEditorSettings::fontSettings());
|
||||||
|
|
||||||
|
// Should not be necessary in this case, but the base text editor
|
||||||
|
// implementation assumes a valid associated editor.
|
||||||
|
auto dummy = new BaseTextEditor;
|
||||||
|
dummy->addContext(Constants::SNIPPET_EDITOR_ID);
|
||||||
|
dummy->setEditorWidget(this);
|
||||||
|
|
||||||
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
|
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
|
||||||
setHighlightCurrentLine(false);
|
setHighlightCurrentLine(false);
|
||||||
setLineNumbersVisible(false);
|
setLineNumbersVisible(false);
|
||||||
setParenthesesMatchingEnabled(true);
|
setParenthesesMatchingEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetEditorWidget::setSyntaxHighlighter(TextEditor::SyntaxHighlighter *highlighter)
|
|
||||||
{
|
|
||||||
textDocument()->setSyntaxHighlighter(highlighter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SnippetEditorWidget::focusOutEvent(QFocusEvent *event)
|
void SnippetEditorWidget::focusOutEvent(QFocusEvent *event)
|
||||||
{
|
{
|
||||||
if (event->reason() != Qt::ActiveWindowFocusReason && document()->isModified()) {
|
if (event->reason() != Qt::ActiveWindowFocusReason && document()->isModified()) {
|
||||||
|
|||||||
@@ -35,20 +35,6 @@
|
|||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class SnippetEditorWidget;
|
|
||||||
class SyntaxHighlighter;
|
|
||||||
class Indenter;
|
|
||||||
|
|
||||||
// Should not be necessary in this case, but the base text editor assumes a
|
|
||||||
// valid editable interface.
|
|
||||||
class TEXTEDITOR_EXPORT SnippetEditor : public BaseTextEditor
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
SnippetEditor();
|
|
||||||
};
|
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT SnippetEditorWidget : public BaseTextEditorWidget
|
class TEXTEDITOR_EXPORT SnippetEditorWidget : public BaseTextEditorWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -56,8 +42,6 @@ class TEXTEDITOR_EXPORT SnippetEditorWidget : public BaseTextEditorWidget
|
|||||||
public:
|
public:
|
||||||
SnippetEditorWidget(QWidget *parent = 0);
|
SnippetEditorWidget(QWidget *parent = 0);
|
||||||
|
|
||||||
void setSyntaxHighlighter(SyntaxHighlighter *highlighter);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void snippetContentChanged();
|
void snippetContentChanged();
|
||||||
|
|
||||||
@@ -68,6 +52,6 @@ protected:
|
|||||||
virtual BaseTextEditor *createEditor();
|
virtual BaseTextEditor *createEditor();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // TextEditor
|
} // namespace TextEditor
|
||||||
|
|
||||||
#endif // SNIPPETEDITOR_H
|
#endif // SNIPPETEDITOR_H
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "ui_snippetssettingspage.h"
|
#include "ui_snippetssettingspage.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <utils/headerviewstretcher.h>
|
#include <utils/headerviewstretcher.h>
|
||||||
@@ -336,7 +337,6 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
|
|||||||
foreach (ISnippetProvider *provider, providers) {
|
foreach (ISnippetProvider *provider, providers) {
|
||||||
m_ui.groupCombo->addItem(provider->displayName(), provider->groupId());
|
m_ui.groupCombo->addItem(provider->displayName(), provider->groupId());
|
||||||
SnippetEditorWidget *snippetEditor = new SnippetEditorWidget(w);
|
SnippetEditorWidget *snippetEditor = new SnippetEditorWidget(w);
|
||||||
snippetEditor->textDocument()->setFontSettings(TextEditorSettings::fontSettings());
|
|
||||||
provider->decorateEditor(snippetEditor);
|
provider->decorateEditor(snippetEditor);
|
||||||
m_ui.snippetsEditorStack->insertWidget(m_ui.groupCombo->count() - 1, snippetEditor);
|
m_ui.snippetsEditorStack->insertWidget(m_ui.groupCombo->count() - 1, snippetEditor);
|
||||||
connect(snippetEditor, SIGNAL(snippetContentChanged()), this, SLOT(setSnippetContent()));
|
connect(snippetEditor, SIGNAL(snippetContentChanged()), this, SLOT(setSnippetContent()));
|
||||||
|
|||||||
Reference in New Issue
Block a user