1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926 |
- 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;
- using PDF_Master.Views.PropertyPanel.ViewModular;
- using PDF_Master.Views.PropertyPanel;
- using System.Windows.Threading;
- using Dropbox.Api.Files;
- using System.Windows.Media;
- using Color = System.Windows.Media.Color;
- using PDFSettings;
- using PDF_Master.Views;
- 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 bool IsMultiSelected { get; set; } = false;
- public OpenFileInfo OpenFileInfo = null;
- public CPDFViewer PDFViewer { get; set; }
- public bool ReadModeIsShowProperty { get; set; } = false;
- public MainContentViewModel mainViewModel { get; set; }
- public bool IsSettingOut = false;
- 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 TextEditContentRegionName { get; set; }
- public string BackgroundContentRegionName { get; set; }
- public PasswordInfo PasswordInfo = new PasswordInfo();
- //若point不赋值或从列表中找不到point,系统会提供默认值为(0,0)的新point,所以改用Tuple<int,int>
- public List<FillAndSignIsShape> FillAndSign = new List<FillAndSignIsShape>();
- /// <summary>
- /// 签名列表
- /// </summary>
- public List<Tuple<int, int>> AnnotSignatures = new List<Tuple<int, int>>();
- /// <summary>
- /// 文档的密码
- /// </summary>
- public string PassWord { get; set; }
- public PasswordInfo passwordInfo = new PasswordInfo();
- private Visibility tipVisible = Visibility.Collapsed;
- /// <summary>
- /// 顶部提示栏的显示状态
- /// </summary>
- public bool IsFileLocked = false;
- 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 || FromClick)
- {
- //阅读模式 不显示属性面板
- //if (mainViewModel.IsBookMode)
- //{
- // this.events.GetEvent<ReadModePropertyOpenEvent>().Publish(new ReadModePropertyOpenArgs() { Unicode = unicode });
- //}
- SetProperty(ref isPorpertyOpen, value);
- }
- }
- }
- /// <summary>
- /// 是否是点击属性面板按钮
- /// </summary>
- private bool FromClick = false;
- 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);
- }
- Settings.Default.AppProperties.InitialVIew.RememberBOTA = openBOTA;
- //关闭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 DispatcherTimer autoSaveTimer = new DispatcherTimer();
- /// <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;
- internal bool IsRightMenuSelectedTextAddLink = 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 CreateFromFile { get; set; }
- public DelegateCommand ClosePropertyCommand { get; set; }
- public DelegateCommand<object> OpenPropertyCommand { 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);
- CreateFromFile = new DelegateCommand(createfromFile);
- OpenPropertyCommand = new DelegateCommand<object>(openProperty);
- 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();
- 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:根据缓存 选择用户上次选择的菜单
- CurrentBar = "TabItemAnnotation";
- EnterSelectedBar("TabItemAnnotation");
- StartAutoSave();
- }
- /// <summary>
- /// 进入全屏模式
- /// </summary>
- private void OpenFullWindow()
- {
- DialogParameters parameters = new DialogParameters();
- //因为全屏模式可能需要设置特定的页面模式,所以只传文件路径,新建一个PDFview对象
- parameters.Add(ParameterNames.FilePath, PDFViewer.Document.FilePath);
- parameters.Add(ParameterNames.PassWord, PDFViewer.Tag == null ? "" : PDFViewer.Tag.ToString());
- dialogs.ShowDialog(DialogNames.FullScreenDialog, parameters, e =>
- {
- if (e.Result == ButtonResult.Cancel)
- {
- //TODO:弹窗提示打开全屏模式失败
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", App.MainPageLoader.GetString("OperationFailWarning"), App.ServiceLoader.GetString("Text_ok"));
- return;
- }
- });
- }
- /// <summary>
- /// 点击展开折叠属性面板
- /// </summary>
- /// <param name="obj"></param>
- private void openProperty(object obj)
- {
- FromClick = true;
- IsPropertyOpen = (bool)obj;
- FromClick = false;
- }
- /// <summary>
- /// 开始自动保存
- /// </summary>
- public void StartAutoSave()
- {
- var autoSave = Settings.Default.AppProperties.Description.AutoSave;
- if (autoSave)
- {
- var interval = Settings.Default.AppProperties.Description.AutoSaveInterval;
- if (autoSaveTimer == null)
- {
- autoSaveTimer = new DispatcherTimer();
- }
- autoSaveTimer.Stop();
- autoSaveTimer.Interval = TimeSpan.FromMinutes(interval);
- autoSaveTimer.Tick -= AutoSaveTimer_Tick;
- autoSaveTimer.Tick += AutoSaveTimer_Tick;
- autoSaveTimer.Start();
- }
- }
- /// <summary>
- /// 释放定时器
- /// 不释放定时器可能会一直运行并占用内存,导致内存泄露
- /// </summary>
- public void CloseAutoSave()
- {
- if (autoSaveTimer != null)
- {
- autoSaveTimer.Stop();
- autoSaveTimer.Tick -= AutoSaveTimer_Tick;
- autoSaveTimer = null;
- }
- }
- private void AutoSaveTimer_Tick(object sender, EventArgs e)
- {
- var autoSave = Settings.Default.AppProperties.Description.AutoSave;
- if (autoSave && !mainViewModel.NewFile && PDFViewer.UndoManager.CanSave)
- {
- //自动保存仅针对已经有文件路径的文档
- saveFile();
- }
- }
- 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;
- }
- }
- }
- }
- }
- private async void createfromFile()
- {
- string txt = Properties.Resources.txtex;
- string word = Properties.Resources.wordex;
- string ppt = Properties.Resources.pptex;
- string excel = Properties.Resources.excelex;
- string html = Properties.Resources.htmlex;
- string image = Properties.Resources.imageex;
- string allfiles = txt + word + excel + ppt + image + html;
- OpenFileDialog dialog = new OpenFileDialog();
- dialog.Multiselect = true;
- dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
- $"Microsoft Office Word({word})|{word}|" +
- $"Microsoft Office Excel({excel})|{excel}|" +
- $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
- $"Txt({txt})|{txt}|" +
- $"Picture({image})|{image}|" +
- $"Html({html})|{html}");
- if ((bool)dialog.ShowDialog())
- {
- for (int i = 0; i < dialog.FileNames.Length; i++)
- {
- if (App.OpenedFileList.Contains(dialog.FileNames[i]))
- {
- App.mainWindowViewModel.SelectItem(dialog.FileNames[i]);
- }
- else
- {
- System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- {
- App.mainWindowViewModel.AddTabItem(dialog.FileNames[i]);
- }));
- await Task.Delay(20);
- ToolMethod.SetFileThumbImg(dialog.FileNames[i]);
- }
- }
- }
- }
- /// <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 && !SecurityInfo.IsPasswordChanged) || (SecurityInfo.IsPasswordRemoved))
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", "No security settings available ", "OK");
- }
- else
- {
- VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
- if (result.IsDiscryptied)
- {
- if (result.Password != null)
- {
- PDFViewer.Document.CheckOwnerPassword(result.Password);
- }
- ShowLeftTip(false);
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
- value.Add(ParameterNames.ViewContentViewModel, this);
- dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e =>
- {
- if (e.Result == ButtonResult.OK)
- {
- if (SecurityInfo.IsPasswordRemoved)
- {
- PDFViewer.UndoManager.CanSave = true;
- }
- ShowLeftTip(false);
- region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
- }
- });
- }
- }
- }
- /// <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)
- {
- if (PDFViewer.Document.UnlockWithPassword(result.Password))
- {
- PDFViewer.Document.CheckOwnerPassword(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()
- {
- FromClick = true;
- IsPropertyOpen = false;
- FromClick = 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("", App.MainPageLoader.GetString("Share_NoOutLookWarning"), App.ServiceLoader.GetString("Text_ok"));
- }
- }
- private void SettingsEvent()
- {
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.ViewContentViewModel, this);
- AnnotToolContentViewModel annotToolContent = null;
- if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
- {
- var views = region.Regions[ToolsBarContentRegionName].Views;
- var isHas = views.FindFirst(q => q is AnnotToolContent);
- if (isHas is AnnotToolContent annotTool)
- {
- annotToolContent = (AnnotToolContentViewModel)annotTool.DataContext;
- }
- }
- dialogs.ShowDialog(DialogNames.SettingsDialog, null, e =>
- {
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotToolContent != null)
- {
- IsSettingOut = true;
- //与注释联动修改颜色
- UpdateFreeHand(annotate, annotToolContent);
- UpdateTextHighlight(annotate, annotToolContent);
- UpdateUnderLine(annotate, annotToolContent);
- UpdateStrikethrough(annotate, annotToolContent);
- UpdateLine(annotate, annotToolContent);
- UpdateArrow(annotate, annotToolContent);
- //IsSettingOut =false;
- }
- });
- if (PDFViewer != null)
- {
- PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
- }
- if (Settings.Default.AppProperties.Description.AutoSave)
- {
- StartAutoSave();
- }
- else
- {
- CloseAutoSave();
- }
- }
- private void UpdateArrow(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
- {
- Color color2 = annotate.ArrowColor;
- Color color1 = (annotToolContent.ArrowColor as SolidColorBrush).Color;
- bool flag = ColorComparison(color2, color1);
- if (flag)
- {
- annotToolContent.ArrowColor = new SolidColorBrush(color2);
- if (annotToolContent.PropertyPanel.LastArrowAnnot != null)
- {
- if (annotToolContent.PropertyPanel.LastArrowAnnot is LineAnnotArgs annotArgs)
- {
- annotArgs.LineColor = color2;
- }
- }
- if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
- {
- CreateRefreshComment(annotToolContent);
- }
- }
- }
- private void UpdateLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
- {
- Color color2 = annotate.LineColor;
- Color color1 = (annotToolContent.LineColor as SolidColorBrush).Color;
- bool flag = ColorComparison(color2, color1);
- if (flag)
- {
- annotToolContent.LineColor = new SolidColorBrush(color2);
- if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null)
- {
- if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] is LineAnnotArgs annotArgs)
- {
- annotArgs.LineColor = color2;
- }
- }
- if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
- {
- CreateRefreshComment(annotToolContent);
- }
- }
- }
- private void UpdateStrikethrough(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
- {
- Color color2 = annotate.StrikethroughColor;
- Color color1 = (annotToolContent.StrikeoutColor as SolidColorBrush).Color;
- bool flag = ColorComparison(color2, color1);
- if (flag)
- {
- annotToolContent.StrikeoutColor = new SolidColorBrush(color2);
- if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
- {
- CreateRefreshComment(annotToolContent);
- }
- }
- }
- private void UpdateUnderLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
- {
- Color color2 = annotate.UnderLineColor;
- Color color1 = (annotToolContent.UnderLineColor as SolidColorBrush).Color;
- bool flag = ColorComparison(color2, color1);
- if (flag)
- {
- annotToolContent.UnderLineColor = new SolidColorBrush(color2);
- if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
- {
- CreateRefreshComment(annotToolContent);
- }
- }
- }
- private void UpdateTextHighlight(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
- {
- Color color2 = annotate.HighLightColor;
- Color color1 = (annotToolContent.HighLightColor as SolidColorBrush).Color;
- bool flag = ColorComparison(color2, color1);
- if (flag)
- {
- annotToolContent.HighLightColor = new SolidColorBrush(color2);
- if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
- {
- CreateRefreshComment(annotToolContent);
- }
- }
- }
- private void UpdateFreeHand(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
- {
- Color color2 = annotate.FreeHandColor;
- Color color1 = (annotToolContent.FreeHandColor as SolidColorBrush).Color;
- bool flag = ColorComparison(color2, color1);
- if (flag)
- {
- annotToolContent.FreeHandColor = new SolidColorBrush(color2);
- if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] != null)
- {
- if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] is FreehandAnnotArgs freehandAnnotArgs)
- {
- freehandAnnotArgs.InkColor = color2;
- }
- }
- if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
- {
- CreateRefreshComment(annotToolContent);
- }
- }
- }
- private void CreateRefreshComment(AnnotToolContentViewModel annotToolContent)
- {
- AnnotHandlerEventArgs annotArgs = null;
- string tag = annotToolContent.StrAnnotToolChecked;
- annotToolContent.FindAnnotTypeKey(tag, ref annotArgs);
- if (annotArgs != null)
- {
- //设置点击页面会创建对应选中注释工具的注释
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- private bool ColorComparison(Color color2, Color color1)
- {
- if (color1.R == color2.R && color1.G == color2.G && color1.B == color2.B
- && color1.A == color2.A)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- 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);
- printValue.Add(ParameterNames.Unicode, unicode);
- 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", ToolsBarContentRegionName);
- 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;
- ToolsBarContentVisible = 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":
- ToolsBarContentVisible = 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)
- {
- //不处于页面编辑模式下时,根据PDFVIewer的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")//如果是页面编辑则进入页面编辑模式
- {
- EnterPageEdit();
- }
- else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
- {
- EnterSelectedBar(CurrentBar);
- isInPageEdit = false;
- }
- previousBar = CurrentBar;
- }
- }
- }
- /// <summary>
- /// 进入页面编辑模式
- /// </summary>
- public void EnterPageEdit()
- {
- if (TabSelectedIndex != 1)
- {
- TabSelectedIndex = 1;
- }
- CurrentBar = "TabItemPageEdit";
- EnterToolMode(barContentByTabItem[CurrentBar]);
- isInPageEdit = true;
- }
- /// <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.DisableClearSelectAnnot(false);
- PDFViewer.ClearSelectAnnots();
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- var annotArgs = new SelectToolArgs();
- PDFViewer.SetToolParam(annotArgs);
- #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 旧版本
- OpenBOTA = false;
- this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = true });
- //模拟一次用户点击 关闭属性面板
- //如果直接设置属性可能因为偏好设置设置成手动的原因 无法生效
- FromClick = true;
- IsPropertyOpen = false;
- FromClick = false;
- 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);
- }
- }
- ///退出阅读模式 显示视图面板
- //IsPropertyOpen = true;
- //if (region.Regions.ContainsRegionWithName(PropertyRegionName))
- //{
- // NavigationParameters param = new NavigationParameters();
- // param.Add(ParameterNames.PDFViewer, PDFViewer);
- // param.Add(ParameterNames.BottomToolContentViewModel, this);
- // region.RequestNavigate(RegionNames.PropertyRegionName, "ViewModularContent", param);
- //}
- if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
- {
- var views = region.Regions[BottomToolRegionName].Views;
- var isHasView = views.FindFirst(q => q is BottomToolContent);
- if (isHasView is BottomToolContent bottomToolContent)
- {
- BottomToolContentViewModel toolContentViewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
- toolContentViewModel.IsShowViewModular = false;
- }
- }
- IsLoading = Visibility.Collapsed;
- PDFViewer.DisableClearSelectAnnot(false);
- PDFViewer.ClearSelectAnnots();
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- var annotArgs = new SelectToolArgs();
- PDFViewer.SetToolParam(annotArgs);
- ShowTip(true);
- this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
- await Task.Delay(3000);
- //ReadModelTip = Visibility.Collapsed;
- TipVisible = Visibility.Collapsed;
- }
- /// <summary>
- /// 高级功能前弹出比较表
- /// </summary>
- /// <param name="post">是否请求服务器</param>
- public bool IAPBeforeFunction(bool post = false)
- {
- if (post)
- {
- //判断本地有没有token,没有显示登录,有再判断登录状态
- if (Settings.Default.AppProperties.LoginToken != "")
- {
- if (ServiceHelper.GetUser() == "401")
- {
- App.mainWindowViewModel.UserVis = Visibility.Collapsed;
- App.mainWindowViewModel.LoginVis = Visibility.Visible;
- App.mainWindowViewModel.OphVis = Visibility.Visible;
- }
- }
- else
- {
- App.mainWindowViewModel.UserVis = Visibility.Collapsed;
- App.mainWindowViewModel.LoginVis = Visibility.Visible;
- App.mainWindowViewModel.OphVis = Visibility.Visible;
- }
- }
- //付费锁
- if (!App.IsLogin)
- {
- dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- return false;
- }
- return true;
- }
- #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 方法
- /// <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;
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- }
- }
- }
- }
- }
- 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()
- {
- PDFViewer.UndoManager.Undo();
- }
- private void Redo()
- {
- PDFViewer.UndoManager.Redo();
- }
- private void LoadControl()
- {
- 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, "PageContent", parameters);
- region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
- //TODO 根据上一次关闭记录的菜单,选中TabItem
- EnterSelectedBar("TabItemAnnotation");
- //}
- //));
- }
- /// <summary>
- /// 各个注释(选中和创建注释)导航到对应注释的属性面板
- /// </summary>
- /// <param name="Content"></param>
- /// <param name="annotPropertyPanel"></param>
- public void SelectedPrpoertyPanel(string Content, AnnotTransfer annotPropertyPanel)
- {
- if (Content == "PropertyPanelContent")
- {
- IsPropertyOpen = false;
- }
- else
- {
- IsPropertyOpen = true;
- }
- 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;
- if (!CheckPassword())
- {
- return false;
- }
- PDFViewer.Load();
- PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
- PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
- //设置移动注释参考线
- ComPDFKitViewer.CommonDrawData.MovePen = new System.Windows.Media.Pen((System.Windows.Media.Brush)new BrushConverter().ConvertFromString("#1770F4"), 1);
- //还原上一次关闭前的视图设置
- GetOpenFileInfo();
- if (!string.IsNullOrEmpty(PassWord))
- {
- //加密文档解密后刷新底部工具栏页码总数
- NavigationParameters parameters = new NavigationParameters();
- parameters.Add(ParameterNames.PDFViewer, PDFViewer);
- parameters.Add(ParameterNames.ViewContentViewModel, this);
- region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
- }
- region.AddToRegion(ViwerRegionName, PDFViewer);
- if (App.mainWindowViewModel != null)
- {
- //更新CurrentPDFViewer对象
- App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
- }
- if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
- {
- App.OpenedFileList.Add(PDFViewer.Document.FilePath);
- }
- return true;
- }
- /// <summary>
- /// 处理密码相关的内容
- /// </summary>
- private bool CheckPassword()
- {
- if (passwordInfo != null && (!string.IsNullOrEmpty(passwordInfo.OpenPassword) || !string.IsNullOrEmpty(passwordInfo.PermissionsPassword)))
- {
- if (!string.IsNullOrEmpty(passwordInfo.OpenPassword))
- {
- PDFViewer.Document.UnlockWithPassword(passwordInfo.OpenPassword);
- }
- if (!string.IsNullOrEmpty(passwordInfo.PermissionsPassword) && passwordInfo.PermissionsPassword != passwordInfo.OpenPassword)
- {
- IsFileLocked = true;
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add(ParameterNames.ViewContentViewModel, this);
- ShowLeftTip(true);
- region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
- }
- }
- else
- {
- 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;
- }
- }
- 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) || mainViewModel.NewFile)
- return saveAsFile();
- //文档已被修复时 提示另存为
- if (PDFViewer.Document.HasRepaired)
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileRepairedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
- if (alertsMessage.result == ContentResult.Ok)
- return saveAsFile();
- else
- return false;
- }
- //文件路径无法存在时
- if (!File.Exists(PDFViewer.Document.FilePath))
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileNotExistWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_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("", App.MainPageLoader.GetString("Main_TheFileReadonlyWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_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 = string.Empty;
- string permissionsPassword = string.Empty;
- 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) && openPassword != permissionsPassword)
- {
- //PDFViewer.Document.CheckOwnerPassword(permissionsPassword);
- IsFileLocked = true;
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add(ParameterNames.ViewContentViewModel, this);
- ShowLeftTip(true);
- region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
- }
- 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
- {
- //弹窗前 激活主窗体
- App.Current.MainWindow.Activate();
- AlertsMessage alertsMessage = new AlertsMessage();
- //文件被占用 保存失败时
- alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
- if (alertsMessage.result == ContentResult.Ok)
- return saveAsFile();
- else
- return false;
- }
- return result;
- }
- catch { return false; }
- finally
- {
- if (!IsFileLocked)
- {
- 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;
- string openPassword = string.Empty;
- string permissionsPassword = string.Empty;
- CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
- if (SecurityInfo.NeedOpenPassword)
- {
- openPassword = SecurityInfo.OpenPassword;
- passwordInfo.OpenPassword = openPassword;
- }
- if (SecurityInfo.NeedPermissionsPassword)
- {
- permissionsPassword = SecurityInfo.PermissionsPassword;
- cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
- passwordInfo.PermissionsPassword = permissionsPassword;
- }
- PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
- result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
- if (result)
- {
- mainViewModel.NewFile = false;
- App.OpenedFileList.Remove(oldpath);
- DoAfterSaveAs(dlg.FileName);
- }
- else
- {
- //提示文件被其他软件占用 无法保存
- //
- //Ex.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>
- /// 转档、压缩、合并前自动保存
- /// </summary>
- public async Task<bool> SaveBeforeOption()
- {
- if (PDFViewer.UndoManager.CanSave)
- {
- string title = "Saving File";
- App.mainWindowViewModel.SetProcessValue(title, 80, 100, false);
- //让保存的效果更明显
- await Task.Delay(200);
- //合并前自动保存一次
- saveFile();
- App.mainWindowViewModel.SetProcessValue(title, 100, 100, false);
- }
- //方便其他调用的地方可以异步 await调用,增加显示保存过程的效果
- return true;
- }
- /// <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)
- {
- PDFViewer.UndoManager.CanSave = false;
- //从新路径重新加载
- //用mianviewmodel.openfile的方法会有其他模块的pdfview更新不过来的情况,需要调整成现有的方法
- PDFViewer.CloseDocument();
- PDFViewer.InitDocument(targetPath);
- //处理解密相关的逻辑 现在的逻辑另存为自动打开后会需要重新输入密码
- CheckPassword();
- PDFViewer.Load();
- //刷新最近文件列表
- OpenFileInfo isnew = SettingHelper.GetFileInfo(targetPath);
- if (isnew == null)
- {
- if (App.OpenedFileList.Contains(targetPath) == false)
- {
- App.OpenedFileList.Add(targetPath);
- }
- }
- //打开文件后,不管是新文件还是旧文件都需要更新排序
- SettingHelper.SortRecentOpenFiles(targetPath);
- //更新页签文件名
- mainViewModel.FilePath = PDFViewer.Document.FilePath;
- App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
- //刷新Bota 和底部工具栏的PDFviwer对象
- LoadControl();
- }
- /// <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 方法
- #region Navigate
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue(ParameterNames.PasswordInfo, out PasswordInfo);
- 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;
- //弹窗需要放到最后(确保在各字段赋值语句的后面),弹窗显示会触发控件的Loaded事件,会导致后续段没有赋值,而加载等事件继续往后跑了
- //例如这里的问题 会因为显示注册弹窗,导致其他模块没有接受到正常的PDFviewer对象
- App.mainWindowViewModel.OphVis = Visibility.Collapsed;
- if (Settings.Default.IsNewInViewContent == true && App.IsLogin == false)
- {
- App.mainWindowViewModel.OpenRegister();
- Settings.Default.IsNewInViewContent = false;
- Settings.Default.Save();
- }
- //需要在pdfview赋值后绑定
- GlobalCommands.FullWindowCommand.RegisterCommand(new DelegateCommand(() => { OpenFullWindow(); }));
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- if (navigationContext != null)
- {
- //另存为打开导航进来时 不能新建一个实例
- return true;
- }
- else
- {
- //一次性打开多个文件时,需要新建实例
- return false;
- }
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
- }
- #endregion Navigate
- }
- }
|