Exemple #1
0
        /// <summary>
        /// In SE Fieldworks we can't depend upon ScrControls.dll We need some decoupling to
        /// prevent the linker from trying to load ScrControls.dll and crashing.
        /// This seems to work. (Although I wonder if we could get away with just calling this method
        /// if IsTEInstalled?)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void LaunchFilterTextsDialog(object sender, EventArgs args)
        {
            IFilterTextsDialog <IStText> dlg = null;

            try
            {
                var interestingTextsList = InterestingTextsDecorator.GetInterestingTextList(m_mediator, m_cache.ServiceLocator);
                var textsToChooseFrom    = new List <IStText>(interestingTextsList.InterestingTexts);
                if (!FwUtils.IsTEInstalled)
                {                   // TE is not installed, so remove scripture from the list
                    textsToChooseFrom = textsToChooseFrom.Where(text => !ScriptureServices.ScriptureIsResponsibleFor(text)).ToList();
                }
                var interestingTexts = textsToChooseFrom.ToArray();
                if (FwUtils.IsTEInstalled)
                {
                    dlg = (IFilterTextsDialog <IStText>)DynamicLoader.CreateObject(
                        "ScrControls.dll", "SIL.FieldWorks.Common.Controls.FilterTextsDialogTE",
                        m_cache, interestingTexts, m_mediator.HelpTopicProvider, m_bookImporter);
                }
                else
                {
                    dlg = new FilterTextsDialog(m_cache, interestingTexts, m_mediator.HelpTopicProvider);
                }
                // LT-12181: Was 'PruneToSelectedTexts(text) and most others were deleted.
                // We want 'PruneToInterestingTextsAndSelect(interestingTexts, selectedText)'
                dlg.PruneToInterestingTextsAndSelect(interestingTexts, (IStText)m_objRoot);
                // LT-12140 Dialog name shouldn't change from Choose Texts
                //dlg.Text = ITextStrings.ksExportInterlinearizedTexts;
                dlg.TreeViewLabel = ITextStrings.ksSelectSectionsExported;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    m_objs.AddRange(dlg.GetListOfIncludedTexts());
                }
            }
            finally
            {
                if (dlg != null)
                {
                    ((IDisposable)dlg).Dispose();
                }
            }
        }
