Skip to content

Commit

Permalink
[NEW_FEATURE] Add Clipboard History feature.
Browse files Browse the repository at this point in the history
- Notepad-plus svn trunk @ 748
  • Loading branch information
donho committed Apr 20, 2011
1 parent 4b2e5f3 commit f653461
Show file tree
Hide file tree
Showing 10 changed files with 402 additions and 7 deletions.
33 changes: 31 additions & 2 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Notepad_plus::Notepad_plus(): _mainWindowStatus(0), _pDocTab(NULL), _pEditView(N
_recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false),
_linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _sysMenuEntering(false),
_autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView), _smartHighlighter(&_findReplaceDlg),
_isFileOpening(false), _rememberThisSession(true), _pAnsiCharPanel(NULL)
_isFileOpening(false), _rememberThisSession(true), _pAnsiCharPanel(NULL), _pClipboardHistoryPanel(NULL)
{
ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange));

Expand Down Expand Up @@ -145,6 +145,9 @@ Notepad_plus::~Notepad_plus()

if (_pAnsiCharPanel)
delete _pAnsiCharPanel;

if (_pClipboardHistoryPanel)
delete _pClipboardHistoryPanel;
}


Expand Down Expand Up @@ -1394,7 +1397,6 @@ void Notepad_plus::enableCommand(int cmdID, bool doEnable, int which) const

void Notepad_plus::checkClipboard()
{

bool hasSelection = (_pEditView->execute(SCI_GETSELECTIONSTART) != _pEditView->execute(SCI_GETSELECTIONEND)) || (_pEditView->execute(SCI_GETSELECTIONS) > 0);
bool canPaste = (_pEditView->execute(SCI_CANPASTE) != 0);
enableCommand(IDM_EDIT_CUT, hasSelection, MENU | TOOLBAR);
Expand Down Expand Up @@ -4563,6 +4565,33 @@ bool Notepad_plus::reloadLang()
return true;
}

void Notepad_plus::launchClipboardHistoryPanel()
{
if (!_pClipboardHistoryPanel)
{
_pClipboardHistoryPanel = new ClipboardHistoryPanel();

_pClipboardHistoryPanel->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), &_pEditView);

tTbData data = {0};
_pClipboardHistoryPanel->create(&data);

::SendMessage(_pPublicInterface->getHSelf(), NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_pClipboardHistoryPanel->getHSelf());
// define the default docking behaviour
data.uMask = DWS_DF_CONT_RIGHT | DWS_ICONTAB | DWS_ADDINFO;
data.hIconTab = (HICON)::LoadImage(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDI_FIND_RESULT_ICON), IMAGE_ICON, 0, 0, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
//data.pszAddInfo = _findAllResultStr;

data.pszModuleName = TEXT("dummy");

// the dlgDlg should be the index of funcItem where the current function pointer is
// in this case is DOCKABLE_DEMO_INDEX
data.dlgID = 0;
::SendMessage(_pPublicInterface->getHSelf(), NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data);
}
_pClipboardHistoryPanel->display();
}

void Notepad_plus::launchAnsiCharPanel()
{
if (!_pAnsiCharPanel)
Expand Down
3 changes: 3 additions & 0 deletions PowerEditor/src/Notepad_plus.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@

#include "localization.h"
#include "ansiCharPanel.h"
#include "clipboardHistoryPanel.h"

#define MENU 0x01
#define TOOLBAR 0x02
Expand Down Expand Up @@ -389,6 +390,7 @@ friend class Notepad_plus_Window;


AnsiCharPanel *_pAnsiCharPanel;
ClipboardHistoryPanel *_pClipboardHistoryPanel;

BOOL notify(SCNotification *notification);
void specialCmd(int id);
Expand Down Expand Up @@ -573,6 +575,7 @@ friend class Notepad_plus_Window;
void wsTabConvert(bool whichWay);
void doTrim(trimOp whichPart);
void launchAnsiCharPanel();
void launchClipboardHistoryPanel();
};


Expand Down
1 change: 1 addition & 0 deletions PowerEditor/src/Notepad_plus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ BEGIN
MENUITEM "Column Mode...", IDM_EDIT_COLUMNMODETIP
MENUITEM "Column Editor...", IDM_EDIT_COLUMNMODE
MENUITEM "Character Panel", IDM_EDIT_CHAR_PANEL
MENUITEM "Clipboard History", IDM_EDIT_CLIPBOARDHISTORY_PANEL
MENUITEM SEPARATOR
MENUITEM "Set Read-Only", IDM_EDIT_SETREADONLY
MENUITEM "Clear Read-Only Flag", IDM_EDIT_CLEARREADONLY
Expand Down
10 changes: 7 additions & 3 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
#include "EncodingMapper.h"
#include "ShortcutMapper.h"
#include "TaskListDlg.h"
#include "clipboardFormats.h"

#define CF_HTML TEXT("HTML Format")
#define CF_RTF TEXT("Rich Text Format")
#define CF_NPPTEXTLEN TEXT("Notepad++ Binary Text Length")

void Notepad_plus::macroPlayback(Macro macro)
{
Expand Down Expand Up @@ -283,6 +281,12 @@ void Notepad_plus::command(int id)
}
break;

