From 98a246c1e551663d6d69d0dafeefd7202750f1ef Mon Sep 17 00:00:00 2001 From: dail8859 Date: Sat, 1 Oct 2016 15:50:01 -0400 Subject: [PATCH] Add option to skip numbers during word completion Closes #2365, Closes #2378 --- PowerEditor/installer/nativeLang/english.xml | 1 + .../nativeLang/english_customizable.xml | 1 + PowerEditor/src/Parameters.cpp | 20 ++++++++++++---- PowerEditor/src/Parameters.h | 1 + .../src/ScitillaComponent/AutoCompletion.cpp | 11 ++++++++- .../src/WinControls/Preference/preference.rc | 2 ++ .../WinControls/Preference/preferenceDlg.cpp | 24 +++++++++++++++++++ .../WinControls/Preference/preference_rc.h | 1 + 8 files changed, 56 insertions(+), 5 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index 8b0b83d5e..1d5391748 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -774,6 +774,7 @@ + diff --git a/PowerEditor/installer/nativeLang/english_customizable.xml b/PowerEditor/installer/nativeLang/english_customizable.xml index ee4411b13..717ada1cf 100644 --- a/PowerEditor/installer/nativeLang/english_customizable.xml +++ b/PowerEditor/installer/nativeLang/english_customizable.xml @@ -767,6 +767,7 @@ + diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index aff8bce54..0a6ef6fdb 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -4555,8 +4555,12 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) if (element->Attribute(TEXT("triggerFromNbChar"), &i)) _nppGUI._autocFromLen = i; - const TCHAR * funcParams = element->Attribute(TEXT("funcParams")); - if (funcParams && !lstrcmp(funcParams, TEXT("yes"))) + const TCHAR * optName = element->Attribute(TEXT("autoCIgnoreNumbers")); + if (optName && !lstrcmp(optName, TEXT("yes"))) + _nppGUI._autocIgnoreNumbers = true; + + optName = element->Attribute(TEXT("funcParams")); + if (optName && !lstrcmp(optName, TEXT("yes"))) _nppGUI._funcParams = true; } else if (!lstrcmp(nm, TEXT("auto-insert"))) @@ -5476,7 +5480,11 @@ bool NppParameters::writeGUIParams() autocExist = true; element->SetAttribute(TEXT("autoCAction"), _nppGUI._autocStatus); element->SetAttribute(TEXT("triggerFromNbChar"), static_cast(_nppGUI._autocFromLen)); - const TCHAR * pStr = _nppGUI._funcParams?TEXT("yes"):TEXT("no"); + + const TCHAR * pStr = _nppGUI._autocIgnoreNumbers?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("autoCIgnoreNumbers"), pStr); + + pStr = _nppGUI._funcParams?TEXT("yes"):TEXT("no"); element->SetAttribute(TEXT("funcParams"), pStr); } else if (!lstrcmp(nm, TEXT("auto-insert"))) @@ -5780,7 +5788,11 @@ bool NppParameters::writeGUIParams() GUIConfigElement->SetAttribute(TEXT("name"), TEXT("auto-completion")); GUIConfigElement->SetAttribute(TEXT("autoCAction"), _nppGUI._autocStatus); GUIConfigElement->SetAttribute(TEXT("triggerFromNbChar"), static_cast(_nppGUI._autocFromLen)); - const TCHAR * pStr = _nppGUI._funcParams?TEXT("yes"):TEXT("no"); + + const TCHAR * pStr = _nppGUI._autocIgnoreNumbers?TEXT("yes"):TEXT("no"); + GUIConfigElement->SetAttribute(TEXT("autoCIgnoreNumbers"), pStr); + + pStr = _nppGUI._funcParams?TEXT("yes"):TEXT("no"); GUIConfigElement->SetAttribute(TEXT("funcParams"), pStr); } diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 5db44a7e1..78a5c8e3b 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -784,6 +784,7 @@ struct NppGUI final enum AutocStatus{autoc_none, autoc_func, autoc_word, autoc_both}; AutocStatus _autocStatus = autoc_both; size_t _autocFromLen = 1; + bool _autocIgnoreNumbers = false; bool _funcParams = false; MatchedPairConf _matchedPairConf; diff --git a/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp index e305279fe..8945560c9 100644 --- a/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp +++ b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp @@ -39,7 +39,12 @@ static bool isInList(generic_string word, const vector & wordArr if (wordArray[i] == word) return true; return false; -}; +} + +static bool isAllDigits(const generic_string &str) +{ + return std::all_of(str.begin(), str.end(), ::isdigit); +} bool AutoCompletion::showApiComplete() @@ -123,6 +128,10 @@ bool AutoCompletion::showApiAndWordComplete() void AutoCompletion::getWordArray(vector & wordArray, TCHAR *beginChars) { const size_t bufSize = 256; + const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI(); + + if (nppGUI._autocIgnoreNumbers && isAllDigits(beginChars)) + return; generic_string expr(TEXT("\\<")); expr += beginChars; diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index 6b12ba93b..c22af795d 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -325,6 +325,8 @@ BEGIN 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 "Ignore numbers",IDD_AUTOC_IGNORENUMBERS, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,278,55,80,10 CONTROL "Function parameters hint on input",IDD_FUNC_CHECK, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,91,72,160,10 GROUPBOX "Auto-Insert",IDD_AUTOCINSERT_GRPSTATIC,86,94,289,84,BS_CENTER diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index b9f03ccd6..f4a18c79d 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -2574,11 +2574,15 @@ INT_PTR CALLBACK AutoCompletionDlg::run_dlgProc(UINT message, WPARAM wParam, LPA ::SendDlgItemMessage(_hSelf, selectedID, BM_SETCHECK, BST_CHECKED, 0); + if (nppGUI._autocStatus == nppGUI.autoc_word || nppGUI._autocStatus == nppGUI.autoc_both) + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_IGNORENUMBERS, BM_SETCHECK, nppGUI._autocIgnoreNumbers ? BST_CHECKED : BST_UNCHECKED, 0); + if (!isEnableAutoC) { ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_FUNCRADIO), FALSE); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_WORDRADIO), FALSE); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_BOTHRADIO), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_IGNORENUMBERS), FALSE); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_FROM), FALSE); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), FALSE); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_CHAR), FALSE); @@ -2695,6 +2699,9 @@ INT_PTR CALLBACK AutoCompletionDlg::run_dlgProc(UINT message, WPARAM wParam, LPA { ::SendDlgItemMessage(_hSelf, IDD_AUTOC_BOTHRADIO, BM_SETCHECK, BST_CHECKED, 0); nppGUI._autocStatus = nppGUI.autoc_both; + + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_IGNORENUMBERS, BM_SETCHECK, BST_UNCHECKED, 0); + nppGUI._autocIgnoreNumbers = false; } else { @@ -2702,10 +2709,14 @@ INT_PTR CALLBACK AutoCompletionDlg::run_dlgProc(UINT message, WPARAM wParam, LPA ::SendDlgItemMessage(_hSelf, IDD_AUTOC_WORDRADIO, BM_SETCHECK, BST_UNCHECKED, 0); ::SendDlgItemMessage(_hSelf, IDD_AUTOC_BOTHRADIO, BM_SETCHECK, BST_UNCHECKED, 0); nppGUI._autocStatus = nppGUI.autoc_none; + + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_IGNORENUMBERS, BM_SETCHECK, BST_UNCHECKED, 0); + nppGUI._autocIgnoreNumbers = false; } ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_FUNCRADIO), isEnableAutoC); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_WORDRADIO), isEnableAutoC); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_BOTHRADIO), isEnableAutoC); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_IGNORENUMBERS), isEnableAutoC); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_FROM), isEnableAutoC); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), isEnableAutoC); ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_CHAR), isEnableAutoC); @@ -2716,18 +2727,31 @@ INT_PTR CALLBACK AutoCompletionDlg::run_dlgProc(UINT message, WPARAM wParam, LPA case IDD_AUTOC_FUNCRADIO : { nppGUI._autocStatus = nppGUI.autoc_func; + + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_IGNORENUMBERS, BM_SETCHECK, BST_UNCHECKED, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_IGNORENUMBERS), FALSE); + nppGUI._autocIgnoreNumbers = false; + return TRUE; } case IDD_AUTOC_WORDRADIO : { nppGUI._autocStatus = nppGUI.autoc_word; + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_IGNORENUMBERS), TRUE); return TRUE; } case IDD_AUTOC_BOTHRADIO : { nppGUI._autocStatus = nppGUI.autoc_both; + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_IGNORENUMBERS), TRUE); + return TRUE; + } + + case IDD_AUTOC_IGNORENUMBERS: + { + nppGUI._autocIgnoreNumbers = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_AUTOC_IGNORENUMBERS, BM_GETCHECK, 0, 0)); return TRUE; } diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index 5bc3a6756..a026c1dee 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -315,6 +315,7 @@ #define IDD_BACKUPDIR_RESTORESESSION_STATIC2 (IDD_PREFERENCE_BACKUP_BOX + 21) #define IDD_BACKUPDIR_RESTORESESSION_PATHLABEL_STATIC (IDD_PREFERENCE_BACKUP_BOX + 22) #define IDD_BACKUPDIR_RESTORESESSION_PATH_EDIT (IDD_PREFERENCE_BACKUP_BOX + 23) + #define IDD_AUTOC_IGNORENUMBERS (IDD_PREFERENCE_BACKUP_BOX + 24) #define IDD_PREFERENCE_AUTOCOMPLETION_BOX 6850 //(IDD_PREFERENCE_BOX + 850) #define IDD_AUTOCINSERT_GRPSTATIC (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 1)