浏览代码

注释列表-添加附注的注释

OYXH\oyxh 2 年之前
父节点
当前提交
bbc855ab93

+ 37 - 51
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -17,6 +17,7 @@ using PDF_Office.Model;
 using PDF_Office.Model.BOTA;
 using PDF_Office.Views.BOTA;
 using PDF_Office.Views.PropertyPanel.AnnotPanel;
+using PDF_Office.Views.Scan;
 using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Regions;
@@ -724,7 +725,7 @@ namespace PDF_Office.ViewModels.BOTA
                     {
                         DialogParameters value = new DialogParameters();
                         value.Add(ParameterNames.Annotation, args);
-                        dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
+                        dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, async e =>
                         {
                             if (e.Result == ButtonResult.OK && e.Parameters != null)
                             {
@@ -732,58 +733,44 @@ namespace PDF_Office.ViewModels.BOTA
                                 if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
                                 {
                                     AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
-
-                                    AnnotAttribEvent annotEvent = e.Parameters.GetValue<AnnotAttribEvent>(ParameterNames.AnnotEvent);
-
-                                    listBoxItem.DataContext = annotation;
-                                    var annot = AnnotationListItems.FirstOrDefault(q => q.PageIndex == annotation.PageIndex && q.AnnotIndex == annotation.AnnotIndex);
-
-                                    //annotEvent?.UpdateAttrib(AnnotAttrib.NoteText, annotation.MarkupContent);
-                                    //annotEvent?.UpdateAnnot();
+                                    RefreshOneListItem(annotation.AnnotHandlerEventArgs);
                                 }
                             }
                         });
                     }
                 }
             }
+        }
 
-            //if (obj is AnnotationHandlerEventArgs data)
-            //{
-            //    if (data != null)
-            //    {
-            //        if (data.EventType != AnnotArgsType.AnnotSticky)
-            //        {
-            //            DialogParameters value = new DialogParameters();
-            //            value.Add(ParameterNames.Annotation, data);
-            //            dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
-            //            {
-            //                if (e.Result == ButtonResult.OK && e.Parameters != null)
-            //                {
-            //                    //PdfViewer.UndoManager.CanSave = true;
-            //                    //    if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
-            //                    //    {
-            //                    //        AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
-
-            //                    //        //AnnotAttribEvent annotEvent = e.Parameters.GetValue<AnnotAttribEvent>(ParameterNames.AnnotEvent);
-
-            //                    //        //annotEvent?.UpdateAttrib(AnnotAttrib.NoteText, annotation.MarkupContent);
-            //                    //        //annotEvent?.UpdateAnnot();
-
-            //                    //    }
-            //                }
-            //            });
-            //        }
-            //        //if(data.EventType == AnnotArgsType.AnnotFreeText)
-            //        //{
-            //        //    ListBoxItem myListBoxItem = (ListBoxItem)(listBox.ItemContainerGenerator.ContainerFromItem(data));
-            //        //    TextBlock txbContent = CommonHelper.FindVisualChild<TextBlock>(myListBoxItem);
-
-            //        //    TextBox txtContent = CommonHelper.FindVisualChild<TextBox>(myListBoxItem);
-            //        //    txbContent.Visibility = Visibility.Collapsed;
-            //        //    txtContent.Visibility = Visibility.Visible;
-            //        //}
-            //    }
-            //}
+        private async void RefreshOneListItem(AnnotHandlerEventArgs annotation)
+        {
+            for (int i = 0; i < AnnotationListItems.Count; i++)
+            {
+                if (AnnotationListItems[i].PageIndex == annotation.PageIndex && AnnotationListItems[i].AnnotIndex == annotation.AnnotIndex)
+                {
+                    AnnotationListItems[i] = GetAddAnnotEventArgs(annotation);
+
+                    for (int j = 0; j < CurrentAnnotationArgs.Count; j++)
+                    {
+                        if (CurrentAnnotationArgs[j].PageIndex == annotation.PageIndex && CurrentAnnotationArgs[j].AnnotIndex == annotation.AnnotIndex)
+                        {
+                            CurrentAnnotationArgs[j] = GetAddAnnotEventArgs(annotation);
+                            break;
+                        }
+                    }
+                    if (!listBox.SelectedItems.Contains(AnnotationListItems[i]))
+                    {
+                        listBox.SelectedItem = AnnotationListItems[i];
+                    }
+
+                    await Task.Delay(1);//不加延时 每页的第一个注释不会展开
+                    ExpandGroupHeader(AnnotationListItems[i], listBox);
+
+                    await Task.Delay(1);//不加延时 会有不滚动的现象
+                    listBox.ScrollIntoView(AnnotationListItems[i]);
+                    break;
+                }
+            }
         }
 
         /// <summary>
