summaryrefslogtreecommitdiff
path: root/Juick/Classes
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/Classes')
-rw-r--r--Juick/Classes/ParagraphBindingBehavior.cs36
-rw-r--r--Juick/Classes/RichTextConverter.cs78
2 files changed, 0 insertions, 114 deletions
diff --git a/Juick/Classes/ParagraphBindingBehavior.cs b/Juick/Classes/ParagraphBindingBehavior.cs
deleted file mode 100644
index 524f4db..0000000
--- a/Juick/Classes/ParagraphBindingBehavior.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Collections.Generic;
-using System.Windows;
-using System.Windows.Documents;
-
-namespace Juick.Classes
-{
- public static class ParagraphBindingBehavior
- {
- public static readonly DependencyProperty AssignedInlinesProperty =
- DependencyProperty.RegisterAttached("AssignedInlines", typeof(IEnumerable<Inline>), typeof(Paragraph), new PropertyMetadata(null, AssignedInlinesCallback));
-
- static void AssignedInlinesCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
- {
- var inlines = ((Paragraph)target).Inlines;
- inlines.Clear();
- var value = e.NewValue as IEnumerable<Inline>;
- if (value != null)
- {
- foreach (var inline in value)
- {
- inlines.Add(inline);
- }
- }
- }
-
- public static IEnumerable<Inline> GetAssignedInlines(DependencyObject obj)
- {
- return (IEnumerable<Inline>)obj.GetValue(AssignedInlinesProperty);
- }
-
- public static void SetAssignedInlines(DependencyObject obj, IEnumerable<Inline> value)
- {
- obj.SetValue(AssignedInlinesProperty, value);
- }
- }
-}
diff --git a/Juick/Classes/RichTextConverter.cs b/Juick/Classes/RichTextConverter.cs
deleted file mode 100644
index 4f78b96..0000000
--- a/Juick/Classes/RichTextConverter.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text.RegularExpressions;
-using System.Windows.Data;
-using System.Windows.Documents;
-
-namespace Juick.Classes
-{
- public class RichTextConverter : IValueConverter
- {
- static readonly Regex UrlRegex = new Regex(@"http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&amp;\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?", RegexOptions.Compiled);
- // TODO: Add more entities
- static readonly Regex JuickEntityRegex = new Regex(@"#(\d+)(/\d+)?", RegexOptions.Compiled);
-
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- var stringValue = (string)value;
- if (string.IsNullOrEmpty(stringValue))
- {
- return Enumerable.Empty<Inline>();
- }
-
- var result = new List<Inline>();
- var index = 0;
- foreach (var match in UrlRegex.Matches(stringValue).OfType<Match>().Union(JuickEntityRegex.Matches(stringValue).OfType<Match>()))
- {
- Uri uri = null;
- if (!Uri.TryCreate(match.Value, UriKind.Absolute, out uri))
- {
- // Juick entity
- uri = new Uri(string.Format("/ThreadView.xaml?mid={0}", JuickEntityRegex.Replace(match.Value, "$1")), UriKind.Relative);
- }
- if (match.Index > 0)
- {
- var length = match.Index - index;
- if (length > 0)
- {
- result.Add(new Run { Text = stringValue.Substring(index, length) });
- }
- }
-
- var hyperLink = new Hyperlink
- {
- NavigateUri = uri
- };
- if (uri.IsAbsoluteUri)
- {
- hyperLink.TargetName = "_blank";
- hyperLink.Inlines.Add(uri.Host);
- }
- else
- {
- hyperLink.Inlines.Add(match.Value);
- }
- result.Add(hyperLink);
-
- index = match.Index + match.Length;
- }
-
- if (index == 0 || index < stringValue.Length - 1)
- {
- var lastRunText = stringValue.Substring(index);
- if (lastRunText.Length > 0)
- {
- result.Add(new Run { Text = lastRunText });
- }
- }
- return result;
- }
-
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return value;
- }
- }
-}