private void ParseText(string value)
        {
            if (value == null)
            {
                value = "";
            }

            if (this.stackPanel == null)
            {
                return;
            }
            // Clear previous TextBlocks
            this.stackPanel.Children.Clear();


            bool fitIn2000Pixels = CheckFitInMaxRenderHeight(value);

            if (fitIn2000Pixels)
            {
                RichTextBox textBlock = this.GetTextBlock();
                BrowserNavigationService.SetText(textBlock, value);
                this.stackPanel.Children.Add(textBlock);
            }
            else
            {
                ParseLineExtended(value);
            }
        }
Beispiel #2
0
        private void ParseText(string value)
        {
            if (value == null)
            {
                value = "";
            }

            if (_stackPanel == null)
            {
                return;
            }
            // Clear previous TextBlocks
            _stackPanel.Children.Clear();

            var suppressParsing = BrowserNavigationService.GetSuppressParsing(this);
            var message         = DataContext as TLMessageBase;
            var fitIn2000Pixels = CheckFitInMaxRenderHeight(value);

            if (fitIn2000Pixels)
            {
                var textBlock = GetTextBlock();
                BrowserNavigationService.SetSuppressParsing(textBlock, suppressParsing);
                BrowserNavigationService.SetMessage(textBlock, message);
                BrowserNavigationService.SetText(textBlock, value);
                _stackPanel.Children.Add(textBlock);
            }
            else
            {
                ParseLineExtended(value);
            }
        }
Beispiel #3
0
        public void Initialize(NewsActivityComment activityComment, IEnumerable <User> users, IEnumerable <Group> groups, bool addSeparator)
        {
            if (activityComment.from_id > 0L)
            {
                User user = users != null?Enumerable.FirstOrDefault <User>(users, (Func <User, bool>)(u => u.id == activityComment.from_id)) : null;

                if (user != null)
                {
                    this._userName = user.Name;
                    string photoMax = user.photo_max;
                    if (!string.IsNullOrEmpty(photoMax))
                    {
                        this._userPhotoUri = new Uri(photoMax);
                    }
                }
            }
            else
            {
                Group group = groups != null?Enumerable.FirstOrDefault <Group>(groups, (Func <Group, bool>)(u => u.id == -activityComment.from_id)) : null;

                if (group != null)
                {
                    this._userName = group.name;
                    string photo200 = group.photo_200;
                    if (!string.IsNullOrEmpty(photo200))
                    {
                        this._userPhotoUri = new Uri(photo200);
                    }
                }
            }
            BrowserNavigationService.SetText((DependencyObject)this.textBoxComment, UIStringFormatterHelper.SubstituteMentionsWithNames(activityComment.text ?? ""));
            BrowserNavigationService.SetDisableHyperlinks((DependencyObject)this.textBoxComment, true);
            ((UIElement)this.textBoxComment).Measure(new Size(364.0, double.PositiveInfinity));
            Size desiredSize = ((UIElement)this.textBoxComment).DesiredSize;
            // ISSUE: explicit reference operation
            double height = ((Size)@desiredSize).Height;

            if (!double.IsNaN(height) && !double.IsInfinity(height) && height < 48.0)
            {
                this._height = this._height - 24.0;
            }
            this._addSeparator      = addSeparator;
            this.textBlockName.Text = this._userName;
            this.textBlockName.CorrectText(364.0);
            Canvas.SetTop((UIElement)this.borderChevron, this._height / 2.0 - ((FrameworkElement)this.borderChevron).Height / 2.0);
            if (this._addSeparator)
            {
                Canvas.SetTop((UIElement)this.rectSeparator, this._height - ((FrameworkElement)this.rectSeparator).Height);
                ((UIElement)this.rectSeparator).Visibility = Visibility.Visible;
            }
            ((FrameworkElement)this.canvasBackground).Height = this._height;
            ((FrameworkElement)this.canvas).Height           = this._height;
        }
 private void GeneratePhotoText()
 {
     if (!string.IsNullOrEmpty(this.PhotoVM.Text))
     {
         BrowserNavigationService.SetText((DependencyObject)this.textPhotoText, this.PhotoVM.Text);
         ((UIElement)this.textPhotoText).Visibility = Visibility.Visible;
     }
     else
     {
         BrowserNavigationService.SetText((DependencyObject)this.textPhotoText, "");
         ((UIElement)this.textPhotoText).Visibility = Visibility.Collapsed;
     }
 }
        private void ParseLineExtended(string allText)
        {
            if (string.IsNullOrEmpty(allText))
            {
                return;
            }


            int cutIndex = MAX_STR_LENGTH;

            if (cutIndex >= allText.Length)
            {
                cutIndex = allText.Length - 1;
            }

            var endOfSentenceIndAfterCut = allText.IndexOf(".", cutIndex);

            if (endOfSentenceIndAfterCut >= 0 && endOfSentenceIndAfterCut - cutIndex < 200)
            {
                cutIndex = endOfSentenceIndAfterCut;
            }
            else
            {
                var whiteSpaceIndAfterCut = allText.IndexOf(' ', cutIndex);

                if (whiteSpaceIndAfterCut >= 0 && whiteSpaceIndAfterCut - cutIndex < 100)
                {
                    cutIndex = whiteSpaceIndAfterCut;
                }
            }

            // add all whitespaces before cut
            while (cutIndex + 1 < allText.Length &&
                   allText[cutIndex + 1] == ' ')
            {
                cutIndex++;
            }

            string      leftSide  = allText.Substring(0, cutIndex + 1);
            RichTextBox textBlock = this.GetTextBlock();

            BrowserNavigationService.SetText(textBlock, leftSide);
            this.stackPanel.Children.Add(textBlock);

            allText = allText.Substring(cutIndex + 1);

            if (allText.Length > 0)
            {
                ParseLineExtended(allText);
            }
        }
