public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { DirectMessage directMessage = value as DirectMessage; if (directMessage != null) { TextBlock tb = new TextBlock(); TweetsTemplate tweetTemplate = new TweetsTemplate(); Hyperlink hyperLinkUser = new Hyperlink(); Style usernameStyle = (Style)tweetTemplate.FindResource("UsernameLinkStyle"); hyperLinkUser.Style = usernameStyle; hyperLinkUser.Command = TOBCommands.ShowUserProfile; hyperLinkUser.CommandParameter = directMessage; Binding bind = new Binding(); bind.Source = directMessage; hyperLinkUser.SetBinding(Hyperlink.DataContextProperty, bind); TextBlock tbUserName = new TextBlock(); tbUserName.Text = directMessage.UserProfile.ScreenName; hyperLinkUser.Inlines.Add(tbUserName); tb.Inlines.Add(hyperLinkUser); tb.Inlines.Add(new Run(" ")); string dmContent = directMessage.Text; string[] statusParts = dmContent.Split(' '); Style linkStyle = (Style)tweetTemplate.FindResource("LinkStyle"); foreach (String part in statusParts) { Run magicRun = new Run(); if (part.StartsWith("http")) { Hyperlink link = new Hyperlink(); link.Style = linkStyle; link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(link_RequestNavigate); TextBlock tblink = new TextBlock(); tblink.Text = part + " "; link.NavigateUri = new Uri(part); link.Inlines.Add(tblink); tb.Inlines.Add(link); magicRun = new Run(); } else { magicRun.Text = part + " "; tb.Inlines.Add(magicRun); } } return tb.Inlines; } else { return null; } }
private static void PrepareTweetDocument(TextBlock textBlock, MetroTwitStatusBase tweet, bool Notification = false) { if (DesignerProperties.GetIsInDesignMode((DependencyObject) textBlock)) return; try { if (textBlock != null && textBlock.Inlines != null && textBlock.Inlines.Count > 0) textBlock.Inlines.Clear(); } catch { foreach (Inline inline in Enumerable.ToArray<Inline>((IEnumerable<Inline>) textBlock.Inlines)) textBlock.Inlines.Remove(inline); } if (Notification) { Span span1 = new Span(); span1.FontWeight = FontWeights.SemiBold; Span span2 = span1; Hyperlink hyperlink = new Hyperlink((Inline) new Run("@" + tweet.User.ScreenName)); hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object)"ModernTextLighterBrush"); hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding("UserProfileCommand") { Mode = BindingMode.OneWay }); hyperlink.SetBinding(Hyperlink.CommandParameterProperty, (BindingBase) new Binding("CurrentTweet.User.ScreenName") { Mode = BindingMode.OneWay }); ((TextElementCollection<Inline>) span2.Inlines).Add((Inline) hyperlink); ((TextElementCollection<Inline>) span2.Inlines).Add((Inline) new Run() { Text = ": " }); ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) span2); } if (tweet != null && tweet.Entities != null && tweet.Entities.Count > 0) { try { int[] numArray = StringInfo.ParseCombiningCharacters(tweet.RawText); IOrderedEnumerable<Entity> orderedEnumerable = Enumerable.OrderBy<Entity, int>((IEnumerable<Entity>) tweet.Entities, (Func<Entity, int>) (x => x.StartIndex)); int num1 = 0; foreach (Entity entity in (IEnumerable<Entity>) orderedEnumerable) { int num2 = 0; if (numArray.Length < tweet.RawText.Length && entity.StartIndex < numArray.Length) num2 = numArray[entity.StartIndex] - entity.StartIndex; int num3 = entity.StartIndex + num2; int num4 = entity.EndIndex + num2; int startIndex1 = num1; if (num3 > startIndex1 && startIndex1 < numArray.Length && startIndex1 + (num3 - startIndex1) < numArray.Length) { string input = WebUtility.HtmlDecode(tweet.RawText.Substring(startIndex1, num3 - startIndex1)); if (!string.IsNullOrEmpty(input)) { Run run = new Run(Regex.Replace(input, "\n{2,}|(\r\n){2,}", "\n\n")); ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) run); } } if (entity is MentionEntity) { MentionEntity mentionEntity = entity as MentionEntity; if (!string.IsNullOrEmpty(mentionEntity.ScreenName)) { Hyperlink hyperlink = new Hyperlink((Inline) new TagMentionLinkRun("@" + mentionEntity.ScreenName)) { CommandParameter = (object) ("@" + mentionEntity.ScreenName) }; hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object) "HyperlinkUsername"); hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding("UserProfileCommand") { Mode = BindingMode.OneTime }); ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) hyperlink); hyperlink.ContextMenu = new ContextMenu(); MenuItem menuItem1 = new MenuItem(); menuItem1.Header = (object) "Filter tweets from this user"; menuItem1.CommandParameter = hyperlink.CommandParameter; MenuItem menuItem2 = menuItem1; menuItem2.SetBinding(MenuItem.CommandProperty, (BindingBase) new Binding("FilterCommand") { Mode = BindingMode.OneTime }); hyperlink.ContextMenu.Items.Add((object) menuItem2); } } else if (entity is HashTagEntity) { HashTagEntity hashTagEntity = entity as HashTagEntity; if (!string.IsNullOrEmpty(hashTagEntity.Text)) { Hyperlink hyperlink = new Hyperlink((Inline) new TagMentionLinkRun("#" + hashTagEntity.Text)) { CommandParameter = (object) ("#" + hashTagEntity.Text) }; hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object) "HyperlinkHashtag"); hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding("TagsCommand") { Mode = BindingMode.OneTime }); ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) hyperlink); hyperlink.ContextMenu = new ContextMenu(); MenuItem menuItem1 = new MenuItem(); menuItem1.Header = (object) "Filter tweets that contain this hashtag"; menuItem1.CommandParameter = hyperlink.CommandParameter; MenuItem menuItem2 = menuItem1; menuItem2.SetBinding(MenuItem.CommandProperty, (BindingBase) new Binding("FilterCommand") { Mode = BindingMode.OneTime }); hyperlink.ContextMenu.Items.Add((object) menuItem2); } } else if (entity is UrlEntity) { UrlEntity url = entity as UrlEntity; if (!string.IsNullOrEmpty(url.Url)) { if (tweet.AdUrls != null && !string.IsNullOrEmpty(tweet.AdUrls.click_url)) url.ExpandedUrl = tweet.AdUrls.click_url; string str = string.IsNullOrEmpty(url.DisplayUrl) || tweet.AdUrls != null ? url.Url : (url.DisplayUrl.Length > 50 ? url.DisplayUrl.Substring(0, 50) + "..." : url.DisplayUrl); if (tweet.AdUrls != null & !string.IsNullOrEmpty(url.DisplayUrl)) str = url.DisplayUrl; if (url.DisplayUrl == null && tweet.AdUrls == null) { try { MatchCollection matchCollection = RegularExpressions.VALID_URL.Matches(url.Url); if (matchCollection.Count == 0 || matchCollection.Count > 0 && !matchCollection[0].Groups[4].Success) url.Url = "http://" + url.Url; } catch { } } if (tweet.AdUrls != null) { if (string.IsNullOrEmpty(url.DisplayUrl)) url.DisplayUrl = url.Url; url.Url = url.ExpandedUrl; } Hyperlink hyperlink = new Hyperlink((Inline) new TagMentionLinkRun(WebUtility.HtmlDecode(str))) { CommandParameter = (object) url }; hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object) "HyperlinkURL"); hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding(Notification ? "LinkCommand" : "ContentLinkCommand") { Mode = BindingMode.OneTime }); hyperlink.ToolTip = (object) url.ExpandedUrl; hyperlink.ContextMenu = new ContextMenu(); MenuItem menuItem1 = new MenuItem(); menuItem1.Header = (object) "Copy URL"; menuItem1.CommandParameter = (object) url; MenuItem menuItem2 = menuItem1; menuItem2.SetBinding(MenuItem.CommandProperty, (BindingBase) new Binding("CopyUrlCommand") { Mode = BindingMode.OneTime }); hyperlink.ContextMenu.Items.Add((object) menuItem2); hyperlink.PreviewMouseDown += (MouseButtonEventHandler) ((clickSender, clickArgs) => Application.Current.Dispatcher.BeginInvoke((Action) (() => { string local_0 = url.Url; if (clickArgs.MiddleButton == MouseButtonState.Pressed || Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { App.LastURLClickMousePosition = new Point?(); CommonCommands.OpenLink(local_0); clickArgs.Handled = true; } else App.LastURLClickMousePosition = new Point?(Application.Current.MainWindow.PointToScreen(Mouse.GetPosition((IInputElement) Application.Current.MainWindow))); }), new object[0])); ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) hyperlink); } } num1 = num4; int startIndex2 = num4; if (Enumerable.Count<Entity>((IEnumerable<Entity>) orderedEnumerable) > 0 && Enumerable.Last<Entity>((IEnumerable<Entity>) orderedEnumerable) == entity && startIndex2 < numArray.Length) { string text = WebUtility.HtmlDecode(tweet.RawText.Substring(startIndex2)); if (!string.IsNullOrEmpty(text)) { Run run = new Run(text); ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) run); } } } } catch { ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) new Run(Regex.Replace(WebUtility.HtmlDecode(tweet.RawText), "\n{2,}|(\r\n){2,}", "\n\n"))); } } else ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) new Run(Regex.Replace(WebUtility.HtmlDecode(tweet.RawText), "\n{2,}|(\r\n){2,}", "\n\n"))); }
private InlineCollection GetInlineCollections(TextBlock tb, string statusContent, Binding bind, TweetsTemplate tweetTemplate, Hyperlink hyperLinkUser) { string[] statusParts = statusContent.Split(' '); Style linkStyle = (Style)tweetTemplate.FindResource("LinkStyle"); string parsedStr = ""; foreach (String part in statusParts) { parsedStr = part.TrimStart(_delimChars); //Check for links if (parsedStr.StartsWith("http") && parsedStr.Length > 7) { Hyperlink link = new Hyperlink(); link.Style = linkStyle; Run run = new Run(part + " "); try { link.NavigateUri = new Uri(parsedStr.TrimEnd(_delimChars)); link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(link_RequestNavigate); } catch (Exception e) { TOB.Logger.TOBLogger.WriteDebugInfo(parsedStr + " failed - " + e.ToString()); } link.Inlines.Add(run); tb.Inlines.Add(link); } //Check for user tags else if (parsedStr.StartsWith("@")) { Hyperlink hplink = new Hyperlink(); hplink.Style = linkStyle; hplink.Command = TOBCommands.ShowUserProfileForTags; hplink.CommandParameter = parsedStr.TrimEnd(_delimChars); hyperLinkUser.SetBinding(Hyperlink.DataContextProperty, bind); Run run = new Run(part + " "); hplink.Inlines.Add(run); tb.Inlines.Add(hplink); } //check for #tags. else if (parsedStr.StartsWith("#")) { Hyperlink hplinks = new Hyperlink(); hplinks.Style = linkStyle; hplinks.Command = TOBCommands.ShowFilterForTags; hplinks.CommandParameter = parsedStr.TrimEnd(_delimChars); Run run = new Run(part + " "); hplinks.Inlines.Add(run); tb.Inlines.Add(hplinks); } else { Run magicRun = new Run(); magicRun.Text = part + " "; tb.Inlines.Add(magicRun); } } return tb.Inlines; }
private string TwitterStatusText(object value, TextBlock tb, TextBlock tbUserName, string statusContent, Binding bind, Hyperlink hyperLinkUser) { TwitterStatus twitterStatus = value as TwitterStatus; hyperLinkUser.CommandParameter = twitterStatus; bind.Source = twitterStatus; hyperLinkUser.SetBinding(Hyperlink.DataContextProperty, bind); tbUserName.Text = twitterStatus.User.ScreenName; hyperLinkUser.Inlines.Add(tbUserName); tb.Inlines.Add(hyperLinkUser); tb.Inlines.Add(new Run(" ")); statusContent = twitterStatus.Text; return statusContent; }
public Hyperlink CreateHyperlink(string text, string url, DependencyProperty foreground, FontWeight weight, RoutedEventHandler handler) { Hyperlink link = new Hyperlink (); link.SetBinding (Hyperlink.ForegroundProperty, CreateBinding (this, foreground.Name, BindingMode.OneWay)); link.Inlines.Add (text); link.Tag = url; link.Click += handler; link.FontWeight = weight; return link; }
protected override void SetEnabledBinding(Hyperlink instance) { instance.SetBinding(ContentElement.IsEnabledProperty, GetOneWayBinding(RootDialogModel.BackModel, "Enabled")); }
protected override void SetCommandBinding(Hyperlink instance) { instance.SetBinding(Hyperlink.CommandProperty, GetOneWayBinding(RootDialogModel.BackModel, "Command")); }