diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 75a120dd..8743bb0f 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -298,7 +298,7 @@ public: void setFindReplaceFolderFilter(const TCHAR *dir, const TCHAR *filters); vector addNppComponents(const TCHAR *destDir, const TCHAR *extFilterName, const TCHAR *extFilter); int getHtmlXmlEncoding(const TCHAR *fileName) const; - HACCEL getAccTable() const{ + HACCEL getAccTable() const{ return _accelerator.getAccTable(); }; bool emergency(generic_string emergencySavedDir); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index d22be5e9..d8f1872e 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -97,6 +97,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isRe } bool globbing = wcsrchr(longFileName, TCHAR('*')) || wcsrchr(longFileName, TCHAR('?')); + bool isOpenningNewEmptyFile = false; if (!isSnapshotMode) // if not backup mode, or backupfile path is invalid { @@ -116,6 +117,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isRe if (res) { isCreateFileSuccessful = true; + isOpenningNewEmptyFile = true; } else { @@ -147,7 +149,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isRe if (encoding == -1) { - encoding = getHtmlXmlEncoding(longFileName); + encoding = getHtmlXmlEncoding(longFileName); } BufferID buffer; @@ -179,10 +181,21 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isRe _isFileOpening = true; Buffer * buf = MainFileManager->getBufferByID(buffer); + // if file is read only, we set the view read only if (isReadOnly) buf->setUserReadOnly(true); + // if it's a new created file, then use new file default settings + if (isOpenningNewEmptyFile) + { + const NewDocDefaultSettings & ndds = (NppParameters::getInstance()->getNppGUI()).getNewDocDefaultSettings(); + buf->setEncoding(ndds._codepage); + buf->setFormat(ndds._format); + buf->setUnicodeMode(ndds._unicodeMode); + buf->setLangType(ndds._lang); + } + // Notify plugins that current file is about to open scnN.nmhdr.code = NPPN_FILEBEFOREOPEN; scnN.nmhdr.idFrom = (uptr_t)buffer; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index c24c599f..9a6bffb6 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -4096,7 +4096,7 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) _nppGUI._newDocDefaultSettings._format = (formatType)i; if (element->Attribute(TEXT("encoding"), &i)) - _nppGUI._newDocDefaultSettings._encoding = (UniMode)i; + _nppGUI._newDocDefaultSettings._unicodeMode = (UniMode)i; if (element->Attribute(TEXT("lang"), &i)) _nppGUI._newDocDefaultSettings._lang = (LangType)i; @@ -5152,7 +5152,7 @@ bool NppParameters::writeGUIParams() else if (!lstrcmp(nm, TEXT("NewDocDefaultSettings"))) { element->SetAttribute(TEXT("format"), _nppGUI._newDocDefaultSettings._format); - element->SetAttribute(TEXT("encoding"), _nppGUI._newDocDefaultSettings._encoding); + element->SetAttribute(TEXT("encoding"), _nppGUI._newDocDefaultSettings._unicodeMode); element->SetAttribute(TEXT("lang"), _nppGUI._newDocDefaultSettings._lang); element->SetAttribute(TEXT("codepage"), _nppGUI._newDocDefaultSettings._codepage); element->SetAttribute(TEXT("openAnsiAsUTF8"), _nppGUI._newDocDefaultSettings._openAnsiAsUtf8?TEXT("yes"):TEXT("no")); @@ -5428,7 +5428,7 @@ bool NppParameters::writeGUIParams() TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); GUIConfigElement->SetAttribute(TEXT("name"), TEXT("NewDocDefaultSettings")); GUIConfigElement->SetAttribute(TEXT("format"), _nppGUI._newDocDefaultSettings._format); - GUIConfigElement->SetAttribute(TEXT("encoding"), _nppGUI._newDocDefaultSettings._encoding); + GUIConfigElement->SetAttribute(TEXT("encoding"), _nppGUI._newDocDefaultSettings._unicodeMode); GUIConfigElement->SetAttribute(TEXT("lang"), _nppGUI._newDocDefaultSettings._lang); GUIConfigElement->SetAttribute(TEXT("codepage"), _nppGUI._newDocDefaultSettings._codepage); GUIConfigElement->SetAttribute(TEXT("openAnsiAsUTF8"), _nppGUI._newDocDefaultSettings._openAnsiAsUtf8?TEXT("yes"):TEXT("no")); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index ed677db9..bd583ba5 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -521,11 +521,11 @@ private : struct NewDocDefaultSettings { formatType _format; - UniMode _encoding; + UniMode _unicodeMode; bool _openAnsiAsUtf8; LangType _lang; int _codepage; // -1 when not using - NewDocDefaultSettings():_format(WIN_FORMAT), _encoding(uniCookie), _openAnsiAsUtf8(true), _lang(L_TEXT), _codepage(-1){}; + NewDocDefaultSettings():_format(WIN_FORMAT), _unicodeMode(uniCookie), _openAnsiAsUtf8(true), _lang(L_TEXT), _codepage(-1){}; }; struct LangMenuItem { diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index f51a3ee0..49f6444c 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -52,7 +52,7 @@ Buffer::Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus NppParameters *pNppParamInst = NppParameters::getInstance(); const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); _format = ndds._format; - _unicodeMode = ndds._encoding; + _unicodeMode = ndds._unicodeMode; _encoding = ndds._codepage; if (_encoding != -1) _unicodeMode = uniCookie; @@ -500,7 +500,7 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin // restore the encoding (ANSI based) while opening the existing file NppParameters *pNppParamInst = NppParameters::getInstance(); const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); - buf->setUnicodeMode(ndds._encoding); + buf->setUnicodeMode(ndds._unicodeMode); buf->setEncoding(-1); if (encoding == -1) diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 36be1990..d42f374f 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -1102,7 +1102,7 @@ BOOL CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) } ::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); - switch (ndds._encoding) + switch (ndds._unicodeMode) { case uni16BE : ID2Check = IDC_RADIO_UCS2BIG; @@ -1185,34 +1185,34 @@ BOOL CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) switch (wParam) { case IDC_RADIO_UCS2BIG: - ndds._encoding = uni16BE; + ndds._unicodeMode = uni16BE; ndds._openAnsiAsUtf8 = false; makeOpenAnsiAsUtf8(false); ndds._codepage = -1; ::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), false); return TRUE; case IDC_RADIO_UCS2SMALL: - ndds._encoding = uni16LE; + ndds._unicodeMode = uni16LE; ndds._openAnsiAsUtf8 = false; makeOpenAnsiAsUtf8(false); ndds._codepage = -1; ::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), false); return TRUE; case IDC_RADIO_UTF8: - ndds._encoding = uniUTF8; + ndds._unicodeMode = uniUTF8; ndds._openAnsiAsUtf8 = false; makeOpenAnsiAsUtf8(false); ndds._codepage = -1; ::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), false); return TRUE; case IDC_RADIO_UTF8SANSBOM: - ndds._encoding = uniCookie; + ndds._unicodeMode = uniCookie; makeOpenAnsiAsUtf8(true); ndds._codepage = -1; ::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), false); return TRUE; case IDC_RADIO_ANSI: - ndds._encoding = uni8Bit; + ndds._unicodeMode = uni8Bit; ndds._openAnsiAsUtf8 = false; makeOpenAnsiAsUtf8(false); ndds._codepage = -1;