From f12faf0ac85f7e37e8a825b53c33365fb91b2e4f Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sun, 16 Mar 2014 21:28:16 +0000 Subject: [PATCH] [NEW_FEATURE] (Author: Giles Payne) Auto-detect character encoding (settings part). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1202 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/installer/nativeLang/chinese.xml | 1 + PowerEditor/installer/nativeLang/english.xml | 1 + .../nativeLang/english_customizable.xml | 1 + PowerEditor/installer/nativeLang/french.xml | 1 + PowerEditor/installer/nativeLang/german.xml | 1 + PowerEditor/installer/nativeLang/spanish.xml | 1 + .../installer/nativeLang/spanish_ar.xml | 1 + PowerEditor/src/Parameters.cpp | 33 +++++++++++++++++-- PowerEditor/src/Parameters.h | 3 +- PowerEditor/src/ScitillaComponent/Buffer.cpp | 3 +- PowerEditor/src/ScitillaComponent/Buffer.h | 1 + .../src/WinControls/Preference/preference.rc | 17 ++++------ .../WinControls/Preference/preferenceDlg.cpp | 5 ++- .../WinControls/Preference/preference_rc.h | 1 + 14 files changed, 54 insertions(+), 16 deletions(-) diff --git a/PowerEditor/installer/nativeLang/chinese.xml b/PowerEditor/installer/nativeLang/chinese.xml index 69a2977dd..08fe8c829 100644 --- a/PowerEditor/installer/nativeLang/chinese.xml +++ b/PowerEditor/installer/nativeLang/chinese.xml @@ -781,6 +781,7 @@ + diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index c51e636b5..970fb50fe 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -777,6 +777,7 @@ + diff --git a/PowerEditor/installer/nativeLang/english_customizable.xml b/PowerEditor/installer/nativeLang/english_customizable.xml index 35d917e06..f08680ded 100644 --- a/PowerEditor/installer/nativeLang/english_customizable.xml +++ b/PowerEditor/installer/nativeLang/english_customizable.xml @@ -774,6 +774,7 @@ + diff --git a/PowerEditor/installer/nativeLang/french.xml b/PowerEditor/installer/nativeLang/french.xml index bb4f1e8dc..117ef65ba 100644 --- a/PowerEditor/installer/nativeLang/french.xml +++ b/PowerEditor/installer/nativeLang/french.xml @@ -801,6 +801,7 @@ + diff --git a/PowerEditor/installer/nativeLang/german.xml b/PowerEditor/installer/nativeLang/german.xml index cafd10984..011d4ab70 100644 --- a/PowerEditor/installer/nativeLang/german.xml +++ b/PowerEditor/installer/nativeLang/german.xml @@ -718,6 +718,7 @@ + diff --git a/PowerEditor/installer/nativeLang/spanish.xml b/PowerEditor/installer/nativeLang/spanish.xml index b4ce9fb7f..5c1f7cfff 100644 --- a/PowerEditor/installer/nativeLang/spanish.xml +++ b/PowerEditor/installer/nativeLang/spanish.xml @@ -746,6 +746,7 @@ + diff --git a/PowerEditor/installer/nativeLang/spanish_ar.xml b/PowerEditor/installer/nativeLang/spanish_ar.xml index e28d670b4..30f330db4 100644 --- a/PowerEditor/installer/nativeLang/spanish_ar.xml +++ b/PowerEditor/installer/nativeLang/spanish_ar.xml @@ -767,6 +767,7 @@ + diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index b670f4a9c..22ca1fb45 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -3441,7 +3441,21 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) } } } - + else if (!lstrcmp(nm, TEXT("DetectEncoding"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._detectEncoding = true; + else + _nppGUI._detectEncoding = false; + } + } + } else if (!lstrcmp(nm, TEXT("MaitainIndent"))) { TiXmlNode *n = childNode->FirstChild(); @@ -4461,6 +4475,7 @@ bool NppParameters::writeGUIParams() bool checkHistoryFilesExist = false; bool trayIconExist = false; bool rememberLastSessionExist = false; + bool detectEncoding = false; bool newDocDefaultSettingsExist = false; bool langsExcludedLstExist = false; bool printSettingExist = false; @@ -4642,7 +4657,16 @@ bool NppParameters::writeGUIParams() else childNode->InsertEndChild(TiXmlText(pStr)); } - + else if (!lstrcmp(nm, TEXT("DetectEncoding"))) + { + detectEncoding = true; + const TCHAR *pStr = _nppGUI._detectEncoding?TEXT("yes"):TEXT("no"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } else if (!lstrcmp(nm, TEXT("MaitainIndent"))) { maitainIndentExist = true; @@ -4982,7 +5006,10 @@ bool NppParameters::writeGUIParams() { insertGUIConfigBoolNode(GUIRoot, TEXT("RememberLastSession"), _nppGUI._rememberLastSession); } - + if (!detectEncoding) + { + insertGUIConfigBoolNode(GUIRoot, TEXT("DetectEncoding"), _nppGUI._detectEncoding); + } if (!newDocDefaultSettingsExist) { TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index a079766b9..50dea0073 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -704,7 +704,7 @@ struct NppGUI _tabStatus(TAB_DRAWTOPBAR | TAB_DRAWINACTIVETAB | TAB_DRAGNDROP), _splitterPos(POS_HORIZOTAL),\ _userDefineDlgStatus(UDD_DOCKED), _tabSize(8), _tabReplacedBySpace(false), _fileAutoDetection(cdEnabled), _fileAutoDetectionOriginalValue(_fileAutoDetection),\ _checkHistoryFiles(true) ,_enableSmartHilite(true), _disableSmartHiliteTmp(false), _enableTagsMatchHilite(true), _enableTagAttrsHilite(true), _enableHiliteNonHTMLZone(false),\ - _isMaximized(false), _isMinimizedToTray(false), _rememberLastSession(true), _backup(bak_none), _useDir(false), _backupDir(TEXT("")),\ + _isMaximized(false), _isMinimizedToTray(false), _rememberLastSession(true), _detectEncoding(true), _backup(bak_none), _useDir(false), _backupDir(TEXT("")),\ _doTaskList(true), _maitainIndent(true), _openSaveDir(dir_followCurrent), _styleMRU(true), _styleURL(0),\ _autocStatus(autoc_both), _autocFromLen(1), _funcParams(false), _definedSessionExt(TEXT("")),\ _doesExistUpdater(false), _caretBlinkRate(250), _caretWidth(1), _enableMultiSelection(false), _shortTitlebar(false), _themeName(TEXT("")), _isLangMenuCompact(false),\ @@ -748,6 +748,7 @@ struct NppGUI bool _isMaximized; bool _isMinimizedToTray; bool _rememberLastSession; + bool _detectEncoding; bool _doTaskList; bool _maitainIndent; bool _enableSmartHilite; diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index ac4817a5d..1b8ad2eb0 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -853,7 +853,8 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Rea } else if (encoding == -1) { - encoding = detectCodepage(data, lenFile); + if (NppParameters::getInstance()->getNppGUI()._detectEncoding) + encoding = detectCodepage(data, lenFile); } isFirstTime = false; } diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index bb257ee3e..3b11135ba 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -127,6 +127,7 @@ private: size_t _nrBufs; int detectCodepage(char* buf, size_t len); + bool loadFileData(Document doc, const TCHAR * filename, Utf8_16_Read * UnicodeConvertor, LangType language, int & encoding, formatType *pFormat = NULL); }; diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index ab0f1ff87..840f68afe 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -124,16 +124,13 @@ BEGIN CONTROL "Enable",IDC_CHECK_ENABLEDOCSWITCHER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,15,69,10 CONTROL "Enable MRU behaviour",IDC_CHECK_STYLEMRU,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,28,140,10 CONTROL "Enable",IDC_CHECK_ENABLSMARTHILITE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,45,57,142,10 - CONTROL "Match case",IDC_CHECK_SMARTHILITECASESENSITIVE, - "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,45,71,142,10 - CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE, - "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,105,150,10 - CONTROL "Auto-indent",IDC_CHECK_MAINTAININDENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,120,150,10 - CONTROL "Minimize to system tray",IDC_CHECK_MIN2SYSTRAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,135,150,10 - CONTROL "Show only filename in title bar",IDC_CHECK_SHORTTITLE, - "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,150,217,10 - CONTROL "Remember current session for next launch",IDC_CHECK_REMEMBERSESSION, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,165,217,10 + CONTROL "Match case",IDC_CHECK_SMARTHILITECASESENSITIVE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,45,71,142,10 + CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,100,150,10 + CONTROL "Autodetect character encoding",IDC_CHECK_DETECTENCODING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,115,217,10 + CONTROL "Auto-indent",IDC_CHECK_MAINTAININDENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,130,150,10 + CONTROL "Minimize to system tray",IDC_CHECK_MIN2SYSTRAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,145,150,10 + CONTROL "Show only filename in title bar",IDC_CHECK_SHORTTITLE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,160,217,10 + CONTROL "Remember current session for next launch",IDC_CHECK_REMEMBERSESSION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,175,217,10 CONTROL "Enable",IDC_CHECK_CLICKABLELINK_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,267,15,140,10 CONTROL "No underline",IDC_CHECK_CLICKABLELINK_NOUNDERLINE, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,267,28,140,10 diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index a0638c07d..febbbf072 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -829,6 +829,7 @@ BOOL CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) ::SendDlgItemMessage(_hSelf, IDC_CHECK_MIN2SYSTRAY, BM_SETCHECK, nppGUI._isMinimizedToTray, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_REMEMBERSESSION, BM_SETCHECK, nppGUI._rememberLastSession, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_DETECTENCODING, BM_SETCHECK, nppGUI._detectEncoding, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_AUTOUPDATE, BM_SETCHECK, nppGUI._autoUpdateOpt._doAutoUpdate, 0); ::ShowWindow(::GetDlgItem(_hSelf, IDC_CHECK_AUTOUPDATE), nppGUI._doesExistUpdater?SW_SHOW:SW_HIDE); @@ -961,7 +962,9 @@ BOOL CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) case IDC_CHECK_REMEMBERSESSION: nppGUI._rememberLastSession = isCheckedOrNot(wParam); return TRUE; - + case IDC_CHECK_DETECTENCODING: + nppGUI._detectEncoding = isCheckedOrNot(wParam); + return TRUE; case IDC_CHECK_ENABLEDOCSWITCHER : { nppGUI._doTaskList = !nppGUI._doTaskList; diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index 588d7d399..97e78a56e 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -158,6 +158,7 @@ #define IDC_CHECK_SHORTTITLE (IDD_PREFERENCE_SETTING_BOX + 31) #define IDC_CHECK_SMARTHILITECASESENSITIVE (IDD_PREFERENCE_SETTING_BOX + 32) #define IDC_SMARTHILITING_STATIC (IDD_PREFERENCE_SETTING_BOX + 33) + #define IDC_CHECK_DETECTENCODING (IDD_PREFERENCE_SETTING_BOX + 34) //-- FLS: xFileEditViewHistoryParameterGUI: Additional Checkbox for enabling the history for restoring the edit view per file. #define IDC_PREFERENCE_OFFSET_FLS 40 #define IDC_CHECK_REMEMBEREDITVIEWPERFILE (IDD_PREFERENCE_SETTING_BOX + IDC_PREFERENCE_OFFSET_FLS + 1)