public bool RefreshDisplay()
        {
            ConcordanceControl concordanceControl = ReCurseControls(this);

            if (concordanceControl != null)
            {
                concordanceControl.RefreshDisplay();
                return(true);
            }
            Debug.Assert(concordanceControl != null, "ConcordanceContainer is missing the concordance control.");
// ReSharper disable HeuristicUnreachableCode
// (because it's wrong)
            return(false);
// ReSharper restore HeuristicUnreachableCode
        }
Esempio n. 2
0
        public void UpdateConcordanceForCustomField_FindsMatches()
        {
            // build pre-existing data
            var sl  = Cache.ServiceLocator;
            var wsf = Cache.WritingSystemFactory;
            var mdc = Cache.ServiceLocator.GetInstance <IFwMetaDataCacheManaged>();

            IWfiWordform word            = null;
            ITsString    para1_1Contents = null;
            Guid         segGuid         = new Guid();

            NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                mdc.AddCustomField("Segment", "test1", CellarPropertyType.String, 0,
                                   "just testing", Cache.DefaultAnalWs, Guid.Empty);
                var text1 = MakeText("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA",
                                     "Sentence one. Sentence 2.");
                var sttext1      = text1.ContentsOA;
                var para1_1      = sttext1.ParagraphsOS[0] as IStTxtPara;
                var segment1_1_1 = para1_1.SegmentsOS[0];
                var testFlid     = mdc.GetFieldId("Segment", "test1", false);
                Cache.MainCacheAccessor.SetString(segment1_1_1.Hvo, testFlid,
                                                  TsStringUtils.MakeString("the big bad wolf", Cache.DefaultAnalWs));

                var text2 = MakeText("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAB",
                                     "Another Sentence one. Another Sentence 2.");
                var sttext2      = text2.ContentsOA;
                var para2_1      = sttext2.ParagraphsOS[0] as IStTxtPara;
                var segment2_1_2 = para2_1.SegmentsOS[1];
                Cache.MainCacheAccessor.SetString(segment2_1_2.Hvo, testFlid,
                                                  TsStringUtils.MakeString("the nice big dog", Cache.DefaultAnalWs));
                var segment2_1_1 = para2_1.SegmentsOS[0];
                Cache.MainCacheAccessor.SetString(segment2_1_1.Hvo, testFlid,
                                                  TsStringUtils.MakeString("the small furry cat", Cache.DefaultAnalWs));

                var paragraphs = new HashSet <IStTxtPara>();
                paragraphs.Add(para1_1);
                paragraphs.Add(para2_1);
                var vwPattern     = VwPatternClass.Create();
                vwPattern.Pattern = TsStringUtils.MakeString("big", Cache.DefaultAnalWs);
                var matcher       = new RegExpMatcher(vwPattern);
                var result        = ConcordanceControl.GetOccurrencesInCustomField(testFlid, paragraphs,
                                                                                   Cache.MainCacheAccessor, matcher);
                Assert.That(result, Has.Count.EqualTo(2));
                Assert.That(result.Any(pf => pf.Segment == segment1_1_1));
                Assert.That(result.Any(pf => pf.Segment == segment2_1_2));
            });
        }
        /// <summary>
        /// This method will handle the RefreshDisplay calls for all the child controls of the ConcordanceContainer, the ConcordanceControl needs to be
        /// refreshed last because its interaction with the Mediator will update the other views, if it isn't called last then the caches and contents
        /// of the other views will be inconsistant with the ConcordanceControl and will lead to crashes or incorrect display behavior.
        /// </summary>
        /// <param name="parentControl">The control to Recurse</param>
        private ConcordanceControl ReCurseControls(Control parentControl)
        {
            ConcordanceControl concordanceControl = null;

            foreach (Control control in parentControl.Controls)
            {
                if (control is ConcordanceControl)
                {
                    concordanceControl = control as ConcordanceControl;
                    continue;
                }
                var cv = control as IClearValues;
                if (cv != null)
                {
                    cv.ClearValues();
                }
                var  refreshable       = control as IRefreshableRoot;
                bool childrenRefreshed = false;
                if (refreshable != null)
                {
                    childrenRefreshed = refreshable.RefreshDisplay();
                }
                if (!childrenRefreshed)
                {
                    //Recurse into the child controls, make sure we only have one concordanceControl
                    if (concordanceControl == null)
                    {
                        concordanceControl = ReCurseControls(control);
                    }
                    else
                    {
                        var thereCanBeOnlyOne = ReCurseControls(control);
                        Debug.Assert(thereCanBeOnlyOne == null,
                                     "Two concordance controls in the same window is not supported. One won't refresh properly.");
                    }
                }
            }
            return(concordanceControl);
        }
Esempio n. 4
0
		internal static List<int> ConcordParagraphs(FdoCache cache, int[] hvosStTxtPara, ProgressState progress,
			IMatcher matcher, ConcordanceControl.ConcordanceLines line)
		{
			using (ParagraphParser pp = new ParagraphParser(cache))
			{
				// this will effectively clear ConcordanceWordforms, which seems overkill, but
				// since we are changing the occurrences on those wordforms,
				// and also possibly adding many new wordforms, we should just allow RecordLists that use
				// ConcordanceWordforms to reload the list.
				// (Enhance: is there any way we can make those lists be smart about when they need to reload,
				// rather than forcing them to?)
				(pp.m_wfi as WordformInventory).SuspendUpdatingConcordanceWordforms = true;
				pp.CreateDummyWordforms = true;
				pp.m_hvosStTxtPara = hvosStTxtPara;
				if (matcher != null)
					pp.m_matchingAnnotations = new List<int>();
				ParagraphParser.ResetParseSessionDependentStaticData();

				// Estimate the number of total number of milestones we'll set.
				// Enhance: we could construct a way to set percentage done based upon
				// number of texts and paragraphs in each text.
				if (progress is MilestoneProgressState)
				{
					MilestoneProgressState mp = progress as SIL.FieldWorks.Common.Controls.MilestoneProgressState;
					for (int i = 0; i < pp.m_hvosStTxtPara.Length; ++i)
					{
						mp.AddMilestone(1);
					}
				}

				// Preload all the paragraphs.
				cache.PreloadIfMissing(hvosStTxtPara, (int)StTxtPara.StTxtParaTags.kflidContents, 0, false);

				// Parse each text to load our paragraph and wordform segment annotations.
				int cPara = 0;
				using (SuppressSubTasks suppressor = new SuppressSubTasks(cache, true))
				{
					foreach (IStTxtPara para in new FdoObjectSet<IStTxtPara>(cache, pp.m_hvosStTxtPara, false))
					{
						++cPara;
						pp.Parse(para, matcher, line);
						progress.SetMilestone();
						progress.Breath();
						if (pp.m_matchingAnnotations != null &&
							pp.m_matchingAnnotations.Count >= ConcordanceControl.MaxConcordanceMatches())
						{
							MessageBox.Show(String.Format(ITextStrings.ksShowingOnlyTheFirstXXXMatches,
								pp.m_matchingAnnotations.Count, cPara, pp.m_hvosStTxtPara.Length),
								ITextStrings.ksNotice, MessageBoxButtons.OK, MessageBoxIcon.Information);
							break;
						}
					}
					pp.CleanupLeftoverAnnotations(progress);
				}
				progress.SetMilestone();
				progress.Breath();
				(pp.m_wfi as WordformInventory).SuspendUpdatingConcordanceWordforms = false;
				return pp.m_matchingAnnotations;
			}
		}
Esempio n. 5
0
		private void Setup(IStTxtPara para, IMatcher matcher, ConcordanceControl.ConcordanceLines line)
		{
			m_para = para;
			m_tssPara = para.Contents.UnderlyingTsString;
			m_paraWs = StringUtils.GetWsAtOffset(m_tssPara, 0);
			m_wordMaker = new WordMaker(m_tssPara, para.Cache.LanguageWritingSystemFactoryAccessor);
			m_paragraphTextScanner.Tss = m_tssPara;
			m_matcher = matcher;
			m_line = line;
		}
Esempio n. 6
0
		private void ParseCore(IStTxtPara para, IMatcher matcher, ConcordanceControl.ConcordanceLines line, bool fUseRealData)
		{
			Setup(para, matcher, line);
			if (fUseRealData && !m_fFinishedBuildAnalysisList)
			{
				BuildAnalysisList(new NullProgressState());	// load any existing data from the database.
			}
			Parse();
			CleanupLeftoverAnnotations(new NullProgressState());
		}
Esempio n. 7
0
		private void Parse(IStTxtPara para, IMatcher matcher, ConcordanceControl.ConcordanceLines line, bool fUseRealData)
		{
			if (m_fSuppressSubTasks)
			{
				using (SuppressSubTasks suppressor = new SuppressSubTasks(para.Cache, true))
				{
					ParseCore(para, matcher, line, fUseRealData);
				}
			}
			else
			{
				ParseCore(para, matcher, line, fUseRealData);
			}
		}
Esempio n. 8
0
		private void Parse(IStTxtPara para, IMatcher matcher, ConcordanceControl.ConcordanceLines line)
		{
			Parse(para, matcher, line, true);
		}
Esempio n. 9
0
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				m_concordanceControl = null;
			}
			base.Dispose(disposing);
		}