Skip to content

Commit

Permalink
Add ability to copy marked text to the clipboard
Browse files Browse the repository at this point in the history
Fix #6095, close #8867
  • Loading branch information
sasumner authored and donho committed Oct 2, 2020
1 parent 5da0817 commit 9ab554a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 7 deletions.
4 changes: 3 additions & 1 deletion PowerEditor/installer/nativeLang/english.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<Item id="42029" name="Current File Path to Clipboard"/>
<Item id="42030" name="Current Filename to Clipboard"/>
<Item id="42031" name="Current Dir. Path to Clipboard"/>
<Item id="42079" name="Marked Text to Clipboard"/>
<Item id="42032" name="&amp;Run a Macro Multiple Times..."/>
<Item id="42033" name="Clear Read-Only Flag"/>
<Item id="42035" name="Single Line Comment"/>
Expand Down Expand Up @@ -398,8 +399,9 @@
<Item id="1641" name="Find All in Current Document"/>
<Item id="1686" name="Transparenc&amp;y"/>
<Item id="1703" name="&amp;. matches newline"/>
<Item id="1721" name=""/>
<Item id="1721" name=""/>
<Item id="1723" name="▼ Find Next"/>
<Item id="1725" name="Copy Marked Text to Clipboard"/>

This comment has been minimized.

Copy link
@rddim

rddim Oct 3, 2020

Contributor

This text (the current one and translated) is out of the room. The button needs to be more height (like Find All in Current Documents)

This comment has been minimized.

Copy link
@sasumner

sasumner Oct 3, 2020

Author Contributor

@rddim That text may have been an error. I intended it to be Copy Marked Text. I will fix it. Is that short enough to keep the button one line in the translation?

This comment has been minimized.

Copy link
@rddim

rddim Oct 3, 2020

Contributor

@sasumner Sorry, no, in Bulgarian translation it needs more - two lines is better. Even with only translated Copy Marked it need some more pixels longer :/

This comment has been minimized.

Copy link
@donho

donho Oct 4, 2020

Member

@rddim
Please use the abbreviation to reduce the length - for checkboxes we can always make it longer but not for the buttons.

</Find>

<FindCharsInRange title="Find Characters in Range...">
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/Notepad_plus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ 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
Expand Down
10 changes: 10 additions & 0 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,15 @@ 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 :
Expand Down Expand Up @@ -3533,6 +3542,7 @@ 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 :
Expand Down
1 change: 1 addition & 0 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ 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 },
Expand Down
64 changes: 60 additions & 4 deletions PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ void FindReplaceDlg::resizeDialogElements(LONG newWidth)

IDD_FINDINFILES_BROWSE_BUTTON, IDCMARKALL, IDC_CLEAR_ALL, IDCCOUNTALL, IDC_FINDALL_OPENEDFILES, IDC_FINDALL_CURRENTFILE,
IDREPLACE, IDREPLACEALL,IDC_REPLACE_OPENEDFILES, IDD_FINDINFILES_FIND_BUTTON, IDD_FINDINFILES_REPLACEINFILES, IDOK, IDCANCEL,
IDC_FINDPREV, IDC_FINDNEXT, IDC_2_BUTTONS_MODE
IDC_FINDPREV, IDC_FINDNEXT, IDC_2_BUTTONS_MODE, IDC_COPY_MARKED_TEXT
};

const UINT flags = SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS;
Expand Down Expand Up @@ -900,8 +900,8 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM

RECT arc;
::GetWindowRect(::GetDlgItem(_hSelf, IDCANCEL), &arc);
_findInFilesClosePos.bottom = _replaceClosePos.bottom = _findClosePos.bottom = arc.bottom - arc.top;
_findInFilesClosePos.right = _replaceClosePos.right = _findClosePos.right = arc.right - arc.left;
_markClosePos.bottom = _findInFilesClosePos.bottom = _replaceClosePos.bottom = _findClosePos.bottom = arc.bottom - arc.top;
_markClosePos.right = _findInFilesClosePos.right = _replaceClosePos.right = _findClosePos.right = arc.right - arc.left;

POINT p;
p.x = arc.left;
Expand All @@ -916,6 +916,10 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
_findInFilesClosePos.left = p.x;
_findInFilesClosePos.top = p.y;

p = getTopPoint(::GetDlgItem(_hSelf, IDC_REPLACE_OPENEDFILES), !_isRTL);
_markClosePos.left = p.x;
_markClosePos.top = p.y;

p = getTopPoint(::GetDlgItem(_hSelf, IDCANCEL), !_isRTL);
_findClosePos.left = p.x;
_findClosePos.top = p.y + 10;
Expand Down Expand Up @@ -1453,6 +1457,13 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
}
}
return TRUE;

case IDC_COPY_MARKED_TEXT:
{
markedTextToClipboard(SCE_UNIVERSAL_FOUND_STYLE);
}
return TRUE;

//Option actions
case IDREDOTMATCHNL:
findHistory._dotMatchesNewline = _options._dotMatchesNewline = isCheckedOrNot(IDREDOTMATCHNL);
Expand Down Expand Up @@ -2669,6 +2680,7 @@ void FindReplaceDlg::enableMarkAllControls(bool isEnable)
showFindDlgItem(IDC_PURGE_CHECK, isEnable);
showFindDlgItem(IDC_CLEAR_ALL, isEnable);
showFindDlgItem(IDC_IN_SELECTION_CHECK, isEnable);
showFindDlgItem(IDC_COPY_MARKED_TEXT, isEnable);
}

