Ticket #6831: stylededit-wordcount-v3.diff
File stylededit-wordcount-v3.diff, 2.8 KB (added by , 13 years ago) |
---|
-
src/apps/stylededit/StyledEditWindow.cpp
41 41 #include <TextControl.h> 42 42 #include <TextView.h> 43 43 #include <TranslationUtils.h> 44 #include <UnicodeChar.h> 44 45 45 46 46 47 using namespace BPrivate; … … 338 339 menu->AddItem(fWrapItem = new BMenuItem(B_TRANSLATE("Wrap lines"), 339 340 new BMessage(WRAP_LINES))); 340 341 fWrapItem->SetMarked(true); 342 menu->AddItem(menuItem = new BMenuItem(B_TRANSLATE("Statistics" B_UTF8_ELLIPSIS), 343 new BMessage(SHOW_STATISTICS))); 341 344 342 345 fSavePanel = NULL; 343 346 fSavePanelEncodingMenu = NULL; … … 645 648 _UpdateCleanUndoRedoSaveRevert(); 646 649 break; 647 650 } 651 case SHOW_STATISTICS: 652 ShowStatistics(); 653 break; 648 654 case ENABLE_ITEMS: 649 655 fCutItem->SetEnabled(true); 650 656 fCopyItem->SetEnabled(true); … … 1559 1565 return false; 1560 1566 } 1561 1567 1568 1569 #undef B_TRANSLATE_CONTEXT 1570 #define B_TRANSLATE_CONTEXT "Statistics" 1571 1572 1573 int32 1574 StyledEditWindow::ShowStatistics() 1575 { 1576 uint64 words = 0; 1577 bool inword = false; 1578 uint64 length = BString(fTextView->Text()).Length(); 1579 1580 for (uint64 i = 0; i < length; i++) { 1581 if (BUnicodeChar::IsSpace(fTextView->Text()[i])) { 1582 inword = false; 1583 } else if (!inword) { 1584 words++; 1585 inword = true; 1586 } 1587 } 1588 1589 BString result; 1590 result << B_TRANSLATE("Document statistics") << '\n' << '\n' 1591 << B_TRANSLATE("Lines:") << ' ' << fTextView->CountLines() << '\n' 1592 << B_TRANSLATE("Characters:") << ' ' 1593 << BString(fTextView->Text()).Length() << '\n' 1594 << B_TRANSLATE("Words:") << ' ' << words; 1595 1596 BAlert* alert = new BAlert("Statistics", result, B_TRANSLATE("OK"), NULL, 1597 NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_INFO_ALERT); 1598 1599 return alert->Go(); 1600 } -
src/apps/stylededit/StyledEditWindow.h
59 59 void SetFontSize(float fontSize); 60 60 void SetFontColor(const rgb_color *color); 61 61 void SetFontStyle(const char *fontFamily, const char *fontStyle); 62 int32 ShowStatistics(); 62 63 status_t _LoadFile(entry_ref* ref); 63 64 void RevertToSaved(); 64 65 void _UpdateCleanUndoRedoSaveRevert(); -
src/apps/stylededit/Constants.h
63 63 const uint32 ALIGN_CENTER = 'ALce'; 64 64 const uint32 ALIGN_RIGHT = 'ALri'; 65 65 const uint32 WRAP_LINES = 'MDwr'; 66 const uint32 SHOW_STATISTICS = 'MDss'; 66 67 67 68 // enables "edit" menuitems 68 69 const uint32 ENABLE_ITEMS = 'ENit';