Commit 4e7c07d9 authored by con's avatar con
Browse files

Add method for default text encoding to editor manager.

Moving the logic out of BaseTextDocument for use at other places.
parent b78c1ef6
...@@ -249,6 +249,8 @@ const char * const SETTINGS_CATEGORY_CORE_ICON = ":/core/images/category_core.pn ...@@ -249,6 +249,8 @@ const char * const SETTINGS_CATEGORY_CORE_ICON = ":/core/images/category_core.pn
const char * const SETTINGS_TR_CATEGORY_CORE = QT_TRANSLATE_NOOP("Core", "Environment"); const char * const SETTINGS_TR_CATEGORY_CORE = QT_TRANSLATE_NOOP("Core", "Environment");
const char * const SETTINGS_ID_ENVIRONMENT = "A.General"; const char * const SETTINGS_ID_ENVIRONMENT = "A.General";
const char * const SETTINGS_DEFAULTTEXTENCODING = "General/DefaultFileEncoding";
const char * const ALL_FILES_FILTER = QT_TRANSLATE_NOOP("Core", "All Files (*)"); const char * const ALL_FILES_FILTER = QT_TRANSLATE_NOOP("Core", "All Files (*)");
const int TARGET_ICON_SIZE = 32; const int TARGET_ICON_SIZE = 32;
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
#include <QtCore/QProcess> #include <QtCore/QProcess>
#include <QtCore/QSet> #include <QtCore/QSet>
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtCore/QTextCodec>
#include <QtGui/QAction> #include <QtGui/QAction>
#include <QtGui/QShortcut> #include <QtGui/QShortcut>
...@@ -1984,6 +1985,15 @@ IFile::ReloadSetting EditorManager::reloadSetting() const ...@@ -1984,6 +1985,15 @@ IFile::ReloadSetting EditorManager::reloadSetting() const
return m_d->m_reloadSetting; return m_d->m_reloadSetting;
} }
QTextCodec *EditorManager::defaultTextEncoding() const
{
QSettings *settings = Core::ICore::instance()->settings();
if (QTextCodec *candidate = QTextCodec::codecForName(
settings->value(QLatin1String(Constants::SETTINGS_DEFAULTTEXTENCODING)).toByteArray()))
return candidate;
return QTextCodec::codecForLocale();
}
Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor) Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor)
{ {
if (!editor->duplicateSupported()) if (!editor->duplicateSupported())
......
...@@ -192,6 +192,8 @@ public: ...@@ -192,6 +192,8 @@ public:
void setReloadSetting(IFile::ReloadSetting behavior); void setReloadSetting(IFile::ReloadSetting behavior);
IFile::ReloadSetting reloadSetting() const; IFile::ReloadSetting reloadSetting() const;
QTextCodec *defaultTextEncoding() const;
// Helper to display a message dialog when encountering a read-only // Helper to display a message dialog when encountering a read-only
// file, prompting the user about how to make it writeable. // file, prompting the user about how to make it writeable.
enum ReadOnlyAction { RO_Cancel, RO_OpenVCS, RO_MakeWriteable, RO_SaveAs }; enum ReadOnlyAction { RO_Cancel, RO_OpenVCS, RO_MakeWriteable, RO_SaveAs };
......
...@@ -130,7 +130,7 @@ QWidget *GeneralSettings::createPage(QWidget *parent) ...@@ -130,7 +130,7 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
QTextCodec *defaultTextCodec = QTextCodec::codecForLocale(); QTextCodec *defaultTextCodec = QTextCodec::codecForLocale();
if (QTextCodec *candidate = QTextCodec::codecForName( if (QTextCodec *candidate = QTextCodec::codecForName(
settings->value(QLatin1String("General/DefaultFileEncoding")).toByteArray())) settings->value(QLatin1String(Constants::SETTINGS_DEFAULTTEXTENCODING)).toByteArray()))
defaultTextCodec = candidate; defaultTextCodec = candidate;
QList<int> mibs = QTextCodec::availableMibs(); QList<int> mibs = QTextCodec::availableMibs();
...@@ -225,7 +225,7 @@ void GeneralSettings::apply() ...@@ -225,7 +225,7 @@ void GeneralSettings::apply()
#endif #endif
QSettings* settings = Core::ICore::instance()->settings(); QSettings* settings = Core::ICore::instance()->settings();
return settings->setValue(QLatin1String("General/DefaultFileEncoding"), return settings->setValue(QLatin1String(Constants::SETTINGS_DEFAULTTEXTENCODING),
m_codecs.at(m_page->encodingBox->currentIndex())->name()); m_codecs.at(m_page->encodingBox->currentIndex())->name());
} }
......
...@@ -132,12 +132,7 @@ BaseTextDocument::BaseTextDocument() ...@@ -132,12 +132,7 @@ BaseTextDocument::BaseTextDocument()
m_lineTerminatorMode = NativeLineTerminator; m_lineTerminatorMode = NativeLineTerminator;
m_fileIsReadOnly = false; m_fileIsReadOnly = false;
m_isBinaryData = false; m_isBinaryData = false;
m_codec = QTextCodec::codecForLocale(); m_codec = Core::EditorManager::instance()->defaultTextEncoding();
QSettings *settings = Core::ICore::instance()->settings();
if (QTextCodec *candidate = QTextCodec::codecForName(
settings->value(QLatin1String("General/DefaultFileEncoding")).toByteArray()))
m_codec = candidate;
m_hasDecodingError = false; m_hasDecodingError = false;
} }
......
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