public void isReplyToItem(TwitterItem item) { if (item == null) { return; } if (item.RetweetedItem != null) { item = item.RetweetedItem; } textBoxTweet.Text = "@" + item.Author.Username + " "; inReplyToId = item.Id; labelInReplyTo.Content = "In reply to @" + item.Author.Username; labelInReplyTo.ToolTip = item.Text; buttonSendTweet.Content = "Send reply"; labelInReplyTo.Visibility = Visibility.Visible; List <string> alreadyShownUser = new List <string>(); int positionOfCursor = textBoxTweet.Text.Length; int lengthOfSelection = 0; if (item.accountId != 0) { try { alreadyShownUser.Add("@" + AppController.Current.getAccountForId(item.accountId).Login.Username.ToLower()); } catch { } } alreadyShownUser.Add("@" + item.Author.Username.ToLower()); if (item.ElementsInText != null) { foreach (TextSubTypes.ISubType element in item.ElementsInText) { if (element.GetType() == typeof(TextSubTypes.User)) { TextSubTypes.User userEnt = element as TextSubTypes.User; if (!alreadyShownUser.Contains(userEnt.userName.ToLower())) { alreadyShownUser.Add(userEnt.userName.ToLower()); textBoxTweet.Text += userEnt.userName.TrimEnd(AppController.Current.TrimCharacters.ToArray()) + " "; lengthOfSelection += userEnt.userName.Length + 2; } } } } textBoxTweet.textBoxContent.Select(positionOfCursor, lengthOfSelection); textBoxTweet.textBoxContent.Focus(); }
void generateElementsTextblock(List <TextSubTypes.ISubType> inlines) { this.Inlines.Clear(); try { IItem item = this.DataContext as IItem; foreach (object inline in inlines) { if (inline.GetType() == typeof(TextSubTypes.Link)) { TextSubTypes.Link element = (TextSubTypes.Link)inline; Hyperlink link = new Hyperlink(); link.TextDecorations = null; Uri target; Uri.TryCreate(element.urlLong, UriKind.Absolute, out target); link.NavigateUri = target; link.ToolTip = element.urlLong; if (Properties.Settings.Default.AutoExpandLinks || string.IsNullOrEmpty(element.urlShort)) { link.Inlines.Add(element.urlLong); } else { link.Inlines.Add(element.urlShort); } link.Click += new RoutedEventHandler(link_Click); ContextMenu contextMenuLink = new ContextMenu(); MenuItem menuItemCopyToClipboard = new MenuItem(); menuItemCopyToClipboard.Header = "Copy link"; menuItemCopyToClipboard.CommandParameter = element.urlLong; menuItemCopyToClipboard.Click += new RoutedEventHandler(menuItemCopyToClipboard_Click); contextMenuLink.Items.Add(menuItemCopyToClipboard); MenuItem menuItemOpenInBrowser = new MenuItem(); menuItemOpenInBrowser.Header = "Open in webbrowser"; menuItemOpenInBrowser.CommandParameter = element.urlLong; menuItemOpenInBrowser.Click += new RoutedEventHandler(menuItemOpenInBrowser_Click); contextMenuLink.Items.Add(menuItemOpenInBrowser); MenuItem contextExternalServices = new MenuItem(); contextExternalServices.Header = "Send to..."; foreach (Nymphicus.ExternalServices.IStore service in AppController.Current.AllIStores) { MenuItem menuItem = new MenuItem(); menuItem.Header = service.Name; externalServiceParameter parameter = new externalServiceParameter(); parameter.storeService = service; parameter.link = element.urlLong; parameter.item = item; menuItem.CommandParameter = parameter; BitmapImage serviceImage = new BitmapImage(new Uri(service.ServiceIcon)); serviceImage.DecodePixelWidth = 16; serviceImage.CacheOption = BitmapCacheOption.OnLoad; menuItem.Icon = new System.Windows.Controls.Image { Source = serviceImage }; menuItem.Click += new RoutedEventHandler(menuItem_Click); contextExternalServices.Items.Add(menuItem); } contextMenuLink.Items.Add(contextExternalServices); link.ContextMenu = contextMenuLink; this.Inlines.Add(link); } else if (inline.GetType() == typeof(TextSubTypes.ImageLink)) { TextSubTypes.ImageLink element = (TextSubTypes.ImageLink)inline; Hyperlink link = new Hyperlink(); link.TextDecorations = null; Uri target; Uri.TryCreate(element.urlLong, UriKind.Absolute, out target); link.NavigateUri = target; Grid tooltipGrid = new Grid(); Image tooltipImage = new Image(); tooltipImage.Source = GetImageFromURL(element.imageUrl); tooltipGrid.Children.Add(tooltipImage); link.ToolTip = tooltipGrid; link.Inlines.Add(element.urlLong); link.Click += new RoutedEventHandler(link_Click); this.Inlines.Add(link); } else if (inline.GetType() == typeof(TextSubTypes.HashTag)) { TextSubTypes.HashTag element = (TextSubTypes.HashTag)inline; Hyperlink hashtag = new Hyperlink(); char[] trimChars = { ',', ';', ':', ' ', '!', '?', '.' }; hashtag.TargetName = element.text.Substring(1).Trim(trimChars); hashtag.TextDecorations = null; hashtag.DataContext = item; hashtag.ToolTip = "Open search for " + element.text; hashtag.Click += new RoutedEventHandler(hashtag_Click); TextBlock hashTextBlock = new TextBlock(); hashTextBlock.Text = element.text; hashTextBlock.TextDecorations = null; hashTextBlock.Foreground = Brushes.Red; hashtag.Inlines.Add(hashTextBlock); ContextMenu contextHashtag = new ContextMenu(); MenuItem menuItemOpenInSearch = new MenuItem(); menuItemOpenInSearch.Header = "Open search for " + element.text; menuItemOpenInSearch.CommandParameter = element.text; menuItemOpenInSearch.Click += new RoutedEventHandler(menuItemOpenInSearch_Click); contextHashtag.Items.Add(menuItemOpenInSearch); MenuItem menuItemMuteHashtag = new MenuItem(); menuItemMuteHashtag.Header = "Mute " + element.text + " in this View (will create a filter)"; menuItemMuteHashtag.CommandParameter = element.text; menuItemMuteHashtag.Click += new RoutedEventHandler(menuItemMuteHashtag_Click); contextHashtag.Items.Add(menuItemMuteHashtag); hashtag.ContextMenu = contextHashtag; this.Inlines.Add(hashtag); } else if (inline.GetType() == typeof(TextSubTypes.User)) { TextSubTypes.User element = (TextSubTypes.User)inline; Hyperlink twitterUser = new Hyperlink(); twitterUser.TextDecorations = null; twitterUser.DataContext = item; twitterUser.ToolTip = "Open user info of " + element.userName; twitterUser.TargetName = element.userName.Substring(1); char[] trimChars = { ',', ';', ':', ' ', '!', '?', '.' }; twitterUser.TargetName = twitterUser.TargetName.Trim(trimChars); twitterUser.Click += new RoutedEventHandler(twitterUser_Click); TextBlock twitterUserBlock = new TextBlock(); twitterUserBlock.TextWrapping = TextWrapping.Wrap; twitterUserBlock.TextDecorations = null; twitterUserBlock.Text = element.userName; twitterUserBlock.Foreground = Brushes.DarkGreen; twitterUser.Inlines.Add(twitterUserBlock); this.Inlines.Add(twitterUser); } else if (inline.GetType() == typeof(TextSubTypes.Text)) { TextSubTypes.Text element = (TextSubTypes.Text)inline; this.Inlines.Add(element.text); } } } catch (Exception exp) { AppController.Current.Logger.writeToLogfile("Tweet text parsing failed"); AppController.Current.Logger.writeToLogfile(exp); try { TwitterItem item = this.DataContext as TwitterItem; AppController.Current.Logger.writeToLogfile("Tweet text: " + item.Text); } catch (Exception exp2) { AppController.Current.Logger.writeToLogfile("Tweet text cannot be casted to string!"); AppController.Current.Logger.writeToLogfile(exp2); } } }