From 15d26d2cef29a05bcf4a1ad70722e04992b22c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 20 Nov 2010 18:17:03 +0000 Subject: [PATCH] =?UTF-8?q?*=20Applied=20patch=20by=20Tam=C3=83=C2=A1s=20K?= =?UTF-8?q?rutki=20that=20adds=20some=20statistic=20info=20to=20StyledEdit?= =?UTF-8?q?.=20=20=20Thanks=20for=20the=20patch!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39546 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/stylededit/Constants.h | 1 + src/apps/stylededit/StyledEditWindow.cpp | 41 ++++++++++++++++++++++++ src/apps/stylededit/StyledEditWindow.h | 1 + 3 files changed, 43 insertions(+) diff --git a/src/apps/stylededit/Constants.h b/src/apps/stylededit/Constants.h index 04f8b7a924..5ca7b94f85 100644 --- a/src/apps/stylededit/Constants.h +++ b/src/apps/stylededit/Constants.h @@ -63,6 +63,7 @@ const uint32 ALIGN_LEFT = 'ALle'; const uint32 ALIGN_CENTER = 'ALce'; const uint32 ALIGN_RIGHT = 'ALri'; const uint32 WRAP_LINES = 'MDwr'; +const uint32 SHOW_STATISTICS = 'MDss'; // enables "edit" menuitems const uint32 ENABLE_ITEMS = 'ENit'; diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index a02c22d680..cdd6422160 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -41,6 +41,7 @@ #include #include #include +#include using namespace BPrivate; @@ -339,6 +340,11 @@ StyledEditWindow::InitWindow(uint32 encoding) new BMessage(WRAP_LINES))); fWrapItem->SetMarked(true); + menu->AddSeparatorItem(); + menu->AddItem(menuItem = new BMenuItem( + B_TRANSLATE("Statistics" B_UTF8_ELLIPSIS), + new BMessage(SHOW_STATISTICS))); + fSavePanel = NULL; fSavePanelEncodingMenu = NULL; // build lazily @@ -645,6 +651,9 @@ StyledEditWindow::MessageReceived(BMessage* message) _UpdateCleanUndoRedoSaveRevert(); break; } + case SHOW_STATISTICS: + _ShowStatistics(); + break; case ENABLE_ITEMS: fCutItem->SetEnabled(true); fCopyItem->SetEnabled(true); @@ -1559,3 +1568,35 @@ StyledEditWindow::IsDocumentEntryRef(const entry_ref* ref) return false; } + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Statistics" + + +int32 +StyledEditWindow::_ShowStatistics() +{ + size_t words = 0; + bool inWord = false; + size_t length = fTextView->TextLength(); + + for (size_t i = 0; i < length; i++) { + if (BUnicodeChar::IsSpace(fTextView->Text()[i])) { + inWord = false; + } else if (!inWord) { + words++; + inWord = true; + } + } + + BString result; + result << B_TRANSLATE("Document statistics") << '\n' << '\n' + << B_TRANSLATE("Lines:") << ' ' << fTextView->CountLines() << '\n' + << B_TRANSLATE("Characters:") << ' ' << length << '\n' + << B_TRANSLATE("Words:") << ' ' << words; + + BAlert* alert = new BAlert("Statistics", result, B_TRANSLATE("OK"), NULL, + NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_INFO_ALERT); + + return alert->Go(); +} diff --git a/src/apps/stylededit/StyledEditWindow.h b/src/apps/stylededit/StyledEditWindow.h index f0ea111591..22871147f8 100644 --- a/src/apps/stylededit/StyledEditWindow.h +++ b/src/apps/stylededit/StyledEditWindow.h @@ -59,6 +59,7 @@ class StyledEditWindow : public BWindow { void SetFontSize(float fontSize); void SetFontColor(const rgb_color *color); void SetFontStyle(const char *fontFamily, const char *fontStyle); + int32 _ShowStatistics(); status_t _LoadFile(entry_ref* ref); void RevertToSaved(); void _UpdateCleanUndoRedoSaveRevert();