void FindReplaceDlg::enableFindInFilesControls(bool isEnable)
Expand Down Expand Up @@ -2701,7 +2713,8 @@ void FindReplaceDlg::enableFindInFilesControls(bool isEnable)
showFindDlgItem(IDC_IN_SELECTION_CHECK, !isEnable);
showFindDlgItem(IDC_CLEAR_ALL, !isEnable);
showFindDlgItem(IDCMARKALL, !isEnable);

showFindDlgItem(IDC_COPY_MARKED_TEXT, !isEnable);

showFindDlgItem(IDREPLACE, !isEnable);
showFindDlgItem(IDC_REPLACEINSELECTION, !isEnable);
showFindDlgItem(IDREPLACEALL, !isEnable);
Expand Down Expand Up @@ -3258,6 +3271,7 @@ void FindReplaceDlg::enableMarkFunc()
::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), _findInFilesClosePos.left + _deltaWidth, _findInFilesClosePos.top, _findInFilesClosePos.right, _findInFilesClosePos.bottom, TRUE);
::MoveWindow(::GetDlgItem(_hSelf, IDC_IN_SELECTION_CHECK), _replaceInSelCheckPos.left + _deltaWidth, _replaceInSelCheckPos.top, _replaceInSelCheckPos.right, _replaceInSelCheckPos.bottom, TRUE);
::MoveWindow(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION), _replaceInSelFramePos.left + _deltaWidth, _replaceInSelFramePos.top, _replaceInSelFramePos.right, _replaceInSelFramePos.bottom, TRUE);
::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), _markClosePos.left + _deltaWidth, _markClosePos.top, _markClosePos.right, _markClosePos.bottom, TRUE);

TCHAR label[MAX_PATH];
_tab.getCurrentTitle(label, MAX_PATH);
Expand Down Expand Up @@ -3392,6 +3406,48 @@ bool FindReplaceDlg::replaceInOpenDocsConfirmCheck(void)
return confirmed;
}

void FindReplaceDlg::markedTextToClipboard(int indiStyle)
{
auto pos = (*_ppEditView)->execute(SCI_INDICATOREND, indiStyle, 0);
if (pos > 0)
{
std::vector<generic_string> 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();
Expand Down
3 changes: 2 additions & 1 deletion PowerEditor/src/ScitillaComponent/FindReplaceDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public :
generic_string getScopeInfoForStatusBar(FindOption const *pFindOpt) const;
Finder * createFinder();
bool removeFinder(Finder *finder2remove);
void markedTextToClipboard(int indiStyle);

protected :
void resizeDialogElements(LONG newWidth);
Expand All @@ -360,7 +361,7 @@ private :
LONG _initialClientWidth;

DIALOG_TYPE _currentStatus;
RECT _findClosePos, _replaceClosePos, _findInFilesClosePos;
RECT _findClosePos, _replaceClosePos, _findInFilesClosePos, _markClosePos;
RECT _countInSelFramePos, _replaceInSelFramePos;
RECT _countInSelCheckPos, _replaceInSelCheckPos;

Expand Down
3 changes: 2 additions & 1 deletion PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BEGIN
PUSHBUTTON "", IDC_FINDPREV, 268, 20, 18, 14, WS_GROUP | BS_MULTILINE
PUSHBUTTON "", IDC_FINDNEXT, 289, 20, 70, 14, WS_GROUP | BS_MULTILINE
PUSHBUTTON "Find Next",IDOK,268,20,91,14,WS_GROUP
CONTROL "", IDC_2_BUTTONS_MODE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 363, 20, 15, 15
CONTROL "", IDC_2_BUTTONS_MODE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 363, 20, 15, 15
PUSHBUTTON "Coun&t",IDCCOUNTALL,268,38,91,14
PUSHBUTTON "Find All in Current &Document",IDC_FINDALL_CURRENTFILE,268,56,91,21,BS_MULTILINE
PUSHBUTTON "Find All in All &Opened Documents",IDC_FINDALL_OPENEDFILES,268,80,91,21,BS_MULTILINE
Expand All @@ -80,6 +80,7 @@ BEGIN
PUSHBUTTON "Replace All in All Opened Doc&uments",IDC_REPLACE_OPENEDFILES,268,74,91,21,BS_MULTILINE
PUSHBUTTON "Find All",IDD_FINDINFILES_FIND_BUTTON,268,20,91,14,WS_GROUP
PUSHBUTTON "Replace in Files",IDD_FINDINFILES_REPLACEINFILES,268,38,91,14
PUSHBUTTON "Copy Marked Text",IDC_COPY_MARKED_TEXT,268,56,91,14
PUSHBUTTON "Close",IDCANCEL,268,98,91,14
GROUPBOX "",IDC_TRANSPARENT_GRPBOX,258,131,99,48
CONTROL "Transparenc&y",IDC_TRANSPARENT_CHECK,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,254,131,80,10
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,6 @@
#define IDC_FINDNEXT 1723
#define IDC_2_BUTTONS_MODE 1724

#define IDC_COPY_MARKED_TEXT 1725

#endif //FINDREPLACE_DLG_H
1 change: 1 addition & 0 deletions PowerEditor/src/menuCmdID.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
#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)
Expand Down

0 comments on commit 9ab554a

Please sign in to comment.