Esempio n. 1
0
        public WordCountForm(string words, bool bOnlySelectedText)
        {
            InitializeComponent();

            gbTableHeader.Font = Res.GetFont(FontSize.Normal, FontStyle.Regular);

            // Set the text that will be analyzed, this will preform the calculations
            WordCounter wc = new WordCounter(words);

            buttonClose.Text = Res.Get(StringId.CloseButton);
            this.Text = Res.Get(StringId.WordCountTitle);
            labelWordCount.Text = Res.Get(StringId.WordCount);
            labelChars.Text = Res.Get(StringId.CharCount);
            labelCharsNoSpaces.Text = Res.Get(StringId.CharNoSpacesCount);
            labelParagraphs.Text = Res.Get(StringId.Paragraphs);

            labelWordCountValue.Text = String.Format(CultureInfo.CurrentCulture, "{0}", wc.Words);
            labelCharsValue.Text = String.Format(CultureInfo.CurrentCulture, "{0}", wc.Chars);
            labelCharsNoSpacesValue.Text = String.Format(CultureInfo.CurrentCulture, "{0}", wc.CharsWithoutSpaces);
            labelParagraphsValue.Text = String.Format(CultureInfo.CurrentCulture, "{0}", wc.Paragraphs);

            // If the text is not the whole document then show the user a message to tell them
            if (bOnlySelectedText)
            {
                gbTableHeader.Text = Res.Get(StringId.StatisticsSelection);
            }
            else
            {
                gbTableHeader.Text = Res.Get(StringId.Statistics);
            }

        }
        private static void CountText(string text, int expectedCount, int? expectedCharCount = null)
        {
            var wordCounter = new WordCounter(text);
            Assert.AreEqual(expectedCount, wordCounter.Words);

            if (expectedCharCount.HasValue)
            {
                Assert.AreEqual(expectedCharCount, wordCounter.Chars);
            }
        }
        void wordCountUpdate(object sender, EventArgs e)
        {
            wordCountTimer.Stop();

            if (!WordCountSettings.EnableRealTimeWordCount)
            {
                StatusBar.SetWordCountMessage(null);
                return;
            }

            try
            {
                using (ApplicationPerformance.LogEvent("RealTimeWordCount"))
                {
                    WordCounter wordCounter = new WordCounter(_currentEditor.GetEditedHtmlFast());
                    StatusBar.SetWordCountMessage(
                        string.Format(CultureInfo.CurrentCulture, Res.Get(StringId.Words), wordCounter.Words));
                }
            }
            catch (Exception ex)
            {
                WordCountSettings.EnableRealTimeWordCount = false;
                Trace.Fail("Unexpected error while trying to update word count.  Real time word count is disabled.  Error: " + ex.ToString());
            }

        }