private bool IsExpressionFound(string searchString, ISegment segment) { var textVisitor = new SegmentTextVisitor(); string text; if (CustomSettings.UseTagContent) { text = CustomSettings.AndOrTagContent ? textVisitor.GetRawText(segment) : textVisitor.GetJustTagContent(segment); } else { text = textVisitor.GetText(segment); } var regexOptions = Settings.IsCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase; var textSearchOptions = Settings.IsCaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; var success = Settings.IsRegularExpression ? ContentHelper.SearchContentRegularExpression(text, searchString, regexOptions) : text.IndexOf(searchString, textSearchOptions) > -1; return(success); }
private string GetSegmentText(ISegment segment) { var textVisitor = new SegmentTextVisitor(); string text; if (CustomSettings.UseTagContent) { text = CustomSettings.AndOrTagContent ? textVisitor.GetText(segment, SegmentTextVisitor.DetailLevel.Raw) : textVisitor.GetText(segment, SegmentTextVisitor.DetailLevel.JustTagContent); } else { text = textVisitor.GetText(segment); } return(text); }
private string GetSegmentText(ISegment segment) { var textVisitor = new SegmentTextVisitor(); string text; if (_customSettings.SearchInTagContent) { text = _customSettings.SearchInTagContentAndText ? textVisitor.GetText(segment, SegmentTextVisitor.DetailLevel.Raw) : textVisitor.GetText(segment, SegmentTextVisitor.DetailLevel.JustTagContent); } else { text = textVisitor.GetText(segment); } return(text); }
protected override void Execute() { var activeDocument = SdlTradosStudio.Application.GetController <EditorController>()?.ActiveDocument; var displayFilterControl = CommunityApplicationInitializer.DisplayFilterControl; if (activeDocument != null && displayFilterControl != null) { var activeSegment = activeDocument.ActiveSegmentPair; var targetText = _segmentTextVisitor.GetText(activeSegment?.Target); displayFilterControl.target_textbox.Text = targetText; displayFilterControl.ApplyFilter(false); } }
private static List <ISegmentPair> GetQualifiedSegmentPairs(IEnumerable <ISegmentPair> segmentPairs, CustomFilterSettings customFilterSettings) { var availableSegmentPairs = new List <ISegmentPair>(); var segmentVisitor = new SegmentTextVisitor(); foreach (var segmentPair in segmentPairs) { var sourceText = segmentVisitor.GetText(segmentPair.Source); var targetText = segmentVisitor.GetText(segmentPair.Target); if (string.IsNullOrEmpty(targetText)) { targetText = sourceText; } if (targetText.Length >= customFilterSettings.QualitySamplingMinCharsValue && targetText.Length <= customFilterSettings.QualitySamplingMaxCharsValue) { availableSegmentPairs.Add(segmentPair); } } return(availableSegmentPairs); }
public bool EvaluateRow(DisplayFilterRowInfo rowInfo) { var success = Settings.ShowAllContent || rowInfo.IsSegment; if (rowInfo.IsSegment) { if (ReverseSearch) { return(CustomFilterHelper.Reverse(Settings, success, rowInfo, CustomSettings, ActiveDocument)); } if (success && Settings.SegmentReviewTypes != null && Settings.SegmentReviewTypes.Any()) { success = rowInfo.IsSegmentReviewTypes(Settings); } if (success && Settings.ConfirmationLevels != null && Settings.ConfirmationLevels.Any()) { success = rowInfo.IsConfirmationLevelFound(Settings); } if (success && Settings.OriginTypes != null && Settings.OriginTypes.Any()) { if (!Settings.OriginTypes.Contains("EditedF") && !Settings.OriginTypes.Contains("UneditedF")) { success = rowInfo.IsOriginTypeFound(Settings); } } if (success && Settings.PreviousOriginTypes != null && Settings.PreviousOriginTypes.Any()) { success = rowInfo.IsPreviousOriginTypeFound(Settings); } if (success && Settings.RepetitionTypes != null && Settings.RepetitionTypes.Any()) { if (!Settings.RepetitionTypes.Contains("Unique")) { success = rowInfo.IsRepetitionTypes(Settings); } } if (success && Settings.SegmentLockingTypes != null && Settings.SegmentLockingTypes.Any()) { success = rowInfo.IsSegmentLockingTypes(Settings); } if (success && Settings.SegmentContentTypes != null && Settings.SegmentContentTypes.Any()) { success = rowInfo.IsSegmentContentTypes(Settings); } if (success && Settings.SourceText.Trim() != string.Empty) { success = rowInfo.IsTextFoundInSource(Settings); if (Settings.IsRegularExpression) { var textVisitor = new SegmentTextVisitor(); var text = textVisitor.GetText(rowInfo.SegmentPair.Source); success = ContentHelper.SearchContentRegularExpression(text, Settings.SourceText); } } if (success && Settings.TargetText.Trim() != string.Empty) { success = rowInfo.IsTextFoundInTarget(Settings); } if (success && !CustomSettings.UseRegexCommentSearch && Settings.CommentText.Trim() != string.Empty) { success = rowInfo.IsTextFoundInComment(Settings); } if (success && Settings.CommentAuthor.Trim() != string.Empty) { success = rowInfo.IsAuthorFoundInComment(Settings); } if (success && Settings.CommentSeverity > 0) { success = rowInfo.IsSeverityFoundInComment(Settings); } if (success && Settings.ContextInfoTypes.Any()) { success = rowInfo.IsContextInfoTypes(Settings); } // check custom settings if (success) { success = CustomFilterHelper.Filter(CustomSettings, rowInfo, success, ActiveDocument); } } return(success); }
public bool EvaluateRow(DisplayFilterRowInfo rowInfo) { var success = !(!Settings.ShowAllContent && !rowInfo.IsSegment); if (rowInfo.IsSegment) { if (ReverseSearch) { return(Reverse(success, rowInfo)); } if (success && Settings.SegmentReviewTypes != null && Settings.SegmentReviewTypes.Any()) { success = rowInfo.IsSegmentReviewTypes(Settings); } if (success && Settings.ConfirmationLevels != null && Settings.ConfirmationLevels.Any()) { success = rowInfo.IsConfirmationLevelFound(Settings); } if (success && Settings.OriginTypes != null && Settings.OriginTypes.Any()) { success = rowInfo.IsOriginTypeFound(Settings); } if (success && Settings.PreviousOriginTypes != null && Settings.PreviousOriginTypes.Any()) { success = rowInfo.IsPreviousOriginTypeFound(Settings); } if (success && Settings.RepetitionTypes != null && Settings.RepetitionTypes.Any()) { if (!Settings.RepetitionTypes.Contains("Unique")) { success = rowInfo.IsRepetitionTypes(Settings); } } if (success && Settings.SegmentLockingTypes != null && Settings.SegmentLockingTypes.Any()) { success = rowInfo.IsSegmentLockingTypes(Settings); } if (success && Settings.SegmentContentTypes != null && Settings.SegmentContentTypes.Any()) { success = rowInfo.IsSegmentContentTypes(Settings); } if (success && Settings.SourceText.Trim() != string.Empty) { success = rowInfo.IsTextFoundInSource(Settings); if (Settings.IsRegularExpression) { var textVisitor = new SegmentTextVisitor(); var text = textVisitor.GetText(rowInfo.SegmentPair.Source); success = ContentHelper.SearchContentRegularExpression(text, Settings.SourceText); } } if (success && Settings.TargetText.Trim() != string.Empty) { success = rowInfo.IsTextFoundInTarget(Settings); } if (success && !CustomSettings.UseRegexCommentSearch && Settings.CommentText.Trim() != string.Empty) { success = rowInfo.IsTextFoundInComment(Settings); } if (success && Settings.CommentAuthor.Trim() != string.Empty) { success = rowInfo.IsAuthorFoundInComment(Settings); } if (success && Settings.CommentSeverity > 0) { success = rowInfo.IsSeverityFoundInComment(Settings); } if (success && Settings.ContextInfoTypes.Any()) { success = rowInfo.IsContextInfoTypes(Settings); } // check custom settings var rowId = rowInfo.SegmentPair.Properties.Id.Id; if (success && CustomSettings.EvenNo) { success = SegmentNumbersHelper.IsEven(rowId); } if (success && CustomSettings.OddsNo) { success = SegmentNumbersHelper.IsOdd(rowId); } if (success && CustomSettings.SplitSegments) { success = SegmentNumbersHelper.IsSplitSegment(rowId, ActiveDocument); } if (success && (CustomSettings.MergedSegments || CustomSettings.MergedAcross)) { success = SegmentNumbersHelper.IsMergedSegment(rowId, ActiveDocument, CustomSettings.MergedAcross); } if (success && CustomSettings.SourceEqualsTarget) { success = SegmentNumbersHelper.IsSourceEqualsToTarget(rowInfo.SegmentPair, CustomSettings.IsEqualsCaseSensitive); } if (success && CustomSettings.Grouped && !string.IsNullOrWhiteSpace(CustomSettings.GroupedList)) { success = SegmentNumbersHelper.IdInRange(rowId, CustomSettings.GroupedList); } if (success && CustomSettings.UseRegexCommentSearch && !string.IsNullOrWhiteSpace(CustomSettings.CommentRegex)) { //create a list with source and target comments var commentsList = rowInfo.SegmentPair.Source.GetComments(); commentsList.AddRange(rowInfo.SegmentPair.Target.GetComments()); success = CommentsHelper.IsCommentTextFoundWithRegex(commentsList, CustomSettings.CommentRegex); } if (success && CustomSettings.Colors.Count > 0) { try { success = ColorPickerHelper.ContainsColor(rowInfo, CustomSettings.Colors); }catch (Exception e) { } } //fuzzy if (success && !string.IsNullOrWhiteSpace(CustomSettings.FuzzyMin) && !string.IsNullOrWhiteSpace(CustomSettings.FuzzyMax)) { success = FuzzyHelper.IsInFuzzyRange(rowInfo, CustomSettings.FuzzyMin, CustomSettings.FuzzyMax); } //unique if (success && CustomSettings.Unique) { var settings = new DisplayFilterSettings { RepetitionTypes = new List <string> { "FirstOccurrences" } }; var isFirst = rowInfo.IsRepetitionsFirstOccurrences(settings); if (isFirst) { return(true); } var isRepeted = rowInfo.SegmentPair.Properties.TranslationOrigin.IsRepeated; if (!isRepeted) { return(true); } return(false); } } return(success); }