Ver código fonte

阅读页-空白右键菜单初版

OYXH\oyxh 2 anos atrás
pai
commit
8641a982ba

+ 81 - 5
PDF Office/Styles/ContextMenuStyle.xaml

@@ -84,11 +84,11 @@
     <!--  注释-内容选择-右键菜单  -->
     <ContextMenu x:Key="SnapshotContextMenu" FontSize="14">
         <!--<ContextMenu.ItemContainerStyle>
-            <Style TargetType="MenuItem">
-                <Setter Property="Padding" Value="0,7,0,7" />
-                <Setter Property="VerticalContentAlignment" Value="Center" />
-                <Setter Property="HorizontalContentAlignment" Value="Left" />
-            </Style>
+        <Style TargetType="MenuItem">
+        <Setter Property="Padding" Value="0,7,0,7" />
+        <Setter Property="VerticalContentAlignment" Value="Center" />
+        <Setter Property="HorizontalContentAlignment" Value="Left" />
+        </Style>
         </ContextMenu.ItemContainerStyle>-->
         <MenuItem
             Name="BtnSnapCopy"
@@ -158,6 +158,82 @@
             </MenuItem.Icon>-->
         </MenuItem>
     </ContextMenu>
+
+    <!--  阅读页点击空白处菜单  -->
+    <ContextMenu x:Key="ViewerContextMenu" FontSize="14">
+        <MenuItem Header="粘贴" InputGestureText="Ctrl+V" />
+        <Separator
+            Height="1"
+            BorderBrush="#33000000"
+            BorderThickness="1"
+            Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
+        <MenuItem Header="添加注释">
+            <MenuItem Header="绘制" Tag="AnnotFreehand" />
+            <MenuItem Header="文本" Tag="AnnotFreeText" />
+            <MenuItem Header="便签" Tag="AnnotSticky" />
+            <Separator
+                Height="1"
+                BorderBrush="#33000000"
+                BorderThickness="1"
+                Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
+            <MenuItem Header="矩形" Tag="AnnotSquare" />
+            <MenuItem Header="椭圆形" Tag="AnnotCircle" />
+            <MenuItem Header="箭头" Tag="AnnotArrow" />
+            <MenuItem Header="直线" Tag="AnnotLine" />
+            <Separator
+                Height="1"
+                BorderBrush="#33000000"
+                BorderThickness="1"
+                Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
+            <MenuItem Header="链接" Tag="AnnotLink" />
+            <MenuItem Header="图章" Tag="AnnotStamp" />
+            <MenuItem Header="签名" Tag="AnnotAutograph" />
+        </MenuItem>
+        <MenuItem Header="隐藏注释" />
+        <MenuItem Header="显示注释" />
+        <MenuItem Header="添加书签" />
+        <MenuItem Header="删除书签" />
+        <Separator
+            Height="1"
+            BorderBrush="#33000000"
+            BorderThickness="1"
+            Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
+        <MenuItem Header="工具模式">
+            <MenuItem Header="默认工具" />
+            <MenuItem Header="滚动工具" />
+            <MenuItem Header="放大镜" />
+            <MenuItem Header="内容选择" />
+            <MenuItem Header="缩放至选定区域" />
+        </MenuItem>
+        <MenuItem Header="进入阅读模式" />
+        <MenuItem Header="退出阅读模式" />
+        <Separator
+            Height="1"
+            BorderBrush="#33000000"
+            BorderThickness="1"
+            Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
+        <MenuItem Header="视图缩放">
+            <MenuItem Header="适应宽度" />
+            <MenuItem Header="适应页面" />
+            <MenuItem Header="实际大小" />
+            <MenuItem Header="放大" />
+            <MenuItem Header="缩小" />
+        </MenuItem>
+        <MenuItem Header="页面显示">
+            <MenuItem Header="单页" />
+            <MenuItem Header="单页连续" />
+            <MenuItem Header="双页" />
+            <MenuItem Header="双页连续" />
+            <MenuItem Header="书本模式" />
+        </MenuItem>
+        <Separator
+            Height="1"
+            BorderBrush="#33000000"
+            BorderThickness="1"
+            Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
+        <MenuItem Header="查找" />
+        <MenuItem Header="打印" />
+    </ContextMenu>
     <ContextMenu x:Key="RedactionContextMenu">
         <MenuItem Name="MenuDelete" Header="Delete" />
         <Separator Style="{StaticResource HorizontalSeparatorStyle}" />

+ 22 - 9
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Properties.cs

@@ -10,7 +10,7 @@ using System.Threading.Tasks;
 using System.Windows.Media;
 
 namespace PDF_Office.ViewModels.Tools
