private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBox text_block = d as RichTextBox;

            if (text_block == null)
            {
                return;
            }
            bool   disableHyperlinks = BrowserNavigationService.GetDisableHyperlinks((DependencyObject)text_block);
            string textId            = BrowserNavigationService.GetTextId((DependencyObject)text_block);

            text_block.Blocks.Clear();
            Paragraph par = new Paragraph();
            string    s   = (string)e.NewValue;

            if (string.IsNullOrEmpty(s))
            {
                return;
            }
            foreach (string str1 in BrowserNavigationService.ParseText(BrowserNavigationService.PreprocessTextForGroupBoardMentions(s)))
            {
                char[] chArray = new char[1] {
                    '\b'
                };
                string[] strArray = str1.Split(chArray);
                if (strArray.Length == 1)
                {
                    BrowserNavigationService.AddRawText(text_block, par, strArray[0]);
                }
                else if (strArray.Length > 1)
                {
                    if (disableHyperlinks)
                    {
                        BrowserNavigationService.AddRawText(text_block, par, strArray[1]);
                    }
                    else
                    {
                        if (strArray[0].Contains(BrowserNavigationService._searchFeedPrefix))
                        {
                            int    num  = strArray[0].IndexOf(BrowserNavigationService._searchFeedPrefix) + BrowserNavigationService._searchFeedPrefix.Length;
                            string str2 = strArray[0].Substring(num);
                            strArray[0] = strArray[0].Substring(0, num) + WebUtility.UrlEncode(str2);
                        }
                        Hyperlink hyperlink = HyperlinkHelper.GenerateHyperlink(strArray[1], strArray[0], (Action <Hyperlink, string>)((h, navstr) =>
                        {
                            EventAggregator.Current.Publish((object)new HyperlinkClickedEvent()
                            {
                                HyperlinkOwnerId = textId
                            });
                            BrowserNavigationService.NavigateOnHyperlink(navstr);
                        }), text_block.Foreground);
                        par.Inlines.Add((Inline)hyperlink);
                    }
                }
            }
            text_block.Blocks.Add((Block)par);
        }
Beispiel #2
0
        public static Hyperlink GenerateHyperlink(string text, string tag, Action <Hyperlink, string> clickedCallback, Brush foregroundBrush = null)
        {
            Hyperlink h = new Hyperlink();

            HyperlinkHelper.SetState(h, HyperlinkState.Normal, foregroundBrush);
            h.Inlines.Add((Inline) new Run()
            {
                Text = text
            });
            h.Click += (RoutedEventHandler)((s, e) => clickedCallback(h, tag));
            return(h);
        }
Beispiel #3
0
 public static void SetState(Hyperlink h, HyperlinkState state, Brush foregroundBrush = null)
 {
     h.TargetName = state.ToString();
     if (state == HyperlinkState.Accent)
     {
         HyperlinkHelper.SetAccentStyleForHyperlink(h);
     }
     else
     {
         HyperlinkHelper.SetAccentStyleForHyperlink(h);
     }
 }
Beispiel #4
0
        public static Hyperlink GenerateHyperlink(string text, string tag, Action <Hyperlink, string> clickedCallback, Brush foregroundBrush = null, HyperlinkState hyperlinkState = HyperlinkState.Normal)
        {
            Hyperlink h = new Hyperlink();

            HyperlinkHelper.SetState(h, hyperlinkState, foregroundBrush);
            PresentationFrameworkCollection <Inline> arg_44_0 = h.Inlines;
            Run expr_3D = new Run();

            expr_3D.Text = (text);
            arg_44_0.Add(expr_3D);
            h.Click += (delegate(object s, RoutedEventArgs e)
            {
                clickedCallback.Invoke(h, tag);
            });
            return(h);
        }
Beispiel #5
0
 public static void SetState(Hyperlink h, HyperlinkState state, Brush foregroundBrush = null)
 {
     h.TargetName = (state.ToString());
     if (state != HyperlinkState.Accent)
     {
         if (state == HyperlinkState.MatchForeground)
         {
             HyperlinkHelper.SetForegroundStyleForHyperlink(h, foregroundBrush as SolidColorBrush);
         }
         else
         {
             HyperlinkHelper.SetAccentStyleForHyperlink(h);
         }
     }
     else
     {
         HyperlinkHelper.SetAccentStyleForHyperlink(h);
     }
 }
        private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBox text_block = d as RichTextBox;

            if (text_block == null)
            {
                return;
            }
            bool   disableHyperlinks    = BrowserNavigationService.GetDisableHyperlinks((DependencyObject)text_block);
            string textId               = BrowserNavigationService.GetTextId((DependencyObject)text_block);
            bool   hyperlinksForeground = BrowserNavigationService.GetHideHyperlinksForeground((DependencyObject)text_block);

            ((PresentationFrameworkCollection <Block>)text_block.Blocks).Clear();
            Paragraph par = new Paragraph();
            // ISSUE: explicit reference operation
            string newValue = (string)e.NewValue;

            if (string.IsNullOrEmpty(newValue))
            {
                return;
            }
            foreach (string str1 in BrowserNavigationService.ParseText(BrowserNavigationService.PreprocessTextForGroupBoardMentions(newValue)))
            {
                string[] innerSplit = str1.Split('\b');
                if (innerSplit.Length == 1)
                {
                    BrowserNavigationService.AddRawText(text_block, par, innerSplit[0]);
                }
                else if (innerSplit.Length > 1)
                {
                    if (disableHyperlinks)
                    {
                        BrowserNavigationService.AddRawText(text_block, par, innerSplit[1]);
                    }
                    else
                    {
                        if (innerSplit[0].Contains(BrowserNavigationService._searchFeedPrefix))
                        {
                            int    num  = innerSplit[0].IndexOf(BrowserNavigationService._searchFeedPrefix) + BrowserNavigationService._searchFeedPrefix.Length;
                            string str2 = innerSplit[0].Substring(num);
                            innerSplit[0] = innerSplit[0].Substring(0, num) + WebUtility.UrlEncode(str2);
                        }
                        Hyperlink hyperlink = HyperlinkHelper.GenerateHyperlink(innerSplit[1], innerSplit[0], (Action <Hyperlink, string>)((h, navstr) =>
                        {
                            EventAggregator.Current.Publish(new HyperlinkClickedEvent()
                            {
                                HyperlinkOwnerId = textId
                            });
                            if (!string.IsNullOrEmpty(textId))
                            {
                                string str = navstr;
                                if (innerSplit.Length > 2)
                                {
                                    str = str.Replace("https://", "vkontakte://");
                                }
                                EventAggregator.Current.Publish(new PostInteractionEvent()
                                {
                                    PostId = textId,
                                    Action = PostInteractionAction.link_click,
                                    Link   = str
                                });
                            }
                            BrowserNavigationService.NavigateOnHyperlink(navstr);
                        }), ((Control)text_block).Foreground, hyperlinksForeground ? HyperlinkState.MatchForeground : HyperlinkState.Normal);
                        ((PresentationFrameworkCollection <Inline>)par.Inlines).Add((Inline)hyperlink);
                    }
                }
            }
            ((PresentationFrameworkCollection <Block>)text_block.Blocks).Add((Block)par);
        }