From 51e96391c67f456c7af1d33160cea05ff35e9fbe Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 1 Dec 2009 01:20:13 +0000 Subject: [PATCH] [BUG_FIXED] Fix brace highlighting breaking issue. [NEW] Add new encodings in the shortcuts map. [CLEAN] Remove annoying encoding issue warning dialogs. [ENHANCE] Enhance Html encoding auto-detection. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@577 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/installer/nppSetup.nsi | 8 +- PowerEditor/src/Notepad_plus.cpp | 148 +++++++++++++++-------------- PowerEditor/src/Notepad_plus.h | 4 +- PowerEditor/src/Parameters.cpp | 55 +++++++---- PowerEditor/src/resource.h | 6 +- 5 files changed, 120 insertions(+), 101 deletions(-) diff --git a/PowerEditor/installer/nppSetup.nsi b/PowerEditor/installer/nppSetup.nsi index 3c9eacd0c..6549bc081 100644 --- a/PowerEditor/installer/nppSetup.nsi +++ b/PowerEditor/installer/nppSetup.nsi @@ -18,10 +18,10 @@ ; Define the application name !define APPNAME "Notepad++" -!define APPVERSION "5.6" -!define APPNAMEANDVERSION "Notepad++ v5.6" +!define APPVERSION "5.6.1" +!define APPNAMEANDVERSION "Notepad++ v5.6.1" !define VERSION_MAJOR 5 -!define VERSION_MINOR 6 +!define VERSION_MINOR 61 !define APPWEBSITE "http://notepad-plus.sourceforge.net/" @@ -29,7 +29,7 @@ Name "${APPNAMEANDVERSION}" InstallDir "$PROGRAMFILES\Notepad++" InstallDirRegKey HKLM "Software\${APPNAME}" "" -OutFile "..\bin\npp.5.6.Installer.exe" +OutFile "..\bin\npp.5.6.1.Installer.exe" ; GetWindowsVersion ; diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 48e700279..0e87fc9b3 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -905,9 +905,12 @@ int Notepad_plus::getHtmlXmlEncoding(const TCHAR *fileName) const } else // if (langT == L_HTML) { - // find encoding by RegExpr - const char *htmlHeaderRegExpr = ""; - + const char *htmlHeaderRegExpr = ""; + const char *htmlHeaderRegExpr2 = ""; + const char *charsetBlock = "charset[ \\t]*=[ \\t]*[^\"']+"; + const char *intermediaire = "=[ \\t]*.+"; + const char *encodingStrRE = "[^ \\t=]+"; + int startPos = 0; int endPos = lenFile-1; _invisibleEditView.execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP|SCFIND_POSIX); @@ -917,36 +920,25 @@ int Notepad_plus::getHtmlXmlEncoding(const TCHAR *fileName) const int posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(htmlHeaderRegExpr), (LPARAM)htmlHeaderRegExpr); - if (posFound != -1) + if (posFound == -1) { - const char *charsetBlockRegExpr = "charset[ \\t]*=[ \\t]*.+[\"]"; - posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(charsetBlockRegExpr), (LPARAM)charsetBlockRegExpr); - - const char *charsetRegExpr = "=[ \\t]*[^\"]+"; - posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(charsetRegExpr), (LPARAM)charsetRegExpr); - - posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingAliasRegExpr), (LPARAM)encodingAliasRegExpr); - - startPos = int(_invisibleEditView.execute(SCI_GETTARGETSTART)); - endPos = int(_invisibleEditView.execute(SCI_GETTARGETEND)); - - char encodingStr[128]; - _invisibleEditView.getText(encodingStr, startPos, endPos); - - EncodingMapper *em = EncodingMapper::getInstance(); - int enc = em->getEncodingFromString(encodingStr); - return (enc==CP_ACP?-1:enc); - } - else - { - const char *htmlHeaderRegExpr2 = ""; posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(htmlHeaderRegExpr2), (LPARAM)htmlHeaderRegExpr2); if (posFound == -1) return -1; - //TODO } + posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(charsetBlock), (LPARAM)charsetBlock); + posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(intermediaire), (LPARAM)intermediaire); + posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingStrRE), (LPARAM)encodingStrRE); - return -1; + startPos = int(_invisibleEditView.execute(SCI_GETTARGETSTART)); + endPos = int(_invisibleEditView.execute(SCI_GETTARGETEND)); + + char encodingStr[128]; + _invisibleEditView.getText(encodingStr, startPos, endPos); + + EncodingMapper *em = EncodingMapper::getInstance(); + int enc = em->getEncodingFromString(encodingStr); + return (enc==CP_ACP?-1:enc); } } @@ -2771,46 +2763,57 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (notification->nmhdr.hwndFrom != _pEditView->getHSelf()) break; - - braceMatch(); - NppGUI & nppGui = (NppGUI &)nppParam->getNppGUI(); + NppGUI & nppGui = (NppGUI &)nppParam->getNppGUI(); + + static int originalColour = _pEditView->execute(SCI_STYLEGETFORE, STYLE_BRACELIGHT); + _pEditView->execute(SCI_STYLESETFORE, STYLE_BRACELIGHT, originalColour); + + if (braceMatch()) + { + _pEditView->clearIndicator(SCE_UNIVERSAL_TAGMATCH); + _pEditView->clearIndicator(SCE_UNIVERSAL_TAGATTR); + } + else + { + if (nppGui._enableTagsMatchHilite) + { + XmlMatchedTagsHighlighter xmlTagMatchHiliter(_pEditView); + pair tagPos = xmlTagMatchHiliter.tagMatch(nppGui._enableTagAttrsHilite); + + int braceAtCaret = tagPos.first; + int braceOpposite = tagPos.second; + + if ((braceAtCaret != -1) && (braceOpposite == -1)) + { + _pEditView->execute(SCI_SETHIGHLIGHTGUIDE, 0); + } + else if (_pEditView->isShownIndentGuide()) + { + int columnAtCaret = int(_pEditView->execute(SCI_GETCOLUMN, braceAtCaret)); + int columnOpposite = int(_pEditView->execute(SCI_GETCOLUMN, braceOpposite)); + + int lineAtCaret = int(_pEditView->execute(SCI_LINEFROMPOSITION, braceAtCaret)); + int lineOpposite = int(_pEditView->execute(SCI_LINEFROMPOSITION, braceOpposite)); + if (lineAtCaret != lineOpposite) + { + + StyleArray & stylers = nppParam->getMiscStylerArray(); + int iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_TAGMATCH); + if (iFind) + { + Style *pStyle = &(stylers.getStyler(iFind)); + _pEditView->execute(SCI_STYLESETFORE, STYLE_BRACELIGHT, pStyle->_bgColor); + } + // braceAtCaret - 1, braceOpposite-1 : walk around to not highlight the '<' + _pEditView->execute(SCI_BRACEHIGHLIGHT, braceAtCaret-1, braceOpposite-1); + _pEditView->execute(SCI_SETHIGHLIGHTGUIDE, (columnAtCaret < columnOpposite)?columnAtCaret:columnOpposite); + } + } + } + } + - if (nppGui._enableTagsMatchHilite) - { - XmlMatchedTagsHighlighter xmlTagMatchHiliter(_pEditView); - pair tagPos = xmlTagMatchHiliter.tagMatch(nppGui._enableTagAttrsHilite); - - int braceAtCaret = tagPos.first; - int braceOpposite = tagPos.second; - - if ((braceAtCaret != -1) && (braceOpposite == -1)) - { - _pEditView->execute(SCI_SETHIGHLIGHTGUIDE, 0); - } - else if (_pEditView->isShownIndentGuide()) - { - int columnAtCaret = int(_pEditView->execute(SCI_GETCOLUMN, braceAtCaret)); - int columnOpposite = int(_pEditView->execute(SCI_GETCOLUMN, braceOpposite)); - - int lineAtCaret = int(_pEditView->execute(SCI_LINEFROMPOSITION, braceAtCaret)); - int lineOpposite = int(_pEditView->execute(SCI_LINEFROMPOSITION, braceOpposite)); - if (lineAtCaret != lineOpposite) - { - StyleArray & stylers = nppParam->getMiscStylerArray(); - int iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_TAGMATCH); - if (iFind) - { - Style *pStyle = &(stylers.getStyler(iFind)); - _pEditView->execute(SCI_STYLESETFORE, STYLE_BRACELIGHT, pStyle->_bgColor); - } - // braceAtCaret - 1, braceOpposite-1 : walk around to not highlight the '<' - _pEditView->execute(SCI_BRACEHIGHLIGHT, braceAtCaret-1, braceOpposite-1); - _pEditView->execute(SCI_SETHIGHLIGHTGUIDE, (columnAtCaret < columnOpposite)?columnAtCaret:columnOpposite); - } - } - } - if (nppGui._enableSmartHilite) { if (nppGui._disableSmartHiliteTmp) @@ -3174,7 +3177,7 @@ void Notepad_plus::findMatchingBracePos(int & braceAtCaret, int & braceOpposite) braceAtCaret = -1; braceOpposite = -1; TCHAR charBefore = '\0'; - //TCHAR styleBefore = '\0'; + int lengthDoc = int(_pEditView->execute(SCI_GETLENGTH)); if ((lengthDoc > 0) && (caretPos > 0)) @@ -3200,8 +3203,8 @@ void Notepad_plus::findMatchingBracePos(int & braceAtCaret, int & braceOpposite) braceOpposite = int(_pEditView->execute(SCI_BRACEMATCH, braceAtCaret, 0)); } - -void Notepad_plus::braceMatch() +// return true if 1 or 2 (matched) brace(s) is found +bool Notepad_plus::braceMatch() { int braceAtCaret = -1; int braceOpposite = -1; @@ -3225,6 +3228,7 @@ void Notepad_plus::braceMatch() } enableCommand(IDM_SEARCH_GOTOMATCHINGBRACE, (braceAtCaret != -1) && (braceOpposite != -1), MENU | TOOLBAR); + return (braceAtCaret != -1); } @@ -3279,7 +3283,7 @@ void Notepad_plus::setUniModeText() int cmdID = em->getIndexFromEncoding(encoding); if (cmdID == -1) { - printStr(TEXT("Encoding problem. Encoding is not added in encoding_table?")); + //printStr(TEXT("Encoding problem. Encoding is not added in encoding_table?")); return; } cmdID += IDM_FORMAT_ENCODE; @@ -4626,7 +4630,7 @@ void Notepad_plus::command(int id) int encoding = em->getEncodingFromIndex(index); if (encoding == -1) { - printStr(TEXT("Encoding problem. Command is not added in encoding_table?")); + //printStr(TEXT("Encoding problem. Command is not added in encoding_table?")); return; } @@ -6401,7 +6405,7 @@ void Notepad_plus::enableConvertMenuItems(formatType f) const enableCommand(IDM_FORMAT_TOMAC, (f != MAC_FORMAT), MENU); } -void Notepad_plus::checkUnicodeMenuItems(/*UniMode um*/) const +void Notepad_plus::checkUnicodeMenuItems() const { Buffer *buf = _pEditView->getCurrentBuffer(); UniMode um = buf->getUnicodeMode(); @@ -6440,7 +6444,7 @@ void Notepad_plus::checkUnicodeMenuItems(/*UniMode um*/) const int cmdID = em->getIndexFromEncoding(encoding); if (cmdID == -1) { - printStr(TEXT("Encoding problem. Encoding is not added in encoding_table?")); + //printStr(TEXT("Encoding problem. Encoding is not added in encoding_table?")); return; } cmdID += IDM_FORMAT_ENCODE; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index c7e7355be..7e31c68b1 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -459,7 +459,7 @@ private: void getMainClientRect(RECT & rc) const; void dynamicCheckMenuAndTB() const; void enableConvertMenuItems(formatType f) const; - void checkUnicodeMenuItems(/*UniMode um*/) const; + void checkUnicodeMenuItems() const; generic_string getLangDesc(LangType langType, bool shortDesc = false); @@ -531,7 +531,7 @@ private: void replaceMarkedline(int ln, const TCHAR *str); generic_string getMarkedLine(int ln); void findMatchingBracePos(int & braceAtCaret, int & braceOpposite); - void braceMatch(); + bool braceMatch(); void activateNextDoc(bool direction); void activateDoc(int pos); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 72d8321f3..00511de66 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -192,26 +192,41 @@ WinMenuKeyDefinition winKeyDefs[] = { {VK_NULL, IDM_FORMAT_CONV2_UTF_8, false, false, false, NULL}, {VK_NULL, IDM_FORMAT_CONV2_UCS_2BE, false, false, false, NULL}, {VK_NULL, IDM_FORMAT_CONV2_UCS_2LE, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_CP855, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_MAC_CYRILLIC, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_KIO8U_CYRILLIC, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_KIO8R_CYRILLIC, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_DOS437, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_WIN1255, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_WIN1257, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_WIN1258, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_WIN1251, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_WIN1252, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_WIN1254, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_ISO_8859_8, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_WIN1250, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_WIN1253, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_WIN1256, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_TIS_620, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_GB2312, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_SHIFT_JIS, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_EUC_KR, false, false, false, NULL}, - {VK_NULL, IDM_FORMAT_BIG5, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_6, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_WIN1256, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_13, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_WIN1257, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_14, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_CP855, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_5, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_MAC_CYRILLIC, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_KIO8R_CYRILLIC, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_KIO8U_CYRILLIC, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_WIN1251, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_WIN1250, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_BIG5, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_GB2312, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_DOS437, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_2, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_7, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_WIN1253, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_8, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_WIN1255, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_SHIFT_JIS, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_EUC_KR, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_10, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_15, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_4, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_16, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_3, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_11, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_TIS_620, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_9, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_WIN1254, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_WIN1252, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ISO_8859_1, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_WIN1258, false, false, false, NULL}, + {VK_NULL, IDM_SETTING_PREFERECE, false, false, false, NULL}, {VK_NULL, IDM_LANGSTYLE_CONFIG_DLG, false, false, false, NULL}, {VK_NULL, IDM_SETTING_SHORTCUT_MAPPER, false, false, false, NULL}, diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index a1e82f30c..33b79c9f5 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -18,9 +18,9 @@ #ifndef RESOURCE_H #define RESOURCE_H -#define NOTEPAD_PLUS_VERSION TEXT("Notepad++ v5.6") -#define VERSION_VALUE TEXT("5.6\0") // should be X.Y : ie. if VERSION_DIGITALVALUE == 4, 7, 1, 0 , then X = 4, Y = 71 -#define VERSION_DIGITALVALUE 5, 6, 0, 0 +#define NOTEPAD_PLUS_VERSION TEXT("Notepad++ v5.6.1") +#define VERSION_VALUE TEXT("5.6.1\0") // should be X.Y : ie. if VERSION_DIGITALVALUE == 4, 7, 1, 0 , then X = 4, Y = 71 +#define VERSION_DIGITALVALUE 5, 6, 1, 0 #ifdef UNICODE #define UNICODE_ANSI_MODE TEXT("(UNICODE)")