[NEW] (Author: Dave Brotherstone) Add NPPM_ALLOCATEMARKER plugin message.
[NEW_FEATURE] Add Statistics feature which is accessible from the menu command "Summary..." (under menu "View") and the 2nd zone of statusbar (double click). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@667 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
16c671a825
commit
00fbd3444b
@ -324,7 +324,12 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV
|
||||
// sets startNumber to the initial command ID if successful
|
||||
// Returns: TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful
|
||||
|
||||
|
||||
#define NPPM_ALLOCATEMARKER (NPPMSG + 82)
|
||||
// BOOL NPPM_ALLOCATEMARKER(int numberRequested, int* startNumber)
|
||||
// sets startNumber to the initial command ID if successful
|
||||
// Allocates a marker number to a plugin
|
||||
// Returns: TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful
|
||||
|
||||
#define RUNCOMMAND_USER (WM_USER + 3000)
|
||||
#define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH)
|
||||
#define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY)
|
||||
|
@ -480,6 +480,18 @@ bool PluginsManager::allocateCmdID(int numberRequired, int *start)
|
||||
|
||||
*start = _dynamicIDAlloc.allocate(numberRequired);
|
||||
|
||||
if (-1 == *start)
|
||||
{
|
||||
*start = 0;
|
||||
retVal = false;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool PluginsManager::allocateMarker(int numberRequired, int *start)
|
||||
{
|
||||
bool retVal = true;
|
||||
*start = _markerAlloc.allocate(numberRequired);
|
||||
if (-1 == *start)
|
||||
{
|
||||
*start = 0;
|
||||
|
@ -72,7 +72,8 @@ struct PluginInfo {
|
||||
|
||||
class PluginsManager {
|
||||
public:
|
||||
PluginsManager() : _hPluginsMenu(NULL), _isDisabled(false), _dynamicIDAlloc(ID_PLUGINS_CMD_DYNAMIC, ID_PLUGINS_CMD_DYNAMIC_LIMIT) {};
|
||||
PluginsManager() : _hPluginsMenu(NULL), _isDisabled(false), _dynamicIDAlloc(ID_PLUGINS_CMD_DYNAMIC, ID_PLUGINS_CMD_DYNAMIC_LIMIT),
|
||||
_markerAlloc(MARKER_PLUGINS, MARKER_PLUGINS_LIMIT) {};
|
||||
~PluginsManager() {
|
||||
|
||||
for (size_t i = 0 ; i < _pluginInfos.size() ; i++)
|
||||
@ -111,6 +112,8 @@ public:
|
||||
bool allocateCmdID(int numberRequired, int *start);
|
||||
bool inDynamicRange(int id) { return _dynamicIDAlloc.isInRange(id); }
|
||||
|
||||
bool allocateMarker(int numberRequired, int *start);
|
||||
|
||||
private:
|
||||
NppData _nppData;
|
||||
HMENU _hPluginsMenu;
|
||||
@ -119,6 +122,7 @@ private:
|
||||
vector<PluginCommand> _pluginsCommands;
|
||||
bool _isDisabled;
|
||||
IDAllocator _dynamicIDAlloc;
|
||||
IDAllocator _markerAlloc;
|
||||
void pluginCrashAlert(const TCHAR *pluginName, const TCHAR *funcSignature) {
|
||||
generic_string msg = pluginName;
|
||||
msg += TEXT(" just crash in\r");
|
||||
|
@ -283,9 +283,9 @@ LRESULT Notepad_plus::init(HWND hwnd)
|
||||
//--Status Bar Section--//
|
||||
bool willBeShown = nppGUI._statusBarShow;
|
||||
_statusBar.init(_pPublicInterface->getHinst(), hwnd, 6);
|
||||
_statusBar.setPartWidth(STATUSBAR_DOC_SIZE, 170);
|
||||
_statusBar.setPartWidth(STATUSBAR_CUR_POS, 300);
|
||||
_statusBar.setPartWidth(STATUSBAR_EOF_FORMAT, 100);
|
||||
_statusBar.setPartWidth(STATUSBAR_DOC_SIZE, 230);
|
||||
_statusBar.setPartWidth(STATUSBAR_CUR_POS, 230);
|
||||
_statusBar.setPartWidth(STATUSBAR_EOF_FORMAT, 110);
|
||||
_statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, 120);
|
||||
_statusBar.setPartWidth(STATUSBAR_TYPING_MODE, 30);
|
||||
_statusBar.display(willBeShown);
|
||||
@ -2265,13 +2265,13 @@ void Notepad_plus::activateDoc(int pos)
|
||||
|
||||
|
||||
static const char utflen[] = {1,1,2,3};
|
||||
/*
|
||||
|
||||
size_t Notepad_plus::getSelectedCharNumber(UniMode u)
|
||||
{
|
||||
size_t result = 0;
|
||||
int numSel = _pEditView->execute(SCI_GETSELECTIONS);
|
||||
if (u == uniUTF8 || u == uniCookie)
|
||||
{
|
||||
int numSel = _pEditView->execute(SCI_GETSELECTIONS);
|
||||
for (int i=0; i < numSel; i++)
|
||||
{
|
||||
size_t line1 = _pEditView->execute(SCI_LINEFROMPOSITION, _pEditView->execute(SCI_GETSELECTIONNSTART, i));
|
||||
@ -2295,7 +2295,7 @@ size_t Notepad_plus::getSelectedCharNumber(UniMode u)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0; i < _numSel; i++)
|
||||
for (int i=0; i < numSel; i++)
|
||||
{
|
||||
size_t stpos = _pEditView->execute(SCI_GETSELECTIONNSTART, i);
|
||||
size_t endpos = _pEditView->execute(SCI_GETSELECTIONNEND, i);
|
||||
@ -2310,7 +2310,7 @@ size_t Notepad_plus::getSelectedCharNumber(UniMode u)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
@ -2330,10 +2330,11 @@ static inline size_t countUtf8Characters(unsigned char *buf, int pos, int endpos
|
||||
}
|
||||
|
||||
|
||||
size_t Notepad_plus::getCurrentDocCharCount(size_t numLines, UniMode u)
|
||||
size_t Notepad_plus::getCurrentDocCharCount(UniMode u)
|
||||
{
|
||||
if (u != uniUTF8 && u != uniCookie)
|
||||
{
|
||||
size_t numLines = _pEditView->execute(SCI_GETLINECOUNT);
|
||||
int result = _pEditView->execute(SCI_GETLENGTH);
|
||||
size_t lines = numLines==0?0:numLines-1;
|
||||
if (_pEditView->execute(SCI_GETEOLMODE) == SC_EOL_CRLF) lines *= 2;
|
||||
@ -2395,46 +2396,71 @@ int Notepad_plus::getBOMSize(UniMode u)
|
||||
|
||||
int Notepad_plus::getSelectedAreas()
|
||||
{
|
||||
_numSel = _pEditView->execute(SCI_GETSELECTIONS);
|
||||
if (_numSel == 1) // either 0 or 1 selection
|
||||
int numSel = _pEditView->execute(SCI_GETSELECTIONS);
|
||||
if (numSel == 1) // either 0 or 1 selection
|
||||
return (_pEditView->execute(SCI_GETSELECTIONNSTART, 0) == _pEditView->execute(SCI_GETSELECTIONNEND, 0)) ? 0 : 1;
|
||||
return (_pEditView->execute(SCI_SELECTIONISRECTANGLE)) ? 1 : _numSel;
|
||||
return (_pEditView->execute(SCI_SELECTIONISRECTANGLE)) ? 1 : numSel;
|
||||
}
|
||||
|
||||
size_t Notepad_plus::getSelectedBytes()
|
||||
{
|
||||
int numSel = _pEditView->execute(SCI_GETSELECTIONS);
|
||||
size_t result = 0;
|
||||
for (int i=0; i<_numSel; i++)
|
||||
for (int i = 0; i < numSel; i++)
|
||||
result += (_pEditView->execute(SCI_GETSELECTIONNEND, i) - _pEditView->execute(SCI_GETSELECTIONNSTART, i));
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
void Notepad_plus::updateStatusBar()
|
||||
{
|
||||
if(!NppParameters::getInstance()->getNppGUI()._statusBarShow) return; // do not update if status bar not shown
|
||||
|
||||
UniMode u = _pEditView->getCurrentBuffer()->getUnicodeMode();
|
||||
TCHAR strLnCol[64];
|
||||
|
||||
int areas = getSelectedAreas();
|
||||
int sizeofChar = (isFormatUnicode(u)) ? 2 : 1;
|
||||
wsprintf(strLnCol, TEXT("Ln : %d Col : %d Sel : %d in %d ranges"),\
|
||||
wsprintf(strLnCol, TEXT("Ln : %d Col : %d Sel : %d (%d bytes) in %d ranges"),\
|
||||
(_pEditView->getCurrentLineNumber() + 1), \
|
||||
(_pEditView->getCurrentColumnNumber() + 1),\
|
||||
getSelectedBytes() * sizeofChar,\
|
||||
getSelectedCharNumber(u), getSelectedBytes() * sizeofChar,\
|
||||
areas);
|
||||
|
||||
_statusBar.setText(strLnCol, STATUSBAR_CUR_POS);
|
||||
|
||||
TCHAR strDonLen[64];
|
||||
size_t numLines = _pEditView->execute(SCI_GETLINECOUNT);
|
||||
wsprintf(strDonLen, TEXT("%d bytes %d lines"),\
|
||||
wsprintf(strDonLen, TEXT("%d chars %d bytes %d lines"),\
|
||||
getCurrentDocCharCount(numLines, u),\
|
||||
_pEditView->execute(SCI_GETLENGTH) * sizeofChar + getBOMSize(u),\
|
||||
numLines);
|
||||
_statusBar.setText(strDonLen, STATUSBAR_DOC_SIZE);
|
||||
_statusBar.setText(_pEditView->execute(SCI_GETOVERTYPE) ? TEXT("OVR") : TEXT("INS"), STATUSBAR_TYPING_MODE);
|
||||
}
|
||||
*/
|
||||
|
||||
void Notepad_plus::updateStatusBar()
|
||||
{
|
||||
TCHAR strLnCol[128];
|
||||
TCHAR strSel[64];
|
||||
|
||||
long nbByte = _pEditView->getSelectedByteNumber();
|
||||
if (nbByte != -1)
|
||||
wsprintf(strSel, TEXT("Sel : %d"), nbByte);
|
||||
else
|
||||
wsprintf(strSel, TEXT("Sel : %s"), TEXT("N/A"));
|
||||
|
||||
wsprintf(strLnCol, TEXT("Ln : %d Col : %d %s"),\
|
||||
(_pEditView->getCurrentLineNumber() + 1), \
|
||||
(_pEditView->getCurrentColumnNumber() + 1),\
|
||||
strSel);
|
||||
|
||||
_statusBar.setText(strLnCol, STATUSBAR_CUR_POS);
|
||||
|
||||
TCHAR strDocLen[256];
|
||||
wsprintf(strDocLen, TEXT("length : %d lines : %d"), _pEditView->getCurrentDocLen(), _pEditView->execute(SCI_GETLINECOUNT));
|
||||
_statusBar.setText(strDocLen, STATUSBAR_DOC_SIZE);
|
||||
_statusBar.setText(_pEditView->execute(SCI_GETOVERTYPE) ? TEXT("OVR") : TEXT("INS"), STATUSBAR_TYPING_MODE);
|
||||
}
|
||||
|
||||
void Notepad_plus::dropFiles(HDROP hdrop)
|
||||
{
|
||||
|
@ -540,10 +540,9 @@ private:
|
||||
void activateDoc(int pos);
|
||||
|
||||
void updateStatusBar();
|
||||
//size_t getSelectedCharNumber(UniMode);
|
||||
size_t getCurrentDocCharCount(size_t numLines, UniMode u);
|
||||
size_t getSelectedCharNumber(UniMode);
|
||||
size_t getCurrentDocCharCount(UniMode u);
|
||||
int getSelectedAreas();
|
||||
int _numSel;
|
||||
size_t getSelectedBytes();
|
||||
bool isFormatUnicode(UniMode);
|
||||
int getBOMSize(UniMode);
|
||||
|
@ -390,7 +390,8 @@ BEGIN
|
||||
MENUITEM "7", IDM_VIEW_UNFOLD_7
|
||||
MENUITEM "8", IDM_VIEW_UNFOLD_8
|
||||
END
|
||||
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Summary...", IDM_VIEW_SUMMARY
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Synchronize Vertical Scrolling", IDM_VIEW_SYNSCROLLV
|
||||
MENUITEM "Synchronize Horizontal Scrolling", IDM_VIEW_SYNSCROLLH
|
||||
|
@ -1602,6 +1602,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
||||
case NPPM_ALLOCATECMDID:
|
||||
return _pluginsManager.allocateCmdID(wParam, reinterpret_cast<int *>(lParam));
|
||||
|
||||
case NPPM_ALLOCATEMARKER:
|
||||
return _pluginsManager.allocateMarker(wParam, reinterpret_cast<int *>(lParam));
|
||||
|
||||
case NPPM_HIDETABBAR :
|
||||
{
|
||||
bool hide = (lParam != 0);
|
||||
|
@ -987,6 +987,91 @@ void Notepad_plus::command(int id)
|
||||
}
|
||||
break;
|
||||
|
||||
case IDM_VIEW_SUMMARY:
|
||||
{
|
||||
generic_string characterNumber = TEXT("");
|
||||
|
||||
Buffer * curBuf = _pEditView->getCurrentBuffer();
|
||||
int fileLen = curBuf->getFileLength();
|
||||
|
||||
if (fileLen != -1)
|
||||
{
|
||||
TCHAR *filePathLabel = TEXT("Full file path: ");
|
||||
TCHAR *fileCreateTimeLabel = TEXT("Created: ");
|
||||
TCHAR *fileModifyTimeLabel = TEXT("Modified: ");
|
||||
TCHAR *fileLenLabel = TEXT("File length (in byte): ");
|
||||
|
||||
characterNumber += filePathLabel;
|
||||
characterNumber += curBuf->getFullPathName();
|
||||
characterNumber += TEXT("\r");
|
||||
|
||||
characterNumber += fileCreateTimeLabel;
|
||||
characterNumber += curBuf->getFileTime(Buffer::ft_created);
|
||||
characterNumber += TEXT("\r");
|
||||
|
||||
characterNumber += fileModifyTimeLabel;
|
||||
characterNumber += curBuf->getFileTime(Buffer::ft_modified);
|
||||
characterNumber += TEXT("\r");
|
||||
|
||||
TCHAR fileLenStr[64];
|
||||
generic_sprintf(fileLenStr, TEXT("%d"), (size_t)fileLen);
|
||||
characterNumber += fileLenLabel;
|
||||
characterNumber += fileLenStr;
|
||||
characterNumber += TEXT("\r");
|
||||
characterNumber += TEXT("\r");
|
||||
}
|
||||
TCHAR *nbCharLabel = TEXT("Characters (without blanks): ");
|
||||
TCHAR *nbByteLabel = TEXT("Current document length: ");
|
||||
TCHAR *nbLineLabel = TEXT("Total lines: ");
|
||||
TCHAR *nbSelLabel1 = TEXT(" selected characters (");
|
||||
TCHAR *nbSelLabel2 = TEXT(" bytes) in ");
|
||||
TCHAR *nbRangeLabel = TEXT(" ranges");
|
||||
|
||||
UniMode um = _pEditView->getCurrentBuffer()->getUnicodeMode();
|
||||
int nbChar = getCurrentDocCharCount(um);
|
||||
size_t nbLine = _pEditView->execute(SCI_GETLINECOUNT);
|
||||
int nbByte = _pEditView->execute(SCI_GETLENGTH);
|
||||
int nbSel = getSelectedCharNumber(um);
|
||||
int nbSelByte = getSelectedBytes();
|
||||
int nbRange = getSelectedAreas();
|
||||
|
||||
TCHAR nbCharStr[64];
|
||||
TCHAR nbByteStr[64];
|
||||
TCHAR nbLineStr[64];
|
||||
TCHAR nbSelStr[64];
|
||||
TCHAR nbSelByteStr[64];
|
||||
TCHAR nbRangeStr[8];
|
||||
|
||||
generic_sprintf(nbCharStr, TEXT("%d"), nbChar);
|
||||
characterNumber += nbCharLabel;
|
||||
characterNumber += nbCharStr;
|
||||
characterNumber += TEXT("\r");
|
||||
|
||||
generic_sprintf(nbByteStr, TEXT("%d"), nbByte);
|
||||
characterNumber += nbByteLabel;
|
||||
characterNumber += nbByteStr;
|
||||
characterNumber += TEXT("\r");
|
||||
|
||||
generic_sprintf(nbLineStr, TEXT("%d"), nbLine);
|
||||
characterNumber += nbLineLabel;
|
||||
characterNumber += nbLineStr;
|
||||
characterNumber += TEXT("\r");
|
||||
|
||||
generic_sprintf(nbSelStr, TEXT("%d"), nbSel);
|
||||
generic_sprintf(nbSelByteStr, TEXT("%d"), nbSelByte);
|
||||
generic_sprintf(nbRangeStr, TEXT("%d"), nbRange);
|
||||
characterNumber += nbSelStr;
|
||||
characterNumber += nbSelLabel1;
|
||||
characterNumber += nbSelByteStr;
|
||||
characterNumber += nbSelLabel2;
|
||||
characterNumber += nbRangeStr;
|
||||
characterNumber += nbRangeLabel;
|
||||
characterNumber += TEXT("\r");
|
||||
|
||||
::MessageBox(_pPublicInterface->getHSelf(), characterNumber.c_str(), TEXT("Summary"), MB_OK|MB_APPLMODAL);
|
||||
}
|
||||
break;
|
||||
|
||||
case IDM_EXECUTE:
|
||||
{
|
||||
bool isFirstTime = !_runDlg.isCreated();
|
||||
|
@ -187,13 +187,6 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi
|
||||
|
||||
bool Notepad_plus::doReload(BufferID id, bool alert)
|
||||
{
|
||||
|
||||
/*
|
||||
//No activation when reloading, defer untill document is actually visible
|
||||
if (alert) {
|
||||
switchToFile(id);
|
||||
}
|
||||
*/
|
||||
if (alert)
|
||||
{
|
||||
if (::MessageBox(_pPublicInterface->getHSelf(), TEXT("Are you sure you want to reload the current file and lose the changes made in Notepad++?"), TEXT("Reload"), MB_YESNO | MB_ICONEXCLAMATION | MB_APPLMODAL) != IDYES)
|
||||
|
@ -392,6 +392,10 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
||||
if (isFirstTime)
|
||||
_nativeLangSpeaker.changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
|
||||
}
|
||||
else if (lpnm->dwItemSpec == DWORD(STATUSBAR_DOC_SIZE))
|
||||
{
|
||||
command(IDM_VIEW_SUMMARY);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -192,6 +192,47 @@ bool Buffer::checkFileState() { //returns true if the status has been changed (i
|
||||
return false;
|
||||
}
|
||||
|
||||
int Buffer::getFileLength()
|
||||
{
|
||||
if (_currentStatus == DOC_UNNAMED)
|
||||
return -1;
|
||||
|
||||
struct _stat buf;
|
||||
|
||||
if (PathFileExists(_fullPathName.c_str()))
|
||||
{
|
||||
if (!generic_stat(_fullPathName.c_str(), &buf))
|
||||
{
|
||||
return buf.st_size;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
generic_string Buffer::getFileTime(fileTimeType ftt)
|
||||
{
|
||||
if (_currentStatus == DOC_UNNAMED)
|
||||
return TEXT("");
|
||||
|
||||
struct _stat buf;
|
||||
|
||||
if (PathFileExists(_fullPathName.c_str()))
|
||||
{
|
||||
if (!generic_stat(_fullPathName.c_str(), &buf))
|
||||
{
|
||||
time_t rawtime = ftt==ft_created?buf.st_ctime:ftt==ft_modified?buf.st_mtime:buf.st_atime;
|
||||
tm *timeinfo = localtime(&rawtime);
|
||||
const int temBufLen = 64;
|
||||
TCHAR tmpbuf[temBufLen];
|
||||
|
||||
generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d %H:%M:%S"), timeinfo);
|
||||
return tmpbuf;
|
||||
}
|
||||
}
|
||||
return TEXT("");
|
||||
}
|
||||
|
||||
|
||||
void Buffer::setPosition(const Position & pos, ScintillaEditView * identifier) {
|
||||
int index = indexOfReference(identifier);
|
||||
if (index == -1)
|
||||
|
@ -312,6 +312,11 @@ public :
|
||||
return _pManager->docLength(_id);
|
||||
};
|
||||
|
||||
int getFileLength(); // return file length. -1 if file is not existing.
|
||||
|
||||
enum fileTimeType {ft_created, ft_modified, ft_accessed};
|
||||
generic_string getFileTime(fileTimeType ftt);
|
||||
|
||||
Lang * getCurrentLang() const;
|
||||
private :
|
||||
FileManager * _pManager;
|
||||
|
@ -434,6 +434,9 @@ public:
|
||||
};
|
||||
|
||||
long getSelectedByteNumber() const {
|
||||
// return -1 if it's multi-selection or rectangle selection
|
||||
if ((execute(SCI_GETSELECTIONS) > 1) || execute(SCI_SELECTIONISRECTANGLE))
|
||||
return -1;
|
||||
long start = long(execute(SCI_GETSELECTIONSTART));
|
||||
long end = long(execute(SCI_GETSELECTIONEND));
|
||||
return (start < end)?end-start:start-end;
|
||||
|
@ -204,6 +204,7 @@
|
||||
#define IDM_VIEW_LWDEF (IDM_VIEW + 46)
|
||||
#define IDM_VIEW_LWALIGN (IDM_VIEW + 47)
|
||||
#define IDM_VIEW_LWINDENT (IDM_VIEW + 48)
|
||||
#define IDM_VIEW_SUMMARY (IDM_VIEW + 49)
|
||||
|
||||
#define IDM_VIEW_FOLD (IDM_VIEW + 50)
|
||||
#define IDM_VIEW_FOLD_1 (IDM_VIEW_FOLD + 1)
|
||||
|
@ -178,6 +178,9 @@
|
||||
|
||||
#define ID_PLUGINS_CMD_DYNAMIC 23000
|
||||
#define ID_PLUGINS_CMD_DYNAMIC_LIMIT 24999
|
||||
|
||||
#define MARKER_PLUGINS 3
|
||||
#define MARKER_PLUGINS_LIMIT 19
|
||||
/*UNLOAD
|
||||
#define ID_PLUGINS_REMOVING 22501
|
||||
#define ID_PLUGINS_REMOVING_END 22600
|
||||
|
Loading…
Reference in New Issue
Block a user