[haiku-commits] r39546 - haiku/trunk/src/apps/stylededit

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 20 Nov 2010 19:17:03 +0100 (CET)

Author: axeld
Date: 2010-11-20 19:17:03 +0100 (Sat, 20 Nov 2010)
New Revision: 39546
Changeset: http://dev.haiku-os.org/changeset/39546

Modified:
   haiku/trunk/src/apps/stylededit/Constants.h
   haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp
   haiku/trunk/src/apps/stylededit/StyledEditWindow.h
Log:
* Applied patch by Tam?\195?\131?\194?\161s Krutki that adds some statistic 
info to StyledEdit.
  Thanks for the patch!


Modified: haiku/trunk/src/apps/stylededit/Constants.h
===================================================================
--- haiku/trunk/src/apps/stylededit/Constants.h 2010-11-20 18:04:35 UTC (rev 
39545)
+++ haiku/trunk/src/apps/stylededit/Constants.h 2010-11-20 18:17:03 UTC (rev 
39546)
@@ -63,6 +63,7 @@
 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';

Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp
===================================================================
--- haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp        2010-11-20 
18:04:35 UTC (rev 39545)
+++ haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp        2010-11-20 
18:17:03 UTC (rev 39546)
@@ -41,6 +41,7 @@
 #include <TextControl.h>
 #include <TextView.h>
 #include <TranslationUtils.h>
+#include <UnicodeChar.h>
 
 
 using namespace BPrivate;
@@ -339,6 +340,11 @@
                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 @@
                        _UpdateCleanUndoRedoSaveRevert();
                        break;
                }
+               case SHOW_STATISTICS:
+                       _ShowStatistics();
+                       break;
                case ENABLE_ITEMS:
                        fCutItem->SetEnabled(true);
                        fCopyItem->SetEnabled(true);
@@ -1559,3 +1568,35 @@
        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();
+}

Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.h
===================================================================
--- haiku/trunk/src/apps/stylededit/StyledEditWindow.h  2010-11-20 18:04:35 UTC 
(rev 39545)
+++ haiku/trunk/src/apps/stylededit/StyledEditWindow.h  2010-11-20 18:17:03 UTC 
(rev 39546)
@@ -59,6 +59,7 @@
                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();


Other related posts: