123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.EventAggregators;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.ViewModels;
- using PDF_Master.ViewModels.PropertyPanel.ViewModular;
- using PDF_Master.ViewModels.Tools;
- using PDF_Master.Views.Dialog;
- using PDF_Master.Views.PropertyPanel.ViewModular;
- using PDF_Master.Views.Tools;
- using Prism.Events;
- using Prism.Regions;
- using System;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Threading;
- namespace PDF_Master.Views
- {
- /// <summary>
- /// Interaction logic for ViewContent
- /// </summary>
- public partial class ViewContent : UserControl
- {
- private ViewContentViewModel viewModel = null;
- private string unicode = "";
- public ViewContent()
- {
- InitializeComponent();
- unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- viewModel = (ViewContentViewModel)this.DataContext;
- viewModel.PropertyChanged += ViewModel_PropertyChanged;
- }
- private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- if (e.PropertyName == "OpenBOTA")
- {
- if (!viewModel.OpenBOTA)
- {
- //动态改变BOTA的最小宽度只能在这里设置,VM里绑定会有异常
- BOTACloumn.MinWidth = 48;
- viewModel.BOTAWidth = new GridLength(48);
- BOTASplitter.Visibility = Visibility.Collapsed;
- }
- else
- {
- BOTACloumn.MinWidth = 260;
- BOTASplitter.Visibility = Visibility.Visible;
- }
- }
- }
- public ViewContent(IEventAggregator eventAggregator) : this()
- {
- eventAggregator.GetEvent<SplitEvent>().Subscribe(ChangeSplitModeUI, e => e.Unicode == unicode);
- eventAggregator.GetEvent<ReadModeEvent>().Subscribe(ChangeReadModeUI, e => e.Unicode == unicode);
- eventAggregator.GetEvent<ReadModePropertyOpenEvent>().Subscribe(ChangeReadModePropertyOpenUI, e => e.Unicode == unicode);
- }
- private void ChangeReadModePropertyOpenUI(ReadModePropertyOpenArgs obj)
- {
- Grid.SetColumnSpan(GridViewer, 3);
- Grid.SetColumn(GridViewer, 0);
- Grid.SetColumn(Scroller, 4);
- }
- private void ChangeReadModeUI(ReadModeArgs obj)
- {
- if (obj.IsReadMode)
- {
- ReadModeContent.Visibility = Visibility.Visible;
- RectangleReadMode.Visibility = Visibility.Collapsed;
- this.TbtnProperty.IsChecked = false;
- Grid.SetRowSpan(DocumentView, 4);
- Grid.SetRow(DocumentView, 0);
- Grid.SetColumnSpan(GridViewer, 4);
- Grid.SetColumn(GridViewer, 0);
- }
- else
- {
- ReadModeContent.Visibility = Visibility.Collapsed;
- RectangleReadMode.Visibility = Visibility.Collapsed;
- //this.TbtnProperty.IsChecked=true;
- Grid.SetRowSpan(DocumentView, 1);
- Grid.SetRow(DocumentView, 2);
- Grid.SetColumnSpan(GridViewer, 1);
- Grid.SetColumn(GridViewer, 2);
- }
- }
- /// <summary>
- /// 鼠标移动到控件范围时显示控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RectangleReadMode_MouseEnter(object sender, MouseEventArgs e)
- {
- //Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(delegate
- //{
- if (viewModel.mainViewModel.IsBookMode)
- {
- this.ReadModeContent.Visibility = Visibility.Visible;
- this.RectangleReadMode.Visibility = Visibility.Collapsed;
- }
- //}));
- }
- /// <summary>
- /// 鼠标移开页面控件,三秒后隐藏该控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private async void ReadModeContent_MouseLeave(object sender, MouseEventArgs e)
- {
- await System.Threading.Tasks.Task.Delay(3000);
- //Thread.Sleep(3000);
- this.ReadModeContent.Visibility = Visibility.Collapsed;
- this.RectangleReadMode.Visibility = Visibility.Visible;
- }
- /// <summary>
- /// 根据Vm事件通知处理分屏布局的事件
- /// </summary>
- /// <param name="e"></param>
- private void ChangeSplitModeUI(SplitEventArgs e)
- {
- switch (e.Mode)
- {
- case EventAggregators.SplitMode.Horizontal:
- //水平分屏 上下
- HorizontalSplitter.Visibility = Visibility.Visible;
- VerticalSplitter.Visibility = Visibility.Collapsed;
- RowRight.Height = new GridLength(1, GridUnitType.Star);
- ColumnBottom.Width = new GridLength(0);
- Grid.SetColumn(SplitPDFViewer, 0);
- Grid.SetRow(SplitPDFViewer, 2);
- break;
- case EventAggregators.SplitMode.Vertical:
- HorizontalSplitter.Visibility = Visibility.Collapsed;
- VerticalSplitter.Visibility = Visibility.Visible;
- RowRight.Height = new GridLength(0);
- ColumnBottom.Width = new GridLength(1, GridUnitType.Star);
- Grid.SetColumn(SplitPDFViewer, 2);
- Grid.SetRow(SplitPDFViewer, 0);
- break;
- case EventAggregators.SplitMode.Single:
- default:
- //退出分屏模式
- HorizontalSplitter.Visibility = Visibility.Collapsed;
- VerticalSplitter.Visibility = Visibility.Collapsed;
- RowRight.Height = new GridLength(0, GridUnitType.Star);
- ColumnBottom.Width = new GridLength(0, GridUnitType.Star);
- break;
- }
- GridViewer.UpdateLayout();
- }
- /// <summary>
- /// 退出阅读模式
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void UserControl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
- {
- if (Key.Escape == e.Key)
- {
- if (viewModel != null)
- {
- if (viewModel.PDFViewer.MouseMode != MouseModes.PanTool)
- {
- if (this.ContentToolsBar.Content is AnnotToolContent annotTool)
- {
- if (annotTool.BtnSelecttool.IsChecked == true)
- {
- AnnotToolContentViewModel model = (AnnotToolContentViewModel)annotTool.DataContext;
- if (model != null)
- {
- if (model.SnapshotEditMenuViewModel.SnapToolArgs != null)
- {
- model.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
- }
- }
- }
- }
- if (viewModel.mainViewModel.IsBookMode == true)
- {
- viewModel.Off_ReadModel();
- }
- }
- else
- {
- if (viewModel.mainViewModel.IsBookMode == true)
- {
- viewModel.Off_ReadModel();
- }
- }
- }
- }
- }
- private void BtnFile_Initialized(object sender, EventArgs e)
- {
- BtnFile.ContextMenu = null;
- }
- private void BtnFile_Click(object sender, RoutedEventArgs e)
- {
- FileMenu.PlacementTarget = BtnFile;
- FileMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
- FileMenu.IsOpen = true;
- }
- private void ContentControl_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- }
- private void MenuRecent_Loaded(object sender, RoutedEventArgs e)
- {
- int count = 0;
- MenuRecent.Items.Clear();
- foreach (var file in Properties.Settings.Default.RecentOpenFiles)
- {
- MenuItem item = new MenuItem();
- item.Height = 32;
- item.Header = file.FileName;
- item.Tag = file.FilePath;
- item.ToolTip = file.FilePath;
- item.Click += RecentItem_Click;
- MenuRecent.Items.Insert(MenuRecent.Items.Count, item);
- count++;
- if (count >= 20)
- break;
- }
- if (Properties.Settings.Default.RecentOpenFiles.Count > 0)
- {
- MenuRecent.Items.Add(Menu_Separator);
- MenuRecent.Items.Add(MenuDeleteAll);
- MenuDeleteAll.IsEnabled = true;
- MenuDeleteAll.Opacity = 1;
- }
- else
- {
- MenuRecent.Items.Add(MenuDeleteAll);
- MenuDeleteAll.IsEnabled = false;
- MenuDeleteAll.Opacity = 0.5;
- }
- }
- private void RecentItem_Click(object sender, RoutedEventArgs e)
- {
- var item = sender as MenuItem;
- string[] filePath = new string[1];
- filePath[0] = item.Tag.ToString();
- if (App.OpenedFileList.Contains(filePath[0]))
- {
- (this.DataContext as ViewContentViewModel).mainViewModel.mainWindowViewModel.SelectItem(filePath[0]);
- }
- else
- {
- (this.DataContext as ViewContentViewModel).mainViewModel.mainWindowViewModel.AddTabItem(filePath[0]);
- }
- }
- private void MenuDeleteAll_Click(object sender, RoutedEventArgs e)
- {
- SettingHelper.RemoveAllRecentOpenFiles();
- }
- private void UserControl_DragEnter(object sender, DragEventArgs e)
- {
- DragDropHelper.DragEnter(this, e);
- }
- private void UserControl_DragOver(object sender, DragEventArgs e)
- {
- DragDropHelper.DragOver(this, e);
- }
- private void UserControl_DragLeave(object sender, DragEventArgs e)
- {
- DragDropHelper.DragLeave();
- }
- private void UserControl_Drop(object sender, DragEventArgs e)
- {
- try
- {
- DragDropHelper.Drop(this, e);
- string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
- //页面编辑模式下 不响应拖拽打开文件
- if (file != null && file.Length > 0 && !(this.DataContext as ViewContentViewModel).isInPageEdit)
- {
- App.mainWindowViewModel.AddTab.Execute();
- (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).homeContentViewModel.AddFileFromDrag(file.ToList());
- }
- }
- catch { }
- }
- private void CloseLeftCommand_Executed(object sender, ExecutedRoutedEventArgs e)
- {
- BOTASplitter.Visibility = Visibility.Collapsed;
- }
- private void CloseRightCommand_Executed(object sender, ExecutedRoutedEventArgs e)
- {
- viewModel.ClosePropertyCommand.Execute();
- }
- }
- }
|