Ticket #6831: stylededit-wordcount-v2.diff
File stylededit-wordcount-v2.diff, 4.9 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; … … 218 219 fCopyItem->SetEnabled(false); 219 220 fCopyItem->SetTarget(fTextView); 220 221 221 menu->AddItem( menuItem = new BMenuItem(B_TRANSLATE("Paste"),222 menu->AddItem(fPasteItem = new BMenuItem(B_TRANSLATE("Paste"), 222 223 new BMessage(B_PASTE), 'V')); 223 224 menuItem->SetTarget(fTextView); 224 225 menu->AddItem(fClearItem = new BMenuItem(B_TRANSLATE("Clear"), … … 240 241 241 242 menu->AddItem(menuItem = new BMenuItem(B_TRANSLATE("Find selection"), 242 243 new BMessage(MENU_FIND_SELECTION), 'H')); 243 menu->AddItem( menuItem = new BMenuItem(244 menu->AddItem(fReplaceItem = new BMenuItem( 244 245 B_TRANSLATE("Replace" B_UTF8_ELLIPSIS), 245 246 new BMessage(MENU_REPLACE), 'R')); 246 247 menu->AddItem(fReplaceSameItem = new BMenuItem(B_TRANSLATE("Replace same"), … … 323 324 fMenuBar->AddItem(menu); 324 325 325 326 // "Align"-subMenu: 326 subMenu = new BMenu(B_TRANSLATE("Align"));327 subMenu->SetRadioMode(true);327 fAlignMenu = new BMenu(B_TRANSLATE("Align")); 328 fAlignMenu->SetRadioMode(true); 328 329 329 subMenu->AddItem(fAlignLeft = new BMenuItem(B_TRANSLATE("Left"),330 fAlignMenu->AddItem(fAlignLeft = new BMenuItem(B_TRANSLATE("Left"), 330 331 new BMessage(ALIGN_LEFT))); 331 332 fAlignLeft->SetMarked(true); 332 333 333 subMenu->AddItem(fAlignCenter = new BMenuItem(B_TRANSLATE("Center"),334 fAlignMenu->AddItem(fAlignCenter = new BMenuItem(B_TRANSLATE("Center"), 334 335 new BMessage(ALIGN_CENTER))); 335 subMenu->AddItem(fAlignRight = new BMenuItem(B_TRANSLATE("Right"),336 fAlignMenu->AddItem(fAlignRight = new BMenuItem(B_TRANSLATE("Right"), 336 337 new BMessage(ALIGN_RIGHT))); 337 menu->AddItem(subMenu); 338 menu->AddItem(fAlignMenu); 339 338 340 menu->AddItem(fWrapItem = new BMenuItem(B_TRANSLATE("Wrap lines"), 339 341 new BMessage(WRAP_LINES))); 340 342 fWrapItem->SetMarked(true); 343 menu->AddItem(fWordCountItem = new BMenuItem(B_TRANSLATE("Word count"), 344 new BMessage(WORD_COUNT))); 341 345 342 346 fSavePanel = NULL; 343 347 fSavePanelEncodingMenu = NULL; … … 645 649 _UpdateCleanUndoRedoSaveRevert(); 646 650 break; 647 651 } 652 case WORD_COUNT: 653 CountWords(); 654 break; 648 655 case ENABLE_ITEMS: 649 656 fCutItem->SetEnabled(true); 650 657 fCopyItem->SetEnabled(true); … … 1559 1566 return false; 1560 1567 } 1561 1568 1569 1570 #undef B_TRANSLATE_CONTEXT 1571 #define B_TRANSLATE_CONTEXT "WordCount" 1572 1573 1574 int32 1575 StyledEditWindow::CountWords() 1576 { 1577 uint64 words = 0; 1578 bool inword = false; 1579 uint64 length = BString(fTextView->Text()).Length(); 1580 1581 for (uint64 i = 0; i < length; i++) { 1582 if (BUnicodeChar::IsSpace(fTextView->Text()[i])) { 1583 inword = false; 1584 } else if (!inword) { 1585 words++; 1586 inword = true; 1587 } 1588 } 1589 1590 BString result; 1591 result << B_TRANSLATE("Word count") << '\n' << '\n' 1592 << B_TRANSLATE("Lines:") << ' ' << fTextView->CountLines() << '\n' 1593 << B_TRANSLATE("Characters:") << ' ' 1594 << BString(fTextView->Text()).Length() << '\n' 1595 << B_TRANSLATE("Words:") << ' ' << words; 1596 1597 BAlert* alert = new BAlert("Word count", result, B_TRANSLATE("OK"), NULL, 1598 NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_INFO_ALERT); 1599 1600 return alert->Go(); 1601 } -
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 CountWords(); 62 63 status_t _LoadFile(entry_ref* ref); 63 64 void RevertToSaved(); 64 65 void _UpdateCleanUndoRedoSaveRevert(); … … 74 75 BMenu *fFontMenu; 75 76 BMenu *fFontSizeMenu; 76 77 BMenu *fFontColorMenu; 78 BMenu *fAlignMenu; 77 79 BMenuItem *fCurrentFontItem; 78 80 BMenuItem *fCurrentStyleItem; 79 81 … … 83 85 BMenuItem *fUndoItem; 84 86 BMenuItem *fCutItem; 85 87 BMenuItem *fCopyItem; 88 BMenuItem *fPasteItem; 86 89 BMenuItem *fClearItem; 87 90 88 91 BMenuItem *fFindAgainItem; 92 BMenuItem *fReplaceItem; 89 93 BMenuItem *fReplaceSameItem; 90 94 91 95 BMenuItem *fBlackItem; … … 97 101 BMenuItem *fYellowItem; 98 102 99 103 BMenuItem *fWrapItem; 104 BMenuItem *fWordCountItem; 100 105 BMenuItem *fAlignLeft; 101 106 BMenuItem *fAlignCenter; 102 107 BMenuItem *fAlignRight; -
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 WORD_COUNT = 'MDwc'; 66 67 67 68 // enables "edit" menuitems 68 69 const uint32 ENABLE_ITEMS = 'ENit';