forked from qt-creator/qt-creator
TextEditor: Use more direct approach for fallback IEditor construction
There are still a few places where the EditorWidget is the primary object, or several of them per "visible" IEditor (e.g. Diff). Provide a means to streamline setup there, too. Change-Id: I14cfbd68e555ebc539e707032a0e5bef563e0a36 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -83,7 +83,6 @@ public slots:
|
||||
void setDisplaySettings(const DisplaySettings &ds);
|
||||
|
||||
protected:
|
||||
BaseTextEditor *createEditor() { return new BaseTextEditor; }
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
|
||||
@@ -98,7 +97,8 @@ private:
|
||||
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
|
||||
: BaseTextEditorWidget(parent)
|
||||
{
|
||||
setSimpleTextDocument("DiffEditor.DescriptionEditor");
|
||||
setupFallBackEditor("DiffEditor.DescriptionEditor");
|
||||
|
||||
DisplaySettings settings = displaySettings();
|
||||
settings.m_textWrapping = false;
|
||||
settings.m_displayLineNumbers = false;
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class DiffEditorPlugin : public ExtensionSystem::IPlugin
|
||||
|
||||
@@ -38,8 +38,8 @@ namespace DiffEditor {
|
||||
SelectableTextEditorWidget::SelectableTextEditorWidget(QWidget *parent)
|
||||
: BaseTextEditorWidget(parent)
|
||||
{
|
||||
setSimpleTextDocument("DiffEditor.UnifiedDiffEditor");
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
setupFallBackEditor("DiffEditor.UnifiedDiffEditor");
|
||||
}
|
||||
|
||||
SelectableTextEditorWidget::~SelectableTextEditorWidget()
|
||||
|
||||
@@ -69,28 +69,10 @@
|
||||
|
||||
using namespace Core;
|
||||
using namespace TextEditor;
|
||||
using namespace Utils;
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
//////////////////////
|
||||
|
||||
class SideDiffEditor : public BaseTextEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SideDiffEditor()
|
||||
{
|
||||
connect(this, SIGNAL(tooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)),
|
||||
this, SLOT(slotTooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)));
|
||||
}
|
||||
|
||||
private slots:
|
||||
void slotTooltipRequested(TextEditor::BaseTextEditor *editor,
|
||||
const QPoint &globalPoint,
|
||||
int position);
|
||||
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
/*
|
||||
class MultiHighlighter : public SyntaxHighlighter
|
||||
@@ -168,7 +150,7 @@ protected:
|
||||
return SelectableTextEditorWidget::extraAreaWidth(markWidthPtr);
|
||||
}
|
||||
void applyFontSettings();
|
||||
BaseTextEditor *createEditor() { return new SideDiffEditor; }
|
||||
|
||||
virtual QString lineNumber(int blockNumber) const;
|
||||
virtual int lineNumberDigits() const;
|
||||
virtual bool selectionVisible(int blockNumber) const;
|
||||
@@ -209,27 +191,6 @@ private:
|
||||
// MultiHighlighter *m_highlighter;
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
|
||||
void SideDiffEditor::slotTooltipRequested(TextEditor::BaseTextEditor *editor,
|
||||
const QPoint &globalPoint,
|
||||
int position)
|
||||
{
|
||||
SideDiffEditorWidget *ew = qobject_cast<SideDiffEditorWidget *>(editorWidget());
|
||||
if (!ew)
|
||||
return;
|
||||
|
||||
QMap<int, DiffFileInfo> fi = ew->fileInfo();
|
||||
QMap<int, DiffFileInfo>::const_iterator it
|
||||
= fi.constFind(ew->document()->findBlock(position).blockNumber());
|
||||
if (it != fi.constEnd()) {
|
||||
Utils::ToolTip::show(globalPoint, Utils::TextContent(it.value().fileName),
|
||||
editor->widget());
|
||||
} else {
|
||||
Utils::ToolTip::hide();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
/*
|
||||
MultiHighlighter::MultiHighlighter(SideDiffEditorWidget *editor, QTextDocument *document)
|
||||
@@ -324,7 +285,8 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
|
||||
m_lineNumberDigits(1),
|
||||
m_inPaintEvent(false)
|
||||
{
|
||||
textDocument()->setId("DiffEditor.SideDiffEditor");
|
||||
setupFallBackEditor("DiffEditor.SideDiffEditor");
|
||||
|
||||
DisplaySettings settings = displaySettings();
|
||||
settings.m_textWrapping = false;
|
||||
settings.m_displayLineNumbers = true;
|
||||
@@ -334,6 +296,16 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
|
||||
settings.m_highlightBlocks = false;
|
||||
SelectableTextEditorWidget::setDisplaySettings(settings);
|
||||
|
||||
BaseTextEditor *editor = this->editor();
|
||||
connect(editor, &BaseTextEditor::tooltipRequested, [this](BaseTextEditor *, const QPoint &point, int position) {
|
||||
int block = textDocument()->document()->findBlock(position).blockNumber();
|
||||
auto it = m_fileInfo.constFind(block);
|
||||
if (it != m_fileInfo.constEnd())
|
||||
ToolTip::show(point, TextContent(it.value().fileName), this);
|
||||
else
|
||||
ToolTip::hide();
|
||||
});
|
||||
|
||||
// setCodeFoldingSupported(true);
|
||||
|
||||
// m_highlighter = new MultiHighlighter(this, baseTextDocument()->document());
|
||||
|
||||
@@ -81,6 +81,8 @@ UnifiedDiffEditorWidget::UnifiedDiffEditorWidget(QWidget *parent)
|
||||
, m_leftLineNumberDigits(1)
|
||||
, m_rightLineNumberDigits(1)
|
||||
{
|
||||
setupFallBackEditor(Id());
|
||||
|
||||
DisplaySettings settings = displaySettings();
|
||||
settings.m_textWrapping = false;
|
||||
settings.m_displayLineNumbers = true;
|
||||
@@ -376,11 +378,6 @@ void UnifiedDiffEditorWidget::patch(int diffFileIndex, int chunkIndex, bool reve
|
||||
m_controller->requestReload();
|
||||
}
|
||||
|
||||
TextEditor::BaseTextEditor *UnifiedDiffEditorWidget::createEditor()
|
||||
{
|
||||
return new BaseTextEditor;
|
||||
}
|
||||
|
||||
void UnifiedDiffEditorWidget::clear(const QString &message)
|
||||
{
|
||||
m_leftLineNumberDigits = 1;
|
||||
|
||||
@@ -68,7 +68,6 @@ public slots:
|
||||
protected:
|
||||
void mouseDoubleClickEvent(QMouseEvent *e);
|
||||
void contextMenuEvent(QContextMenuEvent *e);
|
||||
TextEditor::BaseTextEditor *createEditor();
|
||||
QString lineNumber(int blockNumber) const;
|
||||
int lineNumberDigits() const;
|
||||
|
||||
|
||||
@@ -240,7 +240,12 @@ class BaseTextEditorWidgetPrivate : public QObject
|
||||
{
|
||||
public:
|
||||
BaseTextEditorWidgetPrivate(BaseTextEditorWidget *parent);
|
||||
~BaseTextEditorWidgetPrivate() { delete m_toolBar; }
|
||||
~BaseTextEditorWidgetPrivate()
|
||||
{
|
||||
delete m_toolBar;
|
||||
if (m_editorIsFallBack)
|
||||
delete m_editor;
|
||||
}
|
||||
|
||||
void setupDocumentSignals();
|
||||
void updateLineSelectionColor();
|
||||
@@ -432,6 +437,7 @@ public:
|
||||
QScopedPointer<Internal::ClipboardAssistProvider> m_clipboardAssistProvider;
|
||||
|
||||
bool m_isMissingSyntaxDefinition;
|
||||
bool m_editorIsFallBack;
|
||||
|
||||
QScopedPointer<AutoCompleter> m_autoCompleter;
|
||||
};
|
||||
@@ -486,6 +492,7 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *p
|
||||
m_markDragging(false),
|
||||
m_clipboardAssistProvider(new Internal::ClipboardAssistProvider),
|
||||
m_isMissingSyntaxDefinition(false),
|
||||
m_editorIsFallBack(false),
|
||||
m_autoCompleter(new AutoCompleter)
|
||||
{
|
||||
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
|
||||
@@ -680,11 +687,6 @@ BaseTextEditorWidget::~BaseTextEditorWidget()
|
||||
d = 0;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::setSimpleTextDocument(Id id)
|
||||
{
|
||||
setTextDocument(BaseTextDocumentPtr(new BaseTextDocument(id)));
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::print(QPrinter *printer)
|
||||
{
|
||||
const bool oldFullPage = printer->fullPage();
|
||||
@@ -897,11 +899,8 @@ int BaseTextEditorWidgetPrivate::visualIndent(const QTextBlock &block) const
|
||||
BaseTextEditor *BaseTextEditorWidget::editor() const
|
||||
{
|
||||
if (!d->m_editor) {
|
||||
auto that = const_cast<BaseTextEditorWidget *>(this);
|
||||
d->m_editor = that->createEditor();
|
||||
if (!d->m_editor->m_widget)
|
||||
d->m_editor->setEditorWidget(that);
|
||||
d->m_codeAssistant.configure(d->m_editor);
|
||||
QTC_CHECK("should not happen anymore" && false);
|
||||
const_cast<BaseTextEditorWidget *>(this)->setupFallBackEditor(Id());
|
||||
}
|
||||
return d->m_editor;
|
||||
}
|
||||
@@ -6528,12 +6527,16 @@ QColor BaseTextEditorWidget::replacementPenColor(int blockNumber) const
|
||||
return QColor();
|
||||
}
|
||||
|
||||
BaseTextEditor *BaseTextEditorWidget::createEditor()
|
||||
void BaseTextEditorWidget::setupFallBackEditor(Id id)
|
||||
{
|
||||
QTC_CHECK("should not happen anymore" && false);
|
||||
auto editor = new BaseTextEditor;
|
||||
editor->setEditorWidget(this);
|
||||
return editor;
|
||||
QTC_CHECK(!d->m_editor);
|
||||
QTC_CHECK(!d->m_editorIsFallBack);
|
||||
BaseTextDocumentPtr doc(new BaseTextDocument(id));
|
||||
doc->setFontSettings(TextEditorSettings::fontSettings());
|
||||
setTextDocument(doc);
|
||||
d->m_editor = new BaseTextEditor;
|
||||
d->m_editor->setEditorWidget(this);
|
||||
d->m_editorIsFallBack = true;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
|
||||
|
||||
@@ -240,8 +240,6 @@ public:
|
||||
~BaseTextEditorWidget();
|
||||
|
||||
void setTextDocument(const BaseTextDocumentPtr &doc);
|
||||
void setSimpleTextDocument(Core::Id id); // Convenience.
|
||||
|
||||
BaseTextDocument *textDocument() const;
|
||||
BaseTextDocumentPtr textDocumentPtr() const;
|
||||
|
||||
@@ -540,7 +538,6 @@ protected:
|
||||
virtual bool replacementVisible(int blockNumber) const;
|
||||
virtual QColor replacementPenColor(int blockNumber) const;
|
||||
|
||||
virtual BaseTextEditor *createEditor();
|
||||
virtual void triggerPendingUpdates();
|
||||
virtual void applyFontSettings();
|
||||
|
||||
@@ -581,6 +578,7 @@ public:
|
||||
QString selectedText() const;
|
||||
|
||||
void setupAsPlainEditor();
|
||||
void setupFallBackEditor(Core::Id id);
|
||||
|
||||
protected:
|
||||
/*!
|
||||
|
||||
@@ -49,15 +49,7 @@ namespace TextEditor {
|
||||
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);
|
||||
|
||||
setupFallBackEditor(TextEditor::Constants::SNIPPET_EDITOR_ID);
|
||||
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
|
||||
setHighlightCurrentLine(false);
|
||||
setLineNumbersVisible(false);
|
||||
|
||||
Reference in New Issue
Block a user