123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Office.EventAggregators;
- using PDF_Office.Helper;
- using PDF_Office.Model;
- using PDF_Office.ViewModels;
- using PDF_Office.ViewModels.Tools;
- using PDF_Office.Views.Dialog;
- using PDF_Office.Views.PropertyPanel.ViewModular;
- using PDF_Office.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_Office.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);
- }
- /// <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.UnReadModel();
- }
- }
- else
- {
- if (viewModel.mainViewModel.IsBookMode == true)
- {
- viewModel.UnReadModel();
- }
- }
- }
- }
- }
- 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();
- }
- }
- }
|