Beispiel #6
0
        private void ParseText(string value)
        {
            if (value == null)
            {
                value = "";
            }

            if (_stackPanel == null)
            {
                return;
            }

            //System.Diagnostics.Debug.WriteLine("{0} ParseText", GetHashCode());
            // Clear previous TextBlocks
            _stackPanel.Children.Clear();

            var suppressParsing  = BrowserNavigationService.GetSuppressParsing(this);
            var message          = DataContext as TLMessageBase ?? BrowserNavigationService.GetMessage(this);
            var decryptedMessage = DataContext as TLDecryptedMessageBase;
            var fitIn2000Pixels  = CheckFitInMaxRenderHeight(value);

            if (fitIn2000Pixels)
            {
                var textBlock = GetTextBlock();
                BrowserNavigationService.SetSuppressParsing(textBlock, suppressParsing);
                BrowserNavigationService.SetMessage(textBlock, message);
                BrowserNavigationService.SetDecryptedMessage(textBlock, decryptedMessage);
                BrowserNavigationService.SetAddFooter(textBlock, true);
                BrowserNavigationService.SetText(textBlock, value);
                _stackPanel.Children.Add(textBlock);

                _footerRun = GetFooter(textBlock);
            }
            else
            {
                ParseLineExtended(value);
            }
        }
Beispiel #7
0
        private void ParseLineExtended(string allText)
        {
            if (string.IsNullOrEmpty(allText))
            {
                return;
            }


            int cutIndex = MAX_STR_LENGTH;

            if (cutIndex >= allText.Length)
            {
                cutIndex = allText.Length - 1;
            }

            var endOfSentenceIndAfterCut = allText.IndexOf(".", cutIndex);

            if (endOfSentenceIndAfterCut >= 0 && endOfSentenceIndAfterCut - cutIndex < 200)
            {
                cutIndex = endOfSentenceIndAfterCut;
            }
            else
            {
                var whiteSpaceIndAfterCut = allText.IndexOf(' ', cutIndex);

                if (whiteSpaceIndAfterCut >= 0 && whiteSpaceIndAfterCut - cutIndex < 100)
                {
                    cutIndex = whiteSpaceIndAfterCut;
                }
            }

            // add all whitespaces before cut
            while (cutIndex + 1 < allText.Length &&
                   allText[cutIndex + 1] == ' ')
            {
                cutIndex++;
            }

            var suppressParsing  = BrowserNavigationService.GetSuppressParsing(this);
            var message          = DataContext as TLMessageBase;
            var decryptedMessage = DataContext as TLDecryptedMessageBase;

            var leftSide = allText.Substring(0, cutIndex + 1);

            allText = allText.Substring(cutIndex + 1);
            var isLastTextBlock = allText.Length <= 0;
            var textBlock       = GetTextBlock();

            BrowserNavigationService.SetSuppressParsing(textBlock, suppressParsing);
            BrowserNavigationService.SetMessage(textBlock, message);
            BrowserNavigationService.SetDecryptedMessage(textBlock, decryptedMessage);
            if (isLastTextBlock)
            {
                BrowserNavigationService.SetAddFooter(textBlock, true);
            }
            BrowserNavigationService.SetText(textBlock, leftSide);
            _stackPanel.Children.Add(textBlock);

            _footerRun = GetFooter(textBlock);

            if (!isLastTextBlock)
            {
                ParseLineExtended(allText);
            }
        }