Commit 313c97bc authored by con's avatar con
Browse files

Merge branch 'master' of scm.dev.nokia.troll.no:creator/mainline

parents e327467a 494f71c7
......@@ -39,6 +39,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/mimedatabase.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/plaintexteditor.h>
......@@ -82,6 +83,7 @@ FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditor *editor,
// Force update of open editors model.
connect(&(d->m_file), SIGNAL(saved()), this, SIGNAL(changed()));
connect(&(d->m_file), SIGNAL(changed()), this, SIGNAL(changed()));
connect(this, SIGNAL(changed()), this, SLOT(configureXmlEditor()));
}
FormWindowEditor::~FormWindowEditor()
......@@ -164,6 +166,15 @@ void FormWindowEditor::syncXmlEditor()
syncXmlEditor(contents());
}
void FormWindowEditor::configureXmlEditor() const
{
TextEditor::PlainTextEditor *editor =
qobject_cast<TextEditor::PlainTextEditor *>(d->m_textEditable.editor());
if (editor)
editor->configure(Core::ICore::instance()->mimeDatabase()->findByFile(
d->m_file.fileName()));
}
void FormWindowEditor::syncXmlEditor(const QString &contents)
{
d->m_textEditable.editor()->setPlainText(contents);
......
......@@ -102,6 +102,7 @@ public:
public slots:
void syncXmlEditor();
void configureXmlEditor() const;
private slots:
void slotOpen(const QString &fileName);
......
......@@ -8,6 +8,7 @@
<mime-type type="application/javascript">
<alias type="application/x-javascript"/>
<alias type="text/javascript"/>
<alias type="text/x-javascript"/>
<sub-class-of type="text/plain"/>
<comment>Qt Script file</comment>
<glob pattern="*.js"/>
......
......@@ -6,6 +6,7 @@
<glob pattern="*.txt"/>
</mime-type>
<mime-type type="application/xml">
<alias type="text/xml"/>
<sub-class-of type="text/plain"/>
<comment>XML document</comment>
<glob pattern="*.xml"/>
......
......@@ -78,8 +78,6 @@ QString Manager::definitionIdByName(const QString &name) const
QString Manager::definitionIdByMimeType(const QString &mimeType) const
{
Q_ASSERT(!mimeType.isEmpty());
if (m_idByMimeType.count(mimeType) <= 1) {
return m_idByMimeType.value(mimeType);
} else {
......@@ -94,6 +92,17 @@ QString Manager::definitionIdByMimeType(const QString &mimeType) const
}
}
QString Manager::definitionIdByAnyMimeType(const QStringList &mimeTypes) const
{
QString definitionId;
foreach (const QString &mimeType, mimeTypes) {
definitionId = definitionIdByMimeType(mimeType);
if (!definitionId.isEmpty())
break;
}
return definitionId;
}
const QSharedPointer<HighlightDefinition> &Manager::definition(const QString &id)
{
if (!m_definitions.contains(id)) {
......
......@@ -59,6 +59,7 @@ public:
QString definitionIdByName(const QString &name) const;
QString definitionIdByMimeType(const QString &mimeType) const;
QString definitionIdByAnyMimeType(const QStringList &mimeTypes) const;
bool isBuildingDefinition(const QString &id) const;
const QSharedPointer<HighlightDefinition> &definition(const QString &id);
......
......@@ -37,6 +37,7 @@
#include "highlighter.h"
#include "highlighterexception.h"
#include "manager.h"
#include "normalindenter.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/uniqueidmanager.h>
......@@ -65,6 +66,7 @@ PlainTextEditor::PlainTextEditor(QWidget *parent)
setRequestMarkEnabled(false);
setLineSeparatorsAllowed(true);
setMimeType(QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT));
setDisplayName(tr(Core::Constants::K_DEFAULT_TEXT_EDITOR_DISPLAY_NAME));
m_commentDefinition.clearCommentStyles();
......@@ -72,6 +74,9 @@ PlainTextEditor::PlainTextEditor(QWidget *parent)
connect(file(), SIGNAL(changed()), this, SLOT(configure()));
}
PlainTextEditor::~PlainTextEditor()
{}
QList<int> PlainTextEditorEditable::context() const
{
return m_context;
......@@ -95,32 +100,42 @@ void PlainTextEditor::unCommentSelection()
Utils::unCommentSelection(this, m_commentDefinition);
}
void PlainTextEditor::setFontSettings(const TextEditor::FontSettings & fs)
void PlainTextEditor::setFontSettings(const FontSettings & fs)
{
TextEditor::BaseTextEditor::setFontSettings(fs);
Highlighter *highlighter = static_cast<Highlighter *>(baseTextDocument()->syntaxHighlighter());
if (!highlighter)
return;
BaseTextEditor::setFontSettings(fs);
highlighter->configureFormats(fs);
highlighter->rehighlight();
if (baseTextDocument()->syntaxHighlighter()) {
Highlighter *highlighter =
static_cast<Highlighter *>(baseTextDocument()->syntaxHighlighter());
highlighter->configureFormats(fs);
highlighter->rehighlight();
}
}
void PlainTextEditor::configure()
{
const QString &mimeType = Core::ICore::instance()->mimeDatabase()->findByFile(
QFileInfo(file()->fileName())).type();
baseTextDocument()->setMimeType(mimeType);
configure(Core::ICore::instance()->mimeDatabase()->findByFile(file()->fileName()));
}
void PlainTextEditor::configure(const Core::MimeType &mimeType)
{
if (mimeType.isNull())
return;
const QString &type = mimeType.type();
setMimeType(type);
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
if (definitionId.isEmpty())
definitionId = findDefinitionId(mimeType, true);
const QString &definitionId = Manager::instance()->definitionIdByMimeType(mimeType);
if (!definitionId.isEmpty()) {
try {
const QSharedPointer<HighlightDefinition> &definition =
Manager::instance()->definition(definitionId);
Highlighter *highlighter = new Highlighter(definition->initialContext());
highlighter->configureFormats(TextEditor::TextEditorSettings::instance()->fontSettings());
highlighter->configureFormats(TextEditorSettings::instance()->fontSettings());
baseTextDocument()->setSyntaxHighlighter(highlighter);
......@@ -132,11 +147,27 @@ void PlainTextEditor::configure()
}
}
// @todo: Indentation specification through the definition files is not really being
// used because Kate recommends to configure indentation through another feature.
// Maybe we should provide something similar in Creator? For now, only normal
// indentation is supported.
m_indenter.reset(new TextEditor::NormalIndenter);
// @todo: Indentation specification through the definition files is not really being used
// because Kate recommends to configure indentation through another feature. Maybe we should
// provide something similar in Creator? For now, only normal indentation is supported.
m_indenter.reset(new NormalIndenter);
}
QString PlainTextEditor::findDefinitionId(const Core::MimeType &mimeType,
bool considerParents) const
{
QString definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.aliases());
if (definitionId.isEmpty() && considerParents) {
definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.subClassesOf());
if (definitionId.isEmpty()) {
foreach (const QString &parent, mimeType.subClassesOf()) {
const Core::MimeType &parentMimeType =
Core::ICore::instance()->mimeDatabase()->findByType(parent);
definitionId = findDefinitionId(parentMimeType, considerParents);
}
}
}
return definitionId;
}
void PlainTextEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
......
......@@ -31,16 +31,20 @@
#define PLAINTEXTEDITOR_H
#include "basetexteditor.h"
#include "normalindenter.h"
#include <utils/uncommentselection.h>
#include <QtCore/QList>
#include <QtCore/QScopedPointer>
namespace Core {
class MimeType;
}
namespace TextEditor {
class PlainTextEditor;
class Indenter;
class TEXTEDITOR_EXPORT PlainTextEditorEditable : public BaseTextEditorEditable
{
......@@ -63,10 +67,13 @@ class TEXTEDITOR_EXPORT PlainTextEditor : public BaseTextEditor
public:
PlainTextEditor(QWidget *parent);
~PlainTextEditor();
void configure(const Core::MimeType &mimeType);
public slots:
virtual void unCommentSelection();
virtual void setFontSettings(const TextEditor::FontSettings &);
virtual void setFontSettings(const FontSettings &fs);
private slots:
void configure();
......@@ -76,8 +83,10 @@ protected:
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
private:
QString findDefinitionId(const Core::MimeType &mimeType, bool considerParents) const;
Utils::CommentDefinition m_commentDefinition;
QScopedPointer<TextEditor::Indenter> m_indenter;
QScopedPointer<Indenter> m_indenter;
};
} // namespace TextEditor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment