// --------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Finds objects, within certain scope, having the specified text within the specified properties. /// Returns hints on the found objects. /// </summary> public IList <FoundObjectHint> FindTextInObjects(string SearchedText, bool IsCaseSensitive, bool IsInspectingWholeWord, bool InScopeComposition, bool InScopeDomain, bool IncludeConcepts, bool IncludeRelationships, bool IncludeMarkers, bool IncludeOthers, bool InPropertyName, bool InPropertyTechName, bool InPropertySummary, bool InPropertyDescription, bool InPropertyDetailDesignation, bool InPropertyDetailContent, bool InPropertyTechSpec) { DocumentEngine.SearchProviderOfTextNameWithoutPropertyAccessor = VisualComplement.PROP_FIELD_TEXT; DocumentEngine.SearchProviderOfTextExtractorWithoutPropertyAccessor = TextExtractorWithoutPropertyAccessor; DocumentEngine.SearchProviderOfObjectTypeDetector = ObjectTypeDetector; FoundObjectHint.ClearTemporalDocuments(); var SearchTrace = new List <object>(); var Results = new List <FoundObjectHint>(); if (InScopeComposition) { this.FindTextInTargetObject(SearchedText, this.TargetComposition, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec); } if (InScopeDomain) { if (IncludeConcepts) { this.TargetComposition.CompositeContentDomain.ConceptDefinitions.ForEach(condef => this.FindTextInTargetObject(SearchedText, condef, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec)); } if (IncludeRelationships) { this.TargetComposition.CompositeContentDomain.RelationshipDefinitions.ForEach(reldef => this.FindTextInTargetObject(SearchedText, reldef, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec)); } if (IncludeMarkers) { this.TargetComposition.CompositeContentDomain.MarkerDefinitions.ForEach(mkrdef => this.FindTextInTargetObject(SearchedText, mkrdef, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec)); } if (IncludeOthers) { this.FindTextInTargetObject(SearchedText, this.TargetComposition.CompositeContentDomain, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec); this.TargetComposition.CompositeContentDomain.TableDefinitions.Where(tdef => tdef.Alterability != EAlterability.System).ForEach(tabdef => this.FindTextInTargetObject(SearchedText, tabdef, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec)); this.TargetComposition.CompositeContentDomain.BaseTables.ForEach(bastab => this.FindTextInTargetObject(SearchedText, bastab, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec)); this.TargetComposition.CompositeContentDomain.LinkRoleVariants.ForEach(variant => this.FindTextInTargetObject(SearchedText, variant, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec)); this.TargetComposition.CompositeContentDomain.ExternalLanguages.ForEach(lang => this.FindTextInTargetObject(SearchedText, lang, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec)); this.TargetComposition.CompositeContentDomain.ConceptDefClusters.ForEach(lang => this.FindTextInTargetObject(SearchedText, lang, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec)); this.TargetComposition.CompositeContentDomain.RelationshipDefClusters.ForEach(lang => this.FindTextInTargetObject(SearchedText, lang, Results, SearchTrace, "", IncludeConcepts, IncludeRelationships, IncludeMarkers, IncludeOthers, IsCaseSensitive, IsInspectingWholeWord, InPropertyName, InPropertyTechName, InPropertySummary, InPropertyDescription, InPropertyDetailDesignation, InPropertyDetailContent, InPropertyTechSpec)); } } return(Results); }
/// <summary> /// Replaces text in the specified found object Hints. /// Returns indication of change. /// </summary> public bool ReplaceTextOfFoundObjects(IEnumerable <FoundObjectHint> Hints, string SearchedText, string NewText) { this.StartCommandVariation("Replace Text"); // PENDING: For Rich-Documents (XAML or RTF based) see... // http://shevaspace.blogspot.com/2007/11/how-to-search-text-in-wpf-flowdocument.html // http://stackoverflow.com/questions/9228414/flowdocument-replace-text-in-xamlpackage CachedReplaceableDocumentTextRuns = null; var Changes = new List <FoundObjectHint>(); int Offset = 0; foreach (var Hint in Hints) { Offset = (Hint.MustBeDisplacedOnReplace ? Offset + (NewText.Length - SearchedText.Length) : 0); if (Hint.SourceAccessor != null) { if (!(Hint.SourceObject is IMModelClass)) { continue; } var Text = Hint.SourceAccessor.Read(Hint.SourceObject as IMModelClass) as string; if (Text.IsAbsent()) { continue; } if (Hint.RichDocumentRunSource != null) { Text = Hint.RichDocumentRunSource.Item2.Text; } Text = Text.ReplaceAt(Hint.TextPosition + Offset, SearchedText.Length, NewText); if (Hint.RichDocumentRunSource != null) { Hint.RichDocumentRunSource.Item2.Text = Text; } else { Hint.SourceAccessor.Write(Hint.SourceObject as IMModelClass, Text); } if (!Hint.MustBeDisplacedOnReplace) { if (Hint.SourceObject is Idea) { ((Idea)Hint.SourceObject).VisualRepresentators.ForEach(vrep => vrep.Render()); } if (Hint.SourceObject is IVersionUpdater) { ((IVersionUpdater)Hint.SourceObject).UpdateVersion(); } } Changes.Add(Hint); } else { var TargetComplement = Hint.SourceObject as VisualComplement; if (TargetComplement == null) { continue; } var Text = TargetComplement.GetPropertyField <string>(VisualComplement.PROP_FIELD_TEXT).NullDefault(""); Text = Text.ReplaceAt(Hint.TextPosition + Offset, SearchedText.Length, NewText); TargetComplement.SetPropertyField(VisualComplement.PROP_FIELD_TEXT, Text); if (!Hint.MustBeDisplacedOnReplace) { TargetComplement.GetDisplayingView().UpdateVersion(); } TargetComplement.Render(); Changes.Add(Hint); } } FoundObjectHint.ApplyChanges(Changes); CachedReplaceableDocumentTextRuns = null; this.CompleteCommandVariation(); Console.WriteLine("Text Replaced in {0} occurrences, from '{1}' to '{2}'.", Changes.Count, SearchedText, NewText); return(Changes.Count > 0); }
private void UserControl_Unloaded(object sender, RoutedEventArgs e) { FoundObjectHint.ClearTemporalDocuments(); }