Browse Source

BOTA注释列表-筛选注释

OYXH\oyxh 2 years ago
parent
commit
405195fa77

+ 116 - 14
PDF Office/ViewModels/Dialog/BOTA/ScreenAnnotationDialogViewModel.cs

@@ -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));
         }
     }
 }

+ 71 - 143
PDF Office/Views/Dialog/BOTA/ScreenAnnotationDialog.xaml

@@ -18,12 +18,7 @@
     mc:Ignorable="d">
     <UserControl.Resources>
         <SolidColorBrush x:Key="path.fill" Color="#273C62" />
-        <DataTemplate x:Key="listboxData">
-            <!--<Ellipse
-            Width="20"
-            Height="20"
-            Fill="{Binding Color}" />-->
-
+        <DataTemplate x:Key="ListColorData">
             <Border
                 Width="20"
                 Height="20"
@@ -35,9 +30,19 @@
                     Fill="{Binding Color}" />
             </Border>
         </DataTemplate>
-        <Style x:Key="listboxItemStyle" TargetType="{x:Type ListBoxItem}">
+        <DataTemplate x:Key="ListAuthorData">
+            <TextBlock
+                Name="TxbAuthor"
+                Margin="6,0"
+                HorizontalAlignment="Center"
+                VerticalAlignment="Center"
+                FontSize="12"
+                Text="{Binding Name}" />
+        </DataTemplate>
+        <Style x:Key="ListboxItemStyle" TargetType="{x:Type ListBoxItem}">
             <Setter Property="HorizontalAlignment" Value="Center" />
             <Setter Property="Height" Value="40" />
+            <Setter Property="Width" Value="40" />
             <Setter Property="Margin" Value="4" />
             <!--<EventSetter Event="PreviewMouseRightButtonDown" Handler="listboxItem_PreviewMouseRightButtonDown" />-->
             <Setter Property="Template">
@@ -58,7 +63,40 @@
 
             <Style.Triggers>
                 <Trigger Property="IsMouseOver" Value="True">
-                    <Setter  Property="Background" Value="#e2e3e5" />
+                    <Setter Property="Background" Value="#e2e3e5" />
+                </Trigger>
+                <Trigger Property="IsMouseOver" Value="False">
+                    <Setter Property="Background" Value="Transparent" />
+                </Trigger>
+                <Trigger Property="IsSelected" Value="True">
+                    <Setter Property="Background" Value="#e2e3e5" />
+                </Trigger>
+            </Style.Triggers>
+        </Style>
+        <Style x:Key="ListboxItemStyle1" TargetType="{x:Type ListBoxItem}">
+            <Setter Property="HorizontalAlignment" Value="Center" />
+            <Setter Property="Height" Value="40" />
+            <Setter Property="Margin" Value="4" />
+            <!--<EventSetter Event="PreviewMouseRightButtonDown" Handler="listboxItem_PreviewMouseRightButtonDown" />-->
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type ContentControl}">
+                        <Border
+                            x:Name="border"
+                            Height="40"
+                            HorizontalAlignment="Center"
+                            VerticalAlignment="Center"
+                            Background="{TemplateBinding Background}"
+                            CornerRadius="4">
+                            <ContentPresenter />
+                        </Border>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+
+            <Style.Triggers>
+                <Trigger Property="IsMouseOver" Value="True">
+                    <Setter Property="Background" Value="#e2e3e5" />
                 </Trigger>
                 <Trigger Property="IsMouseOver" Value="False">
                     <Setter Property="Background" Value="Transparent" />
@@ -82,19 +120,19 @@
                 </Grid.RowDefinitions>
                 <TextBlock
                     Grid.Row="0"
-                    Margin="30,0"
+                    Margin="20,0"
                     FontSize="14"
                     FontWeight="Bold"
                     Text="类型" />
                 <TextBlock
                     Grid.Row="2"
-                    Margin="30,0"
+                    Margin="20,0"
                     FontSize="14"
                     FontWeight="Bold"
                     Text="颜色" />
                 <TextBlock
                     Grid.Row="4"
-                    Margin="30,0"
+                    Margin="20,0"
                     FontSize="14"
                     FontWeight="Bold"
                     Text="作者" />
@@ -333,8 +371,8 @@
                     Margin="15,0"
                     Background="Transparent"
                     BorderThickness="0"
-                    ItemContainerStyle="{StaticResource listboxItemStyle}"
-                    ItemTemplate="{StaticResource listboxData}"
+                    ItemContainerStyle="{StaticResource ListboxItemStyle}"
+                    ItemTemplate="{StaticResource ListColorData}"
                     ItemsSource="{Binding AnnotationColors}"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                     ScrollViewer.VerticalScrollBarVisibility="Auto">
@@ -347,136 +385,26 @@
                         </ItemsPanelTemplate>
                     </ListBox.ItemsPanel>
                 </ListBox>
