Commit 4226538a authored by mae's avatar mae

Fix QML to UTF-8, unless changed in editor

Task-id: QTCREATORBUG-3424
parent 96475f95
......@@ -831,7 +831,7 @@ void SessionManager::setEditorCodec(Core::IEditor *editor, const QString &fileNa
if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor))
if (Project *project = projectForFile(fileName)) {
if (QTextCodec *codec = project->editorConfiguration()->defaultTextCodec())
textEditor->setTextCodec(codec);
textEditor->setTextCodec(codec, TextEditor::ITextEditor::TextCodecFromProjectSetting);
}
}
......
......@@ -659,6 +659,7 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
connect(m_cursorPositionTimer, SIGNAL(timeout()), this, SLOT(updateCursorPositionNow()));
baseTextDocument()->setSyntaxHighlighter(new Highlighter(document()));
baseTextDocument()->setCodec(QTextCodec::codecForName("UTF-8")); // qml files are defined to be utf-8
m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<ModelManagerInterface>();
m_contextPane = ExtensionSystem::PluginManager::instance()->getObject<QmlJS::IContextPane>();
......
......@@ -93,4 +93,11 @@ QString QmlJSEditorEditable::preferredModeType() const
return QString();
}
void QmlJSEditorEditable::setTextCodec(QTextCodec *codec, TextCodecReason reason)
{
if (reason != TextCodecOtherReason) // qml is defined to be utf8
return;
editor()->setTextCodec(codec);
}
} // namespace QmlJSEditor
......@@ -54,6 +54,8 @@ public:
bool isTemporary() const { return false; }
virtual bool open(const QString & fileName);
virtual QString preferredModeType() const;
void setTextCodec(QTextCodec *codec, TextCodecReason = TextCodecOtherReason);
private:
Core::Context m_context;
......
......@@ -588,7 +588,7 @@ public:
void setContextHelpId(const QString &id) { m_contextHelpId = id; }
QString contextHelpId() const; // from IContext
inline void setTextCodec(QTextCodec *codec) { e->setTextCodec(codec); }
inline void setTextCodec(QTextCodec *codec, TextCodecReason = TextCodecOtherReason) { e->setTextCodec(codec); }
inline QTextCodec *textCodec() const { return e->textCodec(); }
......
......@@ -119,7 +119,13 @@ public:
virtual void setContextHelpId(const QString &) = 0;
virtual void setTextCodec(QTextCodec *) = 0;
enum TextCodecReason {
TextCodecOtherReason,
TextCodecFromSystemSetting,
TextCodecFromProjectSetting
};
virtual void setTextCodec(QTextCodec *, TextCodecReason reason = TextCodecOtherReason) = 0;
virtual QTextCodec *textCodec() const = 0;
static QMap<QString, QString> openedTextEditorsContents();
......
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