[NEW_FEATURE] Add Copy/Cut/Paste Binary Content feature.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@741 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
a5083edfb5
commit
8b7e0b76c4
@ -1396,7 +1396,10 @@ void Notepad_plus::checkClipboard()
|
||||
bool canPaste = (_pEditView->execute(SCI_CANPASTE) != 0);
|
||||
enableCommand(IDM_EDIT_CUT, hasSelection, MENU | TOOLBAR);
|
||||
enableCommand(IDM_EDIT_COPY, hasSelection, MENU | TOOLBAR);
|
||||
|
||||
enableCommand(IDM_EDIT_PASTE, canPaste, MENU | TOOLBAR);
|
||||
//enableCommand(IDM_EDIT_PASTE, true, MENU | TOOLBAR);
|
||||
|
||||
enableCommand(IDM_EDIT_DELETE, hasSelection, MENU | TOOLBAR);
|
||||
enableCommand(IDM_EDIT_UPPERCASE, hasSelection, MENU);
|
||||
enableCommand(IDM_EDIT_LOWERCASE, hasSelection, MENU);
|
||||
|
@ -267,6 +267,10 @@ BEGIN
|
||||
BEGIN
|
||||
MENUITEM "Paste HTML Content", IDM_EDIT_PASTE_AS_HTML
|
||||
MENUITEM "Paste RTF Content", IDM_EDIT_PASTE_AS_RTF
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Copy Binary Content", IDM_EDIT_COPY_BINARY
|
||||
MENUITEM "Cut Binary Content", IDM_EDIT_CUT_BINARY
|
||||
MENUITEM "Paste Binary Content", IDM_EDIT_PASTE_BINARY
|
||||
END
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Column Mode...", IDM_EDIT_COLUMNMODETIP
|
||||
|
@ -23,7 +23,9 @@
|
||||
|
||||
#define CF_HTML TEXT("HTML Format")
|
||||
#define CF_RTF TEXT("Rich Text Format")
|
||||
#define CF_NPPTEXTLEN TEXT("Notepad++ Binary Text Length")
|
||||
|
||||
static int copyDataLen = 0;
|
||||
|
||||
void Notepad_plus::macroPlayback(Macro macro)
|
||||
{
|
||||
@ -138,6 +140,65 @@ void Notepad_plus::command(int id)
|
||||
checkClipboard();
|
||||
break;
|
||||
|
||||
case IDM_EDIT_COPY_BINARY:
|
||||
case IDM_EDIT_CUT_BINARY:
|
||||
{
|
||||
int textLen = _pEditView->execute(SCI_GETSELTEXT, 0, 0) - 1;
|
||||
if (!textLen)
|
||||
return;
|
||||
|
||||
char *pBinText = new char[textLen + 1];
|
||||
_pEditView->getSelectedText(pBinText, textLen + 1);
|
||||
|
||||
// Open the clipboard, and empty it.
|
||||
if (!OpenClipboard(NULL))
|
||||
return;
|
||||
EmptyClipboard();
|
||||
|
||||
// Allocate a global memory object for the text.
|
||||
HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (textLen + 1) * sizeof(unsigned char));
|
||||
if (hglbCopy == NULL)
|
||||
{
|
||||
CloseClipboard();
|
||||
return;
|
||||
}
|
||||
|
||||
// Lock the handle and copy the text to the buffer.
|
||||
unsigned char *lpucharCopy = (unsigned char *)GlobalLock(hglbCopy);
|
||||
memcpy(lpucharCopy, pBinText, textLen * sizeof(unsigned char));
|
||||
lpucharCopy[textLen] = 0; // null character
|
||||
|
||||
GlobalUnlock(hglbCopy);
|
||||
|
||||
// Place the handle on the clipboard.
|
||||
SetClipboardData(CF_TEXT, hglbCopy);
|
||||
|
||||
|
||||
// Allocate a global memory object for the text length.
|
||||
HGLOBAL hglbLenCopy = GlobalAlloc(GMEM_MOVEABLE, sizeof(unsigned long));
|
||||
if (hglbLenCopy == NULL)
|
||||
{
|
||||
CloseClipboard();
|
||||
return;
|
||||
}
|
||||
|
||||
// Lock the handle and copy the text to the buffer.
|
||||
unsigned long *lpLenCopy = (unsigned long *)GlobalLock(hglbLenCopy);
|
||||
*lpLenCopy = textLen;
|
||||
|
||||
GlobalUnlock(hglbLenCopy);
|
||||
|
||||
// Place the handle on the clipboard.
|
||||
UINT f = RegisterClipboardFormat(CF_NPPTEXTLEN);
|
||||
SetClipboardData(f, hglbLenCopy);
|
||||
|
||||
CloseClipboard();
|
||||
|
||||
if (id == IDM_EDIT_CUT_BINARY)
|
||||
_pEditView->execute(SCI_REPLACESEL, 0, (LPARAM)"");
|
||||
}
|
||||
break;
|
||||
|
||||
case IDM_EDIT_PASTE:
|
||||
{
|
||||
int eolMode = int(_pEditView->execute(SCI_GETEOLMODE));
|
||||
@ -146,6 +207,51 @@ void Notepad_plus::command(int id)
|
||||
}
|
||||
break;
|
||||
|
||||
case IDM_EDIT_PASTE_BINARY:
|
||||
{
|
||||
if (!IsClipboardFormatAvailable(CF_TEXT))
|
||||
return;
|
||||
|
||||
if (!OpenClipboard(NULL))
|
||||
return;
|
||||
|
||||
HGLOBAL hglb = GetClipboardData(CF_TEXT);
|
||||
if (hglb != NULL)
|
||||
{
|
||||
char *lpchar = (char *)GlobalLock(hglb);
|
||||
if (lpchar != NULL)
|
||||
{
|
||||
UINT cf_nppTextLen = RegisterClipboardFormat(CF_NPPTEXTLEN);
|
||||
if (IsClipboardFormatAvailable(cf_nppTextLen))
|
||||
{
|
||||
HGLOBAL hglbLen = GetClipboardData(cf_nppTextLen);
|
||||
if (hglbLen != NULL)
|
||||
{
|
||||
unsigned long *lpLen = (unsigned long *)GlobalLock(hglbLen);
|
||||
if (lpLen != NULL)
|
||||
{
|
||||
_pEditView->execute(SCI_REPLACESEL, 0, (LPARAM)"");
|
||||
_pEditView->execute(SCI_ADDTEXT, *lpLen, (LPARAM)lpchar);
|
||||
|
||||
GlobalUnlock(hglb);
|
||||
}
|
||||
}
|
||||
_pEditView->execute(SCI_REPLACESEL, 0, (LPARAM)"");
|
||||
_pEditView->execute(SCI_ADDTEXT, copyDataLen, (LPARAM)lpchar);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
_pEditView->execute(SCI_REPLACESEL, 0, (LPARAM)lpchar);
|
||||
}
|
||||
GlobalUnlock(hglb);
|
||||
}
|
||||
}
|
||||
CloseClipboard();
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case IDM_EDIT_PASTE_AS_RTF:
|
||||
case IDM_EDIT_PASTE_AS_HTML:
|
||||
{
|
||||
|
@ -101,7 +101,9 @@
|
||||
#define IDM_EDIT_COLUMNMODETIP (IDM_EDIT + 37)
|
||||
#define IDM_EDIT_PASTE_AS_HTML (IDM_EDIT + 38)
|
||||
#define IDM_EDIT_PASTE_AS_RTF (IDM_EDIT + 39)
|
||||
|
||||
#define IDM_EDIT_COPY_BINARY (IDM_EDIT + 48)
|
||||
#define IDM_EDIT_CUT_BINARY (IDM_EDIT + 49)
|
||||
#define IDM_EDIT_PASTE_BINARY (IDM_EDIT + 50)
|
||||
|
||||
#define IDM_EDIT_AUTOCOMPLETE (50000 + 0)
|
||||
#define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000 + 1)
|
||||
|
Loading…
Reference in New Issue
Block a user