forked from qt-creator/qt-creator
TextEditor: Move highlighting support from Plain to Base
Goal is to squash the 'Plain' layer. Change-Id: I2513de57fbbc09e9d0d9d4f1eb008dced76038f0 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
|
||||
#include <texteditor/basetextdocument.h>
|
||||
#include <texteditor/plaintexteditor.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -257,8 +257,8 @@ void DisassemblerAgentPrivate::configureMimeType()
|
||||
MimeType mtype = MimeDatabase::findByType(mimeType);
|
||||
if (mtype) {
|
||||
foreach (IEditor *editor, DocumentModel::editorsForDocument(document))
|
||||
if (PlainTextEditorWidget *widget = qobject_cast<PlainTextEditorWidget *>(editor->widget()))
|
||||
widget->configure(mtype);
|
||||
if (BaseTextEditorWidget *widget = qobject_cast<BaseTextEditorWidget *>(editor->widget()))
|
||||
widget->configureMimeType(mtype);
|
||||
} else {
|
||||
qWarning("Assembler mimetype '%s' not found.", qPrintable(mimeType));
|
||||
}
|
||||
|
||||
@@ -47,9 +47,16 @@
|
||||
#include "texteditoroverlay.h"
|
||||
#include "circularclipboard.h"
|
||||
#include "circularclipboardassist.h"
|
||||
#include "highlighterutils.h"
|
||||
#include <texteditor/codeassist/codeassistant.h>
|
||||
#include <texteditor/codeassist/defaultassistinterface.h>
|
||||
#include <texteditor/generichighlighter/context.h>
|
||||
#include <texteditor/generichighlighter/highlightdefinition.h>
|
||||
#include <texteditor/generichighlighter/highlighter.h>
|
||||
#include <texteditor/generichighlighter/highlightersettings.h>
|
||||
#include <texteditor/generichighlighter/manager.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <aggregation/aggregate.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
@@ -183,7 +190,6 @@ class BaseTextEditorWidgetPrivate
|
||||
|
||||
public:
|
||||
BaseTextEditorWidgetPrivate(BaseTextEditorWidget *parent);
|
||||
~BaseTextEditorWidgetPrivate();
|
||||
|
||||
void setupDocumentSignals();
|
||||
void updateLineSelectionColor();
|
||||
@@ -343,6 +349,9 @@ public:
|
||||
QScopedPointer<AutoCompleter> m_autoCompleter;
|
||||
|
||||
QScopedPointer<Internal::ClipboardAssistProvider> m_clipboardAssistProvider;
|
||||
|
||||
bool m_isMissingSyntaxDefinition;
|
||||
Utils::CommentDefinition m_commentDefinition;
|
||||
};
|
||||
|
||||
class TextEditExtraArea : public QWidget
|
||||
@@ -506,6 +515,8 @@ void BaseTextEditorWidgetPrivate::ctor(const QSharedPointer<BaseTextDocument> &d
|
||||
QObject::connect(&m_delayedUpdateTimer, SIGNAL(timeout()), q->viewport(), SLOT(update()));
|
||||
|
||||
m_moveLineUndoHack = false;
|
||||
|
||||
m_commentDefinition.clearCommentStyles();
|
||||
}
|
||||
|
||||
BaseTextEditorWidget::~BaseTextEditorWidget()
|
||||
@@ -2696,11 +2707,8 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate(BaseTextEditorWidget *p
|
||||
m_blockCount(0),
|
||||
m_markDragging(false),
|
||||
m_autoCompleter(new AutoCompleter),
|
||||
m_clipboardAssistProvider(new Internal::ClipboardAssistProvider)
|
||||
{
|
||||
}
|
||||
|
||||
BaseTextEditorWidgetPrivate::~BaseTextEditorWidgetPrivate()
|
||||
m_clipboardAssistProvider(new Internal::ClipboardAssistProvider),
|
||||
m_isMissingSyntaxDefinition(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -5859,6 +5867,7 @@ void BaseTextEditorWidget::rewrapParagraph()
|
||||
|
||||
void BaseTextEditorWidget::unCommentSelection()
|
||||
{
|
||||
Utils::unCommentSelection(this, d->m_commentDefinition);
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::showEvent(QShowEvent* e)
|
||||
@@ -6924,6 +6933,54 @@ BaseTextEditorWidget *BaseTextEditor::editorWidget() const
|
||||
return d->m_editorWidget;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::configureMimeType(const MimeType &mimeType)
|
||||
{
|
||||
Highlighter *highlighter = new Highlighter();
|
||||
highlighter->setTabSettings(baseTextDocument()->tabSettings());
|
||||
baseTextDocument()->setSyntaxHighlighter(highlighter);
|
||||
|
||||
setCodeFoldingSupported(false);
|
||||
|
||||
if (!mimeType.isNull()) {
|
||||
d->m_isMissingSyntaxDefinition = true;
|
||||
|
||||
setMimeTypeForHighlighter(highlighter, mimeType);
|
||||
const QString &type = mimeType.type();
|
||||
baseTextDocument()->setMimeType(type);
|
||||
|
||||
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
|
||||
if (definitionId.isEmpty())
|
||||
definitionId = findDefinitionId(mimeType, true);
|
||||
|
||||
if (!definitionId.isEmpty()) {
|
||||
d->m_isMissingSyntaxDefinition = false;
|
||||
const QSharedPointer<HighlightDefinition> &definition =
|
||||
Manager::instance()->definition(definitionId);
|
||||
if (!definition.isNull() && definition->isValid()) {
|
||||
d->m_commentDefinition.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces();
|
||||
d->m_commentDefinition.singleLine = definition->singleLineComment();
|
||||
d->m_commentDefinition.multiLineStart = definition->multiLineCommentStart();
|
||||
d->m_commentDefinition.multiLineEnd = definition->multiLineCommentEnd();
|
||||
|
||||
setCodeFoldingSupported(true);
|
||||
}
|
||||
} else {
|
||||
const QString &fileName = baseTextDocument()->filePath();
|
||||
if (TextEditorSettings::highlighterSettings().isIgnoredFilePattern(fileName))
|
||||
d->m_isMissingSyntaxDefinition = false;
|
||||
}
|
||||
}
|
||||
|
||||
baseTextDocument()->setFontSettings(TextEditorSettings::fontSettings());
|
||||
|
||||
emit configured(editor());
|
||||
}
|
||||
|
||||
bool BaseTextEditorWidget::isMissingSyntaxDefinition() const
|
||||
{
|
||||
return d->m_isMissingSyntaxDefinition;
|
||||
}
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
#include "basetexteditor.moc"
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include <coreplugin/find/ifindsupport.h>
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
#include <QSharedPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QToolBar;
|
||||
@@ -52,6 +51,8 @@ class QRect;
|
||||
class QTextBlock;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core { class MimeType; }
|
||||
|
||||
namespace Utils {
|
||||
class CommentDefinition;
|
||||
class LineColumnLabel;
|
||||
@@ -362,6 +363,7 @@ public:
|
||||
|
||||
// the blocks list must be sorted
|
||||
void setIfdefedOutBlocks(const QList<BlockRange> &blocks);
|
||||
bool isMissingSyntaxDefinition() const;
|
||||
|
||||
public slots:
|
||||
virtual void copy();
|
||||
@@ -461,6 +463,7 @@ public slots:
|
||||
|
||||
/// Abort code assistant if it is running.
|
||||
void abortAssist();
|
||||
void configureMimeType(const Core::MimeType &mimeType);
|
||||
|
||||
signals:
|
||||
void assistFinished();
|
||||
@@ -471,6 +474,8 @@ signals:
|
||||
void requestZoomReset();
|
||||
void requestBlockUpdate(const QTextBlock &);
|
||||
|
||||
void configured(Core::IEditor *editor);
|
||||
|
||||
protected:
|
||||
bool event(QEvent *e);
|
||||
void inputMethodEvent(QInputMethodEvent *e);
|
||||
|
||||
@@ -43,8 +43,6 @@
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
using namespace Core;
|
||||
using namespace TextEditor::Internal;
|
||||
|
||||
@@ -90,15 +88,12 @@ PlainTextEditorWidget::PlainTextEditorWidget(PlainTextEditorWidget *other)
|
||||
|
||||
void PlainTextEditorWidget::ctor()
|
||||
{
|
||||
m_isMissingSyntaxDefinition = false;
|
||||
setRevisionsVisible(true);
|
||||
setMarksVisible(true);
|
||||
setLineSeparatorsAllowed(true);
|
||||
|
||||
baseTextDocument()->setMimeType(QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT));
|
||||
|
||||
m_commentDefinition.clearCommentStyles();
|
||||
|
||||
connect(baseTextDocument(), SIGNAL(filePathChanged(QString,QString)),
|
||||
this, SLOT(configure()));
|
||||
connect(Manager::instance(), SIGNAL(mimeTypesRegistered()), this, SLOT(configure()));
|
||||
@@ -112,70 +107,17 @@ IEditor *PlainTextEditor::duplicate()
|
||||
return newWidget->editor();
|
||||
}
|
||||
|
||||
void PlainTextEditorWidget::unCommentSelection()
|
||||
{
|
||||
Utils::unCommentSelection(this, m_commentDefinition);
|
||||
}
|
||||
|
||||
void PlainTextEditorWidget::configure()
|
||||
{
|
||||
MimeType mimeType;
|
||||
if (baseTextDocument())
|
||||
mimeType = MimeDatabase::findByFile(baseTextDocument()->filePath());
|
||||
configure(mimeType);
|
||||
configureMimeType(mimeType);
|
||||
}
|
||||
|
||||
void PlainTextEditorWidget::configure(const QString &mimeType)
|
||||
{
|
||||
configure(MimeDatabase::findByType(mimeType));
|
||||
}
|
||||
|
||||
void PlainTextEditorWidget::configure(const MimeType &mimeType)
|
||||
{
|
||||
Highlighter *highlighter = new Highlighter();
|
||||
highlighter->setTabSettings(baseTextDocument()->tabSettings());
|
||||
baseTextDocument()->setSyntaxHighlighter(highlighter);
|
||||
|
||||
setCodeFoldingSupported(false);
|
||||
|
||||
if (!mimeType.isNull()) {
|
||||
m_isMissingSyntaxDefinition = true;
|
||||
|
||||
setMimeTypeForHighlighter(highlighter, mimeType);
|
||||
const QString &type = mimeType.type();
|
||||
baseTextDocument()->setMimeType(type);
|
||||
|
||||
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
|
||||
if (definitionId.isEmpty())
|
||||
definitionId = findDefinitionId(mimeType, true);
|
||||
|
||||
if (!definitionId.isEmpty()) {
|
||||
m_isMissingSyntaxDefinition = false;
|
||||
const QSharedPointer<HighlightDefinition> &definition =
|
||||
Manager::instance()->definition(definitionId);
|
||||
if (!definition.isNull() && definition->isValid()) {
|
||||
m_commentDefinition.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces();
|
||||
m_commentDefinition.singleLine = definition->singleLineComment();
|
||||
m_commentDefinition.multiLineStart = definition->multiLineCommentStart();
|
||||
m_commentDefinition.multiLineEnd = definition->multiLineCommentEnd();
|
||||
|
||||
setCodeFoldingSupported(true);
|
||||
}
|
||||
} else {
|
||||
const QString &fileName = baseTextDocument()->filePath();
|
||||
if (TextEditorSettings::highlighterSettings().isIgnoredFilePattern(fileName))
|
||||
m_isMissingSyntaxDefinition = false;
|
||||
}
|
||||
}
|
||||
|
||||
baseTextDocument()->setFontSettings(TextEditorSettings::fontSettings());
|
||||
|
||||
emit configured(editor());
|
||||
}
|
||||
|
||||
bool PlainTextEditorWidget::isMissingSyntaxDefinition() const
|
||||
{
|
||||
return m_isMissingSyntaxDefinition;
|
||||
configureMimeType(MimeDatabase::findByType(mimeType));
|
||||
}
|
||||
|
||||
void PlainTextEditorWidget::acceptMissingSyntaxDefinitionInfo()
|
||||
|
||||
@@ -32,14 +32,9 @@
|
||||
|
||||
#include "basetexteditor.h"
|
||||
|
||||
#include <utils/uncommentselection.h>
|
||||
|
||||
namespace Core { class MimeType; }
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
class PlainTextEditorWidget;
|
||||
class Indenter;
|
||||
|
||||
class TEXTEDITOR_EXPORT PlainTextEditor : public BaseTextEditor
|
||||
{
|
||||
@@ -69,19 +64,11 @@ public:
|
||||
PlainTextEditorWidget(PlainTextEditorWidget *other);
|
||||
|
||||
void configure(const QString& mimeType);
|
||||
void configure(const Core::MimeType &mimeType);
|
||||
bool isMissingSyntaxDefinition() const;
|
||||
|
||||
public slots:
|
||||
virtual void unCommentSelection();
|
||||
|
||||
private slots:
|
||||
void configure();
|
||||
void acceptMissingSyntaxDefinitionInfo();
|
||||
|
||||
signals:
|
||||
void configured(Core::IEditor *editor);
|
||||
|
||||
protected:
|
||||
virtual BaseTextEditor *createEditor() { return new PlainTextEditor(this); }
|
||||
|
||||
@@ -89,9 +76,6 @@ private:
|
||||
PlainTextEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
|
||||
PlainTextEditorWidget(BaseTextDocument *, QWidget *); //avoid stupidity
|
||||
void ctor();
|
||||
|
||||
bool m_isMissingSyntaxDefinition;
|
||||
Utils::CommentDefinition m_commentDefinition;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
Reference in New Issue
Block a user