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:
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <texteditor/basetextdocument.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFocusEvent>
|
||||
@@ -44,28 +45,25 @@ namespace TextEditor {
|
||||
\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)
|
||||
: 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);
|
||||
setHighlightCurrentLine(false);
|
||||
setLineNumbersVisible(false);
|
||||
setParenthesesMatchingEnabled(true);
|
||||
}
|
||||
|
||||
void SnippetEditorWidget::setSyntaxHighlighter(TextEditor::SyntaxHighlighter *highlighter)
|
||||
{
|
||||
textDocument()->setSyntaxHighlighter(highlighter);
|
||||
}
|
||||
|
||||
void SnippetEditorWidget::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
if (event->reason() != Qt::ActiveWindowFocusReason && document()->isModified()) {
|
||||
|
||||
@@ -35,20 +35,6 @@
|
||||
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -56,8 +42,6 @@ class TEXTEDITOR_EXPORT SnippetEditorWidget : public BaseTextEditorWidget
|
||||
public:
|
||||
SnippetEditorWidget(QWidget *parent = 0);
|
||||
|
||||
void setSyntaxHighlighter(SyntaxHighlighter *highlighter);
|
||||
|
||||
signals:
|
||||
void snippetContentChanged();
|
||||
|
||||
@@ -68,6 +52,6 @@ protected:
|
||||
virtual BaseTextEditor *createEditor();
|
||||
};
|
||||
|
||||
} // TextEditor
|
||||
} // namespace TextEditor
|
||||
|
||||
#endif // SNIPPETEDITOR_H
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "ui_snippetssettingspage.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/headerviewstretcher.h>
|
||||
@@ -336,7 +337,6 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
|
||||
foreach (ISnippetProvider *provider, providers) {
|
||||
m_ui.groupCombo->addItem(provider->displayName(), provider->groupId());
|
||||
SnippetEditorWidget *snippetEditor = new SnippetEditorWidget(w);
|
||||
snippetEditor->textDocument()->setFontSettings(TextEditorSettings::fontSettings());
|
||||
provider->decorateEditor(snippetEditor);
|
||||
m_ui.snippetsEditorStack->insertWidget(m_ui.groupCombo->count() - 1, snippetEditor);
|
||||
connect(snippetEditor, SIGNAL(snippetContentChanged()), this, SLOT(setSnippetContent()));
|
||||
|
||||
Reference in New Issue
Block a user