123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608 |
- using ComPDFKit.PDFDocument;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using PDF_Office.CustomControl.CompositeControl;
- using PDF_Office.Helper;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.Tools
- {
- //文件说明:与布局相关的代码逻辑:菜单、属性面板
- public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
- {
- #region 属性面板
- /// <summary>
- /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
- /// </summary>
- /// <param name="viewContent">对应的注释面板</param>
- /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
- /// <param name="annot">注释</param>
- /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
- private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null)
- {
- if (annots != null)
- {
- propertyPanel.annotlists = annots;
- propertyPanel.annot = annots[0];
- }
- else
- {
- propertyPanel.annotlists = null;
- propertyPanel.annot = null;
- }
- if (annotAttribsList != null)
- {
- if (annots.Count > 1)
- {
- if (propertyPanel.AnnotEvents == null)
- propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
- propertyPanel.AnnotEvents.Clear();
- foreach (var itemAnnot in annots)
- {
- var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
- propertyPanel.AnnotEvents.Add(eventitem);
- }
- }
- propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
- if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
- {
- propertyPanel.AnnotEvent = annotAttribEvent;
- }
- }
- if (string.IsNullOrEmpty(viewContent) == false)
- {
- viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
- }
- }
- /// <summary>
- /// 展开显示属性面板
- /// </summary>
- private void ShowPropertyPanel(bool show = true)
- {
- viewContentViewModel.IsPropertyOpen = show;
- }
- #endregion 属性面板
- #region 阅读页 - 右键菜单
- private ContextMenu ViewerContextMenu()
- {
- ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
- //contextMenu.Loaded += ContextMenu_Loaded;
- ViewerContextMenu_Loaded(contextMenu, null);
- return contextMenu;
- }
- private void ViewerContextMenu_Loaded(object sender, RoutedEventArgs e)
- {
- ContextMenu contextMenu = sender as ContextMenu;
- if (contextMenu.Items.Count > 0)
- {
- int index = PDFViewer.CurrentIndex;
- //检测是否已存在相同数据
- CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
- if (list != null)
- {
- isAddBookMark = false;
- }
- else
- {
- isAddBookMark = true;
- }
- foreach (var item in contextMenu.Items)
- {
- if (item is MenuItem menuItem1)
- {
- //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
- //{
- // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
- //}
- switch (menuItem1.Tag.ToString())
- {
- case "Copy":
- //粘贴
- if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
- {
- menuItem1.IsEnabled = false;
- menuItem1.Opacity = 0.5;
- }
- else
- {
- menuItem1.IsEnabled = true;
- menuItem1.Opacity = 1;
- }
- menuItem1.CommandTarget = (UIElement)sender;
- menuItem1.Command = ApplicationCommands.Copy;
- break;
- case "AddAnnotation":
- if (menuItem1.Items.Count > 0)
- {
- SetAddAnnotation(menuItem1.Items);
- }
- break;
- case "HiddenAnnot":
- menuItem1.Click -= HiddenAnnot_Click;
- menuItem1.Click += HiddenAnnot_Click;
- SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
- break;
- case "DisplayAnnot":
- menuItem1.Click -= DisplayAnnot_Click;
- menuItem1.Click += DisplayAnnot_Click;
- SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
- break;
- case "AddBookMark":
- //menuItem1.Click -= AddBookMark_Click;
- //menuItem1.Click += AddBookMark_Click;
- menuItem1.Command = AddBookMarkCommand;
- SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark);
- break;
- case "DelBookMark":
- menuItem1.Click -= DelBookMark_Click;
- menuItem1.Click += DelBookMark_Click;
- SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark);
- break;
- case "ToolMode":
- if (menuItem1.Items.Count > 0)
- {
- SetToolMode(menuItem1.Items);
- }
- break;
- case "ReadModel":
- SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", App.IsBookMode);
- menuItem1.Click -= ReadModel_Click;
- menuItem1.Click += ReadModel_Click;
- break;
- case "UnReadModel":
- SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", App.IsBookMode);
- menuItem1.Click -= UnReadModel_Click;
- menuItem1.Click += UnReadModel_Click;
- break;
- case "ViewZoom":
- if (menuItem1.Items.Count > 0)
- {
- ViewZoom(menuItem1.Items);
- }
- break;
- case "PageDisplay":
- if (menuItem1.Items.Count > 0)
- {
- PageDisplay(menuItem1.Items);
- }
- break;
- case "Select":
- menuItem1.Click -= Select_Click;
- menuItem1.Click += Select_Click;
- break;
- case "Print":
- menuItem1.Command = viewContentViewModel.PrintCommand;
- break;
- }
- }
- }
- }
- }
- private void SetMenuItemVisibility(MenuItem menuItem1, string right, string deny, bool flag)
- {
- if (menuItem1.Tag.ToString() == right && flag)
- {
- menuItem1.Visibility = Visibility.Collapsed;
- }
- if (menuItem1.Tag.ToString() == right && flag == false)
- {
- menuItem1.Visibility = Visibility.Visible;
- }
- if (menuItem1.Tag.ToString() == deny && flag == false)
- {
- menuItem1.Visibility = Visibility.Collapsed;
- }
- if (menuItem1.Tag.ToString() == deny && flag)
- {
- menuItem1.Visibility = Visibility.Visible;
- }
- }
- private ContextMenu NoneSelectAnnotContextMenu(object sender, AnnotCommandArgs annotCommand)
- {
- ContextMenu popMenu = new ContextMenu();
- popMenu.FontSize = 14;
- MenuItem menuItem = new MenuItem();
- menuItem = new MenuItem();
- menuItem.CommandTarget = (UIElement)sender;
- menuItem.Command = ApplicationCommands.Copy;
- popMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.CommandTarget = (UIElement)sender;
- menuItem.Command = ApplicationCommands.Paste;
- popMenu.Items.Add(menuItem);
- Separator separator = null;
- if (annotCommand.CommandTarget == TargetType.ImageSelection)
- {
- separator = SetSeparator();
- popMenu.Items.Add(separator);
- SetSelectTextOrImageMenuItem("导出图片...", "ExportPicture", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- }
- else if (annotCommand.CommandTarget == TargetType.Annot)
- {
- separator = SetSeparator();
- popMenu.Items.Add(separator);
- SetSelectTextOrImageMenuItem("高亮", "HighLight", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- SetSelectTextOrImageMenuItem("下划线", "UnderLine", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- SetSelectTextOrImageMenuItem("删除线", "Strikeout", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- }
- separator = SetSeparator();
- popMenu.Items.Add(separator);
- SetSelectTextOrImageMenuItem("文本", "Freetext", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- SetSelectTextOrImageMenuItem("便签", "StickyNote", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- separator = SetSeparator();
- popMenu.Items.Add(separator);
- SetSelectTextOrImageMenuItem("矩形", "Rect", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- SetSelectTextOrImageMenuItem("椭圆形", "Circle", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- SetSelectTextOrImageMenuItem("直线", "Line", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- separator = SetSeparator();
- popMenu.Items.Add(separator);
- SetSelectTextOrImageMenuItem("添加链接", "Link", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- SetSelectTextOrImageMenuItem("添加大纲", "OutLine", annotCommand, out menuItem);
- popMenu.Items.Add(menuItem);
- return popMenu;
- }
- private void SetSelectTextOrImageMenuItem(string header, string tag, AnnotCommandArgs annotCommand, out MenuItem menuItem)
- {
- menuItem = new MenuItem();
- menuItem.Header = header;
- menuItem.Tag = tag;
- menuItem.Click -= AnnotToolMenu_Click;
- menuItem.Click += AnnotToolMenu_Click;
- menuItem.CommandParameter = annotCommand;
- }
- private Separator SetSeparator()
- {
- Separator separator = new Separator
- {
- Height = 1,
- BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33000000")),
- BorderThickness = new Thickness(1),
- Style = (Style)App.Current.FindResource(System.Windows.Controls.ToolBar.SeparatorStyleKey)
- };
- return separator;
- }
- #endregion 阅读页 - 右键菜单
- #region 注释-右键菜单
- //高亮注释,右键菜单
- private ContextMenu SelectHightAnnotMenu(object sender)
- {
- var popMenu = new ContextMenu();
- PopMenu pop = new PopMenu(popMenu);
- ColorContent colorContent = new ColorContent();
- colorContent.Name = "hightcolor";
- colorContent.SelectedColorHandler -= colorContent_SelectedColorHandler;
- colorContent.SelectedColorHandler += colorContent_SelectedColorHandler;
- pop.AddItem(colorContent);
- var menuItem = new MenuItem();
- menuItem.Name = "hightCopyText";
- menuItem.Header = "复制文本";
- pop.BindingEvent(pop.AddItem(menuItem), HightAnnotCopyText_MenuCommand, sender);
- menuItem = new MenuItem();
- menuItem.Name = "hightdelete";
- menuItem.Header = "删除";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete, sender);
- menuItem = new MenuItem();
- menuItem.Name = "hightAddNote";
- menuItem.Header = "添加笔记";
- pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand, sender);
- menuItem = new MenuItem();
- menuItem.Name = "hightdefault";
- menuItem.Header = "设置当前属性为默认值";
- pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand, sender);
- //var popMenu = App.Current.FindResource("HightAnnotContextMenu") as ContextMenu;
- //CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
- ////颜色列表
- //ColorContent colorContent = new ColorContent();
- //colorContent.DataContext = sender;
- //colorContent.SelectedColorHandler -= colorContent_SelectedColorHandler;
- //colorContent.SelectedColorHandler += colorContent_SelectedColorHandler;
- //customMenu.SetMenuUI(0,colorContent);
- ////复制文本
- //customMenu.SetMenuBinding(1, HightAnnotCopyText_MenuCommand);
- ////删除
- //customMenu.SetMenuBinding(2, ApplicationCommands.Delete);
- ////添加笔记
- //customMenu.SetMenuBinding(3, AnnotAddNoteText_MenuCommand);
- ////设置当前属性为默认值
- //customMenu.SetMenuBinding(4, AnnotDefaultValue_MenuCommand);
- return popMenu;
- }
- private void colorContent_SelectedColorHandler(object sender, Color e)
- {
- if (e == null) return;
- var annot =(sender as FrameworkElement).DataContext as AnnotHandlerEventArgs;
- if(annot != null)
- {
- var test = annot as TextHighlightAnnotArgs;
- if(test != null)
- {
- var anvent = AnnotAttribEvent.GetAnnotAttribEvent(test, test.GetAnnotAttrib());
- anvent.UpdateAttrib(AnnotAttrib.Color, e);
- anvent.UpdateAnnot();
- }
-
- }
- }
- //手绘
- private ContextMenu SelectFreeHandAnnotMenu(object sender)
- {
- var popMenu = App.Current.FindResource("FreeHandAnnotContextMenu") as ContextMenu;
- CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
- //复制
- customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
- //剪切
- customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
- //粘贴
- customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
- //删除
- customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
- //颜色
- customMenu.SetMenuBinding(4, AnnotColorPalette_MenuCommand);
- //线段样式
- var freeHand = sender as FreehandAnnotArgs;
- bool IsSolid = true;
- if (freeHand != null)
- {
- IsSolid = AnnotPropertyPanel.IsSolidStyle(freeHand.LineDash);
-
- }
- customMenu.SetSubMenuBinding(5, 0, FreeHandLineStyle_MenuCommand,null, IsSolid);
- customMenu.SetSubMenuBinding(5, 1, FreeHandLineStyle_MenuCommand, null, !IsSolid);
- //添加笔记
- customMenu.SetMenuBinding(6, AnnotAddNoteText_MenuCommand);
- //设置当前属性为默认值
- customMenu.SetMenuBinding(7, AnnotDefaultValue_MenuCommand);
- return popMenu;
- }
- //文本
- private ContextMenu SelectFreeTextAnnotMenu(object sender)
- {
- var popMenu = App.Current.FindResource("FreeTextAnnotContextMenu") as ContextMenu;
- CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
- //复制
- customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
- //剪切
- customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
- //粘贴
- customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
- //删除
- customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
- //文本颜色
- customMenu.SetMenuBinding(4, AnnotColorPalette_MenuCommand);
- //字体
- var annot = sender as FreeTextAnnotArgs;
- customMenu.SetSubMenuBinding(5, 0, FreeTextFontFamily_MenuCommand, null, (annot != null && annot.FontFamily.ToString() == "Arial") ?true:false);
- customMenu.SetSubMenuBinding(5, 1, FreeTextFontFamily_MenuCommand, null,(annot != null && annot.FontFamily.ToString() == "Courier") ? true : false);
- customMenu.SetSubMenuBinding(5, 2, FreeTextFontFamily_MenuCommand, null, (annot != null && annot.FontFamily.ToString() == "Times New Roman") ? true : false);
- //文本对齐
- customMenu.SetSubMenuBinding(6, 0, FreeTextAglin_MenuCommand, null, (annot != null && annot.Align == TextAlignment.Left) ? true : false);
- customMenu.SetSubMenuBinding(6, 1, FreeTextAglin_MenuCommand, null, (annot != null && annot.Align == TextAlignment.Center) ? true : false);
- customMenu.SetSubMenuBinding(6, 2, FreeTextAglin_MenuCommand, null, (annot != null && annot.Align == TextAlignment.Right) ? true : false);
- //设置当前属性为默认值
- customMenu.SetMenuBinding(7, AnnotDefaultValue_MenuCommand);
- return popMenu;
- }
- //便签
- private ContextMenu SelectStrickNoteAnnotMenu(object sender)
- {
- var popMenu = App.Current.FindResource("StrickNoteAnnotContextMenu") as ContextMenu;
- CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
- //复制
- customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
- //剪切
- customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
- //粘贴
- customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
- //删除
- customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
- //颜色
- customMenu.SetMenuBinding(4, AnnotColorPalette_MenuCommand);
- if(sender as StickyAnnotArgs != null)
- {
-
- }
- //编辑便签
- customMenu.SetMenuBinding(5, ApplicationCommands.Delete);//
- //设置当前属性为默认值
- customMenu.SetMenuBinding(7, AnnotDefaultValue_MenuCommand);
- return popMenu;
- }
- //形状
- private ContextMenu SelectShapeAnnotMenu(object sender)
- {
- var popMenu = App.Current.FindResource("ShapeAnnotContextMenu") as ContextMenu;
- CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
- //复制
- customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
- //剪切
- customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
- //粘贴
- customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
- //删除
- customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
- //颜色
- customMenu.SetMenuBinding(4, AnnotColorPalette_MenuCommand);
- //线段样式
- bool IsSolid = true;
- if (sender as SquareAnnotArgs != null)
- {
- IsSolid = AnnotPropertyPanel.IsSolidStyle((sender as SquareAnnotArgs).LineDash);
- }
- else if(sender as CircleAnnotArgs != null)
- {
- IsSolid = AnnotPropertyPanel.IsSolidStyle((sender as CircleAnnotArgs).LineDash);
- }
- else if(sender as LineAnnotArgs != null)
- {
- IsSolid = AnnotPropertyPanel.IsSolidStyle((sender as LineAnnotArgs).LineDash);
- }
- customMenu.SetSubMenuBinding(5, 0, ShapeLineStyle_MenuCommand, null, IsSolid);
- customMenu.SetSubMenuBinding(5, 1, ShapeLineStyle_MenuCommand, null, !IsSolid);
- //线段方向
- if(sender as LineAnnotArgs != null)
- {
- customMenu.SetSubMenuBinding(6, 0, ShapeLineDirect_MenuCommand ,null, true);//暂无,待确认
- customMenu.SetSubMenuBinding(6, 1, ShapeLineDirect_MenuCommand ,null, true);//
- customMenu.SetVisibilityProperty(6, true);
- }
- else
- {
- customMenu.SetVisibilityProperty(6,false);
- }
- //添加笔记
- customMenu.SetMenuBinding(7, AnnotAddNoteText_MenuCommand);
- //设置当前属性为默认值
- customMenu.SetMenuBinding(8, AnnotDefaultValue_MenuCommand);
- return popMenu;
- }
- //链接
- private ContextMenu SelectLinkAnnotMenu(object sender)
- {
- var popMenu = App.Current.FindResource("LinkAnnotContextMenu") as ContextMenu;
- CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
- //复制
- customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
- //剪切
- customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
- //粘贴
- customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
- //删除
- customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
- return popMenu;
- }
- //图章、签名
- private ContextMenu SelectStampAnnotMenu(object sender)
- {
- var popMenu = App.Current.FindResource("StampAnnotContextMenu") as ContextMenu;
- CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
- //复制
- customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
- //剪切
- customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
- //粘贴
- customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
- //删除
- customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
- //导出
- customMenu.SetSubMenuBinding(4, 0, StampExportPicture_MenuCommand);//
- customMenu.SetSubMenuBinding(4, 1, StampExportPicture_MenuCommand);//
- customMenu.SetSubMenuBinding(4, 2, StampExportPicture_MenuCommand);//
- //添加笔记
- customMenu.SetMenuBinding(5, AnnotAddNoteText_MenuCommand);
- return popMenu;
- }
- //多选注释
- private ContextMenu SelectMultiAnnotMenu(object sender, bool isHightAnnot)
- {
- var popMenu = App.Current.FindResource("MultiSelectAnnotContextMenu") as ContextMenu;
- CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
- if (isHightAnnot)
- {
- customMenu.SetVisibilityProperty(0, false);
- customMenu.SetVisibilityProperty(1, false);
- }
- else
- {
- //复制
- customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
- //剪切
- customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
- }
- //删除
- customMenu.SetMenuBinding(2, ApplicationCommands.Delete);
- return popMenu;
- }
- #endregion 注释-右键菜单
- }
- }
|