-{ 
+{
 
     /// <summary>
     /// 改变工具栏注释属性值,主要用来传参数:注释属性和同步工具栏对应图标的属性(颜色)
@@ -22,7 +22,7 @@ namespace PDF_Office.ViewModels.Tools
         public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
         public event EventHandler<Dictionary<AnnotArgsType, object>> AnnotTypeChanged;
         public event EventHandler<object> DefaultStored;
-        public AnnotPropertyPanel(){ }
+        public AnnotPropertyPanel() { }
 
         /// <summary>
         /// 触发到工具栏注释工具,改变工具图标下的颜色值
@@ -51,31 +51,31 @@ namespace PDF_Office.ViewModels.Tools
 
         //
         private double highLightOpacity = 1;
-        public double HighLightOpacity {get { return highLightOpacity; } set { SetProperty(ref highLightOpacity, value); } }
+        public double HighLightOpacity { get { return highLightOpacity; } set { SetProperty(ref highLightOpacity, value); } }
 
         //
         private Brush underLine = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
-        public Brush UnderLineColor {get { return underLine; } set { SetProperty(ref underLine, value); }}
+        public Brush UnderLineColor { get { return underLine; } set { SetProperty(ref underLine, value); } }
 
         //
         private double underLineOpacity = 1;
-        public double UnderLineOpacity { get { return underLineOpacity; } set { SetProperty(ref underLineOpacity, value); }}
+        public double UnderLineOpacity { get { return underLineOpacity; } set { SetProperty(ref underLineOpacity, value); } }
 
         //
         private Brush squigglyColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
-        public Brush SquigglyColor{ get { return squigglyColor; } set { SetProperty(ref squigglyColor, value); } }
+        public Brush SquigglyColor { get { return squigglyColor; } set { SetProperty(ref squigglyColor, value); } }
 
         //
         private double squigglyOpacity = 1;
-        public double SquigglyOpacity {get { return squigglyOpacity; } set { SetProperty(ref squigglyOpacity, value); } }
+        public double SquigglyOpacity { get { return squigglyOpacity; } set { SetProperty(ref squigglyOpacity, value); } }
 
         //
         private Brush strikeoutColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
-        public Brush StrikeoutColor{ get { return strikeoutColor; }  set { SetProperty(ref strikeoutColor, value); }}
+        public Brush StrikeoutColor { get { return strikeoutColor; } set { SetProperty(ref strikeoutColor, value); } }
 
         //
         private double strikeoutOpacity = 1;
-        public double StrikeoutOpacity {get { return strikeoutOpacity; }  set { SetProperty(ref strikeoutOpacity, value); } }
+        public double StrikeoutOpacity { get { return strikeoutOpacity; } set { SetProperty(ref strikeoutOpacity, value); } }
 
         #endregion
 
@@ -89,4 +89,17 @@ namespace PDF_Office.ViewModels.Tools
         public DelegateCommand<CustomIconToggleBtn> MyToolsCommand { get; set; }
         AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
     }
+    public enum AddAnnotType
+    {
+        AnnotFreehand,//绘制
+        AnnotFreeText = 1,//文本
+        AnnotSticky,//便签
+        AnnotSquare,//矩形
+        AnnotCircle,//椭圆形
+        AnnotArrow,//箭头
+        AnnotLine,//直线
+        AnnotLink,//链接
+        AnnotStamp,//图章
+        AnnotAutograph //签名
+    }
 }

+ 159 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -2,6 +2,7 @@
 using ComPDFKitViewer;
 using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
+using Microsoft.Office.Interop.Word;
 using Microsoft.Win32;
 using PDF_Office.CustomControl;
 using PDF_Office.EventAggregators;
@@ -60,11 +61,14 @@ namespace PDF_Office.ViewModels.Tools
         private SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
         public SnapshotEditMenuViewModel SnapshotEditMenuViewModel { get => snapshotEditMenuViewModel; set => snapshotEditMenuViewModel = value; }
 
+        public DelegateCommand<object> SetAddAnnotationCommand { get; set; }
+
         public AnnotToolContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
         {
             region = regionManager;
             events = eventAggregator;
             MyToolsCommand = new DelegateCommand<CustomIconToggleBtn>(BtnMyTools_Click);
+            SetAddAnnotationCommand = new DelegateCommand<object>(AddAnnotation_Click);
             PropertyRegionName = Guid.NewGuid().ToString();
             BindingEvent();
             InitDefaultValue();
@@ -755,12 +759,167 @@ namespace PDF_Office.ViewModels.Tools
                                 e.Handle = true;
                             }
                         }
+                        else
+                        {
+                            e.PopupMenu = ViewerContextMenu();
+                            if (e.PopupMenu != null)
+                            {
+                                e.Handle = true;
+                            }
+                        }
                     }
 
                     break;
             }
         }
 