Exemple #2
0
        private void LaunchFilterTextsDialog(object sender, EventArgs args)
        {
            IFilterTextsDialog <IStText> dlg = null;

            try
            {
                var interestingTextsList = InterestingTextsDecorator.GetInterestingTextList(m_mediator, m_cache.ServiceLocator);
                var textsToChooseFrom    = new List <IStText>(interestingTextsList.InterestingTexts);
                if (!FwUtils.IsOkToDisplayScriptureIfPresent)
                {                   // Mustn't show any Scripture, so remove scripture from the list
                    textsToChooseFrom = textsToChooseFrom.Where(text => !ScriptureServices.ScriptureIsResponsibleFor(text)).ToList();
                }
                var interestingTexts = textsToChooseFrom.ToArray();
                if (FwUtils.IsOkToDisplayScriptureIfPresent)
                {
                    dlg = new FilterTextsDialogTE(m_cache, interestingTexts, m_mediator.HelpTopicProvider, m_bookImporter);
                }
                else
                {
                    dlg = new FilterTextsDialog(m_cache, interestingTexts, m_mediator.HelpTopicProvider);
                }
                // LT-12181: Was 'PruneToSelectedTexts(text) and most others were deleted.
                // We want 'PruneToInterestingTextsAndSelect(interestingTexts, selectedText)'
                dlg.PruneToInterestingTextsAndSelect(interestingTexts, (IStText)m_objRoot);
                dlg.TreeViewLabel = ITextStrings.ksSelectSectionsExported;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    m_objs.AddRange(dlg.GetListOfIncludedTexts());
                }
            }
            finally
            {
                if (dlg != null)
                {
                    ((IDisposable)dlg).Dispose();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Allow the user to export more than one to a single file (LT-11483)
        /// </summary>
        /// <returns>true iff export can proceed to choosing an output file</returns>
        protected override bool PrepareForExport()
        {
            m_objs.Clear();
            var interestingTextsList   = InterestingTextsDecorator.GetInterestingTextList(m_mediator, m_propertyTable, m_cache.ServiceLocator);
            var textsToShow            = interestingTextsList.InterestingTexts;
            var isOkToDisplayScripture = m_cache.ServiceLocator.GetInstance <IScrBookRepository>().AllInstances().Any();

            if (!isOkToDisplayScripture)
            {               // Mustn't show any Scripture, so remove scripture from the list
                textsToShow = textsToShow.Where(text => !ScriptureServices.ScriptureIsResponsibleFor(text));
            }
            var selectedTexts = new[] { (IStText)m_objRoot };

            using (var dlg = new FilterTextsDialog(m_propertyTable.GetValue <IApp>("App"), m_cache, selectedTexts, m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider")))
            {
                dlg.TextsToShow   = textsToShow.ToList();
                dlg.TreeViewLabel = ITextStrings.ksSelectSectionsExported;
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    m_objs.AddRange(dlg.GetListOfIncludedTexts());
                }
            }
            return(m_objs.Count > 0);
        }
 private InterestingTextList GetInterestingTextList()
 {
     return(InterestingTextsDecorator.GetInterestingTextList(m_mediator, Cache.ServiceLocator));
 }
Exemple #5
0
        private void RebuildStatisticsTable()
        {
            statisticsBox.Clear();
            // TODO-Linux: SelectionTabs isn't implemented on Mono
            statisticsBox.SelectionTabs = new int[] { 10, 300 };
            //retrieve the default UI font.
            var font = FontHeightAdjuster.GetFontForStyle(StyleServices.NormalStyleName,
                                                          FontHeightAdjuster.StyleSheetFromMediator(mediator),
                                                          Cache.DefaultUserWs, Cache.WritingSystemFactory);
            //increase the size of the default UI font and make it bold for the header.
            Font headerFont = new Font(font.FontFamily, font.SizeInPoints + 1.0f, FontStyle.Bold, font.Unit, font.GdiCharSet);

            //refresh the statisticsDescription (in case of font changes)
            statisticsBox.Text = ITextStrings.ksStatisticsView_HeaderText;

            int row              = 0;
            var textList         = InterestingTextsDecorator.GetInterestingTextList(mediator, Cache.ServiceLocator);
            int numberOfSegments = 0;
            int wordCount        = 0;
            int uniqueWords      = 0;

            Dictionary <int, int>           languageCount     = new Dictionary <int, int>();
            Dictionary <int, Set <String> > languageTypeCount = new Dictionary <int, Set <String> >();

            //for each interesting text
            foreach (var text in textList.InterestingTexts)
            {
                //if a text is deleted in Interlinear there could be a text in this list which has invalid data.
                if (text.Hvo < 0)
                {
                    continue;
                }
                //for every paragraph in the interesting text
                for (int index = 0; index < text.ParagraphsOS.Count; ++index)
                {
                    //count the segments in this paragraph
                    numberOfSegments += text[index].SegmentsOS.Count;
                    //count all the things analyzed as words
                    var words = new List <IAnalysis>(text[index].Analyses);
                    foreach (var word in words)
                    {
                        var wordForm = word.Wordform;
                        if (wordForm != null)
                        {
                            var valdWSs = wordForm.Form.AvailableWritingSystemIds;
                            foreach (var ws in valdWSs)
                            {
                                // increase the count of words(tokens) for this language
                                int count = 0;
                                if (languageCount.TryGetValue(ws, out count))
                                {
                                    languageCount[ws] = count + 1;
                                }
                                else
                                {
                                    languageCount.Add(ws, 1);
                                }
                                //increase the count of unique words(types) for this language
                                Set <String> pair;
                                if (languageTypeCount.TryGetValue(ws, out pair))
                                {
                                    //add the string for this writing system in all lower case to the set, unique count is case insensitive
                                    pair.Add(word.Wordform.Form.get_String(ws).Text.ToLower());
                                }
                                else
                                {
                                    //add the string for this writing system in all lower case to the set, unique count is case insensitive
                                    languageTypeCount.Add(ws, new Set <String> {
                                        word.Wordform.Form.get_String(ws).Text.ToLower()
                                    });
                                }
                            }
                        }
                    }
                    words.RemoveAll(item => !item.HasWordform);
                    wordCount += words.Count;
                }
            }
            // insert total word type count
            statisticsBox.Text += Environment.NewLine + Environment.NewLine + Environment.NewLine + "\t" + ITextStrings.ksStatisticsViewTotalWordTypesText + "\t";             // Todo: find the right System.?.NewLine constant

            ++row;
            //add one row for the unique words in each language.
            foreach (KeyValuePair <int, Set <String> > keyValuePair in languageTypeCount)
            {
                var ws = Cache.WritingSystemFactory.get_EngineOrNull(keyValuePair.Key);

                string labText = (ws != null ? ws.ToString() : "#unknown#") + @":";
                statisticsBox.Text += Environment.NewLine + Environment.NewLine + "\t" + labText + "\t";                 // Todo: find the right System.?.NewLine constant
                statisticsBox.Text += "" + keyValuePair.Value.Count;
                ++row;
                uniqueWords += keyValuePair.Value.Count;                 //increase the total of unique words
            }

            // next insert the word count.
            statisticsBox.Text += Environment.NewLine + Environment.NewLine + Environment.NewLine + "\t" + ITextStrings.ksStatisticsViewTotalWordTokensText + "\t";             // Todo: find the right System.?.NewLine constant
            statisticsBox.Text += wordCount;
            ++row;
            //add one row for the token count for each language.
            foreach (KeyValuePair <int, int> keyValuePair in languageCount)
            {
                var ws = Cache.WritingSystemFactory.get_EngineOrNull(keyValuePair.Key);

                string labText = (ws != null ? ws.ToString() : "#unknown#") + @":";
                statisticsBox.Text += Environment.NewLine + Environment.NewLine + "\t" + labText + "\t";                 // Todo: find the right System.?.NewLine constant
                statisticsBox.Text += "" + keyValuePair.Value;
                ++row;
            }
            statisticsBox.Text += Environment.NewLine + Environment.NewLine + Environment.NewLine + "\t" + ITextStrings.ksStatisticsViewTotalSentencesText + "\t";             // Todo: find the right System.?.NewLine constant

            // next insert the sentence count.
            statisticsBox.Text += numberOfSegments;

            // insert the total word type count into the richTextBox (it wasn't available earlier)
            statisticsBox.SelectionStart = statisticsBox.Find(ITextStrings.ksStatisticsViewTotalWordTypesText) +
                                           ITextStrings.ksStatisticsViewTotalWordTypesText.Length;
            statisticsBox.SelectionLength = 1;
            statisticsBox.SelectedText    = "\t" + uniqueWords;

            // Set the font for the header. Do this after we add the other stuff to make sure
            // it doesn't apply to extra text added adjacent to it.
            statisticsBox.Select(0, ITextStrings.ksStatisticsView_HeaderText.Length);
            statisticsBox.SelectionFont = headerFont;
            statisticsBox.Select(0, 0);
        }