- enhancement: auto detect "gbk" encoding when running in zh_CN locale under Linux

- enhancement: disable encoding submenu when editor closed
  - enhancement: clear infos in the status bar when editor closed
This commit is contained in:
Roy Qu 2022-03-12 17:37:53 +08:00
parent c563a32be1
commit 5789aeee45
18 changed files with 387 additions and 202 deletions

View File

@ -6,6 +6,10 @@ Red Panda C++ Version 1.0.0
- enhancement: highlight hits in the find panel's result list
- enhancement: optimize startup time
- fix: batch replace in file doesn't respect item check states in the find panel
- enhancement: option for default file encoding in "option" dialog's "editor"->"misc" tab
- enhancement: auto detect "gbk" encoding when running in zh_CN locale under Linux
- enhancement: disable encoding submenu when editor closed
- enhancement: clear infos in the status bar when editor closed
Red Panda C++ Version 0.14.5
- fix: the "gnu c++ 20" option in compiler set options is wrong

View File

@ -319,7 +319,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
QByteArray realEncoding;
QFile file(filename);
editor.lines()->saveToFile(file,ENCODING_AUTO_DETECT,
pSettings->editor().useUTF8ByDefault()? ENCODING_UTF8 : QTextCodec::codecForLocale()->name(),
pSettings->editor().defaultEncoding(),
realEncoding);
}
}

View File

@ -105,10 +105,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
loadFile();
highlighter = highlighterManager.getHighlighter(mFilename);
} else {
if (mEncodingOption == ENCODING_AUTO_DETECT)
mFileEncoding = ENCODING_ASCII;
else
mFileEncoding = mEncodingOption;
mFileEncoding = ENCODING_ASCII;
highlighter=highlighterManager.getCppHighlighter();
}
@ -226,7 +223,7 @@ void Editor::loadFile(QString filename) {
void Editor::saveFile(QString filename) {
QFile file(filename);
this->lines()->saveToFile(file,mEncodingOption,
pSettings->editor().useUTF8ByDefault()? ENCODING_UTF8 : QTextCodec::codecForLocale()->name(),
pSettings->editor().defaultEncoding(),
mFileEncoding);
emit fileSaved(filename, mInProject);
}
@ -528,6 +525,7 @@ void Editor::focusInEvent(QFocusEvent *event)
SynEdit::focusInEvent(event);
pMainWindow->updateAppTitle();
pMainWindow->updateEditorActions();
pMainWindow->updateForEncodingInfo();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
pMainWindow->updateClassBrowserForEditor(this);
@ -537,6 +535,7 @@ void Editor::focusOutEvent(QFocusEvent *event)
{
SynEdit::focusOutEvent(event);
//pMainWindow->updateClassBrowserForEditor(nullptr);
pMainWindow->updateForEncodingInfo();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
pMainWindow->functionTip()->hide();
@ -1192,6 +1191,9 @@ void Editor::closeEvent(QCloseEvent *)
mCompletionPopup->hide();
if (pMainWindow->functionTip())
pMainWindow->functionTip()->hide();
pMainWindow->updateForEncodingInfo(true);
pMainWindow->updateStatusbarForLineCol(true);
pMainWindow->updateForStatusbarModeInfo(true);
}
void Editor::showEvent(QShowEvent */*event*/)

View File

@ -371,7 +371,7 @@ Editor *EditorList::getEditorByFilename(QString filename)
QFileInfo fileInfo(filename);
QString fullname = fileInfo.absoluteFilePath();
if (fileInfo.exists() && fileInfo.isFile())
return newEditor(fullname,ENCODING_AUTO_DETECT,false,false);
return newEditor(fullname,pSettings->editor().autoDetectFileEncoding()?ENCODING_AUTO_DETECT:pSettings->editor().defaultEncoding(),false,false);
return nullptr;
}

View File