+        private ContextMenu ViewerContextMenu()
+        {
+            ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
+            contextMenu.Loaded += ContextMenu_Loaded;
+
+            return contextMenu;
+        }
+
+        private void ContextMenu_Loaded(object sender, RoutedEventArgs e)
+        {
+            ContextMenu contextMenu = sender as ContextMenu;
+            if (contextMenu.Items.Count > 0)
+            {
+                //粘贴
+                MenuItem menuItem = contextMenu.Items[0] as MenuItem;
+                if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
+                {
+                    menuItem.IsEnabled = false;
+                    menuItem.Opacity = 0.5;
+                }
+                else
+                {
+                    menuItem.IsEnabled = true;
+                    menuItem.Opacity = 1;
+                }
+                //添加注释 >
+                MenuItem menuItem1 = contextMenu.Items[2] as MenuItem;
+                if (menuItem1.Items.Count > 0)
+                {
+                    SetAddAnnotation(menuItem1.Items);
+                }
+                //隐藏注释 >
+                MenuItem menuItem2 = contextMenu.Items[3] as MenuItem;
+                //显示注释 >
+                MenuItem menuItem3 = contextMenu.Items[4] as MenuItem;
+                if (menuItem2.Visibility == Visibility.Visible)
+                {
+                    menuItem3.Visibility = Visibility.Collapsed;
+                }
+                else
+                {
+                    menuItem3.Visibility = Visibility.Visible;
+                }
+                //添加书签 >
+                MenuItem menuItem4 = contextMenu.Items[5] as MenuItem;
+                //删除书签 >
+                MenuItem menuItem5 = contextMenu.Items[6] as MenuItem;
+                if (menuItem4.Visibility == Visibility.Visible)
+                {
+                    menuItem5.Visibility = Visibility.Collapsed;
+                }
+                else
+                {
+                    menuItem5.Visibility = Visibility.Visible;
+                }
+                //工具模式 >
+                MenuItem menuItem6 = contextMenu.Items[8] as MenuItem;
+                //进入阅读模式 >
+                MenuItem menuItem7 = contextMenu.Items[9] as MenuItem;
+                //退出阅读模式 >
+                MenuItem menuItem8 = contextMenu.Items[10] as MenuItem;
+                if (App.IsBookMode)
+                {
+                    menuItem7.Visibility = Visibility.Visible;
+                }
+                else
+                {
+                    menuItem7.Visibility = Visibility.Collapsed;
+                }
+                if (menuItem7.Visibility == Visibility.Visible)
+                {
+                    menuItem8.Visibility = Visibility.Collapsed;
+                }
+                else
+                {
+                    menuItem8.Visibility = Visibility.Visible;
+                }
+                //视图缩放 >
+                MenuItem menuItem9 = contextMenu.Items[12] as MenuItem;
+                //页面显示                >
+                MenuItem menuItem10 = contextMenu.Items[13] as MenuItem;
+                //查找
+                MenuItem menuItem11 = contextMenu.Items[15] as MenuItem;
+                //打印...
+                MenuItem menuItem12 = contextMenu.Items[16] as MenuItem;
+            }
+        }
+
+        private void SetAddAnnotation(ItemCollection items)
+        {
+            foreach (var item in items)
+            {
+                if (item is MenuItem menuItem)
+                {
+                    menuItem.CommandParameter = item;
+                    menuItem.Command = SetAddAnnotationCommand;
+                }
+            }
+        }
+
+        private void AddAnnotation_Click(object sender)
+        {
+            if (sender is MenuItem menuItem)
+            {
+                AnnotHandlerEventArgs annotHandler = null;
+                if (menuItem.Tag.ToString() == AddAnnotType.AnnotFreeText.ToString())
+                {
+                    annotHandler = GetFreetext();
+                    //if (annotHandler != null)
+                    //{
+                    //    annotHandler.Author = Settings.Default.AppProperties.Description.Author;
+                    //    PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+                    //    PDFViewer.SetToolParam(annotHandler);
+                    //    ShowPropertyPanel(true);
+                    //}
+                }
+                if (menuItem.Tag.ToString() == AddAnnotType.AnnotLine.ToString())
+                {
+                    annotHandler = GetArrowLine("Line");
+                    //if (annotHandler != null)
+                    //{
+                    //    annotHandler.Author = Settings.Default.AppProperties.Description.Author;
+                    //    PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+                    //    PDFViewer.SetToolParam(annotHandler);
+                    //    ShowPropertyPanel(true);
+                    //}
+                }
+                if (annotHandler != null)
+                {
+                    annotHandler.Author = Settings.Default.AppProperties.Description.Author;
+                    PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+                    PDFViewer.SetToolParam(annotHandler);
+                    ShowPropertyPanel(true);
+                }
+            }
+            //if (sender is AnnotHandlerEventArgs annotHandler)
+            //{
+            //    if (annotHandler != null)
+            //    {
+            //        annotHandler.Author = Settings.Default.AppProperties.Description.Author;
+            //        PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
+            //        PDFViewer.SetToolParam(annotHandler);
+            //        ShowPropertyPanel(true);
+            //    }
+            //}
+        }
+
         private ContextMenu SelectAnnotContextMenu(object sender)
         {
             var popMenu = App.Current.FindResource("SelectAnnotContextMenu") as ContextMenu;