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;
|
int currentIndex = -1;
|
||||||
foreach (int mib, sortedMibs) {
|
foreach (int mib, sortedMibs) {
|
||||||
QTextCodec *c = QTextCodec::codecForMib(mib);
|
QTextCodec *c = QTextCodec::codecForMib(mib);
|
||||||
|
if (!doc->supportsCodec(c))
|
||||||
|
continue;
|
||||||
if (!buf.isEmpty()) {
|
if (!buf.isEmpty()) {
|
||||||
|
|
||||||
// slow, should use a feature from QTextCodec or QTextDecoder (but those are broken currently)
|
// slow, should use a feature from QTextCodec or QTextDecoder (but those are broken currently)
|
||||||
|
@@ -183,9 +183,15 @@ void BaseTextDocument::setCodec(const QTextCodec *codec)
|
|||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << Q_FUNC_INFO << this << (codec ? codec->name() : QByteArray());
|
qDebug() << Q_FUNC_INFO << this << (codec ? codec->name() : QByteArray());
|
||||||
|
if (supportsCodec(codec))
|
||||||
d->m_format.codec = codec;
|
d->m_format.codec = codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BaseTextDocument::supportsCodec(const QTextCodec *) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextDocument::switchUtf8Bom()
|
void BaseTextDocument::switchUtf8Bom()
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
|
@@ -46,6 +46,7 @@ public:
|
|||||||
Utils::TextFileFormat format() const;
|
Utils::TextFileFormat format() const;
|
||||||
const QTextCodec *codec() const;
|
const QTextCodec *codec() const;
|
||||||
void setCodec(const QTextCodec *);
|
void setCodec(const QTextCodec *);
|
||||||
|
virtual bool supportsCodec(const QTextCodec *) const;
|
||||||
void switchUtf8Bom();
|
void switchUtf8Bom();
|
||||||
bool supportsUtf8Bom() const;
|
bool supportsUtf8Bom() const;
|
||||||
Utils::TextFileFormat::LineTerminationMode lineTerminationMode() const;
|
Utils::TextFileFormat::LineTerminationMode lineTerminationMode() const;
|
||||||
|
Reference in New Issue
Block a user