From bd373788ad997f5d3fd97f9f874acf4081bb10bb Mon Sep 17 00:00:00 2001 From: dail8859 Date: Tue, 19 Jul 2016 19:20:41 -0400 Subject: [PATCH] Add thousands separator for Summary and Statusbar Fixes #1329, Fixes #2103 --- PowerEditor/src/MISC/Common/Common.cpp | 9 +++++++ PowerEditor/src/MISC/Common/Common.h | 1 + PowerEditor/src/Notepad_plus.cpp | 15 +++++++----- PowerEditor/src/NppCommands.cpp | 33 +++++++------------------- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 205a413e0..aeb68e0c1 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -26,6 +26,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include #include +#include #include #include #include @@ -37,6 +38,7 @@ WcharMbcsConvertor* WcharMbcsConvertor::_pSelf = new WcharMbcsConvertor; +typedef std::basic_stringstream generic_stringstream; @@ -53,6 +55,13 @@ void printStr(const TCHAR *str2print) ::MessageBox(NULL, str2print, TEXT(""), MB_OK); } +generic_string commafyInt(size_t n) +{ + generic_stringstream ss; + ss.imbue(std::locale("")); + ss << n; + return ss.str(); +} std::string getFileContent(const TCHAR *file2read) { diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index ff9b39580..650b4c735 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -71,6 +71,7 @@ generic_string getFolderName(HWND parent, const TCHAR *defaultDir = NULL); void printInt(int int2print); void printStr(const TCHAR *str2print); +generic_string commafyInt(size_t n); void writeLog(const TCHAR *logFileName, const char *log2write); int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep); diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 6e8e025e9..bbca9f73f 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3031,19 +3031,22 @@ void Notepad_plus::updateStatusBar() long selected_length = _pEditView->getSelectedLength(); if (selected_length != -1) - wsprintf(strSel, TEXT("Sel : %d | %d"), selected_length, selLine); + wsprintf(strSel, TEXT("Sel : %s | %s"), commafyInt(selected_length).c_str(), commafyInt(selLine).c_str()); else wsprintf(strSel, TEXT("Sel : %s"), TEXT("N/A")); - wsprintf(strLnCol, TEXT("Ln : %d Col : %d %s"),\ - (_pEditView->getCurrentLineNumber() + 1), \ - (_pEditView->getCurrentColumnNumber() + 1),\ - strSel); + wsprintf(strLnCol, TEXT("Ln : %s Col : %s %s"), + commafyInt(_pEditView->getCurrentLineNumber() + 1).c_str(), + commafyInt(_pEditView->getCurrentColumnNumber() + 1).c_str(), + strSel); _statusBar.setText(strLnCol, STATUSBAR_CUR_POS); TCHAR strDocLen[256]; - wsprintf(strDocLen, TEXT("length : %d lines : %d"), _pEditView->getCurrentDocLen(), _pEditView->execute(SCI_GETLINECOUNT)); + wsprintf(strDocLen, TEXT("length : %s lines : %s"), + commafyInt(_pEditView->getCurrentDocLen()).c_str(), + commafyInt(_pEditView->execute(SCI_GETLINECOUNT)).c_str()); + _statusBar.setText(strDocLen, STATUSBAR_DOC_SIZE); _statusBar.setText(_pEditView->execute(SCI_GETOVERTYPE) ? TEXT("OVR") : TEXT("INS"), STATUSBAR_TYPING_MODE); } diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index b52bf2e5f..82c6315a5 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1686,10 +1686,8 @@ void Notepad_plus::command(int id) characterNumber += curBuf->getFileTime(Buffer::ft_modified); characterNumber += TEXT("\r"); - TCHAR fileLenStr[64]; - generic_sprintf(fileLenStr, TEXT("%I64u"), static_cast( fileLen ) ); characterNumber += fileLenLabel; - characterNumber += fileLenStr; + characterNumber += commafyInt(static_cast(fileLen)).c_str(); characterNumber += TEXT("\r"); characterNumber += TEXT("\r"); } @@ -1710,42 +1708,27 @@ void Notepad_plus::command(int id) auto nbSelByte = getSelectedBytes(); auto nbRange = getSelectedAreas(); - TCHAR nbCharStr[32]; - TCHAR nbWordStr[16]; - TCHAR nbByteStr[32]; - TCHAR nbLineStr[32]; - TCHAR nbSelStr[32]; - TCHAR nbSelByteStr[32]; - TCHAR nbRangeStr[8]; - - generic_sprintf(nbCharStr, TEXT("%d"), nbChar); characterNumber += nbCharLabel; - characterNumber += nbCharStr; + characterNumber += commafyInt(nbChar).c_str(); characterNumber += TEXT("\r"); - generic_sprintf(nbWordStr, TEXT("%d"), nbWord); characterNumber += nbWordLabel; - characterNumber += nbWordStr; + characterNumber += commafyInt(nbWord).c_str(); characterNumber += TEXT("\r"); - generic_sprintf(nbLineStr, TEXT("%d"), static_cast( nbLine ) ); characterNumber += nbLineLabel; - characterNumber += nbLineStr; + characterNumber += commafyInt(static_cast(nbLine)).c_str(); characterNumber += TEXT("\r"); - generic_sprintf(nbByteStr, TEXT("%d"), nbByte); characterNumber += nbByteLabel; - characterNumber += nbByteStr; + characterNumber += commafyInt(nbByte).c_str(); characterNumber += TEXT("\r"); - generic_sprintf(nbSelStr, TEXT("%d"), nbSel); - generic_sprintf(nbSelByteStr, TEXT("%d"), nbSelByte); - generic_sprintf(nbRangeStr, TEXT("%d"), nbRange); - characterNumber += nbSelStr; + characterNumber += commafyInt(nbSel).c_str(); characterNumber += nbSelLabel1; - characterNumber += nbSelByteStr; + characterNumber += commafyInt(nbSelByte).c_str(); characterNumber += nbSelLabel2; - characterNumber += nbRangeStr; + characterNumber += commafyInt(nbRange).c_str(); characterNumber += nbRangeLabel; characterNumber += TEXT("\r");