[NEW] Apply new file default settings on created new file (opened via commandline).
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1269 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
5d0858d5c7
commit
c92f6cc91d
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue