forked from qt-creator/qt-creator
CppTools: Use editor manager's codec as fallback
...for reading not already opened files.
This partly reverts commit f7c68f6. In case TextFileFormat::detect()
fails, the user configurable editor manager's codec is used instead of
QTextCodec::codecForLocale().
Adds also a qWarning() to easier detect encoding errors.
Task-number: QTCREATORBUG-10378
Change-Id: I0fa4e6b898ed090d85414ce2a001f11b115a42d3
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -2,11 +2,15 @@
|
||||
|
||||
#include "cppmodelmanager.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/textfileformat.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QCryptographicHash>
|
||||
#include <QTextCodec>
|
||||
|
||||
/*!
|
||||
* \class CppTools::Internal::CppPreprocessor
|
||||
@@ -30,7 +34,8 @@ CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager,
|
||||
m_modelManager(modelManager),
|
||||
m_dumpFileNameWhileParsing(dumpFileNameWhileParsing),
|
||||
m_preprocess(this, &m_env),
|
||||
m_revision(0)
|
||||
m_revision(0),
|
||||
m_defaultCodec(Core::EditorManager::defaultTextCodec())
|
||||
{
|
||||
m_preprocess.setKeepComments(true);
|
||||
}
|
||||
@@ -41,7 +46,8 @@ CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager, const S
|
||||
m_modelManager(modelManager),
|
||||
m_dumpFileNameWhileParsing(dumpFileNameWhileParsing),
|
||||
m_preprocess(this, &m_env),
|
||||
m_revision(0)
|
||||
m_revision(0),
|
||||
m_defaultCodec(Core::EditorManager::defaultTextCodec())
|
||||
{
|
||||
m_preprocess.setKeepComments(true);
|
||||
}
|
||||
@@ -182,9 +188,14 @@ void CppPreprocessor::getFileContents(const QString &absoluteFilePath,
|
||||
return;
|
||||
}
|
||||
|
||||
QString errStr;
|
||||
if (contents)
|
||||
Utils::TextFileFormat::readFileUTF8(absoluteFilePath, contents, &errStr);
|
||||
if (contents) {
|
||||
QString error;
|
||||
if (Utils::TextFileFormat::readFileUTF8(absoluteFilePath, m_defaultCodec, contents, &error)
|
||||
!= Utils::TextFileFormat::ReadSuccess) {
|
||||
qWarning("Error reading file \"%s\": \"%s\".", qPrintable(absoluteFilePath),
|
||||
qPrintable(error));
|
||||
}
|
||||
}
|
||||
if (revision)
|
||||
*revision = 0;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include <QHash>
|
||||
#include <QPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextCodec;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace CppTools {
|
||||
namespace Internal {
|
||||
|
||||
@@ -75,6 +79,7 @@ protected:
|
||||
virtual void sourceNeeded(unsigned line, const QString &fileName, IncludeType type);
|
||||
|
||||
private:
|
||||
CppPreprocessor();
|
||||
void addFrameworkPath(const QString &frameworkPath);
|
||||
|
||||
CPlusPlus::Snapshot m_snapshot;
|
||||
@@ -92,6 +97,7 @@ private:
|
||||
QSet<QString> m_processed;
|
||||
unsigned m_revision;
|
||||
QHash<QString, QString> m_fileNameCache;
|
||||
QTextCodec *m_defaultCodec;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user