@@ -875,15 +862,14 @@ namespace PDF_Office.ViewModels.BOTA
                     {
                         if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex && items[j].AnnotIndex == annotIndex)
                         {
-                            AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(items[j]);
-                            AnnotationListItems[k] = args;
+                            //AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(items[j]);
+                            AnnotationListItems[k] = GetAddAnnotEventArgs(items[j]);
 
-                            AnnotationHandlerEventArgs annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
                             for (int i = 0; i < CurrentAnnotationArgs.Count; i++)
                             {
-                                if (annotation1 == CurrentAnnotationArgs[i])
+                                if (CurrentAnnotationArgs[i].PageIndex == pageIndex && CurrentAnnotationArgs[i].AnnotIndex == annotIndex)
                                 {
-                                    CurrentAnnotationArgs[i] = args;
+                                    CurrentAnnotationArgs[i] = GetAddAnnotEventArgs(items[j]);
                                     break;
                                 }
                             }

+ 36 - 7
PDF Office/ViewModels/Dialog/BOTA/AddAnnotationDialogViewModel.cs

@@ -25,7 +25,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
 {
     public class AddAnnotationDialogViewModel : BindableBase, IDialogAware
     {
-        private string title;
+        private string title = "添加笔记";
 
         public string Title
         {
@@ -35,14 +35,24 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
 
         public event Action<IDialogResult> RequestClose;
 
-        private string markupContent;
+        //private string markupContent;
 
-        public string MarkupContent
+        //public string MarkupContent
+        //{
+        //    get { return markupContent; }
+        //    set
+        //    {
+        //        SetProperty(ref markupContent, value);
+        //    }
+        //}
+        private string contentText;
+
+        public string ContentText
         {
-            get { return markupContent; }
+            get { return contentText; }
             set
             {
-                SetProperty(ref markupContent, value);
+                SetProperty(ref contentText, value);
             }
         }
 
@@ -57,6 +67,17 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
             }
         }
 
+        private Visibility tipVisibility;
+
+        public Visibility TipVisibility
+        {
+            get { return tipVisibility; }
+            set
+            {
+                SetProperty(ref tipVisibility, value);
+            }
+        }
+
         public AnnotationHandlerEventArgs Annotation { get; set; }
         public AnnotAttribEvent AnnotEvent { get; set; }
 
@@ -79,7 +100,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
                 if (composite.Parameter is TextBox textBox)
                 {
                     Annotation.Content = textBox.Text;
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.NoteText, Annotation.AnnotHandlerEventArgs.MarkupContent);
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.NoteText, textBox.Text);
                     AnnotEvent?.UpdateAnnot();
                 }
             }
@@ -118,8 +139,16 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
                 Dictionary<AnnotAttrib, object> annotAttribsList = annotation.AnnotHandlerEventArgs.GetAnnotAttrib();
                 AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annotation.AnnotHandlerEventArgs, annotAttribsList);
 
-                MarkupContent = annotation.Content;
+                ContentText = annotation.Content;
                 AnnotationName = "页面" + (annotation.PageIndex + 1).ToString();
+                if (string.IsNullOrEmpty(ContentText))
+                {
+                    TipVisibility = Visibility.Visible;
+                }
+                else
+                {
+                    TipVisibility = Visibility.Collapsed;
+                }
                 return;
             }
         }

+ 1 - 1
PDF Office/Views/BOTA/AnnotationContent.xaml

@@ -73,7 +73,7 @@
                     <Style TargetType="ListBoxItem">
                         <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                         <EventSetter Event="PreviewMouseDown" Handler="ListBoxItem_PreviewMouseDown" />
-                        <!--<EventSetter Event="PreviewMouseRightButtonDown" Handler="ListBoxItem_PreviewMouseRightButtonDown" />-->
+                        <EventSetter Event="PreviewMouseDoubleClick" Handler="ListBoxItem_PreviewMouseDoubleClick" />
 
                         <Setter Property="Template" Value="{StaticResource AnnotationListItemStyle}" />
                         <Setter Property="Padding" Value="0" />

+ 6 - 5
PDF Office/Views/BOTA/AnnotationContent.xaml.cs

@@ -91,12 +91,13 @@ namespace PDF_Office.Views.BOTA
                     }
                 }
             }
-            else if (e.ClickCount == 2)
+        }
+
+        private void ListBoxItem_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
+        {
+            if (Mouse.LeftButton == e.ButtonState)
             {
-                if (Mouse.LeftButton == e.ButtonState)
-                {
-                    viewModel.AddNotesCommand.Execute(sender);
-                }
+                viewModel.AddNotesCommand.Execute(sender);
             }
         }
 

