Наследование: System.Windows.Documents.Span
        private static void OnSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            try
            {
                var textblock = (InReplyToBlock) obj;
                textblock.Inlines.Clear();
                textblock.Visibility = Visibility.Collapsed;

                if (textblock.ReplyID != "0" && !string.IsNullOrEmpty(textblock.ReplyID))
                {
                    var link = new InlineLink();
                    link.HoverColour = (Brush) link.FindResource("HoverColour");
                    link.NormalColour = (Brush) link.FindResource("BaseColour");
                    link.Inlines.Add(textblock.ReplyTo);
                    link.TextDecorations = null;
                    link.ToolTip = "View conversation";
                    link.MouseLeftButtonDown += conversationLink_Click;
                    textblock.Inlines.Add(new Run(" in reply to "));
                    textblock.Inlines.Add(link);
                    textblock.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                CompositionManager.Get<IExceptionReporter>().ReportHandledException(ex);
            }
        }
 public InlineLink Match(string word, Brush lBrush, IStatusUpdate oStatusUpdate)
 {
     MatchCollection mc = _matcher.Matches(word);
     if (mc.Count <= 0)
         return null;
     var cm = new ContextMenu();
     var miIgnore = new MenuItem {Header = "Globally ignore " + mc[0].Value + " hashtag", Tag = mc[0].Value};
     cm.Items.Add(miIgnore);
     var il = new InlineLink
                  {
                      Text = mc[0].Value,
                      FontSize = _textProcessorEngine.FsDefault,
                      FontFamily = _textProcessorEngine.FfDefault,
                      Foreground = lBrush,
                      ToolTip = mc[0].Value,
                      Tag = mc[0].Value,
                      HoverColour = _textProcessorEngine.BrHover,
                      NormalColour = _textProcessorEngine.BrBase,
                      ContextMenu = cm
                  };
     il.ToolTip = "Search for " + word + " in your current tweet stream";
     il.MouseLeftButtonDown +=
         (s, e) => PluginEventHandler.FireEvent("searchHashtag", oStatusUpdate, mc[0].Value);
     miIgnore.Click += (s, e) => _textProcessorEngine.GlobalExcludeSettings.Add(word);
     return il;
 }
        public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
        {
            if (word == null) return null;
            var result =
                _acronymSettingsProvider.AcronymMapping.AsParallel().Any(p => p.Acronym.ToLower() == word.ToLower());
            if (!result) return null;

            var newMeaning =
                _acronymSettingsProvider.AcronymMapping.SingleOrDefault(p => p.Acronym.ToLower() == word.ToLower());
            if (newMeaning != null)
            {
                var il = new InlineLink
                             {
                                 FontFamily = _textProcessorEngine.FfDefault,
                                 FontSize = _textProcessorEngine.FsDefault,
                                 Foreground = _textProcessorEngine.BrText,
                                 FontStyle = FontStyles.Italic,
                                 Text = newMeaning.Meaning,
                                 ToolTip = word
                             };
                return il;
            }
            else
            {
                return null;
            }
        }
 public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
 {
     if (!_fontmap.ContainsKey(word.ToLower()))
         return null;
     var il = new InlineLink();
     il.FontFamily = (FontFamily) il.FindResource(_fontmap[word.ToLower()]);
     il.FontSize = _textProcessorEngine.FsDefault;
     il.Foreground = _textProcessorEngine.BrText;
     il.Text = word;
     il.ToolTip = "Why do people hate on Comic Sans?";
     return il;
 }
        public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
        {
            string word1 = word;
            Match tweetdeckiskillingme = Regex.Match(word, BrokenTweetdeckHttpUrlRgxPattern);
            if (tweetdeckiskillingme.Success)
                word1 = "http://" + tweetdeckiskillingme.Groups["tweetdecksucks"].Value;
                    // pop http:// onto the front of the bastardised tweetdeck shorturl mechanism
            Match mpa = Regex.Match(word1, HttpUrlRgxPattern);
            if (mpa.Success)
            {
                string nmatched = mpa.Groups["urlscheme"].Value + mpa.Groups["domainpath"].Value;
                Uri ilurl;
                if (!Uri.TryCreate(nmatched, UriKind.Absolute, out ilurl)) return null;
                Uri ciurl;
                if (
                    !Uri.TryCreate(
                        "http://" + _textProcessorEngine.ShortenVisualInlineUrl(mpa.Groups["domainpath"].Value) +
                        "/favicon.ico", UriKind.Absolute, out ciurl)) return null;
                var image = new CachedImage
                                {
                                    Url = ciurl,
                                    MaxHeight = 10,
                                    MaxWidth = 10,
                                    Margin = new Thickness(0, 0, 2, 0)
                                };
                var il = new InlineLink
                             {
                                 Url = ilurl,
                                 Text = _textProcessorEngine.ShortenVisualInlineUrl(nmatched) + Ellipsis,
                                 Foreground = lBrush,
                                 ToolTip = "Browse to: " + nmatched,
                                 Tag = false,
                                 Image = image,
                                 HoverColour = _textProcessorEngine.BrHover,
                                 NormalColour = _textProcessorEngine.BrNormal,
                             };
                il.MouseLeftButtonDown += _textProcessorEngine.LinkClick;

                AddImagePreviewIcon(oStatusUpdate, il, nmatched);

                AddAdditionalSmartText(il, nmatched);

                CheckAndConvertToLongUrl(oStatusUpdate, il, nmatched);

                return il;
            }
            return null;
        }
 public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
 {
     if (_highlightWordSettingsProvider.HighlightWords.Any(k => word.ToLower().Contains(k.Text.ToLower())))
     {
         var il = new InlineLink
                      {
                          FontFamily = _textProcessorEngine.FfDefault,
                          FontSize = _textProcessorEngine.FsDefault,
                          Foreground = _textProcessorEngine.BrText,
                          Text = word
                      };
         il.Background = (Brush)il.FindResource("HighlightBackgroundColour");
         return il;
     }
     return null;
 }
 public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
 {
     foreach (var k in _backgroundmap)
     {
         if (!word.ToLower().Contains(k.Key.ToLower())) continue;
         var il = new InlineLink
                      {
                          FontFamily = _textProcessorEngine.FfDefault,
                          FontSize = _textProcessorEngine.FsDefault,
                          Foreground = _textProcessorEngine.BrText,
                          Text = word
                      };
         il.Background = (Brush) il.FindResource(k.Value);
         return il;
     }
     return null;
 }
        public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
        {
            if (word == null) return null;
            bool result = _wordmap.AsParallel().Any(p => p.Key == word.ToLower());
            if (!result) return null;

            var il = new InlineLink
                         {
                             FontFamily = _textProcessorEngine.FfDefault,
                             FontSize = _textProcessorEngine.FsDefault,
                             Foreground = _textProcessorEngine.BrText,
                             FontStyle = FontStyles.Italic,
                             Text = _wordmap[word.ToLower()],
                             ToolTip = word
                         };
            return il;
        }
 public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
 {
     MatchCollection mc = _matcher.Matches(word);
     if (mc.Count <= 0)
     {
         return null;
     }
     var il = new InlineLink
                  {
                      Text = word,
                      Foreground = lBrush,
                      TextDecorations = null,
                      ToolTip = "View " + mc[0].Value + "'s profile",
                      HoverColour = _textProcessorEngine.BrHover,
                      NormalColour = _textProcessorEngine.BrBase
                  };
     il.MouseLeftButtonDown +=
         (s, e) => PluginEventHandler.FireEvent("profileByName", oStatusUpdate, mc[0].Value);
     return il;
 }