case IDM_EDIT_CLIPBOARDHISTORY_PANEL:
{
launchClipboardHistoryPanel();
}
break;

case IDM_EDIT_DELETE:
_pEditView->execute(WM_CLEAR);
break;
Expand Down
200 changes: 200 additions & 0 deletions PowerEditor/src/WinControls/ClipboardHistory/clipboardHistoryPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/*
this file is part of notepad++
Copyright (C)2011 Don HO <donho@altern.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a Copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "precompiledHeaders.h"
#include "clipboardHistoryPanel.h"
#include "ScintillaEditView.h"
#include "clipboardFormats.h"

void ClipboardHistoryPanel::switchEncoding()
{
//int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding();
}

ClipboardData ClipboardHistoryPanel::getClipboadData()
{
ClipboardData clipboardData;
if (!IsClipboardFormatAvailable(CF_UNICODETEXT))
return clipboardData;

if (!OpenClipboard(NULL))
return clipboardData;

HGLOBAL hglb = GetClipboardData(CF_UNICODETEXT);
if (hglb != NULL)
{
char *lpchar = (char *)GlobalLock(hglb);
wchar_t *lpWchar = (wchar_t *)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)
{
for (size_t i = 0 ; i < (*lpLen) ; i++)
{
clipboardData.push_back((unsigned char)lpchar[i]);
}
GlobalUnlock(hglb);
}
}
}
else
{
int nbBytes = (lstrlenW(lpWchar) + 1) * sizeof(wchar_t);
for (int i = 0 ; i < nbBytes ; i++)
{
clipboardData.push_back((unsigned char)lpchar[i]);
}
}
GlobalUnlock(hglb);
}
}
CloseClipboard();
return clipboardData;
}

ByteArray::ByteArray(ClipboardData cd)
{
_length = cd.size();
if (!_length)
{
_pBytes = NULL;
return;
}
_pBytes = new unsigned char[_length];
for (size_t i = 0 ; i < _length ; i++)
{
_pBytes[i] = cd[i];
}
}

StringArray::StringArray(ClipboardData cd, size_t maxLen)
{
if (!cd.size())
{
_pBytes = NULL;
return;
}

bool isCompleted = (cd.size() <= maxLen);
_length = isCompleted?cd.size():maxLen;


_pBytes = new unsigned char[_length+(isCompleted?0:2)];
size_t i = 0;
for ( ; i < _length ; i++)
{
if (!isCompleted && (i == _length-3 || i == _length-2 || i == _length-1))
_pBytes[i] = '.';
else
_pBytes[i] = cd[i];
}

if (!isCompleted)
{
_pBytes[i++] = 0;
_pBytes[i] = 0;
}
}

void ClipboardHistoryPanel::addToClipboadHistory(ClipboardData cbd)
{
_clipboardDataVector.insert(_clipboardDataVector.begin(), cbd);
//wstring s = clipboardDataToDisplayString(cbd);
StringArray sa(cbd, 64);
TCHAR *displayStr = (TCHAR *)sa.getPointer();
::SendDlgItemMessage(_hSelf, IDC_LIST_CLIPBOARD, LB_INSERTSTRING, 0, (LPARAM)displayStr);
}

BOOL CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG :
{
::SetClipboardViewer(_hSelf);
return TRUE;
}
case WM_DRAWCLIPBOARD :
{
//::MessageBoxA(NULL, "Catch u", "", MB_OK);
ClipboardData clipboardData = getClipboadData();
addToClipboadHistory(clipboardData);
return TRUE;
}

case WM_COMMAND :
{
switch (LOWORD(wParam))
{
case IDC_LIST_CLIPBOARD:
{
if (HIWORD(wParam) == LBN_DBLCLK)
{
int i = ::SendDlgItemMessage(_hSelf, IDC_LIST_CLIPBOARD, LB_GETCURSEL, 0, 0);
if (i != LB_ERR)
{
int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding();
if (codepage == -1)
{
int cp = (*_ppEditView)->execute(SCI_GETCODEPAGE);
codepage = cp==SC_CP_UTF8?SC_CP_UTF8:0;
}
else
codepage = SC_CP_UTF8;

ByteArray ba(_clipboardDataVector[i]);

int nbChar = WideCharToMultiByte(codepage, 0, (wchar_t *)ba.getPointer(), ba.getLength(), NULL, 0, NULL, NULL);

char *c = new char[nbChar+1];
WideCharToMultiByte(codepage, 0, (wchar_t *)ba.getPointer(), ba.getLength(), c, nbChar+1, NULL, NULL);

(*_ppEditView)->execute(SCI_REPLACESEL, 0, (LPARAM)"");
(*_ppEditView)->execute(SCI_ADDTEXT, strlen(c), (LPARAM)c);

delete [] c;
}
}
return TRUE;
}
}
}
break;

case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
::MoveWindow(::GetDlgItem(_hSelf, IDC_LIST_CLIPBOARD), 0, 0, width, height, TRUE);
break;
}

default :
return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}
return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}

0 comments on commit f653461

Please sign in to comment.