From 013305f306039998c0ba8a85c03238843879b6cf Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Tue, 6 Oct 2020 15:44:58 -0400 Subject: [PATCH] Add copy styled text to clipboard commands to menu Close #8943, close #8964 --- PowerEditor/installer/nativeLang/english.xml | 18 +++- PowerEditor/src/Notepad_plus.rc | 12 ++- PowerEditor/src/NppCommands.cpp | 55 +++++++++--- PowerEditor/src/Parameters.cpp | 9 +- .../src/ScitillaComponent/FindReplaceDlg.cpp | 44 +--------- .../src/ScitillaComponent/FindReplaceDlg.h | 1 - .../ScitillaComponent/ScintillaEditView.cpp | 85 +++++++++++++++++++ .../src/ScitillaComponent/ScintillaEditView.h | 2 + PowerEditor/src/localization.cpp | 3 +- PowerEditor/src/menuCmdID.h | 11 ++- 10 files changed, 176 insertions(+), 64 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index 3f64f21ca..2aa80d2e0 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -37,6 +37,7 @@ + @@ -166,7 +167,6 @@ - @@ -220,6 +220,13 @@ + + + + + + + @@ -401,7 +408,7 @@ - + @@ -546,6 +553,13 @@ + + + + + + + diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index d9acf9d22..d4cfb149a 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -288,8 +288,6 @@ BEGIN MENUITEM "Current Full File path to Clipboard", IDM_EDIT_FULLPATHTOCLIP MENUITEM "Current Filename to Clipboard", IDM_EDIT_FILENAMETOCLIP MENUITEM "Current Dir. Path to Clipboard", IDM_EDIT_CURRENTDIRTOCLIP - MENUITEM SEPARATOR - MENUITEM "Marked Text to Clipboard", IDM_EDIT_MARKEDTOCLIP END POPUP "Indent" BEGIN @@ -450,6 +448,16 @@ BEGIN MENUITEM "5th Style", IDM_SEARCH_GONEXTMARKER5 MENUITEM "Find Style", IDM_SEARCH_GONEXTMARKER_DEF END + POPUP "Copy Styled Text" + BEGIN + MENUITEM "1st Style", IDM_SEARCH_STYLE1TOCLIP + MENUITEM "2nd Style", IDM_SEARCH_STYLE2TOCLIP + MENUITEM "3rd Style", IDM_SEARCH_STYLE3TOCLIP + MENUITEM "4th Style", IDM_SEARCH_STYLE4TOCLIP + MENUITEM "5th Style", IDM_SEARCH_STYLE5TOCLIP + MENUITEM "All Styles", IDM_SEARCH_ALLSTYLESTOCLIP + MENUITEM "Find Style (Marked)", IDM_SEARCH_MARKEDTOCLIP + END MENUITEM SEPARATOR POPUP "Bookmark" BEGIN diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 4d939f341..9bd2b5d76 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1048,15 +1048,6 @@ void Notepad_plus::command(int id) } break; - case IDM_EDIT_MARKEDTOCLIP: - { - if (_findReplaceDlg.isCreated()) - { - _findReplaceDlg.markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE); - } - } - break; - case IDM_SEARCH_FIND : case IDM_SEARCH_REPLACE : case IDM_SEARCH_MARK : @@ -1338,7 +1329,43 @@ void Notepad_plus::command(int id) } break; - case IDM_SEARCH_GOTOLINE : + case IDM_SEARCH_STYLE1TOCLIP: + { + _pEditView->markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE_EXT1); + } + break; + case IDM_SEARCH_STYLE2TOCLIP: + { + _pEditView->markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE_EXT2); + } + break; + case IDM_SEARCH_STYLE3TOCLIP: + { + _pEditView->markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE_EXT3); + } + break; + case IDM_SEARCH_STYLE4TOCLIP: + { + _pEditView->markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE_EXT4); + } + break; + case IDM_SEARCH_STYLE5TOCLIP: + { + _pEditView->markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE_EXT5); + } + break; + case IDM_SEARCH_ALLSTYLESTOCLIP: + { + _pEditView->markedTextToClipboard(-1, true); + } + break; + case IDM_SEARCH_MARKEDTOCLIP: + { + _pEditView->markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE); + } + break; + + case IDM_SEARCH_GOTOLINE: { bool isFirstTime = !_goToLineDlg.isCreated(); _goToLineDlg.doDialog(_nativeLangSpeaker.isRTL()); @@ -3542,7 +3569,6 @@ void Notepad_plus::command(int id) case IDM_EDIT_FULLPATHTOCLIP : case IDM_EDIT_FILENAMETOCLIP : case IDM_EDIT_CURRENTDIRTOCLIP : - case IDM_EDIT_MARKEDTOCLIP: case IDM_EDIT_CLEARREADONLY : case IDM_EDIT_RTL : case IDM_EDIT_LTR : @@ -3613,6 +3639,13 @@ void Notepad_plus::command(int id) case IDM_SEARCH_GONEXTMARKER4 : case IDM_SEARCH_GONEXTMARKER5 : case IDM_SEARCH_GONEXTMARKER_DEF: + case IDM_SEARCH_STYLE1TOCLIP: + case IDM_SEARCH_STYLE2TOCLIP: + case IDM_SEARCH_STYLE3TOCLIP: + case IDM_SEARCH_STYLE4TOCLIP: + case IDM_SEARCH_STYLE5TOCLIP: + case IDM_SEARCH_ALLSTYLESTOCLIP: + case IDM_SEARCH_MARKEDTOCLIP: case IDM_SEARCH_VOLATILE_FINDNEXT: case IDM_SEARCH_VOLATILE_FINDPREV: case IDM_SEARCH_CUTMARKEDLINES : diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 203ada3c2..0361a2721 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -117,7 +117,6 @@ static const WinMenuKeyDefinition winKeyDefs[] = { VK_NULL, IDM_EDIT_FULLPATHTOCLIP, false, false, false, nullptr }, { VK_NULL, IDM_EDIT_FILENAMETOCLIP, false, false, false, nullptr }, { VK_NULL, IDM_EDIT_CURRENTDIRTOCLIP, false, false, false, nullptr }, - { VK_NULL, IDM_EDIT_MARKEDTOCLIP, false, false, false, nullptr }, { VK_NULL, IDM_EDIT_INS_TAB, false, false, false, nullptr }, { VK_NULL, IDM_EDIT_RMV_TAB, false, false, false, nullptr }, { VK_U, IDM_EDIT_UPPERCASE, true, false, true, nullptr }, @@ -223,7 +222,13 @@ static const WinMenuKeyDefinition winKeyDefs[] = { VK_4, IDM_SEARCH_GONEXTMARKER4, true, false, false, TEXT("Next mark using 4th style") }, { VK_5, IDM_SEARCH_GONEXTMARKER5, true, false, false, TEXT("Next mark using 5th style") }, { VK_0, IDM_SEARCH_GONEXTMARKER_DEF, true, false, false, TEXT("Next mark created with Mark") }, - + { VK_NULL, IDM_SEARCH_STYLE1TOCLIP, false, false, false, TEXT("Copy Styled Text - 1st Style") }, + { VK_NULL, IDM_SEARCH_STYLE2TOCLIP, false, false, false, TEXT("Copy Styled Text - 2nd Style") }, + { VK_NULL, IDM_SEARCH_STYLE3TOCLIP, false, false, false, TEXT("Copy Styled Text - 3rd Style") }, + { VK_NULL, IDM_SEARCH_STYLE4TOCLIP, false, false, false, TEXT("Copy Styled Text - 4th Style") }, + { VK_NULL, IDM_SEARCH_STYLE5TOCLIP, false, false, false, TEXT("Copy Styled Text - 5th Style") }, + { VK_NULL, IDM_SEARCH_ALLSTYLESTOCLIP, false, false, false, TEXT("Copy Styled Text - All Styles") }, + { VK_NULL, IDM_SEARCH_MARKEDTOCLIP, false, false, false, TEXT("Copy Styled Text - Find Style (Marked)") }, { VK_F2, IDM_SEARCH_TOGGLE_BOOKMARK, true, false, false, nullptr }, { VK_F2, IDM_SEARCH_NEXT_BOOKMARK, false, false, false, nullptr }, { VK_F2, IDM_SEARCH_PREV_BOOKMARK, false, false, true, nullptr }, diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index c1b905f69..91f72a273 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -1460,7 +1460,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM case IDC_COPY_MARKED_TEXT: { - markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE); + (*_ppEditView)->markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE); } return TRUE; @@ -3406,48 +3406,6 @@ bool FindReplaceDlg::replaceInOpenDocsConfirmCheck(void) return confirmed; } -void FindReplaceDlg::markedTextToClipboard(int indiStyle) -{ - auto pos = (*_ppEditView)->execute(SCI_INDICATOREND, indiStyle, 0); - if (pos > 0) - { - std::vector markedTextStr; - bool atEndOfIndic = (*_ppEditView)->execute(SCI_INDICATORVALUEAT, indiStyle, 0) != 0; - auto prevPos = pos; - if (atEndOfIndic) prevPos = 0; - - const generic_string cr = TEXT("\r"); - const generic_string lf = TEXT("\n"); - bool dataHasLineEndingChar = false; - - do - { - if (atEndOfIndic) - { - generic_string s = (*_ppEditView)->getGenericTextAsString(prevPos, pos); - if (!dataHasLineEndingChar) - { - if (s.find(cr) != std::string::npos || s.find(lf) != std::string::npos) - { - dataHasLineEndingChar = true; - } - } - markedTextStr.push_back(s); - } - atEndOfIndic = !atEndOfIndic; - prevPos = pos; - pos = (*_ppEditView)->execute(SCI_INDICATOREND, indiStyle, pos); - } while (pos != prevPos); - - if (markedTextStr.size() > 0) - { - const generic_string delim = dataHasLineEndingChar ? TEXT("\r\n----\r\n") : TEXT("\r\n"); - generic_string joined = stringJoin(markedTextStr, delim) + delim; - str2Clipboard(joined, NULL); - } - } -} - generic_string Finder::getHitsString(int count) const { NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h index 2b3595a3c..21a3da52c 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h @@ -340,7 +340,6 @@ public : generic_string getScopeInfoForStatusBar(FindOption const *pFindOpt) const; Finder * createFinder(); bool removeFinder(Finder *finder2remove); - void markedTextToClipboard(int indiStyle); protected : void resizeDialogElements(LONG newWidth); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 8519e80a7..bd01ef005 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -3786,3 +3786,88 @@ int ScintillaEditView::getUnicodeSelectedLength() const return length; }; + + +void ScintillaEditView::markedTextToClipboard(int indiStyle, bool doAll /*= false*/) +{ + int styleIndicators[] = + { + SCE_UNIVERSAL_FOUND_STYLE_EXT1, + SCE_UNIVERSAL_FOUND_STYLE_EXT2, + SCE_UNIVERSAL_FOUND_STYLE_EXT3, + SCE_UNIVERSAL_FOUND_STYLE_EXT4, + SCE_UNIVERSAL_FOUND_STYLE_EXT5, + -1 // end signifier + }; + + if (!doAll) + { + styleIndicators[0] = indiStyle; + styleIndicators[1] = -1; + } + + // vector of pairs: starting position of styled text, and styled text + std::vector> styledVect; + + const generic_string cr = TEXT("\r"); + const generic_string lf = TEXT("\n"); + + bool textContainsLineEndingChar = false; + + for (int si = 0; styleIndicators[si] != -1; ++si) + { + int pos = static_cast(execute(SCI_INDICATOREND, styleIndicators[si], 0)); + if (pos > 0) + { + bool atEndOfIndic = execute(SCI_INDICATORVALUEAT, styleIndicators[si], 0) != 0; + int prevPos = pos; + if (atEndOfIndic) prevPos = 0; + + do + { + if (atEndOfIndic) + { + generic_string styledText = getGenericTextAsString(prevPos, pos); + if (!textContainsLineEndingChar) + { + if (styledText.find(cr) != std::string::npos || + styledText.find(lf) != std::string::npos) + { + textContainsLineEndingChar = true; + } + } + styledVect.push_back(::make_pair(prevPos, styledText)); + } + atEndOfIndic = !atEndOfIndic; + prevPos = pos; + pos = static_cast(execute(SCI_INDICATOREND, styleIndicators[si], pos)); + } while (pos != prevPos); + } + } + + if (styledVect.size() > 0) + { + if (doAll) + { + // sort by starting position of styled text + std::sort(styledVect.begin(), styledVect.end()); + } + + const generic_string delim = + (textContainsLineEndingChar && styledVect.size() > 1) ? + TEXT("\r\n----\r\n") : TEXT("\r\n"); + + generic_string joined; + for (auto item : styledVect) + { + joined += delim + item.second; + } + joined = joined.substr(delim.length()); + if (styledVect.size() > 1) + { + joined += TEXT("\r\n"); + } + + str2Clipboard(joined, NULL); + } +} diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index de36af12a..2fa659d98 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -620,6 +620,8 @@ public: void changeTextDirection(bool isRTL); bool isTextDirectionRTL() const; void setPositionRestoreNeeded(bool val) { _positionRestoreNeeded = val; }; + void markedTextToClipboard(int indiStyle, bool doAll = false); + protected: static HINSTANCE _hLib; static int _refCount; diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index c4a351c4d..e818b4fba 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -69,7 +69,8 @@ MenuPosition menuPos[] = { { 2, 19, -1, "search-unmarkAll" }, { 2, 20, -1, "search-jumpUp" }, { 2, 21, -1, "search-jumpDown" }, - { 2, 23, -1, "search-bookmark" }, + { 2, 22, -1, "search-copyStyledText" }, + { 2, 24, -1, "search-bookmark" }, { 3, 4, -1, "view-currentFileIn" }, { 3, 6, -1, "view-showSymbol" }, diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 6af9a447f..cfc62149f 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -168,7 +168,6 @@ #define IDM_EDIT_FULLPATHTOCLIP (IDM_EDIT + 29) #define IDM_EDIT_FILENAMETOCLIP (IDM_EDIT + 30) #define IDM_EDIT_CURRENTDIRTOCLIP (IDM_EDIT + 31) - #define IDM_EDIT_MARKEDTOCLIP (IDM_EDIT + 79) // Menu macro #define IDM_MACRO_RUNMULTIMACRODLG (IDM_EDIT + 32) @@ -252,7 +251,15 @@ #define IDM_SEARCH_FINDCHARINRANGE (IDM_SEARCH + 52) #define IDM_SEARCH_SELECTMATCHINGBRACES (IDM_SEARCH + 53) #define IDM_SEARCH_MARK (IDM_SEARCH + 54) - + + #define IDM_SEARCH_STYLE1TOCLIP (IDM_SEARCH + 55) + #define IDM_SEARCH_STYLE2TOCLIP (IDM_SEARCH + 56) + #define IDM_SEARCH_STYLE3TOCLIP (IDM_SEARCH + 57) + #define IDM_SEARCH_STYLE4TOCLIP (IDM_SEARCH + 58) + #define IDM_SEARCH_STYLE5TOCLIP (IDM_SEARCH + 59) + #define IDM_SEARCH_ALLSTYLESTOCLIP (IDM_SEARCH + 60) + #define IDM_SEARCH_MARKEDTOCLIP (IDM_SEARCH + 61) + #define IDM_MISC (IDM + 3500) #define IDM_FILESWITCHER_FILESCLOSE (IDM_MISC + 1) #define IDM_FILESWITCHER_FILESCLOSEOTHERS (IDM_MISC + 2)