[NEW_FEATURE] Add Clipboard History feature.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@748 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/trunk
Don Ho 2011-04-20 21:45:18 +00:00
parent 4afbeefc0a
commit 7b54c09db9
10 changed files with 402 additions and 7 deletions

View File

@ -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));
@ -145,6 +145,9 @@ Notepad_plus::~Notepad_plus()
if (_pAnsiCharPanel)
delete _pAnsiCharPanel;
if (_pClipboardHistoryPanel)
delete _pClipboardHistoryPanel;
}
@ -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);
@ -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)

View File

@ -112,6 +112,7 @@
#include "localization.h"
#include "ansiCharPanel.h"
#include "clipboardHistoryPanel.h"
#define MENU 0x01
#define TOOLBAR 0x02
@ -389,6 +390,7 @@ private:
AnsiCharPanel *_pAnsiCharPanel;
ClipboardHistoryPanel *_pClipboardHistoryPanel;
BOOL notify(SCNotification *notification);
void specialCmd(int id);
@ -573,6 +575,7 @@ private:
void wsTabConvert(bool whichWay);
void doTrim(trimOp whichPart);
void launchAnsiCharPanel();
void launchClipboardHistoryPanel();
};

View File

@ -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

View File

@ -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)
{
@ -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;

View File

@ -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);
}

View File

@ -0,0 +1,86 @@
/*
this file is part of notepad++
Copyright (C)2003 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.
*/
#ifndef CLIPBOARDHISTORYPANEL_H
#define CLIPBOARDHISTORYPANEL_H
//#include <windows.h>
#ifndef DOCKINGDLGINTERFACE_H
#include "DockingDlgInterface.h"
#endif //DOCKINGDLGINTERFACE_H
#include "clipboardHistoryPanel_rc.h"
#include <vector>
typedef std::vector<unsigned char> ClipboardData;
class ScintillaEditView;
class ByteArray {
public:
ByteArray():_pBytes(NULL), _length(0) {};
ByteArray(ClipboardData cd);
~ByteArray() {
if (_pBytes)
delete [] _pBytes;
_pBytes = NULL;
_length = 0;
};
const unsigned char * getPointer() const {return _pBytes;};
size_t getLength() const {return _length;};
protected:
unsigned char *_pBytes;
size_t _length;
};
class StringArray : public ByteArray {
public:
StringArray(ClipboardData cd, size_t maxLen);
};
class ClipboardHistoryPanel : public DockingDlgInterface {
public:
ClipboardHistoryPanel(): DockingDlgInterface(IDD_CLIPBOARDHISTORY_PANEL) {};
void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) {
DockingDlgInterface::init(hInst, hPere);
_ppEditView = ppEditView;
};
virtual void display(bool toShow = true) const {
DockingDlgInterface::display(toShow);
};
void setParent(HWND parent2set){
_hParent = parent2set;
};
void switchEncoding();
ClipboardData getClipboadData();
void addToClipboadHistory(ClipboardData cbd);
protected:
virtual BOOL CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
private:
ScintillaEditView **_ppEditView;
std::vector<ClipboardData> _clipboardDataVector;
};
#endif // CLIPBOARDHISTORYPANEL_H

View File

@ -0,0 +1,30 @@
/*
this file is part of notepad++
Copyright (C)2003 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 <windows.h>
#include "clipboardHistoryPanel_rc.h"
IDD_CLIPBOARDHISTORY_PANEL DIALOGEX 26, 41, 142, 324
STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE
CAPTION "Clipboard History"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
LISTBOX IDC_LIST_CLIPBOARD,50,44,78,120,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
END

View File

@ -0,0 +1,25 @@
//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.
#ifndef IDD_CLIPBOARDHISTORYPANEL_RC_H
#define IDD_CLIPBOARDHISTORYPANEL_RC_H
#define IDD_CLIPBOARDHISTORY_PANEL 2800
#define IDC_LIST_CLIPBOARD (IDD_CLIPBOARDHISTORY_PANEL + 1)
#endif //IDD_CLIPBOARDHISTORYPANEL_RC_H

View File

@ -105,6 +105,7 @@
#define IDM_EDIT_CUT_BINARY (IDM_EDIT + 49)
#define IDM_EDIT_PASTE_BINARY (IDM_EDIT + 50)
#define IDM_EDIT_CHAR_PANEL (IDM_EDIT + 51)
#define IDM_EDIT_CLIPBOARDHISTORY_PANEL (IDM_EDIT + 52)
#define IDM_EDIT_AUTOCOMPLETE (50000 + 0)
#define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000 + 1)

View File

@ -133,7 +133,7 @@
Name="VCCLCompilerTool"
Optimization="0"
FavorSizeOrSpeed="0"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common;..\src\tinyxml\tinyXmlA;..\src\WinControls\AnsiCharPanel"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common;..\src\tinyxml\tinyXmlA;..\src\WinControls\AnsiCharPanel;..\src\WinControls\ClipboardHistory"
PreprocessorDefinitions="WIN32;_WINDOWS;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL"
MinimalRebuild="true"
ExceptionHandling="2"
@ -228,7 +228,7 @@
FavorSizeOrSpeed="1"
OmitFramePointers="false"
WholeProgramOptimization="false"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common;..\src\tinyxml\tinyXmlA;..\src\WinControls\AnsiCharPanel"
AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common;..\src\tinyxml\tinyXmlA;..\src\WinControls\AnsiCharPanel;..\src\WinControls\ClipboardHistory"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL"
GeneratePreprocessedFile="0"
StringPooling="true"
@ -519,6 +519,10 @@
RelativePath="..\src\ScitillaComponent\Buffer.cpp"
>
</File>
<File
RelativePath="..\src\WinControls\ClipboardHistory\clipboardHistoryPanel.cpp"
>
</File>
<File
RelativePath="..\src\WinControls\ColourPicker\ColourPicker.cpp"
>
@ -829,6 +833,10 @@
RelativePath="..\src\WinControls\AnsiCharPanel\ansiCharPanel.rc"
>
</File>
<File
RelativePath="..\src\WinControls\ClipboardHistory\clipboardHistoryPanel.rc"
>
</File>
<File
RelativePath="..\src\icons\closeAll.bmp"
>
@ -1382,6 +1390,14 @@
RelativePath="..\src\ScitillaComponent\Buffer.h"
>
</File>
<File
RelativePath="..\src\WinControls\ClipboardHistory\clipboardHistoryPanel.h"
>
</File>
<File
RelativePath="..\src\WinControls\ClipboardHistory\clipboardHistoryPanel_rc.h"
>
</File>
<File
RelativePath="..\src\ScitillaComponent\colors.h"
>