Пример #10
0
 public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
 {
     MatchCollection mc = _matcher.Matches(word);
     if (mc.Count <= 0)
         return null;
     Uri ilurl;
     if (!Uri.TryCreate("mailto:" + mc[0].Value, UriKind.Absolute, out ilurl)) return null;
     var il = new InlineLink
                  {
                      Url = ilurl,
                      Text = mc[0].Value,
                      Foreground = lBrush,
                      ToolTip = "Send email to: " + mc[0].Value,
                      Tag = mc[0].Value,
                      HoverColour = _textProcessorEngine.BrHover,
                      NormalColour = _textProcessorEngine.BrBase
                  };
     il.MouseLeftButtonDown += _textProcessorEngine.LinkClick;
     return il;
 }
        private async void CheckAndConvertToLongUrl(IStatusUpdate oStatusUpdate, InlineLink il, string nmatched)
        {
            if (!_textProcessorEngine.ApplicationSettings.AutoExpandUrls ||
                !_textProcessorEngine.UrlExpanders.IsShortUrl(nmatched)) return;
            //TODO: cleanup the multiple passes, manual vs. web service longurl checker

            string tmatched = nmatched;
            //await CheckAndConvertToManualLongUrl(nmatched); // returns nmatched the same if its not a manual url lengthener
            //tmatched = await _textProcessorEngine.UrlExpanders.ExpandUrl(tmatched);
            //if (tmatched == null) return;

            if (_textProcessorEngine.UrlExpanders.IsShortUrl(tmatched))
                // go one more round to unshortent the url; useful when t.co shortens an existing shortened link
                tmatched = await _textProcessorEngine.UrlExpanders.ExpandUrl(tmatched);
            if (tmatched == null) tmatched = nmatched;

            //tmatched = await CheckAndConvertToManualLongUrl(nmatched); // and go around again

            il.Text = _textProcessorEngine.ShortenVisualInlineUrl(tmatched);
            Uri url;
            if (!Uri.TryCreate("http://" + il.Text + "/favicon.ico", UriKind.Absolute, out url)) return;
            var iimage = new CachedImage
                             {
                                 Url = url,
                                 MaxHeight = _textProcessorEngine.FsDefault,
                                 MaxWidth = _textProcessorEngine.FsDefault,
                                 Margin = new Thickness(0, 0, 2, 0)
                             };
            il.Text = il.Text + Ellipsis;
            il.Image = iimage;
            AddAdditionalSmartText(il, tmatched);
            AddImagePreviewIcon(oStatusUpdate, il, tmatched);
        }
        public async void AddImagePreviewIcon(IStatusUpdate oStatusUpdate, InlineLink il, string matchedurl)
        {
            if (_textProcessorEngine.ApplicationSettings.DisableMediaProviders) return;
            if ((il.Tag is bool && (bool) il.Tag)) return;
            foreach (
                IMediaProvider mediaProvider in
                    _textProcessorEngine.MediaProcessors.Where(mediaProvider => mediaProvider.Match(matchedurl)))
            {
                string source = await mediaProvider.Transform(matchedurl);

                if (source == null) continue;
                il.Tag = true;
                var ili = new ImageMinimisedAttachment(source);
                il.Inlines.Add(new ImageMinimisedAttachmentView(ili));
            }
        }
 private async void AddAdditionalSmartText(InlineLink il, string f)
 {
     foreach (
         IAdditonalTextSmarts textSmarts in
             _textProcessorEngine.AdditonalTextSmarts.Where(textSmarts => textSmarts.CanPageTitle(f)))
     {
         string title = await textSmarts.Process(f);
         if (title == null) continue;
         var ilt = new InlineLink
                       {
                           Text = "\u201C" + title + "\u201D ",
                           FontFamily = _textProcessorEngine.FfDefault,
                           FontSize = _textProcessorEngine.FsDefault,
                           Foreground = _textProcessorEngine.BrText,
                           Background = (Brush) il.FindResource("LighterGreyColour"),
                           HoverColour = _textProcessorEngine.BrText,
                           NormalColour = _textProcessorEngine.BrText,
                           FontStyle = FontStyles.Italic,
                       };
         il.Inlines.Add(_textProcessorEngine.WebSymbolHelper(" \u005D", null));
         il.Inlines.Add(ilt);
     }
 }
        private static void OnSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            try
            {
                var textblock = (TimeReplyToBlock) obj;
                textblock.Inlines.Clear();

                var time = new InlineLink();
                var tweet = textblock.DataContext as Tweet;
                if (tweet == null)
                    return;

                var uri =
                    new Uri(string.Format("http://twitter.com/{0}/status/{1}", tweet.Contact.Name.ToLower(), tweet.ID));

                var clockimage = new InlineLink
                                     {
                                         Text = "P ",
                                         Name = "clockimage",
                                         FontFamily = (FontFamily) textblock.FindResource("WebSymbols"),
                                         FontSize = 9,
                                         Foreground = (Brush) textblock.FindResource("BaseColour"),
                                         HoverColour = (Brush) textblock.FindResource("BaseColour"),
                                         NormalColour = (Brush) textblock.FindResource("BaseColour")
                                     };

                time.Url = uri;
                time.Tag = tweet.Contact.Name.ToLower() + " " + tweet.ID;
                    // grab these now for the dragging and dropping later
                time.MouseMove += time_link_drag;
                time.Inlines.Add(textblock.Time);
                time.MouseUp += link_Click;
                time.TextDecorations = null;
                time.HoverColour = (Brush) time.FindResource("HoverColour");
                time.NormalColour = (Brush) time.FindResource("BaseColour");
                time.ToolTip = "Open tweet in the default browser" + Environment.NewLine + uri + Environment.NewLine +
                               "Or drag to desktop to create link to this tweet";
                textblock.Inlines.Add(clockimage);
                textblock.Inlines.Add(time);

                if (!String.IsNullOrEmpty(textblock.SourceUri) && !String.IsNullOrEmpty(textblock.SourceText))
                {
                    try
                    {
                        if (Uri.TryCreate(textblock.SourceUri, UriKind.Absolute, out uri))
                        {
                            var link = new InlineLink {Url = new Uri(textblock.SourceUri)};
                            link.Inlines.Add(textblock.SourceText);
                            link.HoverColour = (Brush) link.FindResource("HoverColour");
                            link.NormalColour = (Brush) link.FindResource("BaseColour");
                            link.MouseLeftButtonDown += link_Click;
                            link.TextDecorations = null;
                            link.ToolTip = "Open link to tweeting application\'s web site";
                            textblock.Inlines.Add(new Run(" from "));
                            textblock.Inlines.Add(link);
                        }
                        else
                        {
                            textblock.Inlines.Add("from " + textblock.SourceText);
                        }
                    }
                    catch
                    {
                        textblock.Inlines.Add("from " + textblock.SourceText);
                    }
                }
                else if (!String.IsNullOrEmpty(textblock.SourceText))
                {
                    textblock.Inlines.Add(textblock.SourceText);
                }
            }
            catch (Exception ex)
            {
                CompositionManager.Get<IExceptionReporter>().ReportHandledException(ex);
            }
        }
        public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
        {
            Match mcb = Regex.Match(word, RgxPatternBold);
            Match mci = Regex.Match(word, RgxPatternItalic);
            Match mch = Regex.Match(word, RgxPatternHTML);
            Match mcu = Regex.Match(word, RgxPatternUnderline);

            if (mcb.Success)
            {
                var il = new InlineLink
                             {
                                 Text = mcb.Groups["found"].Value,
                                 ToolTip = word,
                                 FontFamily = _textProcessorEngine.FfDefault,
                                 FontSize = _textProcessorEngine.FsDefault,
                                 Foreground = _textProcessorEngine.BrText,
                                 HoverColour = _textProcessorEngine.BrText,
                                 NormalColour = _textProcessorEngine.BrText,
                                 FontWeight = FontWeights.Bold
                             };
                return il;
            }

            if (mci.Success)
            {
                var il = new InlineLink
                             {
                                 Text = "\u201C" + mci.Groups["found"].Value + "\u201D",
                                 ToolTip = word,
                                 FontFamily = _textProcessorEngine.FfDefault,
                                 FontSize = _textProcessorEngine.FsDefault,
                                 Foreground = _textProcessorEngine.BrText,
                                 HoverColour = _textProcessorEngine.BrText,
                                 NormalColour = _textProcessorEngine.BrText,
                                 FontStyle = FontStyles.Italic
                             };
                return il;
            }

            if (mch.Success)
            {
                var il = new InlineLink
                             {
                                 Text = "<" + mch.Groups["found"].Value + ">",
                                 ToolTip = word,
                                 FontFamily = _textProcessorEngine.FfDefault,
                                 FontSize = _textProcessorEngine.FsDefault,
                                 Foreground = _textProcessorEngine.BrText,
                                 HoverColour = _textProcessorEngine.BrText,
                                 NormalColour = _textProcessorEngine.BrText,
                                 FontStyle = FontStyles.Italic
                             };
                return il;
            }

            if (mcu.Success)
            {
                var il = new InlineLink
                             {
                                 Text = mcu.Groups["found"].Value,
                                 ToolTip = word,
                                 FontFamily = _textProcessorEngine.FfDefault,
                                 FontSize = _textProcessorEngine.FsDefault,
                                 Foreground = _textProcessorEngine.BrText,
                                 HoverColour = _textProcessorEngine.BrText,
                                 NormalColour = _textProcessorEngine.BrText,
                                 TextDecorations = TextDecorations.Underline
                             };
                return il;
            }
            return null;
        }
        private static void OnSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            try
            {
                var textblock = (RetweetedBy) obj;
                textblock.Inlines.Clear();
                var tweet = (Tweet) textblock.DataContext;

                if (tweet.RetweetBy != null)
                {
                    var rtimage = new InlineLink
                                      {
                                          Text = " J",
                                          FontFamily = (FontFamily) textblock.FindResource("WebSymbols"),
                                          FontSize = 9,
                                          Foreground = (Brush) textblock.FindResource("BaseColour"),
                                          HoverColour = (Brush) textblock.FindResource("BaseColour"),
                                          NormalColour = (Brush) textblock.FindResource("BaseColour")
                                      };
                    var retweet = new InlineLink();
                    string uri = string.Format("http://twitter.com/{0}/status/{1}", tweet.RetweetBy.Name.ToLower(),
                                               tweet.ID);
                    retweet.Url = new Uri(uri);
                    retweet.Inlines.Add(" retweet via " + tweet.RetweetBy.Name);
                    textblock.Inlines.Add(rtimage);
                    textblock.Inlines.Add(retweet);
                    textblock.Visibility = Visibility.Visible;
                }
                else
                {
                    textblock.Visibility = Visibility.Collapsed;
                }
            }
            catch (Exception ex)
            {
                CompositionManager.Get<IExceptionReporter>().ReportHandledException(ex);
            }
        }
        public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
        {
            if (word == null) return null;
            bool result = _emoticons.AsParallel().Any(p => p.Key == word);
            if (!result) return null;

            var il = new InlineLink
                         {
                             FontFamily = _textProcessorEngine.FfEmoticon,
                             FontSize = _textProcessorEngine.FsDefault*1.2,
                             Foreground = _textProcessorEngine.BrText,
                             HoverColour = _textProcessorEngine.BrText,
                             NormalColour = _textProcessorEngine.BrText,
                             Text = _emoticons[word],
                             ToolTip = word
                         };
            return il;
        }
        public InlineLink Match(String word, Brush lBrush, IStatusUpdate oStatusUpdate)
        {
            if (word == null) return null;
            bool result = _segoeuisymbolify.AsParallel().Any(p => p.Key == word.ToLower());
            if (!result) return null;

            var il = new InlineLink
                         {
                             FontFamily = _textProcessorEngine.FfUisymbol,
                             FontSize = _textProcessorEngine.FsDefault*1.25,
                             Foreground = _textProcessorEngine.BrText,
                             HoverColour = _textProcessorEngine.BrText,
                             NormalColour = _textProcessorEngine.BrText,
                             Text = _segoeuisymbolify[word.ToLower()],
                             ToolTip = word
                         };
            return il;
        }