[NEW_FEATURE] All the supported encoding charsets can be set as default in "New Document Settings".

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@699 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2010-11-13 11:15:06 +00:00
parent a7f127dca0
commit 8b346dc583
9 changed files with 170 additions and 34 deletions

View File

@ -70,7 +70,6 @@ EncodingUnit encodings[] = {
{10007, "x-mac-cyrillic xmaccyrillic"}, //IDM_FORMAT_MAC_CYRILLIC
{21866, "koi8_u"}, //IDM_FORMAT_KOI8U_CYRILLIC
{20866, "koi8_r csKOI8R"} //IDM_FORMAT_KOI8R_CYRILLIC
};
EncodingMapper * EncodingMapper::_pSelf = new EncodingMapper;

View File

@ -204,11 +204,7 @@ public:
//bool doDelete(const TCHAR *fileName) const {return ::DeleteFile(fileName) != 0;};
void fileOpen();
void fileNew() {
BufferID newBufID = MainFileManager->newEmptyDocument();
loadBufferIntoView(newBufID, currentView(), true); //true, because we want multiple new files if possible
activateBuffer(newBufID, currentView());
};
void fileNew();
bool fileReload() {
BufferID buf = _pEditView->getCurrentBufferID();

View File

@ -478,7 +478,8 @@ BEGIN
POPUP "Korean"
BEGIN
MENUITEM "EUC-KR", IDM_FORMAT_EUC_KR
MENUITEM "Windows 949", IDM_FORMAT_KOREAN_WIN
MENUITEM "EUC-KR", IDM_FORMAT_EUC_KR
END
POPUP "North European"

View File

@ -18,6 +18,7 @@
#include "precompiledHeaders.h"
#include "Notepad_plus_Window.h"
#include "FileDialog.h"
#include "EncodingMapper.h"
@ -837,7 +838,26 @@ void Notepad_plus::fileOpen()
}
}
void Notepad_plus::fileNew()
{
BufferID newBufID = MainFileManager->newEmptyDocument();
loadBufferIntoView(newBufID, currentView(), true); //true, because we want multiple new files if possible
activateBuffer(newBufID, currentView());
NppParameters *pNppParam = NppParameters::getInstance();
NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI();
NewDocDefaultSettings & ndds = (NewDocDefaultSettings &)nppGUI.getNewDocDefaultSettings();
if (ndds._codepage != -1)
{
EncodingMapper *em = EncodingMapper::getInstance();
int cmdID = em->getIndexFromEncoding(ndds._codepage);
if (cmdID != -1)
{
cmdID += IDM_FORMAT_ENCODE;
::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, cmdID, 0);
}
}
}
bool Notepad_plus::isFileSession(const TCHAR * filename) {
// if file2open matches the ext of user defined session file ext, then it'll be opened as a session

View File

@ -3269,6 +3269,9 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
if (element->Attribute(TEXT("lang"), &i))
_nppGUI._newDocDefaultSettings._lang = (LangType)i;
if (element->Attribute(TEXT("codepage"), &i))
_nppGUI._newDocDefaultSettings._codepage = (LangType)i;
val = element->Attribute(TEXT("openAnsiAsUTF8"));
if (val)
_nppGUI._newDocDefaultSettings._openAnsiAsUtf8 = (lstrcmp(val, TEXT("yes")) == 0);
@ -4163,6 +4166,7 @@ bool NppParameters::writeGUIParams()
element->SetAttribute(TEXT("format"), _nppGUI._newDocDefaultSettings._format);
element->SetAttribute(TEXT("encoding"), _nppGUI._newDocDefaultSettings._encoding);
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"));
newDocDefaultSettingsExist = true;
}
@ -4354,6 +4358,7 @@ bool NppParameters::writeGUIParams()
GUIConfigElement->SetAttribute(TEXT("format"), _nppGUI._newDocDefaultSettings._format);
GUIConfigElement->SetAttribute(TEXT("encoding"), _nppGUI._newDocDefaultSettings._encoding);
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"));
}

View File

