using ComPDFKitViewer.AnnotEvent;
using ComPDFKitViewer.PdfViewer;
using PDF_Office.CustomControl;
using PDF_Office.EventAggregators;
using PDF_Office.Model;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
namespace PDF_Office.ViewModels.EditTools.Redaction
{
public class RedactionContentViewModel : BindableBase,INavigationAware
{
public IEventAggregator eventAggregator;
public IRegionManager redactionRegion;
public IDialogService dialogs;
private CPDFViewer PDFViewer;
private ViewContentViewModel viewContentViewModel;
public string RedactionDocumentRegionName { get; set; }
public string RedactionBottomBarRegionName { get; set; }
public string RedactionDocumentName = "RedactionDocumentContent";
public string Unicode = null;
public DelegateCommand CloseEditToolCommand { get; set; }
public DelegateCommand ApplyCommmand { get; set; }
public DelegateCommand RemoveCommand { get; set; }
public DelegateCommand PageRedactionCommand { get; set; }
public RedactionContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator,IDialogService dialogService)
{
this.redactionRegion = regionManager;
this.eventAggregator = eventAggregator;
this.dialogs = dialogService;
RedactionDocumentRegionName = Guid.NewGuid().ToString();
Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
CloseEditToolCommand = new DelegateCommand(CloseEditTool);
ApplyCommmand = new DelegateCommand(apply);
RemoveCommand = new DelegateCommand(remove);
PageRedactionCommand = new DelegateCommand(pageMark);
}
///
/// 应用
///
private void apply()
{
AlertsMessage alertsMessage = new AlertsMessage();
alertsMessage.ShowDialog("Apply Redactions", "Use blank blocks to remove selected sensitive content."+
"This action will permanently delete the marked ciphertext information from this document and you will not be able to retrieve the marked ciphertext information.","Cancel","Apply & Save As");
if(alertsMessage.result== ContentResult.Ok)
{
viewContentViewModel.saveAsFile(true);
}
}
///
/// 擦除
///
private void remove()
{
}
private void pageMark()
{
dialogs.ShowDialog(DialogNames.PageMarkDialog);
}
public void CloseEditTool()
{
PDFViewer.SetMouseMode(MouseModes.Default);
redactionRegion.Regions[RegionNames.ViwerRegionName].Remove(PDFViewer);
redactionRegion.Regions[RedactionDocumentRegionName].Remove(PDFViewer);
this.eventAggregator.GetEvent().Publish(new EnumCloseModeUnicode { Unicode = this.Unicode, Status = EnumCloseMode.StatusCancel });
}
#region Navigation
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer);
navigationContext.Parameters.TryGetValue(ParameterNames.ViewContentViewModel, out viewContentViewModel);
if (!redactionRegion.Regions[RedactionDocumentRegionName].Views.Contains(PDFViewer))
{
RedactionAnnotArgs redactionArgs = new RedactionAnnotArgs();
AnnotHandlerEventArgs annotArgs = null;
redactionArgs.LineColor = ((SolidColorBrush)Brushes.Black).Color;
redactionArgs.BgColor = ((SolidColorBrush)Brushes.Black).Color;
redactionArgs.FontColor = ((SolidColorBrush)Brushes.Red).Color;
//redactionArgs.LineColor = Settings.Default.RedactionsSettings.LineColor;
//redactionArgs.BgColor = Settings.Default.RedactionsSettings.BgColor;
//redactionArgs.FontColor = Settings.Default.RedactionsSettings.FontColor;
//redactionArgs.Align = Settings.Default.RedactionsSettings.Align;
//redactionArgs.FontSize = Settings.Default.RedactionsSettings.FontSize;
//redactionArgs.Content = Settings.Default.RedactionsSettings.Content;
//if (!Settings.Default.RedactionsSettings.isUseText)
//{
// redactionArgs.Content = "";
//}
annotArgs = redactionArgs;
if (annotArgs != null)
{
//annotArgs.Author = Settings.Default.AppProperties.Description.Author;
PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
PDFViewer.SetToolParam(annotArgs);
}
redactionRegion.AddToRegion(RedactionDocumentRegionName, PDFViewer);
}
}
#endregion
}
}