From 10e6cbfb619dfd1e16ff44463daffce61f1b3e4f Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 21 Nov 2009 02:38:48 +0000 Subject: [PATCH] [NEW] Add new encodings, make status bar work for the new encodings. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@566 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/installer/nativeLang/slovakA.xml | 2 +- PowerEditor/src/MISC/Common/Common.h | 5 - PowerEditor/src/Notepad_plus.cpp | 191 +++++++++++++------ PowerEditor/src/Notepad_plus.h | 2 +- PowerEditor/src/Notepad_plus.rc | 9 +- PowerEditor/src/localizationString.h | Bin 6534 -> 6622 bytes PowerEditor/src/menuCmdID.h | 31 +-- 7 files changed, 154 insertions(+), 86 deletions(-) diff --git a/PowerEditor/installer/nativeLang/slovakA.xml b/PowerEditor/installer/nativeLang/slovakA.xml index 105b8773..81cb51f0 100644 --- a/PowerEditor/installer/nativeLang/slovakA.xml +++ b/PowerEditor/installer/nativeLang/slovakA.xml @@ -1,4 +1,4 @@ - + diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 57297a51..64df83bc 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -36,11 +36,6 @@ #define NPP_CP_TIS_620 874 - - - - - #ifdef UNICODE #define NppMainEntry wWinMain #define generic_strtol wcstol diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 655ac836..b8447108 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -40,6 +40,25 @@ const char *urlHttpRegExpr = "http://[a-z0-9_\\-\\+~.:?&@=/%#]*"; int docTabIconIDs[] = {IDI_SAVED_ICON, IDI_UNSAVED_ICON, IDI_READONLY_ICON}; enum tb_stat {tb_saved, tb_unsaved, tb_ro}; +int encoding_table[] = { +NPP_CP_WIN_1250, +NPP_CP_WIN_1251, +NPP_CP_WIN_1252, +NPP_CP_WIN_1253, +NPP_CP_WIN_1254, +NPP_CP_WIN_1255, +NPP_CP_WIN_1256, +NPP_CP_WIN_1257, +NPP_CP_WIN_1258, +NPP_CP_BIG5, +NPP_CP_GB2312, +NPP_CP_SHIFT_JIS, +NPP_CP_EUC_KR, +NPP_CP_TIS_620, +NPP_CP_ISO_8859_8 +}; + + #define DIR_LEFT true #define DIR_RIGHT false @@ -3094,27 +3113,59 @@ void Notepad_plus::setDisplayFormat(formatType f) _statusBar.setText(str.c_str(), STATUSBAR_EOF_FORMAT); } -void Notepad_plus::setUniModeText(UniMode um) +void Notepad_plus::setUniModeText(/*UniMode um*/) { - TCHAR *uniModeText; - switch (um) + Buffer *buf = _pEditView->getCurrentBuffer(); + int encoding = buf->getEncoding(); + UniMode um = buf->getUnicodeMode(); + + generic_string uniModeTextString; + + if (encoding == -1) { - case uniUTF8: - uniModeText = TEXT("UTF-8"); break; - case uni16BE: - uniModeText = TEXT("UCS-2 Big Endian"); break; - case uni16LE: - uniModeText = TEXT("UCS-2 Little Endian"); break; - case uni16BE_NoBOM: - uniModeText = TEXT("UCS-2 BE w/o BOM"); break; - case uni16LE_NoBOM: - uniModeText = TEXT("UCS-2 LE w/o BOM"); break; - case uniCookie: - uniModeText = TEXT("ANSI as UTF-8"); break; - default : - uniModeText = TEXT("ANSI"); + switch (um) + { + case uniUTF8: + uniModeTextString = TEXT("UTF-8"); break; + case uni16BE: + uniModeTextString = TEXT("UCS-2 Big Endian"); break; + case uni16LE: + uniModeTextString = TEXT("UCS-2 Little Endian"); break; + case uni16BE_NoBOM: + uniModeTextString = TEXT("UCS-2 BE w/o BOM"); break; + case uni16LE_NoBOM: + uniModeTextString = TEXT("UCS-2 LE w/o BOM"); break; + case uniCookie: + uniModeTextString = TEXT("ANSI as UTF-8"); break; + default : + uniModeTextString = TEXT("ANSI"); + } } - _statusBar.setText(uniModeText, STATUSBAR_UNICODE_TYPE); + else + { + bool found = false; + size_t nbItem = sizeof(encoding_table)/sizeof(int); + size_t i = 0; + for ( ; i < nbItem ; i++) + { + if (encoding_table[i] == encoding) + { + found = true; + break; + } + + } + if (!found) + { + printStr(TEXT("Encoding problem. Encoding is not added in encoding_table?")); + return; + } + const int itemSize = 64; + TCHAR uniModeText[itemSize]; + ::GetMenuString(_mainMenuHandle, i+IDM_FORMAT_ENCODE, uniModeText, itemSize, MF_BYCOMMAND); + uniModeTextString = uniModeText; + } + _statusBar.setText(uniModeTextString.c_str(), STATUSBAR_UNICODE_TYPE); } int Notepad_plus::getFolderMarginStyle() const @@ -4369,8 +4420,17 @@ void Notepad_plus::command(int id) if (shoulBeDirty) buf->setDirty(true); } + buf->setEncoding(-1); break; } + + case IDM_FORMAT_WIN1255 : + case IDM_FORMAT_WIN1257 : + case IDM_FORMAT_WIN1258 : + case IDM_FORMAT_WIN1251 : + case IDM_FORMAT_WIN1252 : + case IDM_FORMAT_WIN1254 : + case IDM_FORMAT_ISO_8859_8 : case IDM_FORMAT_WIN1250 : case IDM_FORMAT_WIN1253 : case IDM_FORMAT_WIN1256 : @@ -4380,47 +4440,56 @@ void Notepad_plus::command(int id) case IDM_FORMAT_EUC_KR : case IDM_FORMAT_BIG5 : { - int encoding = -1; - switch (id) + size_t nbItem = sizeof(encoding_table)/sizeof(int); + int index = id - IDM_FORMAT_ENCODE; + + if (index < 0 || index >= int(nbItem)) { - case IDM_FORMAT_BIG5: - encoding = NPP_CP_BIG5; - break; - case IDM_FORMAT_EUC_KR: - encoding = NPP_CP_EUC_KR; - break; - case IDM_FORMAT_SHIFT_JIS: - encoding = NPP_CP_SHIFT_JIS; - break; - case IDM_FORMAT_GB2312: - encoding = NPP_CP_GB2312; - break; - case IDM_FORMAT_TIS_620: - encoding = NPP_CP_TIS_620; - break; - case IDM_FORMAT_WIN1256: - encoding = NPP_CP_WIN_1256; - break; - case IDM_FORMAT_WIN1253: - encoding = NPP_CP_WIN_1253; - break; - case IDM_FORMAT_WIN1250: - encoding = NPP_CP_WIN_1250; - break; - - default : // IDM_FORMAT_ANSI - encoding = CP_ACP; + printStr(TEXT("Encoding problem. Command is not added in encoding_table?")); + return; } + Buffer * buf = _pEditView->getCurrentBuffer(); + if (buf->isDirty()) + { + int answer = ::MessageBox(NULL, TEXT("You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?"), TEXT("Save Current Modification"), MB_YESNO); + if (answer == IDYES) + { + fileSave(); + _pEditView->execute(SCI_EMPTYUNDOBUFFER); + } + else + return; + } - int len = _pEditView->getCurrentDocLen(); - char *content = new char[len+1]; - _pEditView->execute(SCI_GETTEXT, len+1, (LPARAM)content); - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const char *newContent = wmc->encode(encoding, SC_CP_UTF8, content); - _pEditView->execute(SCI_SETCODEPAGE, SC_CP_UTF8); - _pEditView->execute(SCI_SETTEXT, 0, (LPARAM)newContent); - _pEditView->getCurrentBuffer()->setEncoding(encoding); - delete [] content; + if (_pEditView->execute(SCI_CANUNDO) == TRUE) + { + int answer = ::MessageBox(NULL, TEXT("All the saved modifications can not be undone.\r\rContinue?"), TEXT("Loss Undo Ability Waning"), MB_YESNO); + if (answer == IDYES) + { + // Do nothing + } + else + return; + } + + if (!buf->isDirty()) + { + int len = _pEditView->getCurrentDocLen(); + char *content = new char[len+1]; + _pEditView->execute(SCI_GETTEXT, len+1, (LPARAM)content); + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char *newContent = wmc->encode(encoding_table[index], SC_CP_UTF8, content); + _pEditView->execute(SCI_SETCODEPAGE, SC_CP_UTF8); + _pEditView->execute(SCI_SETTEXT, 0, (LPARAM)newContent); + Buffer *buf = _pEditView->getCurrentBuffer(); + buf->setEncoding(encoding_table[index]); + delete [] content; + + buf->setUnicodeMode(uniEnd); + + _pEditView->execute(SCI_EMPTYUNDOBUFFER); + buf->setDirty(false); + } break; } @@ -7699,8 +7768,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa _subEditView.showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, svp2._lineNumberMarginShow); _mainEditView.showMargin(ScintillaEditView::_SC_MARGE_SYBOLE, svp1._bookMarkMarginShow); _subEditView.showMargin(ScintillaEditView::_SC_MARGE_SYBOLE, svp2._bookMarkMarginShow); - //_mainEditView.showMargin(ScintillaEditView::_SC_MARGE_MODIFMARKER, svp1._docChangeStateMarginShow); - //_subEditView.showMargin(ScintillaEditView::_SC_MARGE_MODIFMARKER, svp2._docChangeStateMarginShow); _mainEditView.showIndentGuideLine(svp1._indentGuideLineShow); _subEditView.showIndentGuideLine(svp2._indentGuideLineShow); @@ -7745,8 +7812,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa _mainEditView.execute(SCI_SETZOOM, svp1._zoom); _subEditView.execute(SCI_SETZOOM, svp2._zoom); - //_mainEditView.execute(SCI_SETMULTIPLESELECTION, true); - //_subEditView.execute(SCI_SETMULTIPLESELECTION, true); ::SendMessage(hwnd, NPPM_INTERNAL_SETMULTISELCTION, 0, 0); _mainEditView.execute(SCI_SETADDITIONALSELECTIONTYPING, true); @@ -7792,7 +7857,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa _statusBar.setPartWidth(STATUSBAR_DOC_SIZE, 200); _statusBar.setPartWidth(STATUSBAR_CUR_POS, 250); _statusBar.setPartWidth(STATUSBAR_EOF_FORMAT, 80); - _statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, 100); + _statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, 150); _statusBar.setPartWidth(STATUSBAR_TYPING_MODE, 30); _statusBar.display(willBeShown); @@ -10568,7 +10633,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) { { updateStatusBar(); checkUnicodeMenuItems(buffer->getUnicodeMode()); - setUniModeText(buffer->getUnicodeMode()); + setUniModeText(/*buffer->getUnicodeMode()*/); setDisplayFormat(buffer->getFormat()); enableConvertMenuItems(buffer->getFormat()); } @@ -10593,7 +10658,7 @@ void Notepad_plus::notifyBufferActivated(BufferID bufid, int view) { setLangStatus(buf->getLangType()); updateStatusBar(); checkUnicodeMenuItems(buf->getUnicodeMode()); - setUniModeText(buf->getUnicodeMode()); + setUniModeText(/*buf->getUnicodeMode()*/); setDisplayFormat(buf->getFormat()); enableConvertMenuItems(buf->getFormat()); generic_string dir(buf->getFullPathName()); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index aaf80e89..a67a3e2d 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -468,7 +468,7 @@ private: void setDisplayFormat(formatType f); - void setUniModeText(UniMode um); + void setUniModeText(/*UniMode um*/); void checkLangsMenu(int id) const ; void setLanguage(LangType langType); diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 95524014..5b6b77a7 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -399,13 +399,20 @@ BEGIN POPUP "More..." BEGIN MENUITEM "Arabic(Windows)", IDM_FORMAT_WIN1256 - MENUITEM "Central European(Windows)" IDM_FORMAT_WIN1250 + MENUITEM "Baltic(Windows)", IDM_FORMAT_WIN1257 + MENUITEM "Cyrillic(Windows)", IDM_FORMAT_WIN1251 + MENUITEM "Central European(Windows)", IDM_FORMAT_WIN1250 MENUITEM "Chinese Traditional(Big5)", IDM_FORMAT_BIG5 MENUITEM "Chinese Simplified(GB2312)", IDM_FORMAT_GB2312 MENUITEM "Greek(Windows)", IDM_FORMAT_WIN1253 + MENUITEM "Hebrew(iso8859-8)", IDM_FORMAT_ISO_8859_8 + MENUITEM "Hebrew(Windows)", IDM_FORMAT_WIN1255 MENUITEM "Japanese(Shift-JIS)", IDM_FORMAT_SHIFT_JIS MENUITEM "Korean(EUC)", IDM_FORMAT_EUC_KR MENUITEM "Thai(Windows)", IDM_FORMAT_TIS_620 + MENUITEM "Turkish(Windows)", IDM_FORMAT_WIN1254 + MENUITEM "Western European(Windows)", IDM_FORMAT_WIN1252 + MENUITEM "Vietnamese(Windows)", IDM_FORMAT_WIN1258 END MENUITEM SEPARATOR MENUITEM "Convert to ANSI", IDM_FORMAT_CONV2_ANSI diff --git a/PowerEditor/src/localizationString.h b/PowerEditor/src/localizationString.h index 658361142d2dab1f2e6ab326f99629f795fd598f..33009b808ba04b5898c001af675ebe6597c99f57 100644 GIT binary patch delta 53 zcmZoOzGu9_O>*)Ab`eo27H<{@7Gof3&Z5BJ#A3l>&0;axQB0IOo1v1Sh#?(FR!ugS G^alV>0t>VN delta 11 Scmca-+-AJNO>*))Ne2KOY6N5e diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index f9c8e215..a5acd1bf 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -238,21 +238,22 @@ #define IDM_FORMAT_CONV2_UCS_2BE (IDM_FORMAT + 12) #define IDM_FORMAT_CONV2_UCS_2LE (IDM_FORMAT + 13) - #define IDM_FORMAT_WIN1250 (IDM_FORMAT + 20) - #define IDM_FORMAT_WIN1251 (IDM_FORMAT + 21) - #define IDM_FORMAT_WIN1252 (IDM_FORMAT + 22) - #define IDM_FORMAT_WIN1253 (IDM_FORMAT + 23) - #define IDM_FORMAT_WIN1254 (IDM_FORMAT + 24) - #define IDM_FORMAT_WIN1255 (IDM_FORMAT + 25) - #define IDM_FORMAT_WIN1256 (IDM_FORMAT + 26) - #define IDM_FORMAT_WIN1257 (IDM_FORMAT + 27) - #define IDM_FORMAT_WIN1258 (IDM_FORMAT + 28) - #define IDM_FORMAT_BIG5 (IDM_FORMAT + 29) - #define IDM_FORMAT_GB2312 (IDM_FORMAT + 30) - #define IDM_FORMAT_SHIFT_JIS (IDM_FORMAT + 31) - #define IDM_FORMAT_EUC_KR (IDM_FORMAT + 32) - #define IDM_FORMAT_TIS_620 (IDM_FORMAT + 33) - + #define IDM_FORMAT_ENCODE (IDM_FORMAT + 20) + #define IDM_FORMAT_WIN1250 (IDM_FORMAT_ENCODE + 0) + #define IDM_FORMAT_WIN1251 (IDM_FORMAT_ENCODE + 1) + #define IDM_FORMAT_WIN1252 (IDM_FORMAT_ENCODE + 2) + #define IDM_FORMAT_WIN1253 (IDM_FORMAT_ENCODE + 3) + #define IDM_FORMAT_WIN1254 (IDM_FORMAT_ENCODE + 4) + #define IDM_FORMAT_WIN1255 (IDM_FORMAT_ENCODE + 5) + #define IDM_FORMAT_WIN1256 (IDM_FORMAT_ENCODE + 6) + #define IDM_FORMAT_WIN1257 (IDM_FORMAT_ENCODE + 7) + #define IDM_FORMAT_WIN1258 (IDM_FORMAT_ENCODE + 8) + #define IDM_FORMAT_BIG5 (IDM_FORMAT_ENCODE + 9) + #define IDM_FORMAT_GB2312 (IDM_FORMAT_ENCODE + 10) + #define IDM_FORMAT_SHIFT_JIS (IDM_FORMAT_ENCODE + 11) + #define IDM_FORMAT_EUC_KR (IDM_FORMAT_ENCODE + 12) + #define IDM_FORMAT_TIS_620 (IDM_FORMAT_ENCODE + 13) + #define IDM_FORMAT_ISO_8859_8 (IDM_FORMAT_ENCODE + 14) #define IDM_LANG (IDM + 6000) #define IDM_LANGSTYLE_CONFIG_DLG (IDM_LANG + 1)