diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index f9d244fe..995fd4b5 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -427,15 +427,15 @@ BOOL Notepad_plus::notify(SCNotification *notification) case SCN_CHARADDED: { - bool indentMaintain = NppParameters::getInstance()->getNppGUI()._maitainIndent; + const NppGUI & nppGui = NppParameters::getInstance()->getNppGUI(); + bool indentMaintain = nppGui._maitainIndent; if (indentMaintain) MaintainIndentation(static_cast(notification->ch)); AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; - MatchedPairConf matchedPairConf; - if (matchedPairConf.hasAnyPairsPair()) - autoC->insertMatchedChars(notification->ch, matchedPairConf); + if (nppGui._matchedPairConf.hasAnyPairsPair()) + autoC->insertMatchedChars(notification->ch, nppGui._matchedPairConf); autoC->update(notification->ch); break; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 25b7811f..8095ce1c 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -4449,6 +4449,7 @@ bool NppParameters::writeGUIParams() bool URLExist = false; bool globalOverrideExist = false; bool autocExist = false; + bool autocInsetExist = false; bool sessionExtExist = false; bool noUpdateExist = false; bool menuBarExist = false; @@ -4783,6 +4784,40 @@ bool NppParameters::writeGUIParams() const TCHAR * pStr = _nppGUI._funcParams?TEXT("yes"):TEXT("no"); element->SetAttribute(TEXT("funcParams"), pStr); } + else if (!lstrcmp(nm, TEXT("auto-insert"))) + { + autocInsetExist = true; + + const TCHAR * pStr = _nppGUI._matchedPairConf._doParentheses?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("parentheses"), pStr); + + pStr = _nppGUI._matchedPairConf._doBrackets?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("brackets"), pStr); + + pStr = _nppGUI._matchedPairConf._doCurlyBrackets?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("curlyBrackets"), pStr); + + pStr = _nppGUI._matchedPairConf._doQuotes?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("quotes"), pStr); + + pStr = _nppGUI._matchedPairConf._doDoubleQuotes?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("doubleQuotes"), pStr); + + pStr = _nppGUI._matchedPairConf._doHtmlXmlTag?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("htmlXmlTag"), pStr); + + TiXmlElement hist_element(TEXT("")); + hist_element.SetValue(TEXT("UserDefinePair")); + for (size_t i = 0, nb = _nppGUI._matchedPairConf._matchedPairs.size(); i < nb; ++i) + { + int open = _nppGUI._matchedPairConf._matchedPairs[i].first; + int close = _nppGUI._matchedPairConf._matchedPairs[i].second; + + (hist_element.ToElement())->SetAttribute(TEXT("open"), open); + (hist_element.ToElement())->SetAttribute(TEXT("close"), close); + childNode->InsertEndChild(hist_element); + } + } else if (!lstrcmp(nm, TEXT("sessionExt"))) { sessionExtExist = true; diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index a6860362..f4cf2d78 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -687,9 +687,9 @@ struct MatchedPairConf { MatchedPairConf(): _doHtmlXmlTag(false), _doParentheses(false), _doBrackets(false), _doCurlyBrackets(false),\ _doQuotes(false), _doDoubleQuotes(false) {}; - bool hasUserDefinedPairs(){ return _matchedPairs.size() != 0; }; - bool hasDefaultPairs() { return _doParentheses||_doBrackets||_doCurlyBrackets||_doQuotes||_doDoubleQuotes||_doHtmlXmlTag; }; - bool hasAnyPairsPair(){ return hasUserDefinedPairs() || hasDefaultPairs(); }; + bool hasUserDefinedPairs() const { return _matchedPairs.size() != 0; }; + bool hasDefaultPairs() const { return _doParentheses||_doBrackets||_doCurlyBrackets||_doQuotes||_doDoubleQuotes||_doHtmlXmlTag; }; + bool hasAnyPairsPair() const { return hasUserDefinedPairs() || hasDefaultPairs(); }; }; struct NppGUI diff --git a/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp index 5c6d279b..f211ce05 100644 --- a/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp +++ b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp @@ -180,14 +180,20 @@ void AutoCompletion::getCloseTag(char *closeTag, size_t closeTagSize, size_t car if (size_t(foundTextLen) > closeTagSize - 2) // buffer size is not large enough. -2 for '/' & '\0' return; - char tagHeader[3]; - _pEditView->getText(tagHeader, targetStart, targetStart+2); + char tagHead[3]; + _pEditView->getText(tagHead, targetStart, targetStart+2); - if (tagHeader[1] == '\\') // "" will be ignored + if (tagHead[1] == '/') // "" will be ignored + return; + + char tagTail[2]; + _pEditView->getText(tagTail, caretPos-2, caretPos-1); + + if (tagTail[0] == '/') // "" and "" will be ignored return; closeTag[0] = '<'; - closeTag[1] = '\\'; + closeTag[1] = '/'; _pEditView->getText(closeTag + 2, targetStart + 1, targetEnd); closeTag[foundTextLen+1] = '>'; closeTag[foundTextLen+2] = '\0'; @@ -238,7 +244,7 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m break; case int('>'): { - if (matchedPairConf._doHtmlXmlTag) + if (matchedPairConf._doHtmlXmlTag && (_curLang == L_HTML || _curLang == L_XML)) { getCloseTag(closeTag, closeTagLen, caretPos); if (closeTag[0] != '\0') diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index 18fd85be..e790bc15 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -304,17 +304,36 @@ IDD_PREFERENCE_AUTOCOMPLETION_BOX DIALOGEX 0, 0, 455, 185 STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN - GROUPBOX "Auto-Completion",IDD_AUTOC_GRPSTATIC,86,40,289,92,BS_CENTER + GROUPBOX "Auto-Completion",IDD_AUTOC_GRPSTATIC,86,4,289,84,BS_CENTER CONTROL "Enable auto-completion on each input",IDD_AUTOC_ENABLECHECK, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,91,51,150,10 - CONTROL "Function completion",IDD_AUTOC_FUNCRADIO,"Button",BS_AUTORADIOBUTTON | WS_GROUP,118,65,145,10 - CONTROL "Word completion",IDD_AUTOC_WORDRADIO,"Button",BS_AUTORADIOBUTTON,118,81,145,10 - RTEXT "From",IDD_AUTOC_STATIC_FROM,248,51,47,8 - CTEXT "1",IDD_AUTOC_STATIC_N,299,51,8,8,WS_TABSTOP - LTEXT "th character",IDD_AUTOC_STATIC_CHAR,313,51,57,8 - LTEXT "Valid value : 1 - 9",IDD_AUTOC_STATIC_NOTE,278,61,93,8 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,91,15,150,10 + CONTROL "Function completion",IDD_AUTOC_FUNCRADIO,"Button",BS_AUTORADIOBUTTON | WS_GROUP,118,29,145,10 + CONTROL "Word completion",IDD_AUTOC_WORDRADIO,"Button",BS_AUTORADIOBUTTON,118,45,145,10 + RTEXT "From",IDD_AUTOC_STATIC_FROM,248,15,47,8 + CTEXT "1",IDD_AUTOC_STATIC_N,299,15,8,8,WS_TABSTOP + LTEXT "th character",IDD_AUTOC_STATIC_CHAR,313,15,57,8 + LTEXT "Valid value : 1 - 9",IDD_AUTOC_STATIC_NOTE,278,25,93,8 CONTROL "Function parameters hint on input",IDD_FUNC_CHECK, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,91,103,160,10 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,91,67,160,10 + + GROUPBOX "Auto-Insert",IDD_AUTOCINSERT_GRPSTATIC,86,94,289,84,BS_CENTER + CONTROL " (",IDD_AUTOCPARENTHESES_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,101,115,24,10 + CONTROL " [",IDD_AUTOCBRACKET_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,101,133,24,10 + CONTROL " {",IDD_AUTOCCURLYBRACKET_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,101,152,24,10 + CONTROL " """,IDD_AUTOC_DOUBLEQUOTESCHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,145,116,24,10 + CONTROL " '",IDD_AUTOC_QUOTESCHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,145,133,24,10 + CONTROL " html/xml close tag",IDD_AUTOCTAG_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,146,152,76,10 + RTEXT "Open",IDC_MACHEDPAIROPEN_STATIC,307,103,25,8 + LTEXT "Close",IDC_MACHEDPAIRCLOSE_STATIC,345,103,25,8 + RTEXT "Matched pair 1:",IDC_MACHEDPAIR_STATIC1,248,117,70,8 + EDITTEXT IDC_MACHEDPAIROPEN_EDIT1,320,115,10,14 + EDITTEXT IDC_MACHEDPAIRCLOSE_EDIT1,348,115,10,14 + RTEXT "Matched pair 2:",IDC_MACHEDPAIR_STATIC2,248,137,70,8 + EDITTEXT IDC_MACHEDPAIROPEN_EDIT2,320,135,10,14 + EDITTEXT IDC_MACHEDPAIRCLOSE_EDIT2,348,135,10,14 + RTEXT "Matched pair 3:",IDC_MACHEDPAIR_STATIC3,248,157,70,8 + EDITTEXT IDC_MACHEDPAIROPEN_EDIT3,320,155,10,14 + EDITTEXT IDC_MACHEDPAIRCLOSE_EDIT3,348,155,10,14 END IDD_PREFERENCE_MULTIINSTANCE_BOX DIALOGEX 0, 0, 455, 185 diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index c5635462..5fc56574 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -2361,7 +2361,7 @@ BOOL CALLBACK AutoCompletionDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM const int NB_MAX_CHAR = 9; ValueDlg valDlg; - NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); + //NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); valDlg.init(NULL, _hSelf, nppGUI._autocFromLen, TEXT("Nb char : ")); valDlg.setNBNumber(1); @@ -2382,6 +2382,37 @@ BOOL CALLBACK AutoCompletionDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM return TRUE; } + case IDD_AUTOCPARENTHESES_CHECK : + { + nppGUI._matchedPairConf._doParentheses = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_AUTOCPARENTHESES_CHECK, BM_GETCHECK, 0, 0)); + return TRUE; + } + case IDD_AUTOCBRACKET_CHECK : + { + nppGUI._matchedPairConf._doBrackets = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_AUTOCBRACKET_CHECK, BM_GETCHECK, 0, 0)); + return TRUE; + } + case IDD_AUTOCCURLYBRACKET_CHECK : + { + nppGUI._matchedPairConf._doCurlyBrackets = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_AUTOCCURLYBRACKET_CHECK, BM_GETCHECK, 0, 0)); + return TRUE; + } + + case IDD_AUTOC_DOUBLEQUOTESCHECK : + { + nppGUI._matchedPairConf._doDoubleQuotes = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_AUTOC_DOUBLEQUOTESCHECK, BM_GETCHECK, 0, 0)); + return TRUE; + } + case IDD_AUTOC_QUOTESCHECK : + { + nppGUI._matchedPairConf._doQuotes = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_AUTOC_QUOTESCHECK, BM_GETCHECK, 0, 0)); + return TRUE; + } + case IDD_AUTOCTAG_CHECK : + { + nppGUI._matchedPairConf._doHtmlXmlTag = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_AUTOCTAG_CHECK, BM_GETCHECK, 0, 0)); + return TRUE; + } default : return FALSE; } diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index 56ce9132..61c2b63a 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -277,5 +277,22 @@ #define IDD_FUNC_CHECK (IDD_PREFERENCE_BACKUP_BOX + 15) #define IDD_PREFERENCE_AUTOCOMPLETION_BOX 6850 //(IDD_PREFERENCE_BOX + 850) - + #define IDD_AUTOCINSERT_GRPSTATIC (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 1) + #define IDD_AUTOCPARENTHESES_CHECK (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 2) + #define IDD_AUTOCBRACKET_CHECK (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 3) + #define IDD_AUTOCCURLYBRACKET_CHECK (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 4) + #define IDD_AUTOC_DOUBLEQUOTESCHECK (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 5) + #define IDD_AUTOC_QUOTESCHECK (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 6) + #define IDD_AUTOCTAG_CHECK (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 7) + #define IDC_MACHEDPAIROPEN_STATIC (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 8) + #define IDC_MACHEDPAIRCLOSE_STATIC (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 9) + #define IDC_MACHEDPAIR_STATIC1 (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 10) + #define IDC_MACHEDPAIROPEN_EDIT1 (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 11) + #define IDC_MACHEDPAIRCLOSE_EDIT1 (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 12) + #define IDC_MACHEDPAIR_STATIC2 (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 13) + #define IDC_MACHEDPAIROPEN_EDIT2 (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 14) + #define IDC_MACHEDPAIRCLOSE_EDIT2 (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 15) + #define IDC_MACHEDPAIR_STATIC3 (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 16) + #define IDC_MACHEDPAIROPEN_EDIT3 (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 17) + #define IDC_MACHEDPAIRCLOSE_EDIT3 (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 18) #endif //PREFERENCE_RC_H