@ -474,7 +474,8 @@ struct NewDocDefaultSettings
UniMode _encoding;
bool _openAnsiAsUtf8;
LangType _lang;
NewDocDefaultSettings():_format(WIN_FORMAT), _encoding(uni8Bit), _openAnsiAsUtf8(false), _lang(L_TEXT){};
int _codepage; // -1 when not using
NewDocDefaultSettings():_format(WIN_FORMAT), _encoding(uni8Bit), _openAnsiAsUtf8(false), _lang(L_TEXT), _codepage(-1){};
};
struct LangMenuItem {

View File

@ -141,29 +141,34 @@ IDD_PREFERENCE_NEWDOCSETTING_BOX DIALOGEX 0, 0, 455, 185
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
GROUPBOX "Format",IDC_FORMAT_GB_STATIC,250,12,110,55,BS_CENTER
CONTROL "Windows",IDC_RADIO_F_WIN,"Button",BS_AUTORADIOBUTTON | WS_GROUP,258,25,48,10
CONTROL "Unix",IDC_RADIO_F_UNIX,"Button",BS_AUTORADIOBUTTON,258,38,56,10
CONTROL "Mac",IDC_RADIO_F_MAC,"Button",BS_AUTORADIOBUTTON,258,52,60,10
GROUPBOX "Encoding",IDC_ENCODING_STATIC,82,11,144,91,BS_CENTER
CONTROL "ANSI",IDC_RADIO_ANSI,"Button",BS_AUTORADIOBUTTON | WS_GROUP,89,20,80,10
CONTROL "UTF-8 without BOM",IDC_RADIO_UTF8SANSBOM,"Button",BS_AUTORADIOBUTTON,89,34,128,10
CONTROL "UTF-8",IDC_RADIO_UTF8,"Button",BS_AUTORADIOBUTTON,89,59,62,10
CONTROL "UCS-2 Big Endian",IDC_RADIO_UCS2BIG,"Button",BS_AUTORADIOBUTTON,89,73,103,10
CONTROL "UCS-2 Little Endian",IDC_RADIO_UCS2SMALL,"Button",BS_AUTORADIOBUTTON,89,87,102,10
RTEXT "Default language :",IDC_DEFAULTLANG_STATIC,228,83,77,8
COMBOBOX IDC_COMBO_DEFAULTLANG,310,81,60,140,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
GROUPBOX "New Document",IDC_NEWDOCUMENT_GR_STATIC,72,2,304,108,BS_CENTER
GROUPBOX "Default Directory (Open/Save)",IDC_OPENSAVEDIR_GR_STATIC,72,117,304,61,BS_CENTER
GROUPBOX "New Document",IDC_NEWDOCUMENT_GR_STATIC,7,2,195,178,BS_CENTER
GROUPBOX "Format",IDC_FORMAT_GB_STATIC,17,12,176,25,BS_CENTER
CONTROL "Windows",IDC_RADIO_F_WIN,"Button",BS_AUTORADIOBUTTON | WS_GROUP,27,23,50,10
CONTROL "Mac",IDC_RADIO_F_MAC,"Button",BS_AUTORADIOBUTTON,80,23,50,10
CONTROL "Unix",IDC_RADIO_F_UNIX,"Button",BS_AUTORADIOBUTTON,135,23,50,10
GROUPBOX "Encoding",IDC_ENCODING_STATIC,17,44,175,110,BS_CENTER
CONTROL "ANSI",IDC_RADIO_ANSI,"Button",BS_AUTORADIOBUTTON | WS_GROUP,27,53,80,10
CONTROL "UTF-8 without BOM",IDC_RADIO_UTF8SANSBOM,"Button",BS_AUTORADIOBUTTON,27,67,128,10
CONTROL "UTF-8",IDC_RADIO_UTF8,"Button",BS_AUTORADIOBUTTON,27,92,62,10
CONTROL "UCS-2 Big Endian",IDC_RADIO_UCS2BIG,"Button",BS_AUTORADIOBUTTON,27,106,103,10
CONTROL "UCS-2 Little Endian",IDC_RADIO_UCS2SMALL,"Button",BS_AUTORADIOBUTTON,27,120,102,10
CONTROL "",IDC_RADIO_OTHERCP,"Button",BS_AUTORADIOBUTTON,27,135,10,10
COMBOBOX IDC_COMBO_OTHERCP,41,134,100,140,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
RTEXT "Default language :",IDC_DEFAULTLANG_STATIC,12,161,77,8
COMBOBOX IDC_COMBO_DEFAULTLANG,94,159,60,140,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
GROUPBOX "Default Directory (Open/Save)",IDC_OPENSAVEDIR_GR_STATIC,213,2,232,63,BS_CENTER
CONTROL "Follow current document",IDC_OPENSAVEDIR_FOLLOWCURRENT_RADIO,
"Button",BS_AUTORADIOBUTTON | WS_GROUP,89,129,200,10
"Button",BS_AUTORADIOBUTTON | WS_GROUP,221,14,200,10
CONTROL "Remember last used directory",IDC_OPENSAVEDIR_REMEMBERLAST_RADIO,
"Button",BS_AUTORADIOBUTTON,89,144,217,10
CONTROL "",IDC_OPENSAVEDIR_ALWAYSON_RADIO,"Button",BS_AUTORADIOBUTTON,89,156,11,10
EDITTEXT IDC_OPENSAVEDIR_ALWAYSON_EDIT,105,157,179,14,ES_AUTOHSCROLL
PUSHBUTTON "...",IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON,291,156,16,14
"Button",BS_AUTORADIOBUTTON,221,29,217,10
CONTROL "",IDC_OPENSAVEDIR_ALWAYSON_RADIO,"Button",BS_AUTORADIOBUTTON,221,43,11,10
EDITTEXT IDC_OPENSAVEDIR_ALWAYSON_EDIT,237,42,179,14,ES_AUTOHSCROLL
PUSHBUTTON "...",IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON,423,41,16,14
CONTROL "Apply to opened ANSI files",IDC_CHECK_OPENANSIASUTF8,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,99,46,124,10
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,79,124,10
END
IDD_PREFERENCE_LANG_BOX DIALOGEX 0, 0, 455, 185

View File

@ -18,11 +18,63 @@
#include "precompiledHeaders.h"
#include "preferenceDlg.h"
#include "lesDlgs.h"
#include "EncodingMapper.h"
const int BLINKRATE_FASTEST = 50;
const int BLINKRATE_SLOWEST = 2500;
const int BLINKRATE_INTERVAL = 50;
// This int encoding array is built from "EncodingUnit encodings[]" (see EncodingMapper.cpp)
// And DefaultNewDocDlg will use "int encoding array" to get more info from "EncodingUnit encodings[]"
int encodings[] = {
1250,
1251,
1252,
1253,
1254,
1255,
1256,
1257,
1258,
28591,
28592,
28593,
28594,
28595,
28596,
28597,
28598,
28599,
28603,
28604,
28605,
437,
720,
737,
775,
850,
852,
855,
857,
858,
860,
861,
862,
863,
865,
866,
869,
950,
936,
932,
949,
51949,
874,
10007,
21866,
20866
};
BOOL CALLBACK PreferenceDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
@ -886,9 +938,37 @@ BOOL CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
default : //uni8Bit
ID2Check = IDC_RADIO_ANSI;
}
::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0);
int selIndex = -1;
generic_string str;
EncodingMapper *em = EncodingMapper::getInstance();
for (int i = 0 ; i <= sizeof(encodings)/sizeof(int) ; i++)
{
int cmdID = em->getIndexFromEncoding(encodings[i]);
if (cmdID != -1)
{
cmdID += IDM_FORMAT_ENCODE;
getNameStrFromCmd(cmdID, str);
int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_OTHERCP, CB_ADDSTRING, 0, (LPARAM)str.c_str());
if (ndds._codepage == encodings[i])
selIndex = index;
::SendDlgItemMessage(_hSelf, IDC_COMBO_OTHERCP, CB_SETITEMDATA, index, (LPARAM)encodings[i]);
}
}
if (ndds._codepage == -1 || selIndex == -1)
{
::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), false);
}
else
{
ID2Check = IDC_RADIO_OTHERCP;
::SendDlgItemMessage(_hSelf, IDC_COMBO_OTHERCP, CB_SETCURSEL, selIndex, 0);
}
::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_OPENANSIASUTF8, BM_SETCHECK, (ID2Check == IDC_RADIO_UTF8SANSBOM && ndds._openAnsiAsUtf8)?BST_CHECKED:BST_UNCHECKED, 0);
::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_OPENANSIASUTF8), ID2Check == IDC_RADIO_UTF8SANSBOM);
int index = 0;
for (int i = L_TEXT ; i < pNppParam->L_END ; i++)
{
@ -929,7 +1009,6 @@ BOOL CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
}
::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT, WM_SETTEXT, 0, (LPARAM)nppGUI._defaultDir);
//::ExpandEnvironmentStrings(nppGUI._defaultDir, nppGUI._defaultDirExp, 500);
::EnableWindow(::GetDlgItem(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT), shouldActivated);
::EnableWindow(::GetDlgItem(_hSelf, IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON), shouldActivated);
@ -962,31 +1041,49 @@ BOOL CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
ndds._encoding = 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._openAnsiAsUtf8 = false;
makeOpenAnsiAsUtf8(false);
ndds._codepage = -1;
::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), false);
return TRUE;
case IDC_RADIO_UTF8:
ndds._encoding = 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;
makeOpenAnsiAsUtf8(true);
ndds._codepage = -1;
::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), false);
return TRUE;
case IDC_RADIO_ANSI:
ndds._encoding = uni8Bit;
ndds._openAnsiAsUtf8 = false;
makeOpenAnsiAsUtf8(false);
ndds._codepage = -1;
::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), false);
return TRUE;
case IDC_CHECK_OPENANSIASUTF8 :
ndds._openAnsiAsUtf8 = (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_OPENANSIASUTF8), BM_GETCHECK, 0, 0));
return TRUE;
case IDC_RADIO_OTHERCP :
{
::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), true);
int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_OTHERCP, CB_GETCURSEL, 0, 0);
int cp = ::SendDlgItemMessage(_hSelf, IDC_COMBO_OTHERCP, CB_GETITEMDATA, index, 0);
ndds._codepage = cp;
return TRUE;
}
case IDC_RADIO_F_MAC:
ndds._format = MAC_FORMAT;
@ -1022,11 +1119,21 @@ BOOL CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
return TRUE;
default:
if ((HIWORD(wParam) == CBN_SELCHANGE) && (LOWORD(wParam) == IDC_COMBO_DEFAULTLANG))
if (HIWORD(wParam) == CBN_SELCHANGE)
{
int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_GETCURSEL, 0, 0);
ndds._lang = _langList[index]._id;
return TRUE;
if (LOWORD(wParam) == IDC_COMBO_DEFAULTLANG)
{
int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_GETCURSEL, 0, 0);
ndds._lang = _langList[index]._id;
return TRUE;
}
else if (LOWORD(wParam) == IDC_COMBO_OTHERCP)
{
int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_OTHERCP, CB_GETCURSEL, 0, 0);
int cp = ::SendDlgItemMessage(_hSelf, IDC_COMBO_OTHERCP, CB_GETITEMDATA, index, 0);
ndds._codepage = cp;
return TRUE;
}
}
return FALSE;
}

View File

@ -142,6 +142,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON (IDD_PREFERENCE_NEWDOCSETTING_BOX + 18)
#define IDC_NEWDOCUMENT_GR_STATIC (IDD_PREFERENCE_NEWDOCSETTING_BOX + 19)
#define IDC_CHECK_OPENANSIASUTF8 (IDD_PREFERENCE_NEWDOCSETTING_BOX + 20)
#define IDC_RADIO_OTHERCP (IDD_PREFERENCE_NEWDOCSETTING_BOX + 21)
#define IDC_COMBO_OTHERCP (IDD_PREFERENCE_NEWDOCSETTING_BOX + 22)
#define IDD_PREFERENCE_LANG_BOX 6500 //(IDD_PREFERENCE_BOX + 500)
#define IDC_LIST_ENABLEDLANG (IDD_PREFERENCE_LANG_BOX + 1)