123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403 |
- using Microsoft.Win32;
- using Prism.Commands;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using ComPDFKitViewer.PdfViewer;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using PDF_Master.CustomControl;
- using PDF_Master.Model;
- using System.Windows;
- using System.Windows.Controls;
- using System.IO;
- using ComPDFKitViewer.AnnotEvent;
- using PDF_Master.ViewModels.Tools;
- using Prism.Events;
- using PDF_Master.EventAggregators;
- using PDF_Master.Helper;
- using ComPDFKit.PDFDocument;
- using PDFSettings.Settings;
- using PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs;
- using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
- using PDF_Master.Model.Dialog.ToolsDialogs;
- using DryIoc;
- using PDF_Master.Model.Dialog.ConverterDialogs;
- using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
- using PDF_Master.Views.PropertyPanel.AnnotPanel;
- using System.Linq;
- using System.Text;
- using PDF_Master.Views.Tools;
- using System.Windows.Input;
- using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
- using ImTools;
- using PDF_Master.Properties;
- using PDF_Master.ViewModels.BOTA;
- using PDF_Master.Views.BOTA;
- using System.Drawing;
- using PDF_Master.ViewModels.Tools.AnnotManager;
- using PDF_Master.Model.FillAndSign;
- namespace PDF_Master.ViewModels
- {
- public class ViewContentViewModel : BindableBase, INavigationAware
- {
- #region 文案
- private string T_file;
- public string T_File
- {
- get { return T_file; }
- set
- {
- SetProperty(ref T_file, value);
- }
- }
- private string T_save;
- public string T_Save
- {
- get { return T_save; }
- set
- {
- SetProperty(ref T_save, value);
- }
- }
- private string T_undo;
- public string T_Undo
- {
- get { return T_undo; }
- set
- {
- SetProperty(ref T_undo, value);
- }
- }
- private string T_redo;
- public string T_Redo
- {
- get { return T_redo; }
- set
- {
- SetProperty(ref T_redo, value);
- }
- }
- private string T_annotation;
- public string T_Annotation
- {
- get { return T_annotation; }
- set
- {
- SetProperty(ref T_annotation, value);
- }
- }
- private string T_pageEdit;
- public string T_PageEdit
- {
- get { return T_pageEdit; }
- set
- {
- SetProperty(ref T_pageEdit, value);
- }
- }
- private string T_converter;
- public string T_Converter
- {
- get { return T_converter; }
- set
- {
- SetProperty(ref T_converter, value);
- }
- }
- private string T_fillSign;
- public string T_FillSign
- {
- get { return T_fillSign; }
- set
- {
- SetProperty(ref T_fillSign, value);
- }
- }
- private string T_tools;
- public string T_Tools
- {
- get { return T_tools; }
- set
- {
- SetProperty(ref T_tools, value);
- }
- }
- private string T_print;
- public string T_Print
- {
- get { return T_print; }
- set
- {
- SetProperty(ref T_print, value);
- }
- }
- private string T_share;
- public string T_Share
- {
- get { return T_share; }
- set
- {
- SetProperty(ref T_share, value);
- }
- }
- private string T_properties;
- public string T_Properties
- {
- get { return T_properties; }
- set
- {
- SetProperty(ref T_properties, value);
- }
- }
- private void InitStirng()
- {
- T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
- T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
- T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
- T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
- T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
- T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
- T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
- T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
- T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
- T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
- T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
- T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
- }
- #endregion 文案
- #region 属性、变量
- public OpenFileInfo OpenFileInfo = null;
- public CPDFViewer PDFViewer { get; set; }
- public MainContentViewModel mainViewModel { get; set; }
- public IRegionManager region;
- public IDialogService dialogs;
- public IEventAggregator events;
- public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
- public string ViwerRegionName { get; set; }
- /// <summary>
- /// 分屏视图的region名称
- /// </summary>
- public string SplitViewerRegionName { get; set; }
- /// <summary>
- /// OCR视图名称
- /// </summary>
- public string OCRViewerRegionName { get; set; }
- public string BOTARegionName { get; set; }
- public string PropertyRegionName { get; set; }
- public string ToolContentRegionName { get; set; }
- public string ToolsBarContentRegionName { get; set; }
- /// <summary>
- /// 顶部提示的Content
- /// </summary>
- public string TipContentRegionName { get; set; }
- public string LeftTipContentRegionName { get; set; }
- //便签弹窗
- public string NotePopupRegionName { get; set; }
- public string ReadModeRegionName { get; set; }
- public string ConverterBarContentRegionName { get; set; }
- public string TextEditContentRegionName { get; set; }
- public string BackgroundContentRegionName { get; set; }
-
- //若point不赋值或从列表中找不到point,系统会提供默认值为(0,0)的新point,所以改用Tuple<int,int>
- public List<FillAndSignIsShape> FillAndSign = new List<FillAndSignIsShape>();
- public List<Tuple<int, int>> AnnotSignatures = new List<Tuple<int, int>>();
- /// <summary>
- /// 文档的密码
- /// </summary>
- public string PassWord { get; set; }
- private Visibility tipVisible = Visibility.Collapsed;
- /// <summary>
- /// 顶部提示栏的显示状态
- /// </summary>
- public Visibility TipVisible
- {
- get { return tipVisible; }
- set
- {
- SetProperty(ref tipVisible, value);
- }
- }
- private Visibility leftTipVisible = Visibility.Collapsed;
- public Visibility LeftTipVisible
- {
- get { return leftTipVisible; }
- set
- {
- SetProperty(ref leftTipVisible, value);
- }
- }
- private Visibility notePopupVisible = Visibility.Collapsed;
- public Visibility NotePopupVisible
- {
- get { return notePopupVisible; }
- set
- {
- SetProperty(ref notePopupVisible, value);
- }
- }
- public bool IsNoteAdd = false;
- private double canvasNoteLeft;
- public double CanvasNoteLeft
- {
- get { return canvasNoteLeft; }
- set
- {
- SetProperty(ref canvasNoteLeft, value);
- }
- }
- private double canvasNoteBottom;
- public double CanvasNoteBottom
- {
- get { return canvasNoteBottom; }
- set
- {
- SetProperty(ref canvasNoteBottom, value);
- }
- }
- /// <summary>
- /// 底部工具栏 RegionName
- /// </summary>
- public string BottomToolRegionName { get; set; }
- private bool _isInPageEdit = false;
- /// <summary>
- /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
- /// </summary>
- public bool isInPageEdit
- {
- get { return _isInPageEdit; }
- set
- {
- SetProperty(ref _isInPageEdit, value);
- if (!value)
- {
- CanRedo = PDFViewer.UndoManager.CanRedo;
- CanUndo = PDFViewer.UndoManager.CanUndo;
- }
- }
- }
- public Action PageEditUndo { get; set; }
- public Action PageEditRedo { get; set; }
- /// <summary>
- ///工具条
- ///0:收起
- ///40:显示
- /// </summary>
- private int toolRowHeight = 40;
- public int ToolRowHeight
- {
- get { return toolRowHeight; }
- set
- {
- SetProperty(ref toolRowHeight, value);
- }
- }
- /// <summary>
- /// 水印,背景侧边栏宽度
- /// 0:收起
- /// 260:显示
- /// </summary>
- private int propertyColumnWidth = 0;
- public int PropertyColumnWidth
- {
- get { return propertyColumnWidth; }
- set
- {
- SetProperty(ref propertyColumnWidth, value);
- }
- }
- private int gridToolRow = 1;
- /// <summary>
- /// 控制ToolContent的Row
- /// </summary>
- public int GridToolRow
- {
- get { return gridToolRow; }
- set
- {
- SetProperty(ref gridToolRow, value);
- }
- }
- private int gridToolRowSpan = 3;
- /// <summary>
- /// 控制ToolContent的RowSpan
- /// </summary>
- public int GridToolRowSpan
- {
- get { return gridToolRowSpan; }
- set
- {
- SetProperty(ref gridToolRowSpan, value);
- }
- }
- private Visibility toolContentVisible = Visibility.Collapsed;
- /// <summary>
- /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
- /// 留意:显示前需要先注入内容、设置好行和跨行数
- /// </summary>
- public Visibility ToolContentVisible
- {
- get { return toolContentVisible; }
- set
- {
- SetProperty(ref toolContentVisible, value);
- }
- }
- private Visibility gridVisibility = Visibility.Visible;
- /// <summary>
- /// 是否正在加载中
- /// </summary>
- public Visibility GridVisibility
- {
- get { return gridVisibility; }
- set
- {
- SetProperty(ref gridVisibility, value);
- }
- }
- private Visibility isLoading = Visibility.Collapsed;
- private Visibility ocrContentVisible = Visibility.Collapsed;
- public Visibility OCRContentVisible
- {
- get { return ocrContentVisible; }
- set
- {
- SetProperty(ref ocrContentVisible, value);
- }
- }
- /// <summary>
- /// 是否正在加载中
- /// </summary>
- public Visibility IsLoading
- {
- get { return isLoading; }
- set
- {
- SetProperty(ref isLoading, value);
- }
- }
- private Visibility converterBarContentVisible = Visibility.Collapsed;
- private Visibility toolsbarContentVisible = Visibility.Collapsed;
- /// <summary>
- /// 控制ToolsBarContent的显示
- /// 留意:显示前需要先注入内容、设置好行和跨行数
- /// </summary>
- public Visibility ConverterBarContentVisible
- {
- get { return converterBarContentVisible; }
- set
- {
- SetProperty(ref converterBarContentVisible, value);
- }
- }
- private Visibility toolsBarContentVisible = Visibility.Collapsed;
- /// <summary>
- /// 控制ToolsBarContent的显示
- /// 留意:显示前需要先注入内容、设置好行和跨行数
- /// </summary>
- public Visibility ToolsBarContentVisible
- {
- get { return toolsBarContentVisible; }
- set
- {
- SetProperty(ref toolsBarContentVisible, value);
- }
- }
- private Visibility textEditToolContentVisible = Visibility.Collapsed;
- /// <summary>
- /// 控制ToolsBarContent的显示
- /// 留意:显示前需要先注入内容、设置好行和跨行数
- /// </summary>
- public Visibility TextEditToolContentVisible
- {
- get { return textEditToolContentVisible; }
- set
- {
- SetProperty(ref textEditToolContentVisible, value);
- }
- }
- private bool isPorpertyOpen = false;
- /// <summary>
- /// 属性栏是否展开
- /// </summary>
- public bool IsPropertyOpen
- {
- get { return isPorpertyOpen; }
- set
- {
- //如果设置为手动展开属性面板时,则不响应代码控制的展开
- if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty)
- {
- if (mainViewModel.IsBookMode)
- {
- this.events.GetEvent<ReadModePropertyOpenEvent>().Publish(new ReadModePropertyOpenArgs() { Unicode = unicode });
- }
- SetProperty(ref isPorpertyOpen, value);
- }
- }
- }
- private Visibility isReadMode = Visibility.Visible;
- /// <summary>
- ///是否为阅读模式
- /// </summary>
- public Visibility IsReadMode
- {
- get { return isReadMode; }
- set
- {
- SetProperty(ref isReadMode, value);
- }
- }
- private bool canSave;
- /// <summary>
- /// 是否可以保存
- /// </summary>
- public bool CanSave
- {
- get { return canSave; }
- set
- {
- if (events != null && canSave == false)
- this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = "Clear", AppUnicode = unicode });
- SetProperty(ref canSave, value);
- }
- }
- private bool canUndo;
- /// <summary>
- /// 是否可以进行Undo
- /// </summary>
- public bool CanUndo
- {
- get { return canUndo; }
- set
- {
- SetProperty(ref canUndo, value);
- }
- }
- private bool canRedo;
- /// <summary>
- /// 是否可以进行Redo
- /// </summary>
- public bool CanRedo
- {
- get { return canRedo; }
- set
- {
- SetProperty(ref canRedo, value);
- }
- }
- private GridLength botaWidth = new GridLength(48);
- /// <summary>
- /// BOTA栏的宽度
- /// </summary>
- public GridLength BOTAWidth
- {
- get { return botaWidth; }
- set
- {
- SetProperty(ref botaWidth, value);
- if (botaWidth.Value <= 48)
- {
- OpenBOTA = false;
- }
- }
- }
- private int selectedIndex;
- /// <summary>
- /// 工具栏选中项的索引
- /// </summary>
- public int TabSelectedIndex
- {
- get { return selectedIndex; }
- set
- {
- SetProperty(ref selectedIndex, value);
- }
- }
- private bool openBOTA = false;
- /// <summary>
- /// 是否展开BOTA
- /// </summary>
- public bool OpenBOTA
- {
- get { return openBOTA; }
- set
- {
- SetProperty(ref openBOTA, value);
- if (openBOTA && BOTAWidth.Value <= 48)
- {
- BOTAWidth = new GridLength(260);
- }
- //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
- }
- }
- public SecurityInfo SecurityInfo = new SecurityInfo();
- private Dictionary<string, string> regionNameByTabItem;
- private Dictionary<string, string> barContentByTabItem;
- private string previousBar = "";
- public string CurrentBar = "";
- public string unicode = null;
- /// <summary>
- /// 用来避免重复触发导航事件的标志符
- /// </summary>
- private bool isOpenFile = false;
- /// <summary>
- /// 鼠标滚轮缩放的缩放值
- /// </summary>
- private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
- /// <summary>
- /// 注释-链接,提示语
- /// </summary>
- private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
- public Visibility LinkAnnotTipVisibility
- {
- get { return linkAnnotTipVisibility; }
- set
- {
- SetProperty(ref linkAnnotTipVisibility, value);
- }
- }
- private string linkAnnotTipText = "Please use the scroll bar, thumbnail tool to locate the target page, click or box the area to select the target range";
- private bool isCreateLink = false;
- public string LinkAnnotTipText
- {
- get { return linkAnnotTipText; }
- set
- {
- SetProperty(ref linkAnnotTipText, value);
- }
- }
- #endregion 属性、变量
- #region 命令
- public DelegateCommand Load { get; set; }
- public DelegateCommand MouseDown { get; set; }
- public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
- public DelegateCommand SaveFile { get; set; }
- public DelegateCommand SaveAsFile { get; set; }
- public DelegateCommand SaveAsFlattenCommand { get; set; }
- public DelegateCommand UndoCommand { get; set; }
- public DelegateCommand RedoCommand { get; set; }
- public DelegateCommand<object> MenuEnterReadMode { get; set; }
- public DelegateCommand PrintCommand { get; set; }
- public DelegateCommand SelectCommand { get; set; }
- public DelegateCommand SettingsCommand { get; set; }
- public DelegateCommand ShareCommand { get; set; }
- public DelegateCommand<object> CreateLinkCommand { get; set; }
- public DelegateCommand PropertyCommand { get; set; }
- public DelegateCommand ShowInFolderCommand { get; set; }
- public DelegateCommand CompressCommand { get; set; }
- public DelegateCommand MergeFileCommand { get; set; }
- public DelegateCommand EncryptCommand { get; set; }
- public DelegateCommand DecryptCommand { get; set; }
- public DelegateCommand<string> ConvertCommand { get; set; }
- public DelegateCommand CloseWindowCommand { get; set; }
- public DelegateCommand OpenFileCommand { get; set; }
- public DelegateCommand<string> HelpCommand { get; set; }
- public DelegateCommand CreateBlankFileCommand { get; set; }
- public DelegateCommand ClosePropertyCommand { get; set; }
- #endregion 命令
- public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
- {
- InitStirng();
- region = regionManager;
- dialogs = dialogService;
- events = eventAggregator;
- unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- Load = new DelegateCommand(LoadControl);
- MouseDown = new DelegateCommand(MouseDownEvent);
- SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
- SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
- SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
- UndoCommand = new DelegateCommand(Undo);
- RedoCommand = new DelegateCommand(Redo);
- ShareCommand = new DelegateCommand(share);
- PropertyCommand = new DelegateCommand(property);
- ShowInFolderCommand = new DelegateCommand(ShowInFolder);
- TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
- CompressCommand = new DelegateCommand(compress);
- MergeFileCommand = new DelegateCommand(mergeFile);
- EncryptCommand = new DelegateCommand(encrypt);
- DecryptCommand = new DelegateCommand(decrypt);
- ConvertCommand = new DelegateCommand<string>(convert);
- CloseWindowCommand = new DelegateCommand(closeWindow);
- OpenFileCommand = new DelegateCommand(openfile);
- HelpCommand = new DelegateCommand<string>(help);
- CreateBlankFileCommand = new DelegateCommand(createBlankFile);
- ViwerRegionName = RegionNames.ViwerRegionName;
- SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
- BOTARegionName = RegionNames.BOTARegionName;
- PropertyRegionName = RegionNames.PropertyRegionName;
- BottomToolRegionName = RegionNames.BottomToolRegionName;
- ReadModeRegionName = RegionNames.ReadModeRegionName;
- MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
- PrintCommand = new DelegateCommand(ShowPrintDialog);
- SelectCommand = new DelegateCommand(SelectClick);
- SettingsCommand = new DelegateCommand(SettingsEvent);
- CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
- ClosePropertyCommand = new DelegateCommand(CloseProperty);
- //未显示时无法注册上Region名称
- ToolContentVisible = Visibility.Visible;
- ToolsBarContentVisible = Visibility.Visible;
- OCRContentVisible = Visibility.Visible;
- TipVisible = Visibility.Visible;
- TipContentRegionName = RegionNames.TipContentRegionName;
- LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
- NotePopupRegionName = RegionNames.NotePopupRegionName;
- OCRViewerRegionName = RegionNames.OCRViewerRegionName;
- ToolContentRegionName = Guid.NewGuid().ToString();
- ToolsBarContentRegionName = Guid.NewGuid().ToString();
- ConverterBarContentRegionName = Guid.NewGuid().ToString();
- TextEditContentRegionName = Guid.NewGuid().ToString();
- ToolContentVisible = Visibility.Collapsed;
- ToolsBarContentVisible = Visibility.Collapsed;
- OCRContentVisible = Visibility.Collapsed;
- TipVisible = Visibility.Collapsed;
- regionNameByTabItem = new Dictionary<string, string>();
- barContentByTabItem = new Dictionary<string, string>();
- InitialregionNameByTabItem(ref regionNameByTabItem);
- InitialbarContentByTabItem(ref barContentByTabItem);
- eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
- eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
- eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTipAsync, e => e.Unicode == unicode);
- //TODO:根据缓存 选择用户上次选择的菜单
- EnterSelectedBar("TabItemAnnotation");
- }
- private void MouseDownEvent()
- {
- if (NotePopupVisible == Visibility.Visible && IsNoteAdd == false)
- {
- NotePopupVisible = Visibility.Collapsed;
- if (region.Regions.ContainsRegionWithName(NotePopupRegionName))
- {
- var views = region.Regions[NotePopupRegionName].Views;
- foreach (var item in views)
- {
- if (item is StickyNotePopup sticky)
- {
- var contentRegion = region.Regions[NotePopupRegionName];
- contentRegion.Remove(sticky);
- break;
- }
- }
- }
- }
- }
- /// <summary>
- ///创建空白文档
- /// </summary>
- private async void createBlankFile()
- {
- App.mainWindowViewModel.AddTab.Execute();
- await Task.Delay(30);
- (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
- }
- private void help(string args)
- {
- string url = "";
- switch (args)
- {
- case "Guid":
- //打开内嵌文档
- if(App.OpenedFileList.Contains(App.GuidPDFPath))
- {
- //如果已经打开时,则选中内嵌文档
- App.mainWindowViewModel.SelectItem(App.GuidPDFPath);
- return;
- }
- if (File.Exists(App.GuidPDFPath))
- {
- App.mainWindowViewModel.AddTabItem(App.GuidPDFPath);
- }
- break;
- case "Online":
- url = @"https://www.pdfreaderpro.com/windows/help";
- break;
- case "More":
- url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
- break;
- case "Template":
- url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
- break;
- case "Blog":
- //TODO:显示订阅电子报弹窗
- break;
- case "ComPDF":
- url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
- break;
- case "FeedBack":
- //调用邮箱 发送邮件
- StringBuilder sr = new StringBuilder();
- sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
- System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
- break;
- default:
- break;
- }
- if (!string.IsNullOrEmpty(url))
- {
- //需要跳转网页的情况
- System.Diagnostics.Process.Start(url);
- }
- }
- /// <summary>
- /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
- /// </summary>
- private void openfile()
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
- openFileDialog.Multiselect = true;
- if ((bool)openFileDialog.ShowDialog())
- {
- if (openFileDialog.FileNames.Count() == 1)
- {
- if (App.OpenedFileList.Contains(openFileDialog.FileName))
- {
- App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
- }
- else
- {
- App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
- }
- ToolMethod.SetFileThumbImg(openFileDialog.FileName);
- }
- else
- {
- var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
- if (fileList.Count <= 0)
- {
- App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
- return;
- }
- mainViewModel.OpenFile(fileList[0]);
- for (int i = 1; i < fileList.Count(); i++)
- {
- if (!App.OpenedFileList.Contains(fileList[i]))
- {
- App.mainWindowViewModel.AddTabItem(fileList[i]);
- }
- ToolMethod.SetFileThumbImg(fileList[i]);
- }
- }
- }
- }
- /// <summary>
- /// 关闭当前窗体
- /// </summary>
- private void closeWindow()
- {
- App.Current.MainWindow.Close();
- }
- /// <summary>
- /// 转档
- /// </summary>
- /// <param name="obj"></param>
- private void convert(string obj)
- {
- if (!string.IsNullOrEmpty(obj))
- {
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.PDFViewer, PDFViewer);
- switch (obj)
- {
- case "Word":
- dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
- {
- ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
- converterDialogsModel.OnOpened((DialogResult)e);
- });
- break;
- case "Excel":
- dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
- {
- ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
- converterDialogsModel.OnOpened((DialogResult)e);
- });
- break;
- case "PPT":
- dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
- {
- ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
- converterDialogsModel.OnOpened((DialogResult)e);
- });
- break;
- case "RTF":
- dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
- {
- ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
- converterDialogsModel.OnOpened((DialogResult)e);
- });
- break;
- case "CSV":
- dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
- {
- ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
- converterDialogsModel.OnOpened((DialogResult)e);
- });
- break;
- case "HTML":
- dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
- {
- ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
- converterDialogsModel.OnOpened((DialogResult)e);
- });
- break;
- case "Text":
- dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
- {
- ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
- converterDialogsModel.OnOpened((DialogResult)e);
- });
- break;
- case "Image":
- dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
- {
- ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
- converterDialogsModel.OnOpened((DialogResult)e);
- });
- break;
- default:
- break;
- }
- }
- }
- /// <summary>
- /// 解密
- /// </summary>
- private void decrypt()
- {
- if (!PDFViewer.Document.IsEncrypted)
- {
- MessageBoxEx.Show("No security settings available ");
- }
- else
- {
- VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
- if (result.IsDiscryptied)
- {
- if (result.Password != null)
- {
- string filePath = PDFViewer.Document.FilePath;
- PDFViewer.Document.Release();
- PDFViewer.InitDocument(filePath);
- PDFViewer.Document.UnlockWithPassword(result.Password);
- }
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
- dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });
- }
- }
- }
- /// <summary>
- /// 加密
- /// </summary>
- private void encrypt()
- {
- if (!this.SecurityInfo.IsPasswordChanged)
- {
- VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
- if (result.IsDiscryptied)
- {
- if (result.Password != null)
- {
- string filePath = PDFViewer.Document.FilePath;
- PDFViewer.Document.Release();
- PDFViewer.InitDocument(filePath);
- PDFViewer.Document.UnlockWithPassword(result.Password);
- }
- }
- }
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.PDFViewer, this.PDFViewer);
- value.Add(ParameterNames.ViewContentViewModel, this);
- dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
- {
- if (e.Result == ButtonResult.OK)
- {
- SecurityHelper.IsPasswordChanged = true;
- if (this.SecurityInfo.IsPasswordChanged)
- {
- this.PDFViewer.UndoManager.CanSave = true;
- }
- this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
- }
- });
- }
- /// <summary>
- /// 合并
- /// </summary>
- private void mergeFile()
- {
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.PDFViewer, PDFViewer);
- dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
- }
- /// <summary>
- /// 压缩
- /// </summary>
- private void compress()
- {
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.PDFViewer, PDFViewer);
- dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
- {
- CompressDialogModel compressDialogModel = new CompressDialogModel();
- compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
- });
- }
- /// <summary>
- /// 设置Tip状态栏的显示状态
- /// </summary>
- /// <param name="show">是否显示</param>
- public void ShowTip(bool show)
- {
- if (show)
- {
- TipVisible = Visibility.Visible;
- }
- else
- {
- TipVisible = Visibility.Collapsed;
- }
- }
- /// <summary>
- /// 设置LeftTip状态栏的显示状态
- /// </summary>
- /// <param name="show">是否显示</param>
- public void ShowLeftTip(bool show)
- {
- if (show)
- {
- LeftTipVisible = Visibility.Visible;
- }
- else
- {
- LeftTipVisible = Visibility.Collapsed;
- }
- }
- public void CheckHaveAllPermission()
- {
- if (SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
- {
- ShowLeftTip(true);
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
- }
- }
- public async void ShowSelectedTipAsync(ShowTipEventArgs showTipEventArgs)
- {
- switch (showTipEventArgs.enumTipKind)
- {
- case EnumTipKind.StatusNone:
- ShowLeftTip(false);
- break;
- case EnumTipKind.StatusSetPasswordSuccessfully:
- ShowLeftTip(true);
- region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
- break;
- case EnumTipKind.StatusRemoveSecuritySuccessfully:
- ShowLeftTip(false);
- region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
- IsLoading = Visibility.Collapsed;
- ShowTip(true);
- await Task.Delay(3000);
- //ReadModelTip = Visibility.Collapsed;
- TipVisible = Visibility.Collapsed;
- break;
- default: break;
- }
- }
- /// <summary>
- /// 右键菜单创建链接
- /// </summary>
- /// <param name="obj"></param>
- private void CreateLinkEvent(object obj)
- {
- if (obj is object[] objArry)
- {
- if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
- {
- LinkAnnotArgs linkArgs = new LinkAnnotArgs();
- linkArgs.URI = string.Empty;
- linkArgs.LinkType = LINK_TYPE.GOTO;
- linkArgs.PageIndex = annotCommand.PageIndex;
- //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
- this.IsRightMenuCreateLink = true;
- List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
- lists.Add(linkArgs);
- AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- this.IsPropertyOpen = true;
- }
- }
- }
- private void CloseProperty()
- {
- IsPropertyOpen = false;
- }
- /// <summary>
- /// 在文件资源管理器中显示
- /// </summary>
- private void ShowInFolder()
- {
- CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
- }
- private void property()
- {
- DialogParameters valuePairs = new DialogParameters();
- valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
- dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
- }
- private void share()
- {
- try
- {
- var path = PDFViewer.Document.FilePath;
- string subject = "分享至" + " " + PDFViewer.Document.FileName;
- System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
- }
- catch
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
- }
- }
- private void SettingsEvent()
- {
- dialogs.ShowDialog(DialogNames.SettingsDialog, null, null);
- if (PDFViewer != null)
- {
- PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
- }
- }
- private bool CanSaveExcute()
- {
- return CanSave;
- }
- private void MenuEnterReadModeEvent(object obj)
- {
- }
- public void ShowPrintDialog()
- {
- DialogParameters printValue = new DialogParameters();
- printValue.Add(ParameterNames.PDFViewer, PDFViewer);
- printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
- printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
- dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
- }
- public void SelectClick()
- {
- if (OpenBOTA == false)
- {
- OpenBOTA = true;
- }
- bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
- if (isBook == false)
- {
- bOTAContent.TabItemSearch.IsSelected = true;
- }
- }
- private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
- {
- bool isTabItem = false;
- bOTAContentViewModel = null;
- bOTAContent = null;
- if (region.Regions.ContainsRegionWithName(this.BOTARegionName))
- {
- var views = region.Regions[this.BOTARegionName].Views;
- var model = views.FirstOrDefault(q => q is BOTAContent);
- if (model is BOTAContent bOTAContent1)
- {
- bOTAContent = bOTAContent1;
- bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
- if (bOTAContentViewModel.CurrentBar == tabItemText)
- {
- isTabItem = true;
- }
- }
- }
- return isTabItem;
- }
- private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
- {
- dictionary.Add("TabItemPageEdit", ToolContentRegionName);
- dictionary.Add("TabItemTool", ToolsBarContentRegionName);
- //其他工具菜单栏共用一个ToolsBarContentRegionName
- dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
- dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
- dictionary.Add("TabItemScan", ToolsBarContentRegionName);
- dictionary.Add("TabItemEdit", TextEditContentRegionName);
- dictionary.Add("TabItemForm", ToolsBarContentRegionName);
- dictionary.Add("TabItemFill", ToolsBarContentRegionName);
- }
- private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
- {
- dictionary.Add("TabItemPageEdit", "PageEditContent");
- dictionary.Add("TabItemTool", "ToolsBarContent");
- dictionary.Add("TabItemAnnotation", "AnnotToolContent");
- dictionary.Add("TabItemConvert", "ConverterBarContent");
- dictionary.Add("TabItemScan", "ScanContent");
- dictionary.Add("TabItemEdit", "TextEditToolContent");
- dictionary.Add("TabItemForm", "FormsToolContent");
- dictionary.Add("TabItemFill", "FillAndSignContent");
- }
- private void UpdateShowContent(string currentBar)
- {
- ToolContentVisible = Visibility.Collapsed;
- ToolsBarContentVisible = Visibility.Collapsed;
- ConverterBarContentVisible = Visibility.Collapsed;
- TextEditToolContentVisible = Visibility.Collapsed;
- OCRContentVisible = Visibility.Collapsed;
- switch (currentBar)
- {
- case "TabItemAnnotation":
- case "TabItemTool":
- case "TabItemForm":
- case "TabItemFill":
- ToolsBarContentVisible = Visibility.Visible;
- break;
- case "TabItemScan":
- ToolsBarContentVisible = Visibility.Visible;
- OCRContentVisible = Visibility.Visible;
- break;
- case "TabItemEdit":
- TextEditToolContentVisible = Visibility.Visible;
- break;
- case "TabItemConvert":
- ConverterBarContentVisible = Visibility.Visible;
- break;
- case "TabItemPageEdit":
- case "HeaderFooterContent":
- case "BatesContent":
- case "WatermarkContent":
- case "BackgroundContent":
- case "RedactionContent":
- ToolContentVisible = Visibility.Visible;
- break;
- default:
- break;
- }
- PDFEditMode(currentBar);
- FormMode(currentBar);
- }
- private void PDFEditMode(string currentBar)
- {
- if (currentBar == "TabItemEdit")
- {
- if (PDFViewer != null)
- {
- PDFViewer.SetMouseMode(MouseModes.PDFEdit);
- //SelectedPrpoertyPanel("TextEditProperty", null);
- //IsPropertyOpen = true;
- }
- }
- else
- {
- if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
- {
- IsPropertyOpen = false;
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- }
- }
- }
- private void FormMode(string currentBar)
- {
- if (currentBar == "TabItemForm")
- {
- if (PDFViewer != null)
- {
- PDFViewer.SetMouseMode(MouseModes.FormEditTool);
- }
- }
- else
- {
- if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- }
- }
- }
- private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- if (!isInPageEdit)
- {
- //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
- //页面编辑模式下,按钮状态根据页面编辑的undo redo来显示
- if (e.PropertyName == "CanUndo")
- {
- CanUndo = PDFViewer.UndoManager.CanUndo;
- }
- if (e.PropertyName == "CanRedo")
- {
- CanRedo = PDFViewer.UndoManager.CanRedo;
- }
- }
- if (e.PropertyName == "CanSave")
- {
- CanSave = PDFViewer.UndoManager.CanSave;
- }
- }
- /// <summary>
- /// 选项卡切换事件
- /// </summary>
- /// <param name="e"></param>
- private void TabControlSelectonChangedEvent(object e)
- {
- var args = e as SelectionChangedEventArgs;
- if (args != null)
- {
- var item = args.AddedItems[0] as TabItem;
- CurrentBar = item.Name;
- if (previousBar != CurrentBar)
- {
- if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
- {
- EnterToolMode(barContentByTabItem[CurrentBar]);
- isInPageEdit = true;
- }
- else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
- {
- EnterSelectedBar(CurrentBar);
- isInPageEdit = false;
- }
- previousBar = CurrentBar;
- }
- }
- }
- /// <summary>
- /// 阅读模式
- /// </summary>
- /// <param name="viewContent"></param>
- public async void On_ReadMode()
- {
- App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
- mainViewModel.IsBookMode = true;
- IsLoading = Visibility.Visible;
- await Task.Delay(1);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- #region 旧版本
- //NavigationParameters param = new NavigationParameters();
- //param.Add(ParameterNames.PDFViewer, PDFViewer);
- //param.Add(ParameterNames.ViewContentViewModel, this);
- //region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
- ////ShowContent(CurrentBar, true);
- //if (GridToolRow != 0)
- //{
- // GridToolRow = 0;
- //}
- //if (GridToolRowSpan != 4)
- //{
- // GridToolRowSpan = 4;
- //}
- ////isInPageEdit = true;
- //UpdateShowContent("TabItemPageEdit");
- #endregion 旧版本
- this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = true });
- if (region.Regions.ContainsRegionWithName(TipContentRegionName))
- {
- var views = region.Regions[TipContentRegionName].Views;
- var isHasView = views.FindFirst(q => q is Views.TipContent.EnterReadModeTip);
- if (isHasView == null)
- {
- region.RequestNavigate(TipContentRegionName, "EnterReadModeTip");
- }
- else
- {
- region.Regions[TipContentRegionName].Activate(isHasView);
- }
- }
- IsLoading = Visibility.Collapsed;
- ShowTip(true);
- await Task.Delay(3000);
- TipVisible = Visibility.Collapsed;
- }
- /// <summary>
- /// 退出阅读模式
- /// </summary>
- public async void Off_ReadModel()
- {
- App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
- mainViewModel.IsBookMode = false;
- IsLoading = Visibility.Visible;
- await Task.Delay(1);
- //PDFViewer.MouseMode = MouseModes.None;
- #region 旧版本
- //if (region.Regions.ContainsRegionWithName(ViwerRegionName))
- //{
- // if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
- // {
- // var contentRegion = region.Regions[ViwerRegionName];
- // contentRegion.Remove(PDFViewer);
- // }
- // //还原背景色
- // PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
- // region.AddToRegion(ViwerRegionName, PDFViewer);
- //}
- //if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
- //{
- // EnterSelectedBar("TabItemAnnotation");
- //}
- //else
- //{
- // EnterSelectedBar(CurrentBar);
- //}
- #endregion 旧版本
- //还原背景色
- PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
- this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = false });
- if (region.Regions.ContainsRegionWithName(TipContentRegionName))
- {
- var views = region.Regions[TipContentRegionName].Views;
- var isHasView = views.FindFirst(q => q is Views.TipContent.ReadModelTip);
- if (isHasView == null)
- {
- region.RequestNavigate(TipContentRegionName, "ReadModelTip");
- }
- else
- {
- region.Regions[TipContentRegionName].Activate(isHasView);
- }
- }
- IsLoading = Visibility.Collapsed;
- ShowTip(true);
- await Task.Delay(3000);
- //ReadModelTip = Visibility.Collapsed;
- TipVisible = Visibility.Collapsed;
- }
- #region PDFViewer鼠标滚轮缩放事件
- public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
- {
- double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
- PDFViewer.Zoom(newZoom);
- }
- public double CheckZoomLevel(double zoom, bool IsGrowth)
- {
- double standardZoom = 100;
- if (zoom <= 0.01)
- {
- return 0.01;
- }
- if (zoom >= 10)
- {
- return 10;
- }
- zoom *= 100;
- for (int i = 0; i < zoomLevel.Length - 1; i++)
- {
- if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
- {
- standardZoom = zoomLevel[i + 1];
- break;
- }
- if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
- {
- standardZoom = zoomLevel[i];
- break;
- }
- }
- return standardZoom / 100;
- }
- #endregion PDFViewer鼠标滚轮缩放事件
- #region Navigate
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- App.mainWindowViewModel.OphVis = Visibility.Collapsed;
- var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
- if (mainVM != null)
- {
- mainViewModel = mainVM;
- mainViewModel.viewContentViewModel = this;
- }
- var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
- if (pdfview != null)
- {
- PDFViewer = pdfview;
- if (loadFile())
- {
- CheckHaveAllPermission();
- }
- }
- //快捷键
- KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
- KeyEventsHelper.KeyDown += ShortCut_KeyDown;
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- if (navigationContext != null)
- {
- //另存为打开导航进来时 不能新建一个实例
- return true;
- }
- else
- {
- //一次性打开多个文件时,需要新建实例
- return false;
- }
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
- }
- #endregion Navigate
- #region 方法
- /// <summary>
- /// 快捷键
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- /// <exception cref="NotImplementedException"></exception>
- private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
- {
- if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
- {
- if (mainViewModel.IsBookMode == true)
- {
- Off_ReadModel();
- }
- //内容选择 退出
- if (PDFViewer.MouseMode != MouseModes.PanTool)
- {
- AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
- if (annotToolContent != null && toolContentViewModel != null)
- {
- if (annotToolContent.BtnSelecttool.IsChecked == true)
- {
- if (toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs != null)
- {
- toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
- annotToolContent.BtnSelecttool.IsChecked = false;
- }
- }
- }
- }
- }
- if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.C))
- {
- //内容选择 复制 快捷键
- AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
- if (annotToolContent != null && toolContentViewModel != null)
- {
- if (annotToolContent.BtnSelecttool.IsChecked == true)
- {
- toolContentViewModel.SnapshotEditMenuViewModel.SnapCopyCommand.Execute();
- }
- }
- }
- if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.P))
- {
- AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
- if (annotToolContent != null && toolContentViewModel != null)
- {
- if (annotToolContent.BtnSelecttool.IsChecked == true)
- {
- toolContentViewModel.SnapshotEditMenuViewModel.PrintCommand.Execute();
- }
- }
- }
- }
- private AnnotToolContent GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel)
- {
- AnnotToolContent toolContent = null;
- toolContentViewModel = null;
- if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
- {
- var views = region.Regions[ToolsBarContentRegionName].Views;
- var model = views.FirstOrDefault(q => q is AnnotToolContent);
- if (model is AnnotToolContent annotToolContent)
- {
- toolContent = annotToolContent;
- toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
- }
- }
- return toolContent;
- }
- /// <summary>
- /// 视图面板 切换分屏模式
- /// </summary>
- /// <param name="mode"></param>
- public void EnterSplitMode(SplitMode mode)
- {
- ///通知UI层更改布局
- this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
- }
- private void Undo()
- {
- if (isInPageEdit)
- {
- //执行页面编辑的Undo
- PageEditUndo?.Invoke();
- }
- else
- {
- PDFViewer.UndoManager.Undo();
- }
- }
- private void Redo()
- {
- if (isInPageEdit)
- {
- //执行页面编辑的Redo
- PageEditRedo?.Invoke();
- }
- else
- {
- PDFViewer.UndoManager.Redo();
- }
- }
- private void LoadControl()
- {
- //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
- // 非必要情况不要使用该异步方法,可能会导致一次性加载多个文件时出现因异步引起的regionname 错乱问题
- //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- // {
- NavigationParameters parameters = new NavigationParameters();
- parameters.Add(ParameterNames.PDFViewer, PDFViewer);
- parameters.Add(ParameterNames.ViewContentViewModel, this);
- region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
- region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
- region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
- region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
- //TODO 根据上一次关闭记录的菜单,选中TabItem
- EnterSelectedBar("TabItemAnnotation");
- //}
- //));
- //if (App.IsBookMode)
- //{
- // RbtnReadMode();
- //}
- //else
- //{
- // UnReadModel();
- //}
- }
- /// <summary>
- /// 各个注释(选中和创建注释)导航到对应注释的属性面板
- /// </summary>
- /// <param name="Content"></param>
- /// <param name="annotPropertyPanel"></param>
- public void SelectedPrpoertyPanel(string Content, AnnotTransfer annotPropertyPanel)
- {
- NavigationParameters parameters = new NavigationParameters();
- //传其他参数:文档类,空注释面板;
- parameters.Add(ParameterNames.PDFViewer, PDFViewer);
- parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
- parameters.Add(ParameterNames.ViewContentViewModel, this);
- region.RequestNavigate(PropertyRegionName, Content, parameters);
- }
- /// <summary>
- /// 将PDFViwer添加到Region
- /// </summary>
- private bool loadFile()
- {
- PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
- PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
- CanSave = PDFViewer.UndoManager.CanSave;
- CanUndo = PDFViewer.UndoManager.CanUndo;
- CanRedo = PDFViewer.UndoManager.CanRedo;
- VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
- if (result.IsDiscryptied)
- {
- if (result.Password != null)
- {
- string filePath = PDFViewer.Document.FilePath;
- PDFViewer.Document.UnlockWithPassword(result.Password);
- PDFViewer.Tag = result.Password;
- //记录密码到内存
- this.PassWord = result.Password;
- }
- }
- if (result.IsDiscryptied == false)
- {
- //未成功解密文档时,释放Document对象,返回
- PDFViewer.Document.Release();
- //取消解密时关闭当前页签
- App.mainWindowViewModel.CloseTabItem(App.mainWindowViewModel.SelectedItem);
- return false;
- }
- PDFViewer.Load();
- PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
- PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
- //还原上一次关闭前的视图设置
- GetOpenFileInfo();
- region.AddToRegion(ViwerRegionName, PDFViewer);
- if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
- {
- App.OpenedFileList.Add(PDFViewer.Document.FilePath);
- }
- return true;
- }
- /// <summary>
- /// 还原上一次浏览的视图相关设置
- /// </summary>
- private void GetOpenFileInfo()
- {
- OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
- //偏好设置里设置了记录上次视图设置时
- if (OpenFileInfo != null && Settings.Default.AppProperties.Description.RecoveryViewWhenOpen)
- {
- if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
- {
- PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
- }
- if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
- {
- PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
- }
- if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
- {
- PDFViewer.Zoom(OpenFileInfo.LastZoom);
- }
- if (OpenFileInfo.LastPageIndex != PDFViewer.CurrentIndex)
- {
- PDFViewer.GoToPage(OpenFileInfo.LastPageIndex);
- }
- PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
- PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
- if (OpenFileInfo.LastPageSpace)
- {
- PDFViewer.SetPageSpacing(8);
- }
- else
- {
- PDFViewer.SetPageSpacing(0);
- }
- if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
- {
- PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
- }
- else
- {
- PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
- }
- }
- else
- {
- //新文档应用默认设置
- PDFViewer.ChangeViewMode(Settings.Default.AppProperties.InitialVIew.PageView);
- PDFViewer.ChangeFitMode(Settings.Default.AppProperties.InitialVIew.ZoomMode);
- PDFViewer.SetShowLink(Settings.Default.AppProperties.InitialVIew.HighlightLink);
- }
- }
- /// <summary>
- /// 已有路径文档的保存逻辑
- /// </summary>
- public bool saveFile()
- {
- try
- {
- if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
- return saveAsFile();
- //文档已被修复时 提示另存为
- if (PDFViewer.Document.HasRepaired)
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
- if (alertsMessage.result == ContentResult.Ok)
- return saveAsFile();
- else
- return false;
- }
- //文件路径无法存在时
- if (!File.Exists(PDFViewer.Document.FilePath))
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
- if (alertsMessage.result == ContentResult.Ok)
- return saveAsFile();
- else
- return false;
- }
- //只读文件无法写入时,提示另存为
- FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
- if (fileInfo.IsReadOnly)
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
- if (alertsMessage.result == ContentResult.Ok)
- return saveAsFile();
- else
- return false;
- }
- //Security Fixed:
- //修改密码后原文档保存的步骤:
- //在设置密码窗口传出“已修改”信号,并允许延迟保存
- //
- if (SecurityInfo.IsPasswordChanged)
- {
- string currentFilePath = PDFViewer.Document.FilePath;
- string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
- string openPassword = null;
- string permissionsPassword = null;
- CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
- if (SecurityInfo.NeedOpenPassword)
- {
- openPassword = SecurityInfo.OpenPassword;
- }
- if (SecurityInfo.NeedPermissionsPassword)
- {
- permissionsPassword = SecurityInfo.PermissionsPassword;
- cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
- }
- try
- {
- string currentPath = PDFViewer.Document.FilePath;
- string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
- if (PDFViewer.Document.Descrypt(tempPath))
- {
- PDFViewer.CloseDocument();
- PDFViewer.InitDocument(tempPath);
- PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
- if (PDFViewer.Document.WriteToFilePath(currentPath))
- {
- PDFViewer.CloseDocument();
- PDFViewer.InitDocument(currentPath);
- if (!string.IsNullOrEmpty(openPassword))
- {
- PDFViewer.Document.UnlockWithPassword(openPassword);
- }
- if (!string.IsNullOrEmpty(permissionsPassword))
- {
- PDFViewer.Document.CheckOwnerPassword(permissionsPassword);
- }
- try
- {
- PDFViewer.Load();
- }
- catch
- {
- }
- PDFViewer.UndoManager.CanSave = false;
- SecurityInfo.IsPasswordChanged = false;
- }
- else
- {
- return false;
- }
- System.IO.File.Delete(tempPath);
- }
- else
- {
- return false;
- }
- return true;
- }
- catch
- {
- return false;
- }
- }
- else if (SecurityInfo.IsPasswordRemoved)
- {
- try
- {
- string currentPath = PDFViewer.Document.FilePath;
- string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
- PDFViewer.Document.Descrypt(tempPath);
- PDFViewer.CloseDocument();
- PDFViewer.InitDocument(tempPath);
- PDFViewer.Document.WriteToFilePath(currentPath);
- PDFViewer.CloseDocument();
- PDFViewer.InitDocument(currentPath);
- PDFViewer.Load();
- System.IO.File.Delete(tempPath);
- }
- catch
- {
- return false;
- }
- }
- bool result = PDFViewer.Document.WriteToLoadedPath();
- if (result)
- {
- PDFViewer.UndoManager.CanSave = false;
- App.Current.Dispatcher.Invoke(() =>
- {
- //保存时更新缩略图
- OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
- try
- {
- if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
- {
- var size = PDFViewer.Document.GetPageSize(0);
- System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
- string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
- if (File.Exists(folderPath))
- File.Delete(folderPath);
- DirectoryInfo folder = new DirectoryInfo(folderPath);
- if (!folder.Exists)
- folder.Create();
- string imagePath = info.ThumbImgPath;
- if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
- {
- string imageName = Guid.NewGuid().ToString();
- imagePath = System.IO.Path.Combine(folderPath, imageName);
- using (FileStream stream = new FileStream(imagePath, FileMode.Create))
- {
- bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
- }
- }
- else
- {
- using (FileStream stream = new FileStream(imagePath, FileMode.Open))
- {
- bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
- }
- }
- info.ThumbImgPath = imagePath;
- SettingHelper.SetFileInfo(info);
- }
- }
- catch
- {
- info.ThumbImgPath = null;
- SettingHelper.SetFileInfo(info);
- }
- });
- PDFViewer.ReloadDocument();
- }
- else
- {
- //文件被占用 保存失败时
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
- if (alertsMessage.result == ContentResult.Ok)
- return saveAsFile();
- else
- return false;
- }
- return result;
- }
- catch { return false; }
- finally
- {
- ShowLeftTip(false);
- }
- }
- /// <summary>
- /// 另存为或新文档保存逻辑
- /// </summary>
- public bool saveAsFile(Action RedactionAction = null)
- {
- var dlg = new Microsoft.Win32.SaveFileDialog();
- dlg.Filter = Properties.Resources.OpenDialogFilter;
- dlg.FileName = PDFViewer.Document.FileName;
- if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
- {
- bool result = false;
- if (RedactionAction != null)
- {
- //保存前进行标记密文处理应用或擦除
- RedactionAction.Invoke();
- }
- if (App.OpenedFileList.Contains(dlg.FileName))
- {
- //提示文件已经被打开
- }
- else
- {
- string oldpath = PDFViewer.Document.FilePath;
- result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
- if (result)
- {
- App.OpenedFileList.Remove(oldpath);
- DoAfterSaveAs(dlg.FileName);
- }
- else
- {
- //提示文件被其他软件占用 无法保存
- //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
- }
- ;
- }
- return result;
- }
- else
- return false;
- }
- /// <summary>
- /// 另存为Flatten
- /// </summary>
- private void saveAsFlatten()
- {
- var dlg = new SaveFileDialog();
- dlg.Filter = Properties.Resources.OpenDialogFilter;
- dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
- if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
- {
- saveFile();
- CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
- if (kmdoc == null)
- return;
- bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
- if (result)
- System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
- kmdoc.Release();
- }
- }
- /// <summary>
- /// 另存为后进行的操作
- /// 重新打开新文档
- /// </summary>
- /// <param name="targetPath"></param>
- public void DoAfterSaveAs(string targetPath)
- {
- string oldFilePath = targetPath;
- PDFViewer.UndoManager.CanSave = false;
- mainViewModel.OpenFile(targetPath);
- //TODO:通知各模块更新PDFview对象
- //var result = OpenFile(targetPath, true);
- //if (result)
- //{
- // FileChanged.Invoke(this, null);
- // Zoomer.PdfViewer = PdfViewer;
- // PageSelector.PdfViewer = PdfViewer;
- // ViewModeSelector.PdfViewer = PdfViewer;
- // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
- // if (fileInfo != null)
- // {
- // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
- // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
- // if (fileInfo.LastFitMode == FitMode.FitFree)
- // PdfViewer.Zoom(fileInfo.LastZoom);
- // PdfViewer.GoToPage(fileInfo.LastPageIndex);
- // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
- // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
- // else
- // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
- // }
- //}
- }
- /// <summary>
- /// 显示前添加内容到Region
- /// </summary>
- /// <param name="isPageEdit"></param>
- private void ShowContent(string currentBar, bool isToolMode = false)
- {
- GridVisibility = Visibility.Visible;
- //显示页面编辑或其他工具
- if (currentBar == "TabItemPageEdit" || isToolMode)
- {
- if (currentBar == "TabItemPageEdit")//进入页面编辑
- {
- if (GridToolRow != 1)
- {
- GridToolRow = 1;
- }
- if (GridToolRowSpan != 3)
- {
- GridToolRowSpan = 3;
- }
- }
- else//进入水印等其他工具模式
- {
- GridVisibility = Visibility.Collapsed;
- if (GridToolRow != 0)
- {
- GridToolRow = 0;
- }
- if (GridToolRowSpan != 4)
- {
- GridToolRowSpan = 4;
- }
- }
- //ToolContent的visible跟toolsbarContent 的visible是互斥的
- UpdateShowContent(currentBar);
- }
- else
- {
- if (GridToolRow != 1)
- {
- GridToolRow = 1;
- }
- UpdateShowContent(currentBar);
- }
- }
- /// <summary>
- /// 从二级工具栏进入需要修改界面布局的场景
- /// </summary>
- /// <param name="EditToolName"></param>
- private void EnterEditTools(StringWithUnicode EditToolName)
- {
- EnterSelectedEditTool(EditToolName);
- }
- private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
- {
- EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
- if (enumCloseMode == EnumCloseMode.StatusConfirm)
- {
- PDFViewer.Document.ReleasePages();
- PDFViewer.ReloadDocument();
- }
- //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
- if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
- {
- region.AddToRegion(ViwerRegionName, PDFViewer);
- }
- CurrentBar = "TabItemTool";
- EnterSelectedBar(CurrentBar);
- }
- /// <summary>
- /// 二级菜单指定目标处理
- /// </summary>
- /// <param name="e"></param>
- private void EnterSelectedEditTool(StringWithUnicode EditToolName)
- {
- CurrentBar = EditToolName.EditToolsContentName;
- EnterToolMode(CurrentBar);
- }
- /// <summary>
- /// 进入工具编辑(如页面编辑、水印、密文等)模式
- /// </summary>
- /// <param name="targetToolMode">要导航过去的控件名称</param>
- /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
- private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
- {
- IsLoading = Visibility.Visible;
- await Task.Delay(3);
- NavigationParameters param = new NavigationParameters();
- if (valuePairs == null)
- {
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add(ParameterNames.ViewContentViewModel, this);
- }
- else//有传入其他内容的参数时
- {
- param = valuePairs;
- }
- region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
- ShowContent(CurrentBar, true);
- IsLoading = Visibility.Collapsed;
- }
- private void EnterSelectedBar(string currentBar)
- {
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add(ParameterNames.ViewContentViewModel, this);
- region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
- if (currentBar == "TabItemScan")
- {
- region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
- }
- ShowContent(currentBar);
- }
- /// <summary>
- /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
- /// </summary>
- public void ExitToolMode()
- {
- ToolContentVisible = Visibility.Collapsed;
- if (isInPageEdit)
- {
- TabSelectedIndex = 0;
- isInPageEdit = false;
- }
- }
- #endregion 方法
- }
- }
|