|
@@ -1,6 +1,8 @@
|
|
|
using ComPDFKit.PDFAnnotation;
|
|
|
using ComPDFKitViewer.AnnotEvent;
|
|
|
+using Dropbox.Api.Users;
|
|
|
using DryIoc;
|
|
|
+using ImTools;
|
|
|
using Microsoft.Office.Interop.Word;
|
|
|
using PDF_Office.CustomControl.CompositeControl;
|
|
|
using PDF_Office.Model;
|
|
@@ -18,15 +20,73 @@ using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Annotations;
|
|
|
+using System.Windows.Media;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
{
|
|
|
+ public class AuthorItem : BindableBase
|
|
|
+ {
|
|
|
+ private string name;
|
|
|
+
|
|
|
+ public string Name
|
|
|
+ {
|
|
|
+ get { return name; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref name, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public AuthorItem(string name)
|
|
|
+ {
|
|
|
+ Name = name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class Compare<T, C> : IEqualityComparer<T>
|
|
|
+ {
|
|
|
+ private Func<T, C> _getField;
|
|
|
+
|
|
|
+ public Compare(Func<T, C> getfield)
|
|
|
+ {
|
|
|
+ this._getField = getfield;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool Equals(T x, T y)
|
|
|
+ {
|
|
|
+ return EqualityComparer<C>.Default.Equals(_getField(x), _getField(y));
|
|
|
+ }
|
|
|
+
|
|
|
+ public int GetHashCode(T obj)
|
|
|
+ {
|
|
|
+ return EqualityComparer<C>.Default.GetHashCode(this._getField(obj));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class CommonHelper
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 自定义Distinct扩展方法
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="T">要去重的对象类</typeparam>
|
|
|
+ /// <typeparam name="C">自定义去重的字段类型</typeparam>
|
|
|
+ /// <param name="source">要去重的对象</param>
|
|
|
+ /// <param name="getfield">获取自定义去重字段的委托</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static IEnumerable<T> MyDistinct<T, C>(this IEnumerable<T> source, Func<T, C> getfield)
|
|
|
+ {
|
|
|
+ return source.Distinct(new Compare<T, C>(getfield));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
internal class ScreenAnnotationDialogViewModel : BindableBase, IDialogAware
|
|
|
{
|
|
|
public string Title => "";
|
|
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
|
|
+ #region 类型的显示隐藏
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 高亮字体
|
|
|
/// </summary>
|
|
@@ -181,6 +241,8 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ #endregion 类型的显示隐藏
|
|
|
+
|
|
|
public DelegateCommand CancelCommand { get; set; }
|
|
|
|
|
|
public DelegateCommand CreateCommnad { get; set; }
|
|
@@ -198,8 +260,19 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private ObservableCollection<AuthorItem> annotationAuthor = new ObservableCollection<AuthorItem>();
|
|
|
+
|
|
|
+ public ObservableCollection<AuthorItem> AnnotationAuthor
|
|
|
+ {
|
|
|
+ get { return annotationAuthor; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref annotationAuthor, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//private List<System.Windows.Media.Color> annotationColors = new List<System.Windows.Media.Color>();
|
|
|
- private List<string> annotationAuthor = new List<string>();
|
|
|
+ //private List<string> annotationAuthor = new List<string>();
|
|
|
|
|
|
public ScreenAnnotationDialogViewModel()
|
|
|
{
|
|
@@ -228,6 +301,28 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+ private void SetColor(System.Windows.Media.Color color)
|
|
|
+ {
|
|
|
+ if (AnnotationColors.Count > 0)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < AnnotationColors.Count; i++)
|
|
|
+ {
|
|
|
+ System.Windows.Media.Color color1 = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(AnnotationColors[i].Color.ToString());
|
|
|
+ if (color1.R == color.R && color1.G == color.G && color1.B == color.B
|
|
|
+ && color1.A == color.A)
|
|
|
+ {
|
|
|
+ AnnotationColors.Remove(AnnotationColors[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ AnnotationColors.Add(new ColorItem(color));
|
|
|
+ //var bFind = AnnotationColors.All<ColorItem>(p => p.Color == new SolidColorBrush(color));
|
|
|
+ //if (bFind)
|
|
|
+ //{
|
|
|
+ // AnnotationColors.Add(new ColorItem(color));
|
|
|
+ //}
|
|
|
+ }
|
|
|
+
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
|
{
|
|
|
ObservableCollection<AnnotationHandlerEventArgs> list;
|
|
@@ -236,14 +331,16 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
|
|
|
foreach (var item in AnnotationListItems)
|
|
|
{
|
|
|
- annotationAuthor.Add(item.Author);
|
|
|
+ AnnotationAuthor.Add(new AuthorItem(item.Author));
|
|
|
+
|
|
|
AnnotHandlerEventArgs data = item.AnnotHandlerEventArgs;
|
|
|
+
|
|
|
switch (item.EventType)
|
|
|
{
|
|
|
case AnnotArgsType.AnnotFreeText://文本
|
|
|
if (data is FreeTextAnnotArgs textAnnotArgs)
|
|
|
{
|
|
|
- AnnotationColors.Add(new ColorItem(textAnnotArgs.FontColor));
|
|
|
+ SetColor(textAnnotArgs.FontColor);
|
|
|
}
|
|
|
AnnotFreeTextVisibility = Visibility.Visible;
|
|
|
break;
|
|
@@ -251,7 +348,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
case AnnotArgsType.AnnotHighlight://高亮
|
|
|
if (data is TextHighlightAnnotArgs highlightAnnotArgs)
|
|
|
{
|
|
|
- AnnotationColors.Add(new ColorItem(highlightAnnotArgs.Color));
|
|
|
+ SetColor(highlightAnnotArgs.Color);
|
|
|
}
|
|
|
HighlightVisibility = Visibility.Visible;
|
|
|
break;
|
|
@@ -259,7 +356,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
case AnnotArgsType.AnnotFreehand://手绘
|
|
|
if (data is FreehandAnnotArgs freehandAnnotArgs)
|
|
|
{
|
|
|
- AnnotationColors.Add(new ColorItem(freehandAnnotArgs.InkColor));
|
|
|
+ SetColor(freehandAnnotArgs.InkColor);
|
|
|
}
|
|
|
FreeHandVisibility = Visibility.Visible;
|
|
|
break;
|
|
@@ -275,7 +372,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
case AnnotArgsType.AnnotStrikeout://删除线
|
|
|
if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
|
|
|
{
|
|
|
- AnnotationColors.Add(new ColorItem(textStrikeoutAnnotArgs.Color));
|
|
|
+ SetColor(textStrikeoutAnnotArgs.Color);
|
|
|
}
|
|
|
AnnotStickyVisibility = Visibility.Visible;
|
|
|
break;
|
|
@@ -283,7 +380,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
case AnnotArgsType.AnnotSticky://便签
|
|
|
if (data is StickyAnnotArgs stickyAnnotArgs)
|
|
|
{
|
|
|
- AnnotationColors.Add(new ColorItem(stickyAnnotArgs.Color));
|
|
|
+ SetColor(stickyAnnotArgs.Color);
|
|
|
}
|
|
|
AnnotStickyVisibility = Visibility.Visible;
|
|
|
break;
|
|
@@ -291,7 +388,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
case AnnotArgsType.AnnotUnderline://下划线
|
|
|
if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
|
|
|
{
|
|
|
- AnnotationColors.Add(new ColorItem(textUnderlineAnnotArgs.Color));
|
|
|
+ SetColor(textUnderlineAnnotArgs.Color);
|
|
|
}
|
|
|
UnderLineVisibility = Visibility.Visible;
|
|
|
break;
|
|
@@ -300,22 +397,22 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
if ((item.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (item.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
|
|
|
{
|
|
|
//箭头
|
|
|
- AnnotationColors.Add(new ColorItem((item.AnnotHandlerEventArgs as LineAnnotArgs).LineColor));
|
|
|
SharpArrowVisibility = Visibility.Visible;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//线
|
|
|
- AnnotationColors.Add(new ColorItem((item.AnnotHandlerEventArgs as LineAnnotArgs).LineColor));
|
|
|
SharpLineVisibility = Visibility.Visible;
|
|
|
}
|
|
|
+ SetColor((item.AnnotHandlerEventArgs as LineAnnotArgs).LineColor);
|
|
|
+
|
|
|
break;
|
|
|
|
|
|
case AnnotArgsType.AnnotSquare://矩形
|
|
|
if (data is SquareAnnotArgs squareAnnotArgs)
|
|
|
{
|
|
|
- //AnnotationColors.Add(new ColorItem(squareAnnotArgs.BgColor));
|
|
|
- AnnotationColors.Add(new ColorItem(squareAnnotArgs.LineColor));
|
|
|
+ SetColor(squareAnnotArgs.BgColor);
|
|
|
+ SetColor(squareAnnotArgs.LineColor);
|
|
|
}
|
|
|
AnnotSquareVisibility = Visibility.Visible;
|
|
|
break;
|
|
@@ -323,13 +420,18 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
|
|
|
case AnnotArgsType.AnnotCircle://圆
|
|
|
if (data is CircleAnnotArgs circleAnnotArgs)
|
|
|
{
|
|
|
- //AnnotationColors.Add(new ColorItem(circleAnnotArgs.BgColor));
|
|
|
- AnnotationColors.Add(new ColorItem(circleAnnotArgs.LineColor));
|
|
|
+ SetColor(circleAnnotArgs.BgColor);
|
|
|
+ SetColor(circleAnnotArgs.LineColor);
|
|
|
}
|
|
|
AnnotCircleVisibility = Visibility.Visible;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ //AnnotationAuthor = AnnotationAuthor.MyDistinct(s => s.Name) as ObservableCollection<AuthorItem>;
|
|
|
+ //AnnotationColors = AnnotationColors.MyDistinct(s => s.Color) as ObservableCollection<ColorItem>;
|
|
|
+
|
|
|
+ AnnotationAuthor = new ObservableCollection<AuthorItem>(AnnotationAuthor.MyDistinct(s => s.Name));
|
|
|
+ //AnnotationColors = new ObservableCollection<ColorItem>(AnnotationColors.MyDistinct(s => s.Color));
|
|
|
}
|
|
|
}
|
|
|
}
|