-                <!--<WrapPanel Grid.Row="3" Margin="25,0">
-                <customControl:CustomIconToggleBtn Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                <Border
-                Width="20"
-                Height="20"
-                Margin="6">
-                <Ellipse
-                Name="EllipseColor1"
-                Width="16"
-                Height="16"
-                Fill="#CBE9CE" />
-                </Border>
-                </customControl:CustomIconToggleBtn>
-                <customControl:CustomIconToggleBtn Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                <Border
-                Width="20"
-                Height="20"
-                Margin="6">
-                <Ellipse
-                Name="EllipseColor2"
-                Width="16"
-                Height="16"
-                Fill="Violet" />
-                </Border>
-                </customControl:CustomIconToggleBtn>
-                <customControl:CustomIconToggleBtn Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                <Border
-                Width="20"
-                Height="20"
-                Margin="6">
-                <Ellipse
-                Name="EllipseColor3"
-                Width="16"
-                Height="16"
-                Fill="Lavender" />
-                </Border>
-                </customControl:CustomIconToggleBtn>
-                <customControl:CustomIconToggleBtn Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                <Border
-                Width="20"
-                Height="20"
-                Margin="6">
-                <Ellipse
-                Name="EllipseColor4"
-                Width="16"
-                Height="16"
-                Fill="OldLace" />
-                </Border>
-                </customControl:CustomIconToggleBtn>
-                <customControl:CustomIconToggleBtn Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                <Border
-                Width="20"
-                Height="20"
-                Margin="6">
-                <Ellipse
-                Name="EllipseColor5"
-                Width="16"
-                Height="16"
-                Fill="DarkBlue" />
-                </Border>
-                </customControl:CustomIconToggleBtn>
-                <customControl:CustomIconToggleBtn Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                <Border
-                Width="20"
-                Height="20"
-                Margin="6">
-                <Ellipse
-                Name="EllipseColor6"
-                Width="16"
-                Height="16"
-                Fill="SaddleBrown" />
-                </Border>
-                </customControl:CustomIconToggleBtn>
-                <customControl:CustomIconToggleBtn Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                <Border
-                Width="20"
-                Height="20"
-                Margin="6">
-                <Ellipse
-                Name="EllipseColor7"
-                Width="16"
-                Height="16"
-                Fill="Gainsboro" />
-                </Border>
-                </customControl:CustomIconToggleBtn>
-                </WrapPanel>-->
-                <WrapPanel Grid.Row="5" Margin="25,0">
-                    <customControl:CustomIconToggleBtn Background="#F7F8FA" Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                        <TextBlock
-                            Name="TxbAuthor1"
-                            FontSize="12"
-                            Text="111" />
-                    </customControl:CustomIconToggleBtn>
-                    <customControl:CustomIconToggleBtn Background="#F7F8FA" Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                        <TextBlock
-                            Name="TxbAuthor2"
-                            FontSize="12"
-                            Text="111" />
-                    </customControl:CustomIconToggleBtn>
-                    <customControl:CustomIconToggleBtn Background="#F7F8FA" Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                        <TextBlock
-                            Name="TxbAuthor3"
-                            FontSize="12"
-                            Text="111" />
-                    </customControl:CustomIconToggleBtn>
-                    <customControl:CustomIconToggleBtn Background="#F7F8FA" Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                        <TextBlock
-                            Name="TxbAuthor4"
-                            FontSize="12"
-                            Text="111" />
-                    </customControl:CustomIconToggleBtn>
-                    <customControl:CustomIconToggleBtn Background="#F7F8FA" Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                        <TextBlock
-                            Name="TxbAuthor5"
-                            FontSize="12"
-                            Text="111" />
-                    </customControl:CustomIconToggleBtn>
-                    <customControl:CustomIconToggleBtn Background="#F7F8FA" Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                        <TextBlock
-                            Name="TxbAuthor6"
-                            FontSize="12"
-                            Text="111" />
-                    </customControl:CustomIconToggleBtn>
-                    <customControl:CustomIconToggleBtn Background="#F7F8FA" Style="{StaticResource ToggleBtnScreenAnnotationStyle}">
-                        <TextBlock
-                            Name="TxbAuthor7"
-                            FontSize="12"
-                            Text="111" />
-                    </customControl:CustomIconToggleBtn>
-                </WrapPanel>
+                <ListBox
+                    x:Name="ListAuthor"
+                    Grid.Row="5"
+                    Margin="15,0"
+                    Background="Transparent"
+                    BorderThickness="0"
+                    ItemContainerStyle="{StaticResource ListboxItemStyle1}"
+                    ItemTemplate="{StaticResource ListAuthorData}"
+                    ItemsSource="{Binding AnnotationAuthor}"
+                    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
+                    ScrollViewer.VerticalScrollBarVisibility="Auto">
+                    <ListBox.ItemsPanel>
+                        <ItemsPanelTemplate>
+                            <WrapPanel
+                                IsItemsHost="True"
+                                Orientation="Horizontal"
+                                ScrollViewer.CanContentScroll="True" />
+                        </ItemsPanelTemplate>
+                    </ListBox.ItemsPanel>
+                </ListBox>
             </Grid>
         </customControl:DialogContent.Content>
         <customControl:DialogContent.BottmBar>