+ 26 - 11
PDF Office/Views/Dialog/BOTA/AddAnnotationDialog.xaml

@@ -2,6 +2,7 @@
     x:Class="PDF_Office.Views.Dialog.BOTA.AddAnnotationDialog"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:convert="clr-namespace:PDF_Office.DataConvert"
     xmlns:customControl="clr-namespace:PDF_Office.CustomControl"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:dialogBOTA="clr-namespace:PDF_Office.ViewModels.Dialog.BOTA"
@@ -11,7 +12,7 @@
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:prism="http://prismlibrary.com/"
     Width="450"
-    MinHeight="180"
+    MinHeight="170"
     d:DataContext="{d:DesignInstance Type=dialogBOTA:AddAnnotationDialogViewModel}"
     prism:Dialog.WindowStyle="{StaticResource DialogWindowStyle}"
     prism:ViewModelLocator.AutoWireViewModel="True"
@@ -19,7 +20,7 @@
     <UserControl.Resources>
         <SolidColorBrush x:Key="path.fill" Color="#273C62" />
     </UserControl.Resources>
-    <customControl:DialogContent Header="添加笔记">
+    <customControl:DialogContent Header="{Binding Title}">
         <customControl:DialogContent.Content>
             <Grid>
                 <Grid.RowDefinitions>
@@ -27,7 +28,7 @@
                     <RowDefinition />
                 </Grid.RowDefinitions>
 
-                <StackPanel Grid.RowSpan="2" HorizontalAlignment="Center">
+                <Grid Grid.RowSpan="2" HorizontalAlignment="Center">
                     <!--<customControl:TextBoxEx
                     x:Name="TxtInput"
                     Margin="15"
@@ -38,17 +39,24 @@
                     FontSize="14"
                     PlaceholderText="请添加附注内容"
                     Text="{Binding MarkupContent}"  TextWrapping="Wrap" />-->
-                    <Border CornerRadius="4" BorderThickness="1" BorderBrush="#000000" Width="380">
+                    <Border
+                        Width="380"
+                        Background="#f5f5f5"
+                        BorderBrush="#000000"
+                        BorderThickness="1"
+                        CornerRadius="4">
                         <TextBox
+                            Padding="5"
                             Name="TxtInput"
-
-                            Padding="15"
                             HorizontalContentAlignment="Left"
                             VerticalContentAlignment="Center"
+                            Background="Transparent"
+                            BorderThickness="0"
                             FontFamily="微软雅黑"
                             FontSize="14"
-                            Text="{Binding MarkupContent}"
-                            TextWrapping="Wrap" BorderThickness="0" Background="Transparent">
+                            GotFocus="TxtInput_GotFocus"
+                            Text="{Binding ContentText}"
+                            TextWrapping="Wrap">
 
                             <i:Interaction.Triggers>
                                 <i:EventTrigger EventName="LostFocus">
@@ -60,7 +68,14 @@
                             </i:Interaction.Triggers>
                         </TextBox>
                     </Border>
-                </StackPanel>
+                    <TextBlock
+                        Name="TxtTip"
+                        Margin="20,0"
+                        VerticalAlignment="Center"
+                        Foreground="#666666"
+                        Text="请添加附注内容"
+                        Visibility="{Binding TipVisibility}" />
+                </Grid>
                 <!--<StackPanel
                 Grid.Row="1"
                 HorizontalAlignment="Center"
@@ -331,7 +346,7 @@
                     Margin="25,0,0,0"
                     HorizontalAlignment="Left"
                     Command="{Binding CreateCommnad}"
-                    Content="确定" />
+                    Content="确定" Style="{StaticResource Btn.cta}" />
                 <Button
                     Grid.Column="1"
                     Width="150"
@@ -339,7 +354,7 @@
                     Margin="0,0,25,0"
                     HorizontalAlignment="Right"
                     Command="{Binding CancelCommand}"
-                    Content="取消" />
+                    Content="取消"  Style="{StaticResource Btn.cta}" />
             </Grid>
         </customControl:DialogContent.BottmBar>
     </customControl:DialogContent>

+ 6 - 1
PDF Office/Views/Dialog/BOTA/AddAnnotationDialog.xaml.cs

@@ -24,5 +24,10 @@ namespace PDF_Office.Views.Dialog.BOTA
         {
             InitializeComponent();
         }
+
+        private void TxtInput_GotFocus(object sender, RoutedEventArgs e)
+        {
+            TxtTip.Visibility = Visibility.Collapsed;
+        }
     }
-}
+}