123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using Prism.Commands;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Media;
- using System.Windows;
- using PDF_Office.Model.PropertyPanel.AnnotPanel;
- using System.Windows.Controls;
- using Prism.Regions;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Office.Model;
- using Microsoft.Win32;
- using PDF_Office.CustomControl;
- using ComPDFKitViewer;
- namespace PDF_Office.ViewModels.Tools
- {
- public class TextEditToolContentViewModel: BindableBase, INavigationAware
- {
- #region Command
- public DelegateCommand<object> AddContentCommand { get; set; }
- #endregion
- private IRegionManager regions;
- private Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
- public TextEditToolContentViewModel(IRegionManager regionManager)
- {
- regions = regionManager;
- InitCommand();
- InitBtnToProperty();
- }
- private void InitBtnToProperty()
- {
- btnToProperty.Add("Text", "TextEditProperty");
- btnToProperty.Add("Image", "ImageEditProperty");
- btnToProperty.Add("TextAndImage", "ImageTextEditProperty");
- btnToProperty.Add("PropertyPanelContent", "PropertyPanelContent");
- }
- private void AddToPropertyPanel(string type, List<PDFEditEvent> e)
- {
- if (btnToProperty.ContainsKey(type))
- {
- NavigationParameters parameters = new NavigationParameters();
- parameters.Add(ParameterNames.PDFViewer, PDFViewer);
- parameters.Add(ParameterNames.AnnotEvent, e);
- System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- {
- regions.RequestNavigate(RegionNames.PropertyRegionName, btnToProperty[type], parameters);
- }));
- ShowPropertyPanel(true);
- }
- }
- private void ShowPropertyPanel(bool show = true)
- {
- viewContentViewModel.IsPropertyOpen = show;
- }
- private void InitCommand()
- {
- AddContentCommand = new DelegateCommand<object>(AddContent);
- }
- public void AddContent(object obj)
- {
- if (PDFViewer == null || obj == null || obj as CustomIconToggleBtn == null) return;
- var btn = obj as CustomIconToggleBtn;
- if(btn.IsChecked == true)
- {
- if (btn.Tag.ToString() == "Text")
- {
- PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
- }
- else
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
- openFileDialog.Multiselect = true;
- if ((bool)openFileDialog.ShowDialog())
- {
- if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
- {
- PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
- PDFViewer.AddPDFEditImage(openFileDialog.FileName);
- }
- }
- btn.IsChecked = false;
- }
- }
- else
- {
- PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
- PDFViewer.SetMouseMode(MouseModes.PDFEdit);
- }
- }
- public ViewContentViewModel viewContentViewModel;
- private CPDFViewer PDFViewer;
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- if (PDFViewer != null)
- {
- PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
- PDFViewer.PDFEditActiveHandler += PDFViewer_PDFEditActiveHandler;
- }
- }
- private void PDFViewer_PDFEditActiveHandler(object sender, List<PDFEditEvent> e)
- {
-
- if (e != null && e.Count > 0)
- {
- bool isText = false;
- bool isImg = false;
- foreach (var item in e)
- {
- if (item.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
- {
- isImg = true;
- }
- if (item.EditType == ComPDFKit.PDFPage.CPDFEditType.EditText)
- {
- isText = true;
- }
- }
- if (isText == true && isImg == false)
- {
- AddToPropertyPanel("Text", e);
- }
- if (isText == false && isImg == true)
- {
- AddToPropertyPanel("Image", e);
- }
- if (isText == true && isImg == true)
- {
- AddToPropertyPanel("TextAndImage", e);
- }
- }
- else
- {
- AddToPropertyPanel("PropertyPanelContent", null);
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
-
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
- ShowPropertyPanel(false);
- }
- }
- }
|