forked from qt-creator/qt-creator
TextEditor: Fix dropping explicitly set codec to System
If we set the default encoding to the System-wide encoding we failed to distinguish them as separate encodings. Explicitly handle 'System' encoding to avoid dropping to the 'System' encoding when setting an encoding that matches this one exactly. Fixes: QTCREATORBUG-22843 Change-Id: Ib4fa50268ca6f792cdff001b9b07bb18804c4401 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -195,7 +195,7 @@ void BehaviorSettingsPage::apply()
|
|||||||
|
|
||||||
if (s) {
|
if (s) {
|
||||||
s->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING),
|
s->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING),
|
||||||
d->m_page->behaviorWidget->assignedCodec()->name());
|
d->m_page->behaviorWidget->assignedCodecName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,9 @@
|
|||||||
|
|
||||||
#include "tabsettingswidget.h"
|
#include "tabsettingswidget.h"
|
||||||
|
|
||||||
|
#include <coreplugin/coreconstants.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <texteditor/typingsettings.h>
|
#include <texteditor/typingsettings.h>
|
||||||
#include <texteditor/storagesettings.h>
|
#include <texteditor/storagesettings.h>
|
||||||
#include <texteditor/behaviorsettings.h>
|
#include <texteditor/behaviorsettings.h>
|
||||||
@@ -132,17 +135,30 @@ void BehaviorSettingsWidget::setActive(bool active)
|
|||||||
|
|
||||||
void BehaviorSettingsWidget::setAssignedCodec(QTextCodec *codec)
|
void BehaviorSettingsWidget::setAssignedCodec(QTextCodec *codec)
|
||||||
{
|
{
|
||||||
|
const QString codecName = Core::ICore::settings()->value(
|
||||||
|
Core::Constants::SETTINGS_DEFAULTTEXTENCODING).toString();
|
||||||
|
|
||||||
|
int rememberedSystemPosition = -1;
|
||||||
for (int i = 0; i < d->m_codecs.size(); ++i) {
|
for (int i = 0; i < d->m_codecs.size(); ++i) {
|
||||||
if (codec == d->m_codecs.at(i)) {
|
if (codec == d->m_codecs.at(i)) {
|
||||||
|
if (d->m_ui.encodingBox->itemText(i) == codecName) {
|
||||||
d->m_ui.encodingBox->setCurrentIndex(i);
|
d->m_ui.encodingBox->setCurrentIndex(i);
|
||||||
break;
|
return;
|
||||||
|
} else { // we've got System matching encoding - but have explicitly set the codec
|
||||||
|
rememberedSystemPosition = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (rememberedSystemPosition != -1)
|
||||||
|
d->m_ui.encodingBox->setCurrentIndex(rememberedSystemPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCodec *BehaviorSettingsWidget::assignedCodec() const
|
QByteArray BehaviorSettingsWidget::assignedCodecName() const
|
||||||
{
|
{
|
||||||
return d->m_codecs.at(d->m_ui.encodingBox->currentIndex());
|
return d->m_ui.encodingBox->currentIndex() == 0
|
||||||
|
? QByteArray("System") // we prepend System to the available codecs
|
||||||
|
: d->m_codecs.at(d->m_ui.encodingBox->currentIndex())->name();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BehaviorSettingsWidget::setCodeStyle(ICodeStylePreferences *preferences)
|
void BehaviorSettingsWidget::setCodeStyle(ICodeStylePreferences *preferences)
|
||||||
|
@@ -55,7 +55,7 @@ public:
|
|||||||
void setActive(bool active);
|
void setActive(bool active);
|
||||||
|
|
||||||
void setAssignedCodec(QTextCodec *codec);
|
void setAssignedCodec(QTextCodec *codec);
|
||||||
QTextCodec *assignedCodec() const;
|
QByteArray assignedCodecName() const;
|
||||||
|
|
||||||
void setCodeStyle(ICodeStylePreferences *preferences);
|
void setCodeStyle(ICodeStylePreferences *preferences);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user