@ -291,10 +291,11 @@ int main(int argc, char *argv[])
tempFile.remove();
return -1;
}
QString language;
{
QSettings languageSetting(settingFilename,QSettings::IniFormat);
languageSetting.beginGroup(SETTING_ENVIRONMENT);
QString language = languageSetting.value("language",QLocale::system().name()).toString();
language = languageSetting.value("language",QLocale::system().name()).toString();
if (trans.load("RedPandaIDE_"+language,":/i18n/")) {
app.installTranslator(&trans);
@ -314,7 +315,7 @@ int main(int argc, char *argv[])
SystemConsts systemConsts;
pSystemConsts = &systemConsts;
pCharsetInfoManager = new CharsetInfoManager();
pCharsetInfoManager = new CharsetInfoManager(language);
auto charsetInfoManager = std::unique_ptr<CharsetInfoManager>(pCharsetInfoManager);
//load settings
pSettings = new Settings(settingFilename);

View File

@ -357,9 +357,9 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::updateForEncodingInfo() {
void MainWindow::updateForEncodingInfo(bool clear) {
Editor * editor = mEditorList->getEditor();
if (editor!=NULL) {
if (!clear && editor!=NULL) {
if (editor->encodingOption() != editor->fileEncoding()) {
mFileEncodingStatus->setText(
QString("%1(%2)")
@ -395,6 +395,7 @@ void MainWindow::updateEditorActions()
ui->actionAuto_Detect->setEnabled(false);
ui->actionEncode_in_ANSI->setEnabled(false);
ui->actionEncode_in_UTF_8->setEnabled(false);
mMenuEncoding->setEnabled(false);
ui->actionConvert_to_ANSI->setEnabled(false);
ui->actionConvert_to_UTF_8->setEnabled(false);
ui->actionCopy->setEnabled(false);
@ -439,6 +440,7 @@ void MainWindow::updateEditorActions()
ui->actionAuto_Detect->setEnabled(true);
ui->actionEncode_in_ANSI->setEnabled(true);
ui->actionEncode_in_UTF_8->setEnabled(true);
mMenuEncoding->setEnabled(true);
ui->actionConvert_to_ANSI->setEnabled(e->encodingOption()!=ENCODING_SYSTEM_DEFAULT
&& e->fileEncoding()!=ENCODING_SYSTEM_DEFAULT);
ui->actionConvert_to_UTF_8->setEnabled(e->encodingOption()!=ENCODING_UTF8 && e->fileEncoding()!=ENCODING_UTF8);
@ -1011,10 +1013,10 @@ QMenuBar *MainWindow::menuBar() const
return ui->menubar;
}
void MainWindow::updateStatusbarForLineCol()
void MainWindow::updateStatusbarForLineCol(bool clear)
{
Editor* e = mEditorList->getEditor();
if (e!=nullptr) {
if (!clear && e!=nullptr) {
int col = e->charToColumn(e->caretY(),e->caretX());
QString msg = tr("Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5")
.arg(e->caretY())
@ -1028,10 +1030,10 @@ void MainWindow::updateStatusbarForLineCol()
}
}
void MainWindow::updateForStatusbarModeInfo()
void MainWindow::updateForStatusbarModeInfo(bool clear)
{
Editor* e = mEditorList->getEditor();
if (e!=nullptr) {
if (!clear && e!=nullptr) {
QString msg;
if (e->readOnly()) {
msg = tr("Read Only");
@ -1087,7 +1089,8 @@ void MainWindow::openFile(const QString &filename, QTabWidget* page)
unit = mProject->findUnitByFilename(filename);
}
bool inProject = (mProject && unit);
QByteArray encoding = unit ? unit->encoding() : ENCODING_AUTO_DETECT;
QByteArray encoding = unit ? unit->encoding() :
(pSettings->editor().autoDetectFileEncoding()? ENCODING_AUTO_DETECT : pSettings->editor().defaultEncoding());
editor = mEditorList->newEditor(filename,encoding,
inProject, false, page);
// if (mProject) {
@ -2125,7 +2128,8 @@ void MainWindow::loadLastOpens()
unit = mProject->findUnitByFilename(editorFilename);
}
bool inProject = (mProject && unit);
QByteArray encoding = unit ? unit->encoding() : ENCODING_AUTO_DETECT;
QByteArray encoding = unit ? unit->encoding() :
(pSettings->editor().autoDetectFileEncoding()? ENCODING_AUTO_DETECT : pSettings->editor().defaultEncoding());
Editor * editor = mEditorList->newEditor(editorFilename, encoding, inProject,false,page);
// if (mProject) {
// mProject->associateEditorToUnit(editor,unit);
@ -2213,7 +2217,7 @@ void MainWindow::newEditor()
{
try {
Editor * editor=mEditorList->newEditor("",
pSettings->editor().useUTF8ByDefault()?ENCODING_UTF8:ENCODING_AUTO_DETECT,
pSettings->editor().defaultEncoding(),
false,true);
editor->activate();
updateForEncodingInfo();

View File

@ -100,9 +100,9 @@ public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
void updateForEncodingInfo();
void updateStatusbarForLineCol();
void updateForStatusbarModeInfo();
void updateForEncodingInfo(bool clear=false);
void updateStatusbarForLineCol(bool clear=false);
void updateForStatusbarModeInfo(bool clear=false);
void updateStatusbarMessage(const QString& s);
void updateEditorSettings();
void updateEditorActions();

View File

@ -77,6 +77,16 @@ QList<PCharsetInfo> CharsetInfoManager::findCharsetsByLanguageName(const QString
return result;
}
QList<PCharsetInfo> CharsetInfoManager::findCharsetByLocale(const QString &localeName)
{
QList<PCharsetInfo> result;
foreach (const PCharsetInfo& info, mCodePages) {
if (info->enabled && info->localeName == localeName)
result.append(info);
}
return result;
}
QString CharsetInfoManager::findLanguageByCharsetName(const QString &encodingName)
{
@ -88,168 +98,176 @@ QString CharsetInfoManager::findLanguageByCharsetName(const QString &encodingNam
return "Unknown";
}
CharsetInfoManager::CharsetInfoManager():QObject()
const QString &CharsetInfoManager::localeName() const
{
mCodePages.append(std::make_shared<CharsetInfo>(37,"IBM037","",false));
mCodePages.append(std::make_shared<CharsetInfo>(437,"IBM437","",false));
mCodePages.append(std::make_shared<CharsetInfo>(500,"IBM500","",false));
mCodePages.append(std::make_shared<CharsetInfo>(708,"ASMO-708","",false));
mCodePages.append(std::make_shared<CharsetInfo>(709,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(710,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(720,"DOS-720",tr("Arabic"),false));
mCodePages.append(std::make_shared<CharsetInfo>(737,"ibm737",tr("Greek"),false));
mCodePages.append(std::make_shared<CharsetInfo>(775,"ibm775",tr("Baltic"),false));
mCodePages.append(std::make_shared<CharsetInfo>(850,"ibm850",tr("Western Europe"),false));
mCodePages.append(std::make_shared<CharsetInfo>(852,"ibm852",tr("Central Europe"),false));
mCodePages.append(std::make_shared<CharsetInfo>(855,"IBM855",tr("Cyrillic"),false));
mCodePages.append(std::make_shared<CharsetInfo>(857,"ibm857",tr("Turkish"),false));
mCodePages.append(std::make_shared<CharsetInfo>(858,"ibm858",tr("Western Europe"),false));
mCodePages.append(std::make_shared<CharsetInfo>(860,"IBM860",tr("Western Europe"),false));
mCodePages.append(std::make_shared<CharsetInfo>(861,"ibm861",tr("Northern Europe"),false));
mCodePages.append(std::make_shared<CharsetInfo>(862,"DOS-862",tr("Hebrew"),false));
mCodePages.append(std::make_shared<CharsetInfo>(863,"IBM863",tr("Western Europe"),false));
mCodePages.append(std::make_shared<CharsetInfo>(864,"IBM864","",false));
mCodePages.append(std::make_shared<CharsetInfo>(865,"IBM865",tr("Northern Europe"),false));
mCodePages.append(std::make_shared<CharsetInfo>(866,"cp866",tr("Cyrillic"),false));
mCodePages.append(std::make_shared<CharsetInfo>(869,"ibm869",tr("Greek"),false));
mCodePages.append(std::make_shared<CharsetInfo>(870,"IBM870","",false));
mCodePages.append(std::make_shared<CharsetInfo>(874,"tis-620",tr("Thai"),true));
mCodePages.append(std::make_shared<CharsetInfo>(875,"cp875","",false));
mCodePages.append(std::make_shared<CharsetInfo>(932,"shift_jis",tr("Japanese"),true));
mCodePages.append(std::make_shared<CharsetInfo>(936,"gbk",tr("Chinese"),true));
mCodePages.append(std::make_shared<CharsetInfo>(949,"windows-949",tr("Korean"),true));
mCodePages.append(std::make_shared<CharsetInfo>(950,"big5",tr("Chinese"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1026,"IBM1026","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1047,"IBM01047","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1140,"IBM01140","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1141,"IBM01141","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1142,"IBM01142","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1143,"IBM01143","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1144,"IBM01144","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1145,"IBM01145","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1146,"IBM01146","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1147,"IBM01147","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1148,"IBM01148","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1149,"IBM01149","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1200,"utf-16","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1201,"unicodeFFFE","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1250,"windows-1250",tr("Central Europe"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1251,"windows-1251",tr("Cyrillic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1252,"windows-1252",tr("Western Europe"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1253,"windows-1253",tr("Greek"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1254,"windows-1254",tr("Turkish"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1255,"windows-1255",tr("Hebrew"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1256,"windows-1256",tr("Arabic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1257,"windows-1257",tr("Baltic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1258,"windows-1258",tr("Vietnamese"),true));
mCodePages.append(std::make_shared<CharsetInfo>(1361,"Johab","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10000,"macintosh",tr("Cyrillic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(10001,"x-mac-japanese","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10002,"x-mac-chinesetrad","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10003,"x-mac-korean","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10004,"x-mac-arabic","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10005,"x-mac-hebrew","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10006,"x-mac-greek","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10007,"x-mac-cyrillic","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10008,"x-mac-chinesesimp","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10010,"x-mac-romanian","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10017,"x-mac-ukrainian","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10021,"x-mac-thai","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10029,"x-mac-ce","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10079,"x-mac-icelandic","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10081,"x-mac-turkish","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10082,"x-mac-croatian","",false));
mCodePages.append(std::make_shared<CharsetInfo>(12000,"utf-32","",false));
mCodePages.append(std::make_shared<CharsetInfo>(12001,"utf-32BE","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20000,"x-Chinese_CNS","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20001,"x-cp20001","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20002,"x_Chinese-Eten","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20003,"x-cp20003","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20004,"x-cp20004","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20005,"x-cp20005","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20105,"x-IA5","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20106,"x-IA5-German","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20107,"x-IA5-Swedish","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20108,"x-IA5-Norwegian","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20127,"us-ascii","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20261,"x-cp20261","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20269,"x-cp20269","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20273,"IBM273","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20277,"IBM277","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20278,"IBM278","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20280,"IBM280","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20284,"IBM284","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20285,"IBM285","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20290,"IBM290","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20297,"IBM297","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20420,"IBM420","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20423,"IBM423","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20424,"IBM424","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20833,"x-EBCDIC-KoreanExtended","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20838,"IBM-Thai","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20866,"koi8-r",tr("Cyrillic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(20871,"IBM871","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20880,"IBM880","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20905,"IBM905","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20924,"IBM00924","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20932,"EUC-JP","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20936,"x-cp20936","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20949,"x-cp20949","",false));
mCodePages.append(std::make_shared<CharsetInfo>(21025,"cp1025","",false));
mCodePages.append(std::make_shared<CharsetInfo>(21027,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(21866,"koi8-u",tr("Cyrillic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28591,"iso-8859-1",tr("Western Europe"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28592,"iso-8859-2",tr("Eastern Europe"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28593,"iso-8859-3",tr("Turkish"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28594,"iso-8859-4",tr("Baltic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28595,"iso-8859-5",tr("Cyrillic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28596,"iso-8859-6",tr("Arabic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28597,"iso-8859-7",tr("Greek"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28598,"iso-8859-8",tr("Hebrew"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28599,"iso-8859-9",tr("Turkish"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28603,"iso-8859-13",tr("Baltic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(-1,"iso-8859-14",tr("Celtic"),true));
mCodePages.append(std::make_shared<CharsetInfo>(28605,"iso-8859-15",tr("Western Europe"),true));
mCodePages.append(std::make_shared<CharsetInfo>(29001,"x-Europa","",false));
mCodePages.append(std::make_shared<CharsetInfo>(38598,"iso-8859-8-i","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50220,"iso-2022-jp","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50221,"csISO2022JP","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50222,"iso-2022-jp","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50225,"iso-2022-kr","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50227,"x-cp50227","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50229,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50930,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50931,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50933,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50935,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50936,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50937,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50939,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(51932,"euc-jp",tr("Japanese"),true));
mCodePages.append(std::make_shared<CharsetInfo>(51936,"euc-cn","",false));
mCodePages.append(std::make_shared<CharsetInfo>(51949,"euc-kr",tr("Korean"),true));
mCodePages.append(std::make_shared<CharsetInfo>(51950,"","",false));
mCodePages.append(std::make_shared<CharsetInfo>(52936,"hz-gb-2312","",false));
mCodePages.append(std::make_shared<CharsetInfo>(54936,"gb18030",tr("Chinese"),true));
mCodePages.append(std::make_shared<CharsetInfo>(57002,"x-iscii-de","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57003,"x-iscii-be","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57004,"x-iscii-ta","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57005,"x-iscii-te","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57006,"x-iscii-as","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57007,"x-iscii-or","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57008,"x-iscii-ka","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57009,"x-iscii-ma","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57010,"x-iscii-gu","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57011,"x-iscii-pa","",false));
mCodePages.append(std::make_shared<CharsetInfo>(65000,"utf-7","",false));
mCodePages.append(std::make_shared<CharsetInfo>(65001,"utf-8","",false));
return mLocaleName;
}
CharsetInfoManager::CharsetInfoManager(const QString& localeName):
QObject(),
mLocaleName(localeName)
{
mCodePages.append(std::make_shared<CharsetInfo>(37,"IBM037","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(437,"IBM437","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(500,"IBM500","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(708,"ASMO-708","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(709,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(710,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(720,"DOS-720",tr("Arabic"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(737,"ibm737",tr("Greek"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(775,"ibm775",tr("Baltic"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(850,"ibm850",tr("Western Europe"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(852,"ibm852",tr("Central Europe"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(855,"IBM855",tr("Cyrillic"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(857,"ibm857",tr("Turkish"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(858,"ibm858",tr("Western Europe"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(860,"IBM860",tr("Western Europe"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(861,"ibm861",tr("Northern Europe"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(862,"DOS-862",tr("Hebrew"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(863,"IBM863",tr("Western Europe"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(864,"IBM864","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(865,"IBM865",tr("Northern Europe"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(866,"cp866",tr("Cyrillic"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(869,"ibm869",tr("Greek"),"",false));
mCodePages.append(std::make_shared<CharsetInfo>(870,"IBM870","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(874,"tis-620",tr("Thai"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(875,"cp875","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(932,"shift_jis",tr("Japanese"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(936,"gbk",tr("Chinese"),"zh_CN",true));
mCodePages.append(std::make_shared<CharsetInfo>(949,"windows-949",tr("Korean"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(950,"big5",tr("Chinese"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1026,"IBM1026","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1047,"IBM01047","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1140,"IBM01140","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1141,"IBM01141","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1142,"IBM01142","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1143,"IBM01143","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1144,"IBM01144","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1145,"IBM01145","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1146,"IBM01146","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1147,"IBM01147","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1148,"IBM01148","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1149,"IBM01149","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1200,"utf-16","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1201,"unicodeFFFE","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(1250,"windows-1250",tr("Central Europe"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1251,"windows-1251",tr("Cyrillic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1252,"windows-1252",tr("Western Europe"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1253,"windows-1253",tr("Greek"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1254,"windows-1254",tr("Turkish"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1255,"windows-1255",tr("Hebrew"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1256,"windows-1256",tr("Arabic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1257,"windows-1257",tr("Baltic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1258,"windows-1258",tr("Vietnamese"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(1361,"Johab","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10000,"macintosh",tr("Cyrillic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(10001,"x-mac-japanese","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10002,"x-mac-chinesetrad","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10003,"x-mac-korean","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10004,"x-mac-arabic","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10005,"x-mac-hebrew","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10006,"x-mac-greek","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10007,"x-mac-cyrillic","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10008,"x-mac-chinesesimp","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10010,"x-mac-romanian","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10017,"x-mac-ukrainian","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10021,"x-mac-thai","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10029,"x-mac-ce","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10079,"x-mac-icelandic","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10081,"x-mac-turkish","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(10082,"x-mac-croatian","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(12000,"utf-32","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(12001,"utf-32BE","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20000,"x-Chinese_CNS","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20001,"x-cp20001","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20002,"x_Chinese-Eten","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20003,"x-cp20003","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20004,"x-cp20004","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20005,"x-cp20005","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20105,"x-IA5","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20106,"x-IA5-German","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20107,"x-IA5-Swedish","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20108,"x-IA5-Norwegian","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20127,"us-ascii","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20261,"x-cp20261","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20269,"x-cp20269","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20273,"IBM273","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20277,"IBM277","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20278,"IBM278","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20280,"IBM280","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20284,"IBM284","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20285,"IBM285","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20290,"IBM290","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20297,"IBM297","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20420,"IBM420","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20423,"IBM423","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20424,"IBM424","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20833,"x-EBCDIC-KoreanExtended","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20838,"IBM-Thai","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20866,"koi8-r",tr("Cyrillic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(20871,"IBM871","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20880,"IBM880","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20905,"IBM905","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20924,"IBM00924","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20932,"EUC-JP","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20936,"x-cp20936","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(20949,"x-cp20949","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(21025,"cp1025","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(21027,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(21866,"koi8-u",tr("Cyrillic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28591,"iso-8859-1",tr("Western Europe"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28592,"iso-8859-2",tr("Eastern Europe"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28593,"iso-8859-3",tr("Turkish"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28594,"iso-8859-4",tr("Baltic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28595,"iso-8859-5",tr("Cyrillic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28596,"iso-8859-6",tr("Arabic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28597,"iso-8859-7",tr("Greek"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28598,"iso-8859-8",tr("Hebrew"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28599,"iso-8859-9",tr("Turkish"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28603,"iso-8859-13",tr("Baltic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(-1,"iso-8859-14",tr("Celtic"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(28605,"iso-8859-15",tr("Western Europe"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(29001,"x-Europa","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(38598,"iso-8859-8-i","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50220,"iso-2022-jp","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50221,"csISO2022JP","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50222,"iso-2022-jp","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50225,"iso-2022-kr","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50227,"x-cp50227","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50229,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50930,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50931,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50933,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50935,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50936,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50937,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(50939,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(51932,"euc-jp",tr("Japanese"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(51936,"euc-cn","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(51949,"euc-kr",tr("Korean"),"",true));
mCodePages.append(std::make_shared<CharsetInfo>(51950,"","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(52936,"hz-gb-2312","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(54936,"gb18030",tr("Chinese"),"zh_CN",true));
mCodePages.append(std::make_shared<CharsetInfo>(57002,"x-iscii-de","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57003,"x-iscii-be","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57004,"x-iscii-ta","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57005,"x-iscii-te","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57006,"x-iscii-as","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57007,"x-iscii-or","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57008,"x-iscii-ka","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57009,"x-iscii-ma","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57010,"x-iscii-gu","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(57011,"x-iscii-pa","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(65000,"utf-7","","",false));
mCodePages.append(std::make_shared<CharsetInfo>(65001,"utf-8","","",false));
}
CharsetInfo::CharsetInfo(int codepage, const QByteArray &name, const QString &language, bool enabled)
CharsetInfo::CharsetInfo(int codepage, const QByteArray &name, const QString &language,const QString& localeName, bool enabled)
{
this->codepage = codepage;
this->name = name;
this->language = language;
this->localeName = localeName;
this->enabled = enabled;
}

View File

@ -25,10 +25,12 @@ struct CharsetInfo{
int codepage;
QByteArray name;
QString language;
QString localeName;
bool enabled;
explicit CharsetInfo(int codepage,
const QByteArray& name,
const QString& language,
const QString& locale,
bool enabled);
};
@ -37,14 +39,18 @@ using PCharsetInfo = std::shared_ptr<CharsetInfo>;
class CharsetInfoManager: public QObject {
Q_OBJECT
public:
explicit CharsetInfoManager();
explicit CharsetInfoManager(const QString& localeName);
QByteArray getDefaultSystemEncoding();
PCharsetInfo findCharsetByCodepage(int codepage);
QStringList languageNames();
QList<PCharsetInfo> findCharsetsByLanguageName(const QString& languageName);
QList<PCharsetInfo> findCharsetByLocale(const QString& localeName);
QString findLanguageByCharsetName(const QString& encodingName);
const QString &localeName() const;
private:
QList<PCharsetInfo> mCodePages;
QString mLocaleName;
};
using PCharsetInfoManager = std::shared_ptr<CharsetInfo>;

View File

@ -517,6 +517,34 @@ void SynEditStringList::insertText(int Index, const QString &NewText)
insertStrings(Index,lines);
}
bool SynEditStringList::tryLoadFileByEncoding(QByteArray encodingName, QFile& file) {
QTextCodec* codec = QTextCodec::codecForName(encodingName);
if (!codec)
return false;
file.reset();
internalClear();
QTextCodec::ConverterState state;
while (true) {
if (file.atEnd()){
break;
}
QByteArray line = file.readLine();
if (line.endsWith("\r\n")) {
line.remove(line.length()-2,2);
} else if (line.endsWith("\r")) {
line.remove(line.length()-1,1);
} else if (line.endsWith("\n")){
line.remove(line.length()-1,1);
}
QString newLine = codec->toUnicode(line.constData(),line.length(),&state);
if (state.invalidChars>0) {
return false;
break;
}
addItem(newLine);
}
return true;
}
void SynEditStringList::loadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding)
{
QMutexLocker locker(&mMutex);
@ -587,7 +615,30 @@ void SynEditStringList::loadFromFile(const QString& filename, const QByteArray&
realEncoding = ENCODING_ASCII;
return;
}
realEncoding = ENCODING_SYSTEM_DEFAULT;
realEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
QList<PCharsetInfo> charsets = pCharsetInfoManager->findCharsetByLocale(pCharsetInfoManager->localeName());
if (!charsets.isEmpty()) {
if (tryLoadFileByEncoding(realEncoding,file)) {
emit inserted(0,mList.count());
return;
}
QSet<QByteArray> encodingSet;
for (int i=0;i<charsets.size();i++) {
encodingSet.insert(charsets[i]->name);
}
encodingSet.remove(realEncoding);
foreach (const QByteArray& encodingName,encodingSet) {
if (encodingName == ENCODING_UTF8)
continue;
if (tryLoadFileByEncoding(encodingName,file)) {
qDebug()<<encodingName;
realEncoding = encodingName;
emit inserted(0,mList.count());
return;
}
}
}
} else {
realEncoding = encoding;
}

View File

@ -131,6 +131,8 @@ protected:
void addItem(const QString& s);
void putTextStr(const QString& text);
void internalClear();
private:
bool tryLoadFileByEncoding(QByteArray encodingName, QFile& file);
private:
SynEditStringRecList mList;

View File

@ -574,16 +574,6 @@ void Settings::Editor::setMouseWheelScrollSpeed(int newMouseWheelScrollSpeed)
mMouseWheelScrollSpeed = newMouseWheelScrollSpeed;
}
bool Settings::Editor::useUTF8ByDefault() const
{
return mUseUTF8ByDefault;
}
void Settings::Editor::setUseUTF8ByDefault(bool newUseUTF8ByDefault)
{
mUseUTF8ByDefault = newUseUTF8ByDefault;
}
bool Settings::Editor::highlightMathingBraces() const
{
return mHighlightMathingBraces;
@ -624,6 +614,16 @@ void Settings::Editor::setMouseSelectionScrollSpeed(int newMouseSelectionScrollS
mMouseSelectionScrollSpeed = newMouseSelectionScrollSpeed;
}
bool Settings::Editor::autoDetectFileEncoding() const
{
return mAutoDetectFileEncoding;
}
void Settings::Editor::setAutoDetectFileEncoding(bool newAutoDetectFileEncoding)
{
mAutoDetectFileEncoding = newAutoDetectFileEncoding;
}
bool Settings::Editor::highlightCurrentWord() const
{
return mHighlightCurrentWord;
@ -1201,8 +1201,7 @@ void Settings::Editor::doSave()
saveValue("readonly_system_header",mReadOnlySytemHeader);
saveValue("auto_load_last_files",mAutoLoadLastFiles);
saveValue("default_file_cpp",mDefaultFileCpp);
saveValue("use_utf8_by_default",mUseUTF8ByDefault);
saveValue("auto_detect_file_encoding",mAutoDetectFileEncoding);
//tooltips
saveValue("enable_tooltips",mEnableTooltips);
@ -1331,11 +1330,15 @@ void Settings::Editor::doLoad()
mEnableAutolink = boolValue("enable_autolink",true);
//misc
mDefaultEncoding = value("default_encoding", ENCODING_SYSTEM_DEFAULT).toByteArray();
mReadOnlySytemHeader = boolValue("readonly_system_header",true);
mAutoLoadLastFiles = boolValue("auto_load_last_files",true);
mDefaultFileCpp = boolValue("default_file_cpp",true);
mUseUTF8ByDefault = boolValue("use_utf8_by_default",false);
bool useUTF8ByDefault = boolValue("use_utf8_by_default",false);
if (useUTF8ByDefault)
mDefaultEncoding = ENCODING_UTF8;
else
mDefaultEncoding = value("default_encoding", ENCODING_SYSTEM_DEFAULT).toByteArray();
mAutoDetectFileEncoding = boolValue("auto_detect_file_encoding",true);
//tooltips
mEnableTooltips = boolValue("enable_tooltips",true);

View File

@ -357,9 +357,6 @@ public:
int mouseWheelScrollSpeed() const;
void setMouseWheelScrollSpeed(int newMouseWheelScrollSpeed);
bool useUTF8ByDefault() const;
void setUseUTF8ByDefault(bool newUseUTF8ByDefault);
bool highlightCurrentWord() const;
void setHighlightCurrentWord(bool newHighlightCurrentWord);
@ -375,6 +372,9 @@ public:
int mouseSelectionScrollSpeed() const;
void setMouseSelectionScrollSpeed(int newMouseSelectionScrollSpeed);
bool autoDetectFileEncoding() const;
void setAutoDetectFileEncoding(bool newAutoDetectFileEncoding);
private:
//General
// indents
@ -477,10 +477,10 @@ public:
//Misc
QByteArray mDefaultEncoding;
bool mAutoDetectFileEncoding;
bool mReadOnlySytemHeader;
bool mAutoLoadLastFiles;
bool mDefaultFileCpp;
bool mUseUTF8ByDefault;
//hints tooltip
bool mEnableTooltips;

View File

@ -146,7 +146,8 @@ static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSet
if (pSet->execCharset() == ENCODING_AUTO_DETECT
|| pSet->execCharset() == ENCODING_SYSTEM_DEFAULT
|| pSet->execCharset() == ENCODING_UTF8) {
ui->cbEncoding->setCurrentText(pSet->execCharset());
int index =ui->cbEncoding->findData(pSet->execCharset());
ui->cbEncoding->setCurrentIndex(index);
ui->cbEncodingDetails->clear();
ui->cbEncodingDetails->setVisible(false);
} else {

View File

@ -17,6 +17,7 @@
#include "editormiscwidget.h"
#include "ui_editormiscwidget.h"
#include "../settings.h"
#include "../platform.h"
EditorMiscWidget::EditorMiscWidget(const QString& name, const QString& group,
QWidget *parent) :
@ -40,7 +41,27 @@ void EditorMiscWidget::doLoad()
} else {
ui->rbCFile->setChecked(true);
}
ui->chkUseUTF8ByDefault->setChecked(pSettings->editor().useUTF8ByDefault());
ui->chkAutoDetectFileEncoding->setChecked(pSettings->editor().autoDetectFileEncoding());
QByteArray defaultEncoding = pSettings->editor().defaultEncoding();
if (defaultEncoding == ENCODING_AUTO_DETECT
|| defaultEncoding == ENCODING_SYSTEM_DEFAULT
|| defaultEncoding == ENCODING_UTF8) {
int index =ui->cbEncoding->findData(defaultEncoding);
ui->cbEncoding->setCurrentIndex(index);
ui->cbEncodingDetail->clear();
ui->cbEncodingDetail->setVisible(false);
} else {
QString language = pCharsetInfoManager->findLanguageByCharsetName(defaultEncoding);
ui->cbEncoding->setCurrentText(language);
ui->cbEncodingDetail->setVisible(true);
ui->cbEncodingDetail->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(language);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetail->addItem(info->name);
}
ui->cbEncodingDetail->setCurrentText(defaultEncoding);
}
}
void EditorMiscWidget::doSave()
@ -48,6 +69,43 @@ void EditorMiscWidget::doSave()
pSettings->editor().setReadOnlySytemHeader(ui->chkReadonlySystemHeaders->isChecked());
pSettings->editor().setAutoLoadLastFiles(ui->chkLoadLastFiles->isChecked());
pSettings->editor().setDefaultFileCpp(ui->rbCppFile->isChecked());
pSettings->editor().setUseUTF8ByDefault(ui->chkUseUTF8ByDefault->isChecked());
pSettings->editor().setAutoDetectFileEncoding(ui->chkAutoDetectFileEncoding->isChecked());
if (ui->cbEncodingDetail->isVisible()) {
pSettings->editor().setDefaultEncoding(ui->cbEncodingDetail->currentData().toByteArray());
} else {
pSettings->editor().setDefaultEncoding(ui->cbEncoding->currentData().toByteArray());
}
pSettings->editor().save();
}
void EditorMiscWidget::init()
{
ui->cbEncodingDetail->setVisible(false);
ui->cbEncoding->clear();
ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT);
ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8);
foreach (const QString& langName, pCharsetInfoManager->languageNames()) {
ui->cbEncoding->addItem(langName,langName);
}
SettingsWidget::init();
}
void EditorMiscWidget::on_cbEncoding_currentTextChanged(const QString &/*arg1*/)
{
QString userData = ui->cbEncoding->currentData().toString();
if (userData == ENCODING_AUTO_DETECT
|| userData == ENCODING_SYSTEM_DEFAULT
|| userData == ENCODING_UTF8) {
ui->cbEncodingDetail->setVisible(false);
ui->cbEncodingDetail->clear();
} else {
ui->cbEncodingDetail->setVisible(true);
ui->cbEncodingDetail->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(userData);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetail->addItem(info->name);
}
}
}

View File

@ -39,6 +39,12 @@ private:
protected:
void doLoad() override;
void doSave() override;
// SettingsWidget interface
public:
void init() override;
private slots:
void on_cbEncoding_currentTextChanged(const QString &arg1);
};
#endif // EDITORMISCWIDGET_H

View File

@ -29,12 +29,40 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkUseUTF8ByDefault">
<widget class="QCheckBox" name="chkAutoDetectFileEncoding">
<property name="text">
<string>Use UTF-8 as the default encoding for new file</string>
<string>Auto detect encoding when openning files</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Default file encoding</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="cbEncoding"/>
</item>
<item>
<widget class="QComboBox" name="cbEncodingDetail"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">

View File

@ -112,7 +112,8 @@ void ProjectFilesWidget::loadUnitEncoding(PProjectUnit unit)
if (unit->encoding() == ENCODING_AUTO_DETECT
|| unit->encoding() == ENCODING_SYSTEM_DEFAULT
|| unit->encoding() == ENCODING_UTF8) {
ui->cbEncoding->setCurrentText(unit->encoding());
int index =ui->cbEncoding->findData(unit->encoding());
ui->cbEncoding->setCurrentIndex(index);
ui->cbEncodingDetail->clear();
ui->cbEncodingDetail->setVisible(false);
} else {