From 3a2edb99c40f5577a29307f1321d9a3cbe2a69cb Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Fri, 7 Aug 2020 15:38:21 -0400 Subject: [PATCH] Add word-wrap option to find-results context menu Close #8624, close #8681 --- PowerEditor/installer/nativeLang/english.xml | 1 + PowerEditor/src/Parameters.cpp | 17 +++++++++ PowerEditor/src/Parameters.h | 2 + .../src/ScitillaComponent/FindReplaceDlg.cpp | 38 +++++++++++++++++++ .../src/ScitillaComponent/FindReplaceDlg.h | 2 + PowerEditor/src/resource.h | 1 + 6 files changed, 61 insertions(+) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index 078c5e68..f3881610 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1253,6 +1253,7 @@ Find in all files except exe, obj && log: + diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 765caa55..0ffc4a7e 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -4563,6 +4563,15 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) } } + else if (!lstrcmp(nm, TEXT("FinderConfig"))) + { + const TCHAR* val = element->Attribute(TEXT("wrappedLines")); + if (val) + { + _nppGUI._finderLinesAreCurrentlyWrapped = (!lstrcmp(val, TEXT("yes"))); + } + } + else if (!lstrcmp(nm, TEXT("NewDocDefaultSettings"))) { int i; @@ -5648,6 +5657,14 @@ void NppParameters::createXmlTreeFromGUIParams() GUIConfigElement->SetAttribute(TEXT("bottom"), _nppGUI._findWindowPos.bottom); } + // + { + TiXmlElement* GUIConfigElement = (newGUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("FinderConfig")); + const TCHAR* pStr = _nppGUI._finderLinesAreCurrentlyWrapped ? TEXT("yes") : TEXT("no"); + GUIConfigElement->SetAttribute(TEXT("wrappedLines"), pStr); + } + // no { TiXmlElement *element = insertGUIConfigBoolNode(newGUIRoot, TEXT("noUpdate"), !_nppGUI._autoUpdateOpt._doAutoUpdate); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 3fbfa066..44601892 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -803,6 +803,8 @@ struct NppGUI final int _tabSize = 4; bool _tabReplacedBySpace = false; + bool _finderLinesAreCurrentlyWrapped = false; + int _fileAutoDetection = cdEnabledNew; bool _checkHistoryFiles = false; diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index 88fb7459..2d9028f7 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -2346,6 +2346,13 @@ void FindReplaceDlg::findAllIn(InWhat op) _pFinder->_scintView.execute(SCI_SETUSETABS, true); _pFinder->_scintView.execute(SCI_SETTABWIDTH, 4); + NppParameters& nppParam = NppParameters::getInstance(); + NppGUI& nppGUI = const_cast(nppParam.getNppGUI()); + _pFinder->_longLinesAreWrapped = nppGUI._finderLinesAreCurrentlyWrapped; + _pFinder->_scintView.wrap(_pFinder->_longLinesAreWrapped); + _pFinder->_scintView.setWrapMode(LINEWRAP_INDENT); + _pFinder->_scintView.showWrapSymbol(true); + // allow user to start selecting as a stream block, then switch to a column block by adding Alt keypress _pFinder->_scintView.execute(SCI_SETMOUSESELECTIONRECTANGULARSWITCH, true); @@ -2454,6 +2461,12 @@ Finder * FindReplaceDlg::createFinder() pFinder->_scintView.execute(SCI_SETUSETABS, true); pFinder->_scintView.execute(SCI_SETTABWIDTH, 4); + // inherit setting from current state of main finder: + pFinder->_longLinesAreWrapped = _pFinder->_longLinesAreWrapped; + pFinder->_scintView.wrap(pFinder->_longLinesAreWrapped); + pFinder->_scintView.setWrapMode(LINEWRAP_INDENT); + pFinder->_scintView.showWrapSymbol(true); + // allow user to start selecting as a stream block, then switch to a column block by adding Alt keypress pFinder->_scintView.execute(SCI_SETMOUSESELECTIONRECTANGULARSWITCH, true); @@ -3447,6 +3460,20 @@ void Finder::openAll() } } +void Finder::wrapLongLinesToggle() +{ + _longLinesAreWrapped = !_longLinesAreWrapped; + _scintView.wrap(_longLinesAreWrapped); + + if (!_canBeVolatiled) + { + // only remember this setting from the original finder + NppParameters& nppParam = NppParameters::getInstance(); + NppGUI& nppGUI = const_cast(nppParam.getNppGUI()); + nppGUI._finderLinesAreCurrentlyWrapped = _longLinesAreWrapped; + } +} + bool Finder::isLineActualSearchResult(const generic_string & s) const { const auto firstColon = s.find(TEXT("\tLine ")); @@ -3678,6 +3705,12 @@ INT_PTR CALLBACK Finder::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) return TRUE; } + case NPPM_INTERNAL_SCINTILLAFINDERWRAP: + { + wrapLongLinesToggle(); + return TRUE; + } + default : { return FALSE; @@ -3704,6 +3737,7 @@ INT_PTR CALLBACK Finder::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) generic_string selectAll = pNativeSpeaker->getLocalizedStrFromID("finder-select-all", TEXT("Select all")); generic_string clearAll = pNativeSpeaker->getLocalizedStrFromID("finder-clear-all", TEXT("Clear all")); generic_string openAll = pNativeSpeaker->getLocalizedStrFromID("finder-open-all", TEXT("Open all")); + generic_string wrapLongLines = pNativeSpeaker->getLocalizedStrFromID("finder-wrap-long-lines", TEXT("Word wrap long lines")); tmp.push_back(MenuItemUnit(NPPM_INTERNAL_FINDINFINDERDLG, findInFinder)); if (_canBeVolatiled) @@ -3717,9 +3751,13 @@ INT_PTR CALLBACK Finder::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINFERCLEARALL, clearAll)); tmp.push_back(MenuItemUnit(0, TEXT("Separator"))); tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINFEROPENALL, openAll)); + tmp.push_back(MenuItemUnit(0, TEXT("Separator"))); + tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINDERWRAP, wrapLongLines)); scintillaContextmenu.create(_hSelf, tmp); + scintillaContextmenu.checkItem(NPPM_INTERNAL_SCINTILLAFINDERWRAP, _longLinesAreWrapped); + scintillaContextmenu.display(p); return TRUE; } diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h index e1b9e429..743f430c 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h @@ -130,6 +130,7 @@ public: void setFinderStyle(); void removeAll(); void openAll(); + void wrapLongLinesToggle(); void copy(); void beginNewFilesSearch(); void finishFilesSearch(int count, int searchedCount, bool isMatchLines, bool searchedEntireNotSelection); @@ -166,6 +167,7 @@ private: bool _canBeVolatiled = true; + bool _longLinesAreWrapped = false; void setFinderReadOnly(bool isReadOnly) { _scintView.execute(SCI_SETREADONLY, isReadOnly); diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index d9efbc10..8c63f91d 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -444,6 +444,7 @@ #define NPPM_INTERNAL_EDGEBACKGROUND (NOTEPADPLUS_USER_INTERNAL + 50) #define NPPM_INTERNAL_EDGEMULTISETSIZE (NOTEPADPLUS_USER_INTERNAL + 51) #define NPPM_INTERNAL_UPDATECLICKABLELINKS (NOTEPADPLUS_USER_INTERNAL + 52) + #define NPPM_INTERNAL_SCINTILLAFINDERWRAP (NOTEPADPLUS_USER_INTERNAL + 53) // See Notepad_plus_msgs.h //#define NOTEPADPLUS_USER (WM_USER + 1000)