12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677 |
- 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;
- 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 PDF_Master.Views;
- using System.Windows.Documents;
- using ComPDFKit.PDFPage;
- using ComPDFKitViewer;
- using SplitMode = PDF_Master.EventAggregators.SplitMode;
- using System.Windows.Resources;
- using System.Windows.Media.Imaging;
- using ComPDFKit.PDFWatermark;
- using PDF_Master.ViewModels.PageEdit;
- using System.Windows.Annotations;
- using PDFReader_WPF.Helper;
- 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 string _T_EditPDF;
- public string T_EditPDF
- {
- get { return _T_EditPDF; }
- set
- {
- SetProperty(ref _T_EditPDF, 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_EditPDF = App.MainPageLoader.GetString("ViewTopToolbar_T_EditPDF");
- 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 属性、变量
- /// <summary>
- /// 显示 隐藏注释
- /// </summary>
- public bool IsHiddenAnnot = false;
- 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 BottomToolContentViewModel bottom { get; set; }
- public BOTAContentViewModel botaViewModel { get; set; }
- private CPDFWatermark watermark;
- 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);
- }
- }
- 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);
- }
- }
- private GridLength _ToolTooRow = new GridLength(40);
- public GridLength ToolTooRow
- {
- get { return _ToolTooRow; }
- set
- {
- SetProperty(ref _ToolTooRow, 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);
- }
- }
- ///// <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);
- }
- }
- /// <summary>
- /// 定义BOTA展开后的最小宽度,小于等于该宽度时无法再缩小宽度,再往左边拖动便是收起BOTA
- /// </summary>
- public double BOTAMiniWidth = 260;
- 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(BOTAMiniWidth);
- }
- Settings.Default.AppProperties.InitialVIew.RememberBOTA = openBOTA;
- //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
- }
- }
- /// <summary>
- /// 防止自动保存异步导致弹窗出现两次
- /// </summary>
- private bool _isPopupInProgress;
- public bool IsPopupInProgress
- {
- get { return _isPopupInProgress; }
- set { SetProperty(ref _isPopupInProgress, value); }
- }
- 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 double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000, 2000, 4000, 10000 };
- /// <summary>
- /// 注释-链接,提示语
- /// </summary>
- private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
- public Visibility LinkAnnotTipVisibility
- {
- get { return linkAnnotTipVisibility; }
- set
- {
- SetProperty(ref linkAnnotTipVisibility, value);
- }
- }
- private string linkAnnotTipText = "Turn to the target page, then click or box area on the page to select the target page where the link will jump.";
- private bool isCreateLink = false;
- internal bool IsRightMenuSelectedTextAddLink = false;
- internal bool IsSelectedTextAddLink = false;
- /// <summary>
- /// 上下左右滑动的距离
- /// </summary>
- private double scrolloffset = 50;
- public string LinkAnnotTipText
- {
- get { return linkAnnotTipText; }
- set
- {
- SetProperty(ref linkAnnotTipText, value);
- }
- }
- private bool botaState = false;
- private bool propertyOpenState = false;
- public bool _IsCrop = false;
- public bool IsCrop
- {
- get { return _IsCrop; }
- set
- {
- SetProperty(ref _IsCrop, 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 AITranslationCommand { get; set; }
- public DelegateCommand PrintCommand { get; set; }
- public DelegateCommand SelectCommand { get; set; }
- public DelegateCommand SettingsCommand { get; set; }
- public DelegateCommand AboutDialogCommmand { 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 RefreshCommand { get; set; }
- public DelegateCommand CreateFromFile { get; set; }
- public DelegateCommand ClosePropertyCommand { get; set; }
- public DelegateCommand<object> OpenPropertyCommand { get; set; }
- public DelegateCommand LostFoucsCommand { get; set; }
- /// <summary>
- /// 用于底部工具栏的部分Bug
- /// </summary>
- public DelegateCommand RealSizeCommand { get; set; }
- public DelegateCommand OpenFullCommand { get; set; }
- public DelegateCommand SinglePageCommand { get; set; }
- public DelegateCommand DoublePageCommand { get; set; }
- public DelegateCommand FirstPageCommand { get; set; }
- public DelegateCommand LastPageCommand { get; set; }
- public DelegateCommand UpCommand { get; set; }
- public DelegateCommand DownCommand { get; set; }
- public DelegateCommand RightCommand { get; set; }
- public DelegateCommand LeftCommand { get; set; }
- public DelegateCommand PrePageCommand { get; set; }
- public DelegateCommand NextPageCommmand { get; set; }
- public DelegateCommand PreViewCommand { get; set; }
- public DelegateCommand NextViewCommand { get; set; }
- public DelegateCommand ZoomInCommand { get; set; }
- public DelegateCommand ZoomOutCommand { get; set; }
- /// <summary>
- /// 是否显示视图面板
- /// </summary>
- public bool IsReadModeShow { get; internal set; } = false;
- #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);
- RefreshCommand = new DelegateCommand(Refresh);
- CreateFromFile = new DelegateCommand(createfromFile);
- OpenPropertyCommand = new DelegateCommand<object>(openProperty);
- AboutDialogCommmand = new DelegateCommand(about);
- ViwerRegionName = RegionNames.ViwerRegionName;
- SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
- BOTARegionName = RegionNames.BOTARegionName;
- PropertyRegionName = RegionNames.PropertyRegionName;
- BottomToolRegionName = RegionNames.BottomToolRegionName;
- ReadModeRegionName = RegionNames.ReadModeRegionName;
- MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
- AITranslationCommand = new DelegateCommand(ShowAITranslationDialog);
- PrintCommand = new DelegateCommand(ShowPrintDialog);
- SelectCommand = new DelegateCommand(SelectClick);
- SettingsCommand = new DelegateCommand(SettingsEvent);
- CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
- ClosePropertyCommand = new DelegateCommand(CloseProperty);
- //底部工具栏相关的命令 绑在这一层响应更快
- RealSizeCommand = new DelegateCommand(realsize);
- OpenFullCommand = new DelegateCommand(OpenFullWindow);
- FirstPageCommand = new DelegateCommand(firstpage);
- LastPageCommand = new DelegateCommand(lastpage);
- PreViewCommand = new DelegateCommand(preview);
- NextViewCommand = new DelegateCommand(nextview);
- PrePageCommand = new DelegateCommand(prepage);
- NextPageCommmand = new DelegateCommand(nextpage);
- ZoomInCommand = new DelegateCommand(zoomin);
- ZoomOutCommand = new DelegateCommand(zoomout);
- UpCommand = new DelegateCommand(up);
- DownCommand = new DelegateCommand(down);
- SinglePageCommand = new DelegateCommand(singlepage);
- DoublePageCommand = new DelegateCommand(doublepage);
- LeftCommand = new DelegateCommand(left);
- RightCommand = new DelegateCommand(right);
- //未显示时无法注册上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();
- }
- private void about()
- {
- dialogs.ShowDialog(DialogNames.AboutDialog);
- }
- private void doublepage()
- {
- bottom?.DoublePageCommand.Execute();
- }
- private void singlepage()
- {
- bottom?.SinglePageCommand.Execute();
- }
- private void down()
- {
- PDFViewer.ScrollToVerticalOffset(PDFViewer.GetVerticalOffset() + scrolloffset);
- }
- private void up()
- {
- PDFViewer.ScrollToVerticalOffset(PDFViewer.GetVerticalOffset() - scrolloffset);
- }
- /// <summary>
- /// 右键逻辑
- /// </summary>
- private void right()
- {
- //当延申宽度大于实际显示的宽度时,说明可以左右滚动,此时左右键不能进行翻页,而是左右滑动
- if (PDFViewer.GetExtendWidth() > PDFViewer.ActualWidth)
- {
- PDFViewer.ScrollToHorizontalOffset(PDFViewer.GetHorizontalOffset() + 50);
- }
- else
- {
- bottom?.NextPageCommand.Execute();
- }
- }
- /// <summary>
- /// 左键逻辑
- /// </summary>
- private void left()
- {
- //当延申宽度大于实际显示的宽度时,说明可以左右滚动,此时左右键不能进行翻页,而是左右滑动
- if (PDFViewer.GetExtendWidth() > PDFViewer.ActualWidth)
- {
- PDFViewer.ScrollToHorizontalOffset(PDFViewer.GetHorizontalOffset() - 50);
- }
- else
- {
- bottom?.PrePageCommand.Execute();
- }
- }
- private void zoomin()
- {
- bottom?.ZoomInCommand.Execute();
- }
- private void zoomout()
- {
- bottom?.ZoomOutCommand.Execute();
- }
- private void nextpage()
- {
- bottom?.NextPageCommand.Execute();
- }
- private void prepage()
- {
- bottom?.PrePageCommand.Execute();
- }
- private void nextview()
- {
- bottom?.NextViewCommnad.Execute();
- }
- private void preview()
- {
- bottom?.PreViewCommand.Execute();
- }
- private void lastpage()
- {
- bottom?.LastPageCommand.Execute();
- }
- private void firstpage()
- {
- bottom?.FirstPageCommand.Execute();
- }
- /// <summary>
- /// 底部工具栏的缩放至实际大小
- /// </summary>
- private void realsize()
- {
- bottom?.RealSizeCommand.Execute();
- }
- /// <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>
- /// <returns></returns>
- public bool CheckPermissionBeforeOption()
- {
- VerifyPasswordResult verifyResult = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, EnumPermissionsSet.StatusAllowsCopying, dialogs);
- if (verifyResult.IsDiscryptied)
- {
- if (verifyResult.Password != null)
- {
- PDFViewer.Document.CheckOwnerPassword(verifyResult.Password);
- }
- ShowLeftTip(false);
- return true;
- }
- else
- {
- return 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)
- {
- //未付费的用户不进行自动保存
- if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1)
- {
- return;
- }
- 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
- {
- await 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);
- }
- else
- {
- //因为文件被占用等情况,复制内嵌文档到新路径失败时,先打开项目内的文档
- string tempfile = Path.Combine(Environment.CurrentDirectory, "Resources\\GuidPDF\\Quick Start Guide.pdf");
- if (File.Exists(tempfile))
- {
- App.mainWindowViewModel.AddTabItem(tempfile);
- }
- }
- 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>
- /// 打开文件Translation
- /// </summary>
- public void OpenFile(string[] newfile)
- {
- if (App.OpenedFileList.Contains(newfile[0]))
- {
- App.mainWindowViewModel.SelectItem(newfile[0]);
- }
- else
- {
- App.mainWindowViewModel.AddTabItem(newfile[0]);
- }
- ToolMethod.SetFileThumbImg(newfile[0]);
- }
- /// <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("", App.MainPageLoader.GetString("NoPasswrod_Waring"), App.ServiceLoader.GetString("Text_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 async void share()
- {
- if (IsPopupInProgress)
- {
- return;
- }
- IsPopupInProgress=true;
- try
- {
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Share");
- //分享前自动保存
- if (!await SaveBeforeOption(true))
- {
- IsPopupInProgress = false;
- return;
- }
- IsPopupInProgress = false;
- var path = PDFViewer.Document.FilePath;
- string subject = "Share With" + " " + PDFViewer.Document.FileName;
- System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
- }
- catch
- {
- IsPopupInProgress = false;
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Share_NoOutLookWarning"), App.ServiceLoader.GetString("Text_ok"));
- }
- IsPopupInProgress = false;
- }
- private void SettingsEvent()
- {
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.ViewContentViewModel, this);
- AnnotToolContentViewModel annotToolContent = GetAnnotToolContentVM(); ;
- 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 AnnotToolContentViewModel GetAnnotToolContentVM()
- {
- 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;
- }
- }
- return annotToolContent;
- }
- 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 ShowAITranslationDialog()
- {
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_AITranslate");
- DialogParameters printValue = new DialogParameters();
- printValue.Add(ParameterNames.PDFViewer, PDFViewer);
- printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
- printValue.Add(ParameterNames.ViewContentViewModel, this);
- printValue.Add(ParameterNames.Unicode, unicode);
- dialogs.ShowDialog(DialogNames.DocumentaryTranslation, printValue, e => { });
- }
- public void ShowPrintDialog()
- {
- //保存并继续,使用了高级功能则弹窗权益弹窗
- if (!saveFile(true))
- {
- return;
- }
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Print");
- 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;
- }
- }
- public 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;
- //当退出页面编辑后
- //缩略图选中页面,要和当前显示的页面,一致
- if (PDFViewer != null)
- {
- //防止部分情况PDFViewer.CurrentIndex获取异常问题
- if (PDFViewer.Document.PageCount > 0)
- {
- events.GetEvent<PageEditSelectedItemEvent>().Publish(new PageEditSelectedItemEventArgs() { Unicode = unicode, SelectedItemIndex = PDFViewer.CurrentIndex, IsSingle = true });
- }
- }
- #region 方案一,比较耗时,需要遍历
- //bool isTabItemThumbnail = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemThumbnail");
- //if (isTabItemThumbnail)
- //{
- // Views.PageEdit.PageEditContent pageEditContent = null;
- // PageEditContentViewModel viewModel = GetPageEditContentVM(bOTAContentViewModel, out pageEditContent);
- // if (viewModel != null)
- // {
- // viewModel.ListSelectedIndex = PDFViewer.CurrentIndex;
- // pageEditContent.ListPageEdit.ScrollIntoView(pageEditContent.ListPageEdit.SelectedItem);
- // }
- //}
- #endregion 方案一,比较耗时,需要遍历
- break;
- case "TabItemScan":
- ToolsBarContentVisible = Visibility.Visible;
- OCRContentVisible = Visibility.Visible;
- break;
- case "TabItemEdit":
- TextEditToolContentVisible = Visibility.Visible;
- break;
- case "TabItemConvert":
- ToolsBarContentVisible = Visibility.Visible;
- //当退出页面编辑后
- //缩略图选中页面,要和当前显示的页面,一致
- if (PDFViewer != null)
- {
- events.GetEvent<PageEditSelectedItemEvent>().Publish(new PageEditSelectedItemEventArgs() { Unicode = unicode, SelectedItemIndex = PDFViewer.CurrentIndex, IsSingle = true });
- }
- 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)
- {
- SolidColorBrush brush = new SolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString("#18A0FB"));
- brush.Opacity = 0.2;
- PDFViewer.SetMouseMode(MouseModes.PDFEdit);
- CommonDrawData.PDFEditCoverBrush = brush;
- CommonDrawData.PDFEditCoverPen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1);
- PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
- PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
- //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 && args.AddedItems.Count > 0)
- {
- var item = args.AddedItems[0] as TabItem;
- CurrentBar = item.Name;
- TabControlSelectonDataTracking(item.Name);
- if (previousBar != CurrentBar)
- {
- if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
- {
- EnterPageEdit();
- }
- else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
- {
- EnterSelectedBar(CurrentBar);
- isInPageEdit = false;
- }
- previousBar = CurrentBar;
- }
- }
- }
- /// <summary>
- /// 选项卡切换事件埋点
- /// </summary>
- /// <param name="e"></param>
- private void TabControlSelectonDataTracking(string currentBar)
- {
- switch (currentBar) {
- case "TabItemAnnotation":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Annotation");
- break;
- case "TabItemEdit":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_EditPDF");
- break;
- case "TabItemPageEdit":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_PageEdit");
- break;
- case "TabItemConvert":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Converter");
- break;
- case "TabItemTool":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Tools");
- break;
- }
-
- }
- /// <summary>
- /// 进入页面编辑模式
- /// </summary>
- //工具栏添加功能应注意自处
- public void EnterPageEdit()
- {
- if (TabSelectedIndex != 2)
- {
- TabSelectedIndex = 2;
- }
- 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 旧版本
- //5.15
- //15722 【视图-阅读模式】退出阅读模式,页面应保持原来的视图结构
- botaState = OpenBOTA;
- propertyOpenState = IsPropertyOpen;
- //5.6注释
- //已调整左右侧边栏层级,暂时注释掉,修复展开BOTA,进入阅读模式再退出后,BOTA保持展开,但没有选中的问题
- //留意测试阶段是否会有问题,如果没问题,在上线前删除
- //OpenBOTA = false;
- this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = true });
- //模拟一次用户点击 关闭属性面板
- //如果直接设置属性可能因为偏好设置设置成手动的原因 无法生效
- FromClick = true;
- IsPropertyOpen = false;
- FromClick = false;
- AnnotToolContentViewModel annotToolContent = GetAnnotToolContentVM();
- if (annotToolContent != null)
- {
- annotToolContent.StrAnnotToolChecked = "";
- }
- 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);
- }
- }
- ///退出阅读模式 显示视图面板
- BottomToolContent bottomTool = null;
- BottomToolContentViewModel bottomToolVM = GetBottomToolContentVM(ref bottomTool);
- if (bottomToolVM != null)
- {
- bottomToolVM.IsShowViewModular = propertyOpenState;
- IsPropertyOpen = propertyOpenState;
- if (bottomToolVM.IsShowViewModular && bottomTool != null)
- {
- bottomToolVM.ShowViewModularCommand.Execute(true);
- }
- }
- //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 = propertyOpenState;
- // IsPropertyOpen = propertyOpenState;
- // }
- //}
- IsLoading = Visibility.Collapsed;
- //5.6注释
- //已调整左右侧边栏层级,暂时注释掉,修复展开BOTA,进入阅读模式再退出后,BOTA保持展开,但没有选中的问题
- //留意测试阶段是否会有问题,如果没问题,在上线前删除
- //5.15
- //15722 【视图-阅读模式】退出阅读模式,页面应保持原来的视图结构
- OpenBOTA = botaState;
- 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;
- }
- public BottomToolContentViewModel GetBottomToolContentVM(ref BottomToolContent bottomTool)
- {
- BottomToolContentViewModel viewModel = null;
- if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
- {
- var views = region.Regions[BottomToolRegionName].Views;
- var isHasView = views.FindFirst(q => q is BottomToolContent);
- if (isHasView is BottomToolContent bottomToolContent)
- {
- bottomTool = bottomToolContent;
- viewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
- }
- }
- return viewModel;
- }
- #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;
- //最小缩放倍数 0.01倍
- double minrate = 0.01;
- //最大缩放倍数 100倍
- double maxrate = 100;
- if (zoom <= minrate)
- {
- return minrate;
- }
- //最大缩放倍数 100倍
- if (zoom >= maxrate)
- {
- return maxrate;
- }
- 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))
- {
- //判断是不是不是注释工具下
- bool isunannotTool = true;
- //内容选择 退出
- 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);
- isunannotTool = false;
- }
- }
- else
- {
- //如果注释是在拖拉创建中 或者 选中 了图片 不退出阅读模式
- if (toolContentViewModel != null)
- {
- if (toolContentViewModel.IsCreateAnnot)
- {
- isunannotTool = false;
- toolContentViewModel.IsCreateAnnot = false;
- }
- if (toolContentViewModel.IsSelectImage)
- {
- isunannotTool = false;
- toolContentViewModel.IsSelectImage = false;
- }
- }
- }
- }
- }
- if (mainViewModel.IsBookMode == true && isunannotTool)
- {
- Off_ReadModel();
- }
- }
- 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();
- PDFViewer.DisableClearSelectAnnot(false);
- PDFViewer.ClearSelectAnnots();
- //使用编辑功能时Undo刷新缩略图
- if (PDFViewer.MouseMode == MouseModes.PDFEdit)
- {
- events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode));
- }
- }
- private void Redo()
- {
- PDFViewer.UndoManager.Redo();
- //使用编辑功能时Redo刷新缩略图
- if (PDFViewer.MouseMode == MouseModes.PDFEdit)
- {
- events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode));
- }
- }
- /// <summary>
- /// 加载阅读页必要组件,BOTA,底部工具栏等
- /// </summary>
- /// <param name="fromSaveAs"></param>
- private void LoadControl(bool fromSaveAs = false)
- {
- 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
- if (!fromSaveAs)
- {
- 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);
- ComPDFKitViewer.CommonDrawData.DrawAnnotGuidesLine = true;
- //还原上一次关闭前的视图设置
- GetOpenFileInfo();
- if (!string.IsNullOrEmpty(PassWord))
- {
- //加密文档解密后刷新底部工具栏页码总数
- NavigationParameters parameters = new NavigationParameters();
- parameters.Add(ParameterNames.PDFViewer, PDFViewer);
- parameters.Add(ParameterNames.ViewContentViewModel, this);
- region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
- //解密后,刷新侧边栏逻辑
- botaViewModel.OpenBOTA();
- }
- PDFViewer.SnapsToDevicePixels = true;
- PDFViewer.UseLayoutRounding = true;
- RenderOptions.SetBitmapScalingMode(PDFViewer, BitmapScalingMode.Fant);
- 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);
- }
- 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);
- }
- if (OpenFileInfo.LastPageIndex == 0 && PDFViewer.GetVerticalOffset() != 0)
- {
- PDFViewer.ScrollToVerticalOffset(0);
- }
- }
- 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(bool autosave = false)
- {
- try
- {
- //是否取消了水印保存步骤
- bool flg = false;
- //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
- if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && ((App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP == true||PDFViewer.UndoManager.PDFEditChanged==true))
- {
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.ViewContentViewModel, this);
- if (autosave)
- {
- value.Add(ParameterNames.Open, "Auto");
- }
- dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
- {
- if (dialogResult.Result == ButtonResult.OK)
- {
- flg = true;
- }
- else
- {
- flg = false;
- }
- });
- return flg;
- }
- if ((string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile) && !autosave)
- {
- 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;
- }
- //记录保存前的当前页
- int pageindex = PDFViewer.CurrentIndex;
- //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();
- //跳转到保存前的页面
- PDFViewer.GoToPage(pageindex);
- }
- catch
- {
- }
- if (!autosave)
- {
- 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();
- //跳转到保存前的页面
- PDFViewer.GoToPage(pageindex);
- System.IO.File.Delete(tempPath);
- }
- catch
- {
- return false;
- }
- }
- //自动裁剪保存
- List<int> cropPageList = new List<int>();
- for (int i = 0; i < PDFViewer.Document.PageCount; i++)
- {
- cropPageList.Clear();
- cropPageList.Add(i);
- CPDFPage cPDFPage = PDFViewer.Document.PageAtIndex(i);
- if (PDFViewer.IsCropMode(i) == true)
- {
- Rect rect = cPDFPage.GetCropBounds();
- PDFViewer?.CropPage(CPDFDisplayBox.CropBox, rect, cropPageList);
- }
- }
- bool result = PDFViewer.Document.WriteToLoadedPath();
- if (result)
- {
- if (!autosave)
- {
- PDFViewer.UndoManager.CanSave = false;
- }
- App.Current.Dispatcher.Invoke(() =>
- {
- //保存时更新缩略图
- OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
- try
- {
- if (info != null && !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);
- }
- });
- //编辑不要刷新,否则保存时会崩溃
- if (PDFViewer.GetPDFEditCreateType() == ComPDFKit.PDFPage.CPDFEditType.None)
- {
- PDFViewer.ReloadDocument();
- }
- //PDFViewer.ReloadDocument();
- }
- else
- {
- //弹窗前 激活主窗体
- //App.Current.MainWindow.Activate();
- AlertsMessage alertsMessage = new AlertsMessage();
- //文件被占用 保存失败时
- alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
- //显示当前窗体,防止窗口置底
- App.Current.MainWindow.Activate();
- 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, String IsFormSave = null)
- {
- //是否来自savefile方法
- if (IsFormSave == "FormSave")
- {
- 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))
- {
- //文件已经被打开
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
- }
- 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);
- Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
- StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
- if (resourceInfo != null)
- {
- using (Stream stream = resourceInfo.Stream)
- {
- BitmapFrame frame = null;
- int width = 0;
- int height = 0;
- BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
- if (decoder != null && decoder.Frames.Count > 0)
- {
- frame = decoder.Frames[0];
- }
- if (frame != null)
- {
- var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
- width = frame.PixelWidth;
- height = frame.PixelHeight;
- frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
- watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
- watermark.SetImage(ImageArray, width, height);
- watermark.SetScale(1);
- watermark.SetRotation(0);
- watermark.SetOpacity(255);
- watermark.SetFront(true);
- watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
- watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
- watermark.SetFullScreen(false);
- watermark.SetVertOffset(0);
- watermark.SetHorizOffset(0);
- watermark.SetHorizontalSpacing(0);
- watermark.SetVerticalSpacing(0);
- string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
- watermark.SetPages(setpages);
- watermark.UpdateWatermark();
- PDFViewer.Document.ReleasePages();
- PDFViewer.ReloadDocument();
- }
- }
- }
- result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
- if (result)
- {
- mainViewModel.NewFile = false;
- App.OpenedFileList.Remove(oldpath);
- DoAfterSaveAs(dlg.FileName);
- }
- else
- { //提示文件被其他软件占用 无法保存
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
- }
- }
- return result;
- }
- else
- return false;
- }
- else
- {
- bool flg = false;
- //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
- if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && ((App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP == true || PDFViewer.UndoManager.PDFEditChanged == true))
- {
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.ViewContentViewModel, this);
- value.Add(ParameterNames.Open, "saveAs");
- dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
- {
- if (dialogResult.Result == ButtonResult.OK)
- {
- flg = true;
- }
- else
- {
- flg = false;
- }
- });
- if (flg == false)
- {
- return false;
- }
- }
- 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))
- {
- //文件已经被占用
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
- }
- 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);
- //是否需要加水印
- if (flg == true)
- {
- Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
- StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
- if (resourceInfo != null)
- {
- using (Stream stream = resourceInfo.Stream)
- {
- BitmapFrame frame = null;
- int width = 0;
- int height = 0;
- BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
- if (decoder != null && decoder.Frames.Count > 0)
- {
- frame = decoder.Frames[0];
- }
- if (frame != null)
- {
- var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
- width = frame.PixelWidth;
- height = frame.PixelHeight;
- frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
- watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
- watermark.SetImage(ImageArray, width, height);
- watermark.SetScale(1);
- watermark.SetRotation(0);
- watermark.SetOpacity(255);
- watermark.SetFront(true);
- watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
- watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
- watermark.SetFullScreen(false);
- watermark.SetVertOffset(0);
- watermark.SetHorizOffset(0);
- watermark.SetHorizontalSpacing(0);
- watermark.SetVerticalSpacing(0);
- string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
- watermark.SetPages(setpages);
- watermark.UpdateWatermark();
- PDFViewer.Document.ReleasePages();
- PDFViewer.ReloadDocument();
- }
- }
- }
- }
- result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
- if (result)
- {
- mainViewModel.NewFile = false;
- App.OpenedFileList.Remove(oldpath);
- DoAfterSaveAs(dlg.FileName);
- }
- else
- {
- //文件已经被占用
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
- }
- }
- return result;
- }
- else
- return false;
- }
- }
- /// <summary>
- /// 转档、压缩、合并、分享前自动保存
- /// </summary>
- public async Task<bool> SaveBeforeOption(bool NoIAP=false)
- {
- if(NoIAP == false)
- { //添加付费拦截锁
- if (!ServiceHelper.IAPBeforeFunction())
- {
- return false;
- }
- }
- bool result = true;
- //因配合权益弹窗弹出,暂时移除可保存条件判断
- //if (PDFViewer.UndoManager.CanSave)
- {
- string title = "Saving File";
- App.mainWindowViewModel.SetProcessValue(title, 80, 100, false);
- //让保存的效果更明显
- await Task.Delay(200);
- //合并前自动保存一次
- result = saveFile(true);
- App.mainWindowViewModel.SetProcessValue(title, 100, 100, false);
- }
- //方便其他调用的地方可以异步 await调用,增加显示保存过程的效果
- return result;
- }
- /// <summary>
- /// 另存为Flatten
- /// </summary>
- private void saveAsFlatten()
- {
- //添加付费拦截锁
- if (!ServiceHelper.IAPBeforeFunction())
- {
- return;
- }
- bool flg = false;
- //权益弹窗
- //PDFViewer.UndoManager.PDFEditChanged为是否在编辑中对文档进行了改动
- if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && ((App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP == true || PDFViewer.UndoManager.PDFEditChanged == true))
- {
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.ViewContentViewModel, this);
- dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
- {
- if (dialogResult.Result == ButtonResult.OK)
- {
- flg = true;
- }
- else
- {
- flg = false;
- }
- });
- if (flg == false)
- {
- return ;
- }
- }
- var dlg = new SaveFileDialog();
- dlg.Filter = Properties.Resources.OpenDialogFilter;
- dlg.FileName = PDFViewer.Document.FileName + "_Flattened.pdf";
- if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
- {
- saveFile();
- CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FilePath);
- 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();
- //更新打开文件列表
- 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(true);
- }
- /// <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;
- }
- }
- /// <summary>
- /// 刷新账号信息
- /// </summary>
- public void Refresh()
- {
- ServiceHelper.GetUser();
- }
- #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对象
- Settings.Default.UserDate.CheckRegisterStatus();
- App.mainWindowViewModel.OphVis = Visibility.Collapsed;
- if (Settings.Default.UserDate.TodayRegister == false && App.IsLogin == false)
- {
- Settings.Default.UserDate.TodayRegister = true;
- DateTime currentTime = DateTime.Now;
- Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
- Settings.Default.Save();
- App.mainWindowViewModel.OpenRegister();
- }
- //需要在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;
- }
- internal void FindPageEditContent(out Views.PageEdit.PageEditContent pageEditContent)
- {
- pageEditContent = null;
- if (region.Regions.ContainsRegionWithName(ToolContentRegionName))
- {
- var views = region.Regions[ToolContentRegionName].Views;
- var model = views.FirstOrDefault(q => q is Views.PageEdit.PageEditContent);
- if (model is Views.PageEdit.PageEditContent page)
- {
- pageEditContent = page;
- }
- }
- }
- #endregion Navigate
- }
- }
|