forked from qt-creator/qt-creator
Core: introduce codec support check for text documents
So indiviual documents can block codecs they do not support like ui or qml files. Change-Id: I65b605762c696d38be9049f0064fd68aad0193da Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -87,6 +87,8 @@ CodecSelector::CodecSelector(QWidget *parent, Core::BaseTextDocument *doc)
|
||||
int currentIndex = -1;
|
||||
foreach (int mib, sortedMibs) {
|
||||
QTextCodec *c = QTextCodec::codecForMib(mib);
|
||||
if (!doc->supportsCodec(c))
|
||||
continue;
|
||||
if (!buf.isEmpty()) {
|
||||
|
||||
// slow, should use a feature from QTextCodec or QTextDecoder (but those are broken currently)
|
||||
|
@@ -183,7 +183,13 @@ void BaseTextDocument::setCodec(const QTextCodec *codec)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << this << (codec ? codec->name() : QByteArray());
|
||||
d->m_format.codec = codec;
|
||||
if (supportsCodec(codec))
|
||||
d->m_format.codec = codec;
|
||||
}
|
||||
|
||||
bool BaseTextDocument::supportsCodec(const QTextCodec *) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseTextDocument::switchUtf8Bom()
|
||||
|
@@ -46,6 +46,7 @@ public:
|
||||
Utils::TextFileFormat format() const;
|
||||
const QTextCodec *codec() const;
|
||||
void setCodec(const QTextCodec *);
|
||||
virtual bool supportsCodec(const QTextCodec *) const;
|
||||
void switchUtf8Bom();
|
||||
bool supportsUtf8Bom() const;
|
||||
Utils::TextFileFormat::LineTerminationMode lineTerminationMode() const;
|
||||
|
Reference in New Issue
Block a user