* Applied patch by Tamás Krutki that adds some statistic info to StyledEdit.
Thanks for the patch! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39546 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
cae9b9d83a
commit
15d26d2cef
@ -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';
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <TextControl.h>
|
||||
#include <TextView.h>
|
||||
#include <TranslationUtils.h>
|
||||
#include <UnicodeChar.h>
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user