Commit ab9f138a authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

move default encoding setting to text editor/behavior

parent 36f2e31f
......@@ -45,7 +45,6 @@
#include <QtCore/QDir>
#include <QtCore/QLibraryInfo>
#include <QtCore/QSettings>
#include <QtCore/QTextCodec>
#include "ui_generalsettings.h"
......@@ -128,35 +127,6 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
QSettings* settings = Core::ICore::instance()->settings();
fillLanguageBox();
QTextCodec *defaultTextCodec = QTextCodec::codecForLocale();
if (QTextCodec *candidate = QTextCodec::codecForName(
settings->value(QLatin1String(Constants::SETTINGS_DEFAULTTEXTENCODING)).toByteArray()))
defaultTextCodec = candidate;
QList<int> mibs = QTextCodec::availableMibs();
qSort(mibs);
QList<int> sortedMibs;
foreach (int mib, mibs)
if (mib >= 0)
sortedMibs += mib;
foreach (int mib, mibs)
if (mib < 0)
sortedMibs += mib;
int i = 0;
foreach (int mib, sortedMibs) {
QTextCodec *codec = QTextCodec::codecForMib(mib);
m_codecs += codec;
QString name = codec->name();
foreach (const QByteArray &alias, codec->aliases()) {
name += QLatin1String(" / ");
name += QString::fromLatin1(alias);
}
m_page->encodingBox->addItem(name);
if (defaultTextCodec == codec)
m_page->encodingBox->setCurrentIndex(i);
i++;
}
m_page->colorButton->setColor(StyleHelper::requestedBaseColor());
m_page->externalEditorEdit->setText(EditorManager::instance()->externalEditor());
m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadSetting());
......@@ -223,11 +193,6 @@ void GeneralSettings::apply()
Utils::UnixUtils::setFileBrowser(Core::ICore::instance()->settings(), m_page->externalFileBrowserEdit->text());
#endif
#endif
QSettings* settings = Core::ICore::instance()->settings();
return settings->setValue(QLatin1String(Constants::SETTINGS_DEFAULTTEXTENCODING),
m_codecs.at(m_page->encodingBox->currentIndex())->name());
}
void GeneralSettings::finish()
......
......@@ -82,7 +82,6 @@ private:
Ui::GeneralSettings *m_page;
QString m_searchKeywords;
QPointer<QMessageBox> m_dialog;
QList<QTextCodec *> m_codecs;
};
} // namespace Internal
......
......@@ -104,46 +104,6 @@
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="encodingLabel">
<property name="text">
<string>Default file encoding: </string>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="encodingBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
<property name="minimumContentsLength">
<number>20</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>285</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="languageLabel">
<property name="text">
......
......@@ -35,8 +35,10 @@
#include "ui_behaviorsettingspage.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <QtCore/QSettings>
#include <QtCore/QTextCodec>
#include <QtCore/QTextStream>
using namespace TextEditor;
......@@ -105,6 +107,34 @@ QWidget *BehaviorSettingsPage::createPage(QWidget *parent)
<< ' ' << m_d->m_page.groupBoxMouse->title();
m_d->m_searchKeywords.remove(QLatin1Char('&'));
}
QSettings *settings = Core::ICore::instance()->settings();
QTextCodec *defaultTextCodec = QTextCodec::codecForLocale();
if (QTextCodec *candidate = QTextCodec::codecForName(
settings->value(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING)).toByteArray()))
defaultTextCodec = candidate;
QList<int> mibs = QTextCodec::availableMibs();
qSort(mibs);
QList<int> sortedMibs;
foreach (int mib, mibs)
if (mib >= 0)
sortedMibs += mib;
foreach (int mib, mibs)
if (mib < 0)
sortedMibs += mib;
for (int i = 0; i < sortedMibs.count(); i++) {
QTextCodec *codec = QTextCodec::codecForMib(sortedMibs.at(i));
m_codecs += codec;
QString name = codec->name();
foreach (const QByteArray &alias, codec->aliases()) {
name += QLatin1String(" / ");
name += QString::fromLatin1(alias);
}
m_d->m_page.encodingBox->addItem(name);
if (defaultTextCodec == codec)
m_d->m_page.encodingBox->setCurrentIndex(i);
}
return w;
}
......@@ -142,6 +172,11 @@ void BehaviorSettingsPage::apply()
emit behaviorSettingsChanged(newBehaviorSettings);
}
QSettings* settings = Core::ICore::instance()->settings();
settings->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING),
m_codecs.at(m_d->m_page.encodingBox->currentIndex())->name());
}
void BehaviorSettingsPage::settingsFromUI(TabSettings &tabSettings,
......
......@@ -79,6 +79,8 @@ private:
StorageSettings &storageSettings,
BehaviorSettings &behaviorSettings) const;
void settingsToUI();
QList<QTextCodec *> m_codecs;
struct BehaviorSettingsPagePrivate;
BehaviorSettingsPagePrivate *m_d;
};
......
......@@ -10,8 +10,8 @@
<height>538</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBoxTabAndIndentSettings">
<property name="title">
<string>Tabs and Indentation</string>
......@@ -305,7 +305,7 @@ Influences the indentation of continuation lines.
</layout>
</widget>
</item>
<item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBoxStorageSettings">
<property name="toolTip">
<string>Cleanup actions which are automatically performed right before the file is saved to disk.</string>
......@@ -400,7 +400,7 @@ Influences the indentation of continuation lines.
</layout>
</widget>
</item>
<item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="groupBoxMouse">
<property name="title">
<string>Mouse</string>
......@@ -423,7 +423,7 @@ Influences the indentation of continuation lines.
</layout>
</widget>
</item>
<item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -436,6 +436,68 @@ Influences the indentation of continuation lines.
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>File Encodings</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="encodingBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
<property name="minimumContentsLength">
<number>20</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>285</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="encodingLabel">
<property name="text">
<string>Default encoding: </string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>
......
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