diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index a680c5cf..b7743280 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -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) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index b672154e..0c4834f6 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -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; diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h index 615c7dd2..371fe12f 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h @@ -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 _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"); diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 89e944cb..9332ce7a 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -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 @@ -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) { diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 307504c7..d75cdb9e 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -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); diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index fa610fa5..d1f2fd4f 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -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 diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index c4e77ccc..7df04f39 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -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(lParam)); + case NPPM_ALLOCATEMARKER: + return _pluginsManager.allocateMarker(wParam, reinterpret_cast(lParam)); + case NPPM_HIDETABBAR : { bool hide = (lParam != 0); diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 7dffb247..42eb3125 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -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(); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index d8c1167f..8c07d197 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -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) diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 1f34960f..c987581a 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -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; } diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 44c99665..a39919c5 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -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) diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 7b6cecc5..eb3ef2a7 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -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; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index d00b70c2..8fe8b810 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -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; diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index b57bf5de..e2c540f3 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -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) diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index fa04b5c9..c8883125 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -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