123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.CustomControl;
- using PDF_Master.EventAggregators;
- using PDF_Master.Model;
- using PDF_Master.ViewModels.Tools;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Controls;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement;
- using Button = System.Windows.Controls.Button;
- namespace PDF_Master.ViewModels.EditTools.Watermark
- {
- public class WatermarkTemplateListBaseContentViewModel : BindableBase, INavigationAware
- {
- public IRegionManager watermarkTemplateListRegion;
- private readonly IEventAggregator eventAggregator;
- private CPDFViewer CurrentPDFViewer;
- private string WatermarkTemplateListTextContentName = "WatermarkTemplateListTextContent";
- private string WatermarkTemplateListFileContentName = "WatermarkTemplateListFileContent";
- public bool IsFirstEnter = true;
- public EnumTextOrFile CurrentCreateMod;
- private string _currentTemplateListModName;
- public string CurrentTemplateListModName
- {
- get { return _currentTemplateListModName; }
- set { _currentTemplateListModName = value; }
- }
- private string watermarkTemplateListRegionName;
- public string WatermarkTemplateListRegionName
- {
- get => watermarkTemplateListRegionName;
- set => SetProperty(ref watermarkTemplateListRegionName, value);
- }
- private System.Windows.Visibility watermarkTemplateListVisible;
- public System.Windows.Visibility WatermarkTemplateListVisible
- {
- get => watermarkTemplateListVisible;
- set => SetProperty(ref watermarkTemplateListVisible, value);
- }
- public DelegateCommand<object> ChangeTemplateListModCommand { get; set; }
- public DelegateCommand EnterCreateCommand { get; set; }
- public string Unicode = null;
- public WatermarkTemplateListBaseContentViewModel(IRegionManager watermarkTemplateListRegion, IEventAggregator eventAggregator)
- {
- this.watermarkTemplateListRegion = watermarkTemplateListRegion;
- this.eventAggregator = eventAggregator;
- Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- WatermarkTemplateListRegionName = Guid.NewGuid().ToString();
- ChangeTemplateListModCommand = new DelegateCommand<object>(ChangeTemplateListMod);
- EnterCreateCommand = new DelegateCommand(EnterCreate);
- EnterSelectedTemplateListMod("WatermarkTemplateListColorContent");
- eventAggregator.GetEvent<CurrentWatermarkPDFViewerEvent>().Subscribe(CurrentWatermarkPDFViewer, e => e.Unicode == Unicode);
- }
- public void CurrentWatermarkPDFViewer(CPDFViewerUnicode cPDFViewerunicode)
- {
- CurrentPDFViewer = cPDFViewerunicode.Status;
- }
- public void EnterCreate()
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- if (CurrentPDFViewer.Document.GetWatermarkCount() > 0)
- {
- alertsMessage.ShowDialog("文件中已添加水印,您要替换现有的水印吗?", "", "取消", "确定");
- if (alertsMessage.result == ContentResult.Ok)
- {
- this.eventAggregator.GetEvent<DeleteWatermarkEvent>().Publish(new EnumDeleteUnicode
- {
- Unicode = Unicode,
- Status = EnumDelete.StatusDeleteInitial
- });
- }
- else
- {
- //this.eventAggregator.GetEvent<DeleteWatermarkEvent>().Publish(new EnumDeleteUnicode
- //{
- // Unicode = Unicode,
- // Status = EnumDelete.StatusCreate
- //});
- return;
- }
- }
- this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
- {
- Unicode = Unicode,
- Status = EnumTemplateListOrCreate.StatusCreate
- });
- }
- public void EnterSelectedTemplateListMod(string currentTemplateListName)
- {
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, CurrentPDFViewer);
- watermarkTemplateListRegion.RequestNavigate(WatermarkTemplateListRegionName, currentTemplateListName, param);
- eventAggregator.GetEvent<CurrentWatermarkPDFViewerEvent>().Publish(new CPDFViewerUnicode
- {
- Unicode = Unicode,
- Status = CurrentPDFViewer
- });
- watermarkTemplateListVisible = System.Windows.Visibility.Visible;
- }
- public void ChangeTemplateListMod(object e)
- {
- var args = e as Button;
- if (args != null)
- {
- CurrentTemplateListModName = args.Name;
- EnterSelectedTemplateListMod(CurrentTemplateListModName);
- eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(new stringUnicode
- {
- Unicode = Unicode,
- Status = CurrentTemplateListModName
- });
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- if (IsFirstEnter)
- {
- CurrentTemplateListModName = WatermarkTemplateListTextContentName;
- EnterSelectedTemplateListMod(CurrentTemplateListModName);
- IsFirstEnter = false;
- }
- else
- {
- navigationContext.Parameters.TryGetValue<EnumTextOrFile>("CurrentCreateModName", out CurrentCreateMod);
- if (CurrentCreateMod == EnumTextOrFile.StatusText)
- {
- CurrentTemplateListModName = WatermarkTemplateListTextContentName;
- }
- else
- {
- CurrentTemplateListModName = WatermarkTemplateListFileContentName;
- }
- EnterSelectedTemplateListMod(CurrentTemplateListModName);
- eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(new stringUnicode
- {
- Unicode = Unicode,
- Status = CurrentTemplateListModName
- });
- }
- }
- }
- }
|