Ticket #6831: stylededit-wordcount-showasreadonly.diff
File stylededit-wordcount-showasreadonly.diff, 5.9 KB (added by , 13 years ago) |
---|
-
src/apps/stylededit/StyledEditWindow.cpp
218 218 fCopyItem->SetEnabled(false); 219 219 fCopyItem->SetTarget(fTextView); 220 220 221 menu->AddItem( menuItem = new BMenuItem(B_TRANSLATE("Paste"),221 menu->AddItem(fPasteItem = new BMenuItem(B_TRANSLATE("Paste"), 222 222 new BMessage(B_PASTE), 'V')); 223 223 menuItem->SetTarget(fTextView); 224 224 menu->AddItem(fClearItem = new BMenuItem(B_TRANSLATE("Clear"), … … 240 240 241 241 menu->AddItem(menuItem = new BMenuItem(B_TRANSLATE("Find selection"), 242 242 new BMessage(MENU_FIND_SELECTION), 'H')); 243 menu->AddItem( menuItem = new BMenuItem(243 menu->AddItem(fReplaceItem = new BMenuItem( 244 244 B_TRANSLATE("Replace" B_UTF8_ELLIPSIS), 245 245 new BMessage(MENU_REPLACE), 'R')); 246 246 menu->AddItem(fReplaceSameItem = new BMenuItem(B_TRANSLATE("Replace same"), … … 323 323 fMenuBar->AddItem(menu); 324 324 325 325 // "Align"-subMenu: 326 subMenu = new BMenu(B_TRANSLATE("Align"));327 subMenu->SetRadioMode(true);326 fAlignMenu = new BMenu(B_TRANSLATE("Align")); 327 fAlignMenu->SetRadioMode(true); 328 328 329 subMenu->AddItem(fAlignLeft = new BMenuItem(B_TRANSLATE("Left"),329 fAlignMenu->AddItem(fAlignLeft = new BMenuItem(B_TRANSLATE("Left"), 330 330 new BMessage(ALIGN_LEFT))); 331 331 fAlignLeft->SetMarked(true); 332 332 333 subMenu->AddItem(fAlignCenter = new BMenuItem(B_TRANSLATE("Center"),333 fAlignMenu->AddItem(fAlignCenter = new BMenuItem(B_TRANSLATE("Center"), 334 334 new BMessage(ALIGN_CENTER))); 335 subMenu->AddItem(fAlignRight = new BMenuItem(B_TRANSLATE("Right"),335 fAlignMenu->AddItem(fAlignRight = new BMenuItem(B_TRANSLATE("Right"), 336 336 new BMessage(ALIGN_RIGHT))); 337 menu->AddItem(subMenu); 337 menu->AddItem(fAlignMenu); 338 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(fReadOnlyItem = new BMenuItem(B_TRANSLATE("Show as read only"), 343 new BMessage(SET_READONLY))); 344 menu->AddItem(fWordCountItem = new BMenuItem(B_TRANSLATE("Word count"), 345 new BMessage(WORD_COUNT))); 341 346 342 347 fSavePanel = NULL; 343 348 fSavePanelEncodingMenu = NULL; … … 645 650 _UpdateCleanUndoRedoSaveRevert(); 646 651 break; 647 652 } 653 case SET_READONLY: 654 { 655 if (fTextView->IsEditable()) 656 { 657 fPasteItem->SetEnabled(false); 658 fReplaceItem->SetEnabled(false); 659 fReplaceSameItem->SetEnabled(false); 660 fFontMenu->SetEnabled(false); 661 fAlignMenu->SetEnabled(false); 662 fWrapItem->SetEnabled(false); 663 } else 664 { 665 fPasteItem->SetEnabled(true); 666 fReplaceItem->SetEnabled(true); 667 fReplaceSameItem->SetEnabled(true); 668 fFontMenu->SetEnabled(true); 669 fAlignMenu->SetEnabled(true); 670 fWrapItem->SetEnabled(true); 671 } 672 673 fTextView->MakeEditable(!fTextView->IsEditable()); 674 fReadOnlyItem->SetMarked(!fReadOnlyItem->IsMarked()); 675 676 bool fCleanTmp = fClean; 677 _UpdateCleanUndoRedoSaveRevert(); 678 fClean = fCleanTmp; 679 680 break; 681 } 682 case WORD_COUNT: 683 { 684 CountWords(); 685 686 break; 687 } 648 688 case ENABLE_ITEMS: 649 689 fCutItem->SetEnabled(true); 650 690 fCopyItem->SetEnabled(true); … … 1559 1599 return false; 1560 1600 } 1561 1601 1602 1603 #undef B_TRANSLATE_CONTEXT 1604 #define B_TRANSLATE_CONTEXT "WordCount" 1605 1606 1607 int32 1608 StyledEditWindow::CountWords() 1609 { 1610 uint64 words = 0; 1611 bool inword = false; 1612 uint64 length = BString(fTextView->Text()).Length(); 1613 1614 // recognized word separators: spaces, tabs, newlines, commas 1615 for (uint64 i = 0; i < length; i++) 1616 { 1617 if (fTextView->Text()[i] == '\n' || fTextView->Text()[i] == ' '|| 1618 fTextView->Text()[i] == ' ' || fTextView->Text()[i] == ',') 1619 { 1620 inword = false; 1621 } else 1622 { 1623 if (!inword) 1624 { 1625 words++; 1626 inword = true; 1627 } 1628 } 1629 } 1630 1631 BString result; 1632 result << B_TRANSLATE("Word count") << '\n' << '\n' 1633 << B_TRANSLATE("Lines:") << " " << fTextView->CountLines() << '\n' 1634 << B_TRANSLATE("Characters:") << " " << BString(fTextView->Text()).Length() << '\n' 1635 << B_TRANSLATE("Words:") << " " << words; 1636 1637 BAlert* alert = new BAlert("Word count", result, B_TRANSLATE("OK"), NULL, 1638 NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_INFO_ALERT); 1639 1640 return alert->Go(); 1641 } -
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 *fReadOnlyItem; 105 BMenuItem *fWordCountItem; 100 106 BMenuItem *fAlignLeft; 101 107 BMenuItem *fAlignCenter; 102 108 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 SET_READONLY = 'MDro'; 67 const uint32 WORD_COUNT = 'MDwc'; 66 68 67 69 // enables "edit" menuitems 68 70 const uint32 ENABLE_ITEMS = 'ENit';