ViewContentViewModel.cs 146 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744
  1. using Microsoft.Win32;
  2. using Prism.Commands;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. using ComPDFKitViewer.PdfViewer;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using PDF_Master.CustomControl;
  11. using PDF_Master.Model;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.IO;
  15. using ComPDFKitViewer.AnnotEvent;
  16. using PDF_Master.ViewModels.Tools;
  17. using Prism.Events;
  18. using PDF_Master.EventAggregators;
  19. using PDF_Master.Helper;
  20. using ComPDFKit.PDFDocument;
  21. using PDFSettings;
  22. using PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs;
  23. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
  24. using PDF_Master.Model.Dialog.ToolsDialogs;
  25. using DryIoc;
  26. using PDF_Master.Model.Dialog.ConverterDialogs;
  27. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  28. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  29. using System.Linq;
  30. using System.Text;
  31. using PDF_Master.Views.Tools;
  32. using System.Windows.Input;
  33. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  34. using ImTools;
  35. using PDF_Master.Properties;
  36. using PDF_Master.ViewModels.BOTA;
  37. using PDF_Master.Views.BOTA;
  38. using System.Drawing;
  39. using PDF_Master.ViewModels.Tools.AnnotManager;
  40. using PDF_Master.Model.FillAndSign;
  41. using PDF_Master.Views.PropertyPanel.ViewModular;
  42. using PDF_Master.Views.PropertyPanel;
  43. using System.Windows.Threading;
  44. using Dropbox.Api.Files;
  45. using System.Windows.Media;
  46. using Color = System.Windows.Media.Color;
  47. using PDF_Master.Views;
  48. using System.Windows.Documents;
  49. using ComPDFKit.PDFPage;
  50. using ComPDFKitViewer;
  51. using SplitMode = PDF_Master.EventAggregators.SplitMode;
  52. using System.Windows.Resources;
  53. using System.Windows.Media.Imaging;
  54. using ComPDFKit.PDFWatermark;
  55. using PDF_Master.ViewModels.PageEdit;
  56. using System.Windows.Annotations;
  57. using PDFReader_WPF.Helper;
  58. namespace PDF_Master.ViewModels
  59. {
  60. public class ViewContentViewModel : BindableBase, INavigationAware
  61. {
  62. #region 文案
  63. private string T_file;
  64. public string T_File
  65. {
  66. get { return T_file; }
  67. set
  68. {
  69. SetProperty(ref T_file, value);
  70. }
  71. }
  72. private string T_save;
  73. public string T_Save
  74. {
  75. get { return T_save; }
  76. set
  77. {
  78. SetProperty(ref T_save, value);
  79. }
  80. }
  81. private string T_undo;
  82. public string T_Undo
  83. {
  84. get { return T_undo; }
  85. set
  86. {
  87. SetProperty(ref T_undo, value);
  88. }
  89. }
  90. private string T_redo;
  91. public string T_Redo
  92. {
  93. get { return T_redo; }
  94. set
  95. {
  96. SetProperty(ref T_redo, value);
  97. }
  98. }
  99. private string T_annotation;
  100. public string T_Annotation
  101. {
  102. get { return T_annotation; }
  103. set
  104. {
  105. SetProperty(ref T_annotation, value);
  106. }
  107. }
  108. private string T_pageEdit;
  109. public string T_PageEdit
  110. {
  111. get { return T_pageEdit; }
  112. set
  113. {
  114. SetProperty(ref T_pageEdit, value);
  115. }
  116. }
  117. private string T_converter;
  118. public string T_Converter
  119. {
  120. get { return T_converter; }
  121. set
  122. {
  123. SetProperty(ref T_converter, value);
  124. }
  125. }
  126. private string T_fillSign;
  127. public string T_FillSign
  128. {
  129. get { return T_fillSign; }
  130. set
  131. {
  132. SetProperty(ref T_fillSign, value);
  133. }
  134. }
  135. private string T_tools;
  136. public string T_Tools
  137. {
  138. get { return T_tools; }
  139. set
  140. {
  141. SetProperty(ref T_tools, value);
  142. }
  143. }
  144. private string T_print;
  145. public string T_Print
  146. {
  147. get { return T_print; }
  148. set
  149. {
  150. SetProperty(ref T_print, value);
  151. }
  152. }
  153. private string T_share;
  154. public string T_Share
  155. {
  156. get { return T_share; }
  157. set
  158. {
  159. SetProperty(ref T_share, value);
  160. }
  161. }
  162. private string T_properties;
  163. public string T_Properties
  164. {
  165. get { return T_properties; }
  166. set
  167. {
  168. SetProperty(ref T_properties, value);
  169. }
  170. }
  171. private string _T_EditPDF;
  172. public string T_EditPDF
  173. {
  174. get { return _T_EditPDF; }
  175. set
  176. {
  177. SetProperty(ref _T_EditPDF, value);
  178. }
  179. }
  180. private void InitStirng()
  181. {
  182. T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
  183. T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
  184. T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
  185. T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
  186. T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
  187. T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
  188. T_EditPDF = App.MainPageLoader.GetString("ViewTopToolbar_T_EditPDF");
  189. T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
  190. T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
  191. T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
  192. T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
  193. T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
  194. T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
  195. }
  196. #endregion 文案
  197. #region 属性、变量
  198. /// <summary>
  199. /// 用于退出页面编辑 设置bota搜索框
  200. /// </summary>
  201. private SearchContent searchContent = null;
  202. /// <summary>
  203. /// 显示 隐藏注释
  204. /// </summary>
  205. public bool IsHiddenAnnot = false;
  206. public bool IsMultiSelected { get; set; } = false;
  207. public OpenFileInfo OpenFileInfo = null;
  208. public CPDFViewer PDFViewer { get; set; }
  209. public bool ReadModeIsShowProperty { get; set; } = false;
  210. public MainContentViewModel mainViewModel { get; set; }
  211. public BottomToolContentViewModel bottom { get; set; }
  212. public BOTAContentViewModel botaViewModel { get; set; }
  213. private CPDFWatermark watermark;
  214. public bool IsSettingOut = false;
  215. public IRegionManager region;
  216. public IDialogService dialogs;
  217. public IEventAggregator events;
  218. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  219. public string ViwerRegionName { get; set; }
  220. /// <summary>
  221. /// 分屏视图的region名称
  222. /// </summary>
  223. public string SplitViewerRegionName { get; set; }
  224. /// <summary>
  225. /// OCR视图名称
  226. /// </summary>
  227. public string OCRViewerRegionName { get; set; }
  228. public string BOTARegionName { get; set; }
  229. public string PropertyRegionName { get; set; }
  230. public string ToolContentRegionName { get; set; }
  231. public string ToolsBarContentRegionName { get; set; }
  232. /// <summary>
  233. /// 顶部提示的Content
  234. /// </summary>
  235. public string TipContentRegionName { get; set; }
  236. public string LeftTipContentRegionName { get; set; }
  237. //便签弹窗
  238. public string NotePopupRegionName { get; set; }
  239. public string ReadModeRegionName { get; set; }
  240. public string TextEditContentRegionName { get; set; }
  241. public string BackgroundContentRegionName { get; set; }
  242. public PasswordInfo PasswordInfo = new PasswordInfo();
  243. //若point不赋值或从列表中找不到point,系统会提供默认值为(0,0)的新point,所以改用Tuple<int,int>
  244. public List<FillAndSignIsShape> FillAndSign = new List<FillAndSignIsShape>();
  245. /// <summary>
  246. /// 签名列表
  247. /// </summary>
  248. public List<Tuple<int, int>> AnnotSignatures = new List<Tuple<int, int>>();
  249. /// <summary>
  250. /// 文档的密码
  251. /// </summary>
  252. public string PassWord { get; set; }
  253. public PasswordInfo passwordInfo = new PasswordInfo();
  254. private Visibility tipVisible = Visibility.Collapsed;
  255. /// <summary>
  256. /// 顶部提示栏的显示状态
  257. /// </summary>
  258. public bool IsFileLocked = false;
  259. public Visibility TipVisible
  260. {
  261. get { return tipVisible; }
  262. set
  263. {
  264. SetProperty(ref tipVisible, value);
  265. }
  266. }
  267. private Visibility leftTipVisible = Visibility.Collapsed;
  268. public Visibility LeftTipVisible
  269. {
  270. get { return leftTipVisible; }
  271. set
  272. {
  273. SetProperty(ref leftTipVisible, value);
  274. }
  275. }
  276. private Visibility notePopupVisible = Visibility.Collapsed;
  277. public Visibility NotePopupVisible
  278. {
  279. get { return notePopupVisible; }
  280. set
  281. {
  282. SetProperty(ref notePopupVisible, value);
  283. }
  284. }
  285. public bool IsNoteAdd = false;
  286. private double canvasNoteLeft;
  287. public double CanvasNoteLeft
  288. {
  289. get { return canvasNoteLeft; }
  290. set
  291. {
  292. SetProperty(ref canvasNoteLeft, value);
  293. }
  294. }
  295. private double canvasNoteBottom;
  296. public double CanvasNoteBottom
  297. {
  298. get { return canvasNoteBottom; }
  299. set
  300. {
  301. SetProperty(ref canvasNoteBottom, value);
  302. }
  303. }
  304. /// <summary>
  305. /// 底部工具栏 RegionName
  306. /// </summary>
  307. public string BottomToolRegionName { get; set; }
  308. private bool _isInPageEdit = false;
  309. /// <summary>
  310. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  311. /// </summary>
  312. public bool isInPageEdit
  313. {
  314. get { return _isInPageEdit; }
  315. set
  316. {
  317. SetProperty(ref _isInPageEdit, value);
  318. }
  319. }
  320. public Action PageEditUndo { get; set; }
  321. public Action PageEditRedo { get; set; }
  322. /// <summary>
  323. ///工具条
  324. ///0:收起
  325. ///40:显示
  326. /// </summary>
  327. private int toolRowHeight = 40;
  328. public int ToolRowHeight
  329. {
  330. get { return toolRowHeight; }
  331. set
  332. {
  333. SetProperty(ref toolRowHeight, value);
  334. }
  335. }
  336. private GridLength _ToolTooRow = new GridLength(40);
  337. public GridLength ToolTooRow
  338. {
  339. get { return _ToolTooRow; }
  340. set
  341. {
  342. SetProperty(ref _ToolTooRow, value);
  343. }
  344. }
  345. /// <summary>
  346. /// 水印,背景侧边栏宽度
  347. /// 0:收起
  348. /// 260:显示
  349. /// </summary>
  350. private int propertyColumnWidth = 0;
  351. public int PropertyColumnWidth
  352. {
  353. get { return propertyColumnWidth; }
  354. set
  355. {
  356. SetProperty(ref propertyColumnWidth, value);
  357. }
  358. }
  359. private int gridToolRow = 1;
  360. /// <summary>
  361. /// 控制ToolContent的Row
  362. /// </summary>
  363. public int GridToolRow
  364. {
  365. get { return gridToolRow; }
  366. set
  367. {
  368. SetProperty(ref gridToolRow, value);
  369. }
  370. }
  371. private int gridToolRowSpan = 3;
  372. /// <summary>
  373. /// 控制ToolContent的RowSpan
  374. /// </summary>
  375. public int GridToolRowSpan
  376. {
  377. get { return gridToolRowSpan; }
  378. set
  379. {
  380. SetProperty(ref gridToolRowSpan, value);
  381. }
  382. }
  383. private Visibility toolContentVisible = Visibility.Collapsed;
  384. /// <summary>
  385. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  386. /// 留意:显示前需要先注入内容、设置好行和跨行数
  387. /// </summary>
  388. public Visibility ToolContentVisible
  389. {
  390. get { return toolContentVisible; }
  391. set
  392. {
  393. SetProperty(ref toolContentVisible, value);
  394. }
  395. }
  396. private Visibility gridVisibility = Visibility.Visible;
  397. /// <summary>
  398. /// 是否正在加载中
  399. /// </summary>
  400. public Visibility GridVisibility
  401. {
  402. get { return gridVisibility; }
  403. set
  404. {
  405. SetProperty(ref gridVisibility, value);
  406. }
  407. }
  408. private Visibility isLoading = Visibility.Collapsed;
  409. private Visibility ocrContentVisible = Visibility.Collapsed;
  410. public Visibility OCRContentVisible
  411. {
  412. get { return ocrContentVisible; }
  413. set
  414. {
  415. SetProperty(ref ocrContentVisible, value);
  416. }
  417. }
  418. /// <summary>
  419. /// 是否正在加载中
  420. /// </summary>
  421. public Visibility IsLoading
  422. {
  423. get { return isLoading; }
  424. set
  425. {
  426. SetProperty(ref isLoading, value);
  427. }
  428. }
  429. ///// <summary>
  430. ///// 控制ToolsBarContent的显示
  431. ///// 留意:显示前需要先注入内容、设置好行和跨行数
  432. ///// </summary>
  433. //public Visibility ConverterBarContentVisible
  434. //{
  435. // get { return converterBarContentVisible; }
  436. // set
  437. // {
  438. // SetProperty(ref converterBarContentVisible, value);
  439. // }
  440. //}
  441. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  442. /// <summary>
  443. /// 控制ToolsBarContent的显示
  444. /// 留意:显示前需要先注入内容、设置好行和跨行数
  445. /// </summary>
  446. public Visibility ToolsBarContentVisible
  447. {
  448. get { return toolsBarContentVisible; }
  449. set
  450. {
  451. SetProperty(ref toolsBarContentVisible, value);
  452. }
  453. }
  454. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  455. /// <summary>
  456. /// 控制ToolsBarContent的显示
  457. /// 留意:显示前需要先注入内容、设置好行和跨行数
  458. /// </summary>
  459. public Visibility TextEditToolContentVisible
  460. {
  461. get { return textEditToolContentVisible; }
  462. set
  463. {
  464. SetProperty(ref textEditToolContentVisible, value);
  465. }
  466. }
  467. private bool isPorpertyOpen = false;
  468. /// <summary>
  469. /// 属性栏是否展开
  470. /// </summary>
  471. public bool IsPropertyOpen
  472. {
  473. get { return isPorpertyOpen; }
  474. set
  475. {
  476. //如果设置为手动展开属性面板时,则不响应代码控制的展开
  477. //或者手动点击按钮时 也展开
  478. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty || FromClick)
  479. {
  480. //阅读模式 不显示属性面板
  481. //if (mainViewModel.IsBookMode)
  482. //{
  483. // this.events.GetEvent<ReadModePropertyOpenEvent>().Publish(new ReadModePropertyOpenArgs() { Unicode = unicode });
  484. //}
  485. SetProperty(ref isPorpertyOpen, value);
  486. }
  487. }
  488. }
  489. /// <summary>
  490. /// 是否是点击属性面板按钮
  491. /// </summary>
  492. private bool FromClick = false;
  493. private Visibility isReadMode = Visibility.Visible;
  494. /// <summary>
  495. ///是否为阅读模式
  496. /// </summary>
  497. public Visibility IsReadMode
  498. {
  499. get { return isReadMode; }
  500. set
  501. {
  502. SetProperty(ref isReadMode, value);
  503. }
  504. }
  505. private bool canSave;
  506. /// <summary>
  507. /// 是否可以保存
  508. /// </summary>
  509. public bool CanSave
  510. {
  511. get { return canSave; }
  512. set
  513. {
  514. if (events != null && canSave == false)
  515. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = "Clear", AppUnicode = unicode });
  516. SetProperty(ref canSave, value);
  517. }
  518. }
  519. private bool canUndo;
  520. /// <summary>
  521. /// 是否可以进行Undo
  522. /// </summary>
  523. public bool CanUndo
  524. {
  525. get { return canUndo; }
  526. set
  527. {
  528. SetProperty(ref canUndo, value);
  529. }
  530. }
  531. private bool canRedo;
  532. /// <summary>
  533. /// 是否可以进行Redo
  534. /// </summary>
  535. public bool CanRedo
  536. {
  537. get { return canRedo; }
  538. set
  539. {
  540. SetProperty(ref canRedo, value);
  541. }
  542. }
  543. /// <summary>
  544. /// 定义BOTA展开后的最小宽度,小于等于该宽度时无法再缩小宽度,再往左边拖动便是收起BOTA
  545. /// </summary>
  546. public double BOTAMiniWidth = 260;
  547. private GridLength botaWidth = new GridLength(48);
  548. /// <summary>
  549. /// BOTA栏的宽度
  550. /// </summary>
  551. public GridLength BOTAWidth
  552. {
  553. get { return botaWidth; }
  554. set
  555. {
  556. SetProperty(ref botaWidth, value);
  557. if (botaWidth.Value <= 48)
  558. {
  559. OpenBOTA = false;
  560. }
  561. }
  562. }
  563. private int selectedIndex;
  564. /// <summary>
  565. /// 工具栏选中项的索引
  566. /// </summary>
  567. public int TabSelectedIndex
  568. {
  569. get { return selectedIndex; }
  570. set
  571. {
  572. SetProperty(ref selectedIndex, value);
  573. }
  574. }
  575. private bool openBOTA = false;
  576. /// <summary>
  577. /// 是否展开BOTA
  578. /// </summary>
  579. public bool OpenBOTA
  580. {
  581. get { return openBOTA; }
  582. set
  583. {
  584. SetProperty(ref openBOTA, value);
  585. if (openBOTA && BOTAWidth.Value <= 48)
  586. {
  587. BOTAWidth = new GridLength(BOTAMiniWidth);
  588. }
  589. Settings.Default.AppProperties.InitialVIew.RememberBOTA = openBOTA;
  590. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  591. }
  592. }
  593. /// <summary>
  594. /// 防止自动保存异步导致弹窗出现两次
  595. /// </summary>
  596. private bool _isPopupInProgress;
  597. public bool IsPopupInProgress
  598. {
  599. get { return _isPopupInProgress; }
  600. set { SetProperty(ref _isPopupInProgress, value); }
  601. }
  602. public SecurityInfo SecurityInfo = new SecurityInfo();
  603. private Dictionary<string, string> regionNameByTabItem;
  604. private Dictionary<string, string> barContentByTabItem;
  605. private string previousBar = "";
  606. public string CurrentBar = "";
  607. public string unicode = null;
  608. /// <summary>
  609. /// 自动保存的定时器
  610. /// </summary>
  611. private DispatcherTimer autoSaveTimer = new DispatcherTimer();
  612. /// <summary>
  613. /// 鼠标滚轮缩放的缩放值
  614. /// </summary>
  615. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000, 2000, 4000, 10000 };
  616. /// <summary>
  617. /// 注释-链接,提示语
  618. /// </summary>
  619. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  620. public Visibility LinkAnnotTipVisibility
  621. {
  622. get { return linkAnnotTipVisibility; }
  623. set
  624. {
  625. SetProperty(ref linkAnnotTipVisibility, value);
  626. }
  627. }
  628. 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.";
  629. private bool isCreateLink = false;
  630. internal bool IsRightMenuSelectedTextAddLink = false;
  631. internal bool IsSelectedTextAddLink = false;
  632. /// <summary>
  633. /// 上下左右滑动的距离
  634. /// </summary>
  635. private double scrolloffset = 50;
  636. public string LinkAnnotTipText
  637. {
  638. get { return linkAnnotTipText; }
  639. set
  640. {
  641. SetProperty(ref linkAnnotTipText, value);
  642. }
  643. }
  644. private bool botaState = false;
  645. private bool propertyOpenState = false;
  646. public bool _IsCrop = false;
  647. public bool IsCrop
  648. {
  649. get { return _IsCrop; }
  650. set
  651. {
  652. SetProperty(ref _IsCrop, value);
  653. }
  654. }
  655. #endregion 属性、变量
  656. #region 命令
  657. public DelegateCommand Load { get; set; }
  658. public DelegateCommand MouseDown { get; set; }
  659. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  660. public DelegateCommand SaveFile { get; set; }
  661. public DelegateCommand SaveAsFile { get; set; }
  662. public DelegateCommand SaveAsFlattenCommand { get; set; }
  663. public DelegateCommand UndoCommand { get; set; }
  664. public DelegateCommand RedoCommand { get; set; }
  665. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  666. public DelegateCommand AITranslationCommand { get; set; }
  667. public DelegateCommand PrintCommand { get; set; }
  668. public DelegateCommand SelectCommand { get; set; }
  669. public DelegateCommand SettingsCommand { get; set; }
  670. public DelegateCommand AboutDialogCommmand { get; set; }
  671. public DelegateCommand ShareCommand { get; set; }
  672. public DelegateCommand<object> CreateLinkCommand { get; set; }
  673. public DelegateCommand PropertyCommand { get; set; }
  674. public DelegateCommand ShowInFolderCommand { get; set; }
  675. public DelegateCommand CompressCommand { get; set; }
  676. public DelegateCommand MergeFileCommand { get; set; }
  677. public DelegateCommand EncryptCommand { get; set; }
  678. public DelegateCommand DecryptCommand { get; set; }
  679. public DelegateCommand<string> ConvertCommand { get; set; }
  680. public DelegateCommand CloseWindowCommand { get; set; }
  681. public DelegateCommand OpenFileCommand { get; set; }
  682. public DelegateCommand<string> HelpCommand { get; set; }
  683. public DelegateCommand CreateBlankFileCommand { get; set; }
  684. public DelegateCommand RefreshCommand { get; set; }
  685. public DelegateCommand CreateFromFile { get; set; }
  686. public DelegateCommand ClosePropertyCommand { get; set; }
  687. public DelegateCommand<object> OpenPropertyCommand { get; set; }
  688. public DelegateCommand LostFoucsCommand { get; set; }
  689. /// <summary>
  690. /// 用于底部工具栏的部分Bug
  691. /// </summary>
  692. public DelegateCommand RealSizeCommand { get; set; }
  693. public DelegateCommand OpenFullCommand { get; set; }
  694. public DelegateCommand SinglePageCommand { get; set; }
  695. public DelegateCommand DoublePageCommand { get; set; }
  696. public DelegateCommand FirstPageCommand { get; set; }
  697. public DelegateCommand LastPageCommand { get; set; }
  698. public DelegateCommand UpCommand { get; set; }
  699. public DelegateCommand DownCommand { get; set; }
  700. public DelegateCommand RightCommand { get; set; }
  701. public DelegateCommand LeftCommand { get; set; }
  702. public DelegateCommand PrePageCommand { get; set; }
  703. public DelegateCommand NextPageCommmand { get; set; }
  704. public DelegateCommand PreViewCommand { get; set; }
  705. public DelegateCommand NextViewCommand { get; set; }
  706. public DelegateCommand ZoomInCommand { get; set; }
  707. public DelegateCommand ZoomOutCommand { get; set; }
  708. /// <summary>
  709. /// 是否显示视图面板
  710. /// </summary>
  711. public bool IsReadModeShow { get; internal set; } = false;
  712. #endregion 命令
  713. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  714. {
  715. InitStirng();
  716. region = regionManager;
  717. dialogs = dialogService;
  718. events = eventAggregator;
  719. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  720. Load = new DelegateCommand(() => { LoadControl(); });
  721. MouseDown = new DelegateCommand(MouseDownEvent);
  722. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  723. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  724. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  725. UndoCommand = new DelegateCommand(Undo);
  726. RedoCommand = new DelegateCommand(Redo);
  727. ShareCommand = new DelegateCommand(share);
  728. PropertyCommand = new DelegateCommand(property);
  729. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  730. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  731. CompressCommand = new DelegateCommand(compress);
  732. MergeFileCommand = new DelegateCommand(mergeFile);
  733. EncryptCommand = new DelegateCommand(encrypt);
  734. DecryptCommand = new DelegateCommand(decrypt);
  735. ConvertCommand = new DelegateCommand<string>(convert);
  736. CloseWindowCommand = new DelegateCommand(closeWindow);
  737. OpenFileCommand = new DelegateCommand(openfile);
  738. HelpCommand = new DelegateCommand<string>(help);
  739. CreateBlankFileCommand = new DelegateCommand(createBlankFile);
  740. RefreshCommand = new DelegateCommand(Refresh);
  741. CreateFromFile = new DelegateCommand(createfromFile);
  742. OpenPropertyCommand = new DelegateCommand<object>(openProperty);
  743. AboutDialogCommmand = new DelegateCommand(about);
  744. ViwerRegionName = RegionNames.ViwerRegionName;
  745. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  746. BOTARegionName = RegionNames.BOTARegionName;
  747. PropertyRegionName = RegionNames.PropertyRegionName;
  748. BottomToolRegionName = RegionNames.BottomToolRegionName;
  749. ReadModeRegionName = RegionNames.ReadModeRegionName;
  750. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  751. AITranslationCommand = new DelegateCommand(ShowAITranslationDialog);
  752. PrintCommand = new DelegateCommand(ShowPrintDialog);
  753. SelectCommand = new DelegateCommand(SelectClick);
  754. SettingsCommand = new DelegateCommand(SettingsEvent);
  755. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  756. ClosePropertyCommand = new DelegateCommand(CloseProperty);
  757. //底部工具栏相关的命令 绑在这一层响应更快
  758. RealSizeCommand = new DelegateCommand(realsize);
  759. OpenFullCommand = new DelegateCommand(OpenFullWindow);
  760. FirstPageCommand = new DelegateCommand(firstpage);
  761. LastPageCommand = new DelegateCommand(lastpage);
  762. PreViewCommand = new DelegateCommand(preview);
  763. NextViewCommand = new DelegateCommand(nextview);
  764. PrePageCommand = new DelegateCommand(prepage);
  765. NextPageCommmand = new DelegateCommand(nextpage);
  766. ZoomInCommand = new DelegateCommand(zoomin);
  767. ZoomOutCommand = new DelegateCommand(zoomout);
  768. UpCommand = new DelegateCommand(up);
  769. DownCommand = new DelegateCommand(down);
  770. SinglePageCommand = new DelegateCommand(singlepage);
  771. DoublePageCommand = new DelegateCommand(doublepage);
  772. LeftCommand = new DelegateCommand(left);
  773. RightCommand = new DelegateCommand(right);
  774. //未显示时无法注册上Region名称
  775. ToolContentVisible = Visibility.Visible;
  776. ToolsBarContentVisible = Visibility.Visible;
  777. OCRContentVisible = Visibility.Visible;
  778. TipVisible = Visibility.Visible;
  779. TipContentRegionName = RegionNames.TipContentRegionName;
  780. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  781. NotePopupRegionName = RegionNames.NotePopupRegionName;
  782. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  783. ToolContentRegionName = Guid.NewGuid().ToString();
  784. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  785. TextEditContentRegionName = Guid.NewGuid().ToString();
  786. ToolContentVisible = Visibility.Collapsed;
  787. ToolsBarContentVisible = Visibility.Collapsed;
  788. OCRContentVisible = Visibility.Collapsed;
  789. TipVisible = Visibility.Collapsed;
  790. regionNameByTabItem = new Dictionary<string, string>();
  791. barContentByTabItem = new Dictionary<string, string>();
  792. InitialregionNameByTabItem(ref regionNameByTabItem);
  793. InitialbarContentByTabItem(ref barContentByTabItem);
  794. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  795. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  796. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTipAsync, e => e.Unicode == unicode);
  797. //TODO:根据缓存 选择用户上次选择的菜单
  798. CurrentBar = "TabItemAnnotation";
  799. EnterSelectedBar("TabItemAnnotation");
  800. StartAutoSave();
  801. }
  802. private void about()
  803. {
  804. dialogs.ShowDialog(DialogNames.AboutDialog);
  805. }
  806. private void doublepage()
  807. {
  808. bottom?.DoublePageCommand.Execute();
  809. }
  810. private void singlepage()
  811. {
  812. bottom?.SinglePageCommand.Execute();
  813. }
  814. private void down()
  815. {
  816. PDFViewer.ScrollToVerticalOffset(PDFViewer.GetVerticalOffset() + scrolloffset);
  817. }
  818. private void up()
  819. {
  820. PDFViewer.ScrollToVerticalOffset(PDFViewer.GetVerticalOffset() - scrolloffset);
  821. }
  822. /// <summary>
  823. /// 右键逻辑
  824. /// </summary>
  825. private void right()
  826. {
  827. //当延申宽度大于实际显示的宽度时,说明可以左右滚动,此时左右键不能进行翻页,而是左右滑动
  828. if (PDFViewer.GetExtendWidth() > PDFViewer.ActualWidth)
  829. {
  830. PDFViewer.ScrollToHorizontalOffset(PDFViewer.GetHorizontalOffset() + 50);
  831. }
  832. else
  833. {
  834. bottom?.NextPageCommand.Execute();
  835. }
  836. }
  837. /// <summary>
  838. /// 左键逻辑
  839. /// </summary>
  840. private void left()
  841. {
  842. //当延申宽度大于实际显示的宽度时,说明可以左右滚动,此时左右键不能进行翻页,而是左右滑动
  843. if (PDFViewer.GetExtendWidth() > PDFViewer.ActualWidth)
  844. {
  845. PDFViewer.ScrollToHorizontalOffset(PDFViewer.GetHorizontalOffset() - 50);
  846. }
  847. else
  848. {
  849. bottom?.PrePageCommand.Execute();
  850. }
  851. }
  852. private void zoomin()
  853. {
  854. bottom?.ZoomInCommand.Execute();
  855. }
  856. private void zoomout()
  857. {
  858. bottom?.ZoomOutCommand.Execute();
  859. }
  860. private void nextpage()
  861. {
  862. bottom?.NextPageCommand.Execute();
  863. }
  864. private void prepage()
  865. {
  866. bottom?.PrePageCommand.Execute();
  867. }
  868. private void nextview()
  869. {
  870. bottom?.NextViewCommnad.Execute();
  871. }
  872. private void preview()
  873. {
  874. bottom?.PreViewCommand.Execute();
  875. }
  876. private void lastpage()
  877. {
  878. bottom?.LastPageCommand.Execute();
  879. }
  880. private void firstpage()
  881. {
  882. bottom?.FirstPageCommand.Execute();
  883. }
  884. /// <summary>
  885. /// 底部工具栏的缩放至实际大小
  886. /// </summary>
  887. private void realsize()
  888. {
  889. bottom?.RealSizeCommand.Execute();
  890. }
  891. /// <summary>
  892. /// 进入全屏模式
  893. /// </summary>
  894. private void OpenFullWindow()
  895. {
  896. DialogParameters parameters = new DialogParameters();
  897. //因为全屏模式可能需要设置特定的页面模式,所以只传文件路径,新建一个PDFview对象
  898. parameters.Add(ParameterNames.FilePath, PDFViewer.Document.FilePath);
  899. parameters.Add(ParameterNames.PassWord, PDFViewer.Tag == null ? "" : PDFViewer.Tag.ToString());
  900. dialogs.ShowDialog(DialogNames.FullScreenDialog, parameters, e =>
  901. {
  902. if (e.Result == ButtonResult.Cancel)
  903. {
  904. //TODO:弹窗提示打开全屏模式失败
  905. AlertsMessage alertsMessage = new AlertsMessage();
  906. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("OperationFailWarning"), App.ServiceLoader.GetString("Text_ok"));
  907. return;
  908. }
  909. });
  910. }
  911. /// <summary>
  912. /// 点击展开折叠属性面板
  913. /// </summary>
  914. /// <param name="obj"></param>
  915. private void openProperty(object obj)
  916. {
  917. FromClick = true;
  918. IsPropertyOpen = (bool)obj;
  919. FromClick = false;
  920. }
  921. /// <summary>
  922. /// 复制、剪切操作前校验是否有文档操作权限,没有则弹出权限解密弹窗
  923. /// </summary>
  924. /// <returns></returns>
  925. public bool CheckPermissionBeforeOption()
  926. {
  927. VerifyPasswordResult verifyResult = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, EnumPermissionsSet.StatusAllowsCopying, dialogs);
  928. if (verifyResult.IsDiscryptied)
  929. {
  930. if (verifyResult.Password != null)
  931. {
  932. PDFViewer.Document.CheckOwnerPassword(verifyResult.Password);
  933. }
  934. ShowLeftTip(false);
  935. return true;
  936. }
  937. else
  938. {
  939. return false;
  940. }
  941. }
  942. /// <summary>
  943. /// 开始自动保存
  944. /// </summary>
  945. public void StartAutoSave()
  946. {
  947. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  948. if (autoSave)
  949. {
  950. var interval = Settings.Default.AppProperties.Description.AutoSaveInterval;
  951. if (autoSaveTimer == null)
  952. {
  953. autoSaveTimer = new DispatcherTimer();
  954. }
  955. autoSaveTimer.Stop();
  956. autoSaveTimer.Interval = TimeSpan.FromMinutes(interval);
  957. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  958. autoSaveTimer.Tick += AutoSaveTimer_Tick;
  959. autoSaveTimer.Start();
  960. }
  961. }
  962. /// <summary>
  963. /// 释放定时器
  964. /// 不释放定时器可能会一直运行并占用内存,导致内存泄露
  965. /// </summary>
  966. public void CloseAutoSave()
  967. {
  968. if (autoSaveTimer != null)
  969. {
  970. autoSaveTimer.Stop();
  971. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  972. autoSaveTimer = null;
  973. }
  974. }
  975. private void AutoSaveTimer_Tick(object sender, EventArgs e)
  976. {
  977. //未付费的用户不进行自动保存
  978. if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1)
  979. {
  980. return;
  981. }
  982. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  983. if (autoSave && !mainViewModel.NewFile && PDFViewer.UndoManager.CanSave)
  984. {
  985. //自动保存仅针对已经有文件路径的文档
  986. saveFile();
  987. }
  988. }
  989. private void MouseDownEvent()
  990. {
  991. if (NotePopupVisible == Visibility.Visible && IsNoteAdd == false)
  992. {
  993. NotePopupVisible = Visibility.Collapsed;
  994. if (region.Regions.ContainsRegionWithName(NotePopupRegionName))
  995. {
  996. var views = region.Regions[NotePopupRegionName].Views;
  997. foreach (var item in views)
  998. {
  999. if (item is StickyNotePopup sticky)
  1000. {
  1001. var contentRegion = region.Regions[NotePopupRegionName];
  1002. contentRegion.Remove(sticky);
  1003. break;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. }
  1009. private async void createfromFile()
  1010. {
  1011. string txt = Properties.Resources.txtex;
  1012. string word = Properties.Resources.wordex;
  1013. string ppt = Properties.Resources.pptex;
  1014. string excel = Properties.Resources.excelex;
  1015. string html = Properties.Resources.htmlex;
  1016. string image = Properties.Resources.imageex;
  1017. string allfiles = txt + word + excel + ppt + image + html;
  1018. OpenFileDialog dialog = new OpenFileDialog();
  1019. dialog.Multiselect = true;
  1020. dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
  1021. $"Microsoft Office Word({word})|{word}|" +
  1022. $"Microsoft Office Excel({excel})|{excel}|" +
  1023. $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
  1024. $"Txt({txt})|{txt}|" +
  1025. $"Picture({image})|{image}|" +
  1026. $"Html({html})|{html}");
  1027. if ((bool)dialog.ShowDialog())
  1028. {
  1029. for (int i = 0; i < dialog.FileNames.Length; i++)
  1030. {
  1031. if (App.OpenedFileList.Contains(dialog.FileNames[i]))
  1032. {
  1033. App.mainWindowViewModel.SelectItem(dialog.FileNames[i]);
  1034. }
  1035. else
  1036. {
  1037. await System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1038. {
  1039. App.mainWindowViewModel.AddTabItem(dialog.FileNames[i]);
  1040. }));
  1041. await Task.Delay(20);
  1042. ToolMethod.SetFileThumbImg(dialog.FileNames[i]);
  1043. }
  1044. }
  1045. }
  1046. }
  1047. /// <summary>
  1048. ///创建空白文档
  1049. /// </summary>
  1050. private async void createBlankFile()
  1051. {
  1052. App.mainWindowViewModel.AddTab.Execute();
  1053. await Task.Delay(30);
  1054. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
  1055. }
  1056. private void help(string args)
  1057. {
  1058. string url = "";
  1059. switch (args)
  1060. {
  1061. case "Guid":
  1062. //打开内嵌文档
  1063. if (App.OpenedFileList.Contains(App.GuidPDFPath))
  1064. {
  1065. //如果已经打开时,则选中内嵌文档
  1066. App.mainWindowViewModel.SelectItem(App.GuidPDFPath);
  1067. return;
  1068. }
  1069. if (File.Exists(App.GuidPDFPath))
  1070. {
  1071. App.mainWindowViewModel.AddTabItem(App.GuidPDFPath);
  1072. }
  1073. else
  1074. {
  1075. //因为文件被占用等情况,复制内嵌文档到新路径失败时,先打开项目内的文档
  1076. string tempfile = Path.Combine(Environment.CurrentDirectory, "Resources\\GuidPDF\\Quick Start Guide.pdf");
  1077. if (File.Exists(tempfile))
  1078. {
  1079. App.mainWindowViewModel.AddTabItem(tempfile);
  1080. }
  1081. }
  1082. break;
  1083. case "Online":
  1084. url = @"https://www.pdfreaderpro.com/windows/help";
  1085. break;
  1086. case "More":
  1087. url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
  1088. break;
  1089. case "Template":
  1090. url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
  1091. break;
  1092. case "Blog":
  1093. //TODO:显示订阅电子报弹窗
  1094. break;
  1095. case "ComPDF":
  1096. url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
  1097. break;
  1098. case "FeedBack":
  1099. //调用邮箱 发送邮件
  1100. StringBuilder sr = new StringBuilder();
  1101. sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
  1102. System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
  1103. break;
  1104. default:
  1105. break;
  1106. }
  1107. if (!string.IsNullOrEmpty(url))
  1108. {
  1109. //需要跳转网页的情况
  1110. System.Diagnostics.Process.Start(url);
  1111. }
  1112. }
  1113. /// <summary>
  1114. /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
  1115. /// </summary>
  1116. private void openfile()
  1117. {
  1118. OpenFileDialog openFileDialog = new OpenFileDialog();
  1119. openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
  1120. openFileDialog.Multiselect = true;
  1121. if ((bool)openFileDialog.ShowDialog())
  1122. {
  1123. if (openFileDialog.FileNames.Count() == 1)
  1124. {
  1125. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  1126. {
  1127. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  1128. }
  1129. else
  1130. {
  1131. App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
  1132. }
  1133. ToolMethod.SetFileThumbImg(openFileDialog.FileName);
  1134. }
  1135. else
  1136. {
  1137. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  1138. if (fileList.Count <= 0)
  1139. {
  1140. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  1141. return;
  1142. }
  1143. mainViewModel.OpenFile(fileList[0]);
  1144. for (int i = 1; i < fileList.Count(); i++)
  1145. {
  1146. if (!App.OpenedFileList.Contains(fileList[i]))
  1147. {
  1148. App.mainWindowViewModel.AddTabItem(fileList[i]);
  1149. }
  1150. ToolMethod.SetFileThumbImg(fileList[i]);
  1151. }
  1152. }
  1153. }
  1154. }
  1155. /// <summary>
  1156. /// 打开文件Translation
  1157. /// </summary>
  1158. public void OpenFile(string[] newfile)
  1159. {
  1160. if (App.OpenedFileList.Contains(newfile[0]))
  1161. {
  1162. App.mainWindowViewModel.SelectItem(newfile[0]);
  1163. }
  1164. else
  1165. {
  1166. App.mainWindowViewModel.AddTabItem(newfile[0]);
  1167. }
  1168. ToolMethod.SetFileThumbImg(newfile[0]);
  1169. }
  1170. /// <summary>
  1171. /// 关闭当前窗体
  1172. /// </summary>
  1173. private void closeWindow()
  1174. {
  1175. App.Current.MainWindow.Close();
  1176. }
  1177. /// <summary>
  1178. /// 转档
  1179. /// </summary>
  1180. /// <param name="obj"></param>
  1181. private void convert(string obj)
  1182. {
  1183. if (!string.IsNullOrEmpty(obj))
  1184. {
  1185. DialogParameters value = new DialogParameters();
  1186. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1187. switch (obj)
  1188. {
  1189. case "Word":
  1190. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  1191. {
  1192. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1193. converterDialogsModel.OnOpened((DialogResult)e);
  1194. });
  1195. break;
  1196. case "Excel":
  1197. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  1198. {
  1199. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1200. converterDialogsModel.OnOpened((DialogResult)e);
  1201. });
  1202. break;
  1203. case "PPT":
  1204. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  1205. {
  1206. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1207. converterDialogsModel.OnOpened((DialogResult)e);
  1208. });
  1209. break;
  1210. case "RTF":
  1211. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  1212. {
  1213. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1214. converterDialogsModel.OnOpened((DialogResult)e);
  1215. });
  1216. break;
  1217. case "CSV":
  1218. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  1219. {
  1220. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1221. converterDialogsModel.OnOpened((DialogResult)e);
  1222. });
  1223. break;
  1224. case "HTML":
  1225. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  1226. {
  1227. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1228. converterDialogsModel.OnOpened((DialogResult)e);
  1229. });
  1230. break;
  1231. case "Text":
  1232. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  1233. {
  1234. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1235. converterDialogsModel.OnOpened((DialogResult)e);
  1236. });
  1237. break;
  1238. case "Image":
  1239. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  1240. {
  1241. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1242. converterDialogsModel.OnOpened((DialogResult)e);
  1243. });
  1244. break;
  1245. default:
  1246. break;
  1247. }
  1248. }
  1249. }
  1250. /// <summary>
  1251. /// 解密
  1252. /// </summary>
  1253. private void decrypt()
  1254. {
  1255. ///无可用安全性设置的原因:
  1256. ///文件本身无安全性设置,且没有设置过密码
  1257. ///文件安全性已经被重置
  1258. ///
  1259. if ((!PDFViewer.Document.IsEncrypted && !SecurityInfo.IsPasswordChanged) || (SecurityInfo.IsPasswordRemoved))
  1260. {
  1261. AlertsMessage alertsMessage = new AlertsMessage();
  1262. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("NoPasswrod_Waring"), App.ServiceLoader.GetString("Text_ok"));
  1263. }
  1264. else
  1265. {
  1266. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1267. if (result.IsDiscryptied)
  1268. {
  1269. if (result.Password != null)
  1270. {
  1271. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1272. }
  1273. ShowLeftTip(false);
  1274. DialogParameters value = new DialogParameters();
  1275. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1276. value.Add(ParameterNames.ViewContentViewModel, this);
  1277. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e =>
  1278. {
  1279. if (e.Result == ButtonResult.OK)
  1280. {
  1281. if (SecurityInfo.IsPasswordRemoved)
  1282. {
  1283. PDFViewer.UndoManager.CanSave = true;
  1284. }
  1285. ShowLeftTip(false);
  1286. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1287. }
  1288. });
  1289. }
  1290. }
  1291. }
  1292. /// <summary>
  1293. /// 加密
  1294. /// </summary>
  1295. private void encrypt()
  1296. {
  1297. if (!this.SecurityInfo.IsPasswordChanged)
  1298. {
  1299. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1300. if (result.IsDiscryptied)
  1301. {
  1302. if (result.Password != null)
  1303. {
  1304. if (PDFViewer.Document.UnlockWithPassword(result.Password))
  1305. {
  1306. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1307. }
  1308. }
  1309. }
  1310. }
  1311. DialogParameters value = new DialogParameters();
  1312. value.Add(ParameterNames.PDFViewer, this.PDFViewer);
  1313. value.Add(ParameterNames.ViewContentViewModel, this);
  1314. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
  1315. {
  1316. if (e.Result == ButtonResult.OK)
  1317. {
  1318. SecurityHelper.IsPasswordChanged = true;
  1319. if (this.SecurityInfo.IsPasswordChanged)
  1320. {
  1321. this.PDFViewer.UndoManager.CanSave = true;
  1322. }
  1323. this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
  1324. }
  1325. });
  1326. }
  1327. /// <summary>
  1328. /// 合并
  1329. /// </summary>
  1330. private void mergeFile()
  1331. {
  1332. DialogParameters value = new DialogParameters();
  1333. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1334. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  1335. }
  1336. /// <summary>
  1337. /// 压缩
  1338. /// </summary>
  1339. private void compress()
  1340. {
  1341. DialogParameters value = new DialogParameters();
  1342. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1343. dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
  1344. {
  1345. CompressDialogModel compressDialogModel = new CompressDialogModel();
  1346. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  1347. });
  1348. }
  1349. /// <summary>
  1350. /// 设置Tip状态栏的显示状态
  1351. /// </summary>
  1352. /// <param name="show">是否显示</param>
  1353. public void ShowTip(bool show)
  1354. {
  1355. if (show)
  1356. {
  1357. TipVisible = Visibility.Visible;
  1358. }
  1359. else
  1360. {
  1361. TipVisible = Visibility.Collapsed;
  1362. }
  1363. }
  1364. /// <summary>
  1365. /// 设置LeftTip状态栏的显示状态
  1366. /// </summary>
  1367. /// <param name="show">是否显示</param>
  1368. public void ShowLeftTip(bool show)
  1369. {
  1370. if (show)
  1371. {
  1372. LeftTipVisible = Visibility.Visible;
  1373. }
  1374. else
  1375. {
  1376. LeftTipVisible = Visibility.Collapsed;
  1377. }
  1378. }
  1379. public void CheckHaveAllPermission()
  1380. {
  1381. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  1382. {
  1383. ShowLeftTip(true);
  1384. NavigationParameters param = new NavigationParameters();
  1385. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1386. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  1387. }
  1388. }
  1389. public async void ShowSelectedTipAsync(ShowTipEventArgs showTipEventArgs)
  1390. {
  1391. switch (showTipEventArgs.enumTipKind)
  1392. {
  1393. case EnumTipKind.StatusNone:
  1394. ShowLeftTip(false);
  1395. break;
  1396. case EnumTipKind.StatusSetPasswordSuccessfully:
  1397. ShowLeftTip(true);
  1398. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  1399. break;
  1400. case EnumTipKind.StatusRemoveSecuritySuccessfully:
  1401. ShowLeftTip(false);
  1402. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1403. IsLoading = Visibility.Collapsed;
  1404. ShowTip(true);
  1405. await Task.Delay(3000);
  1406. //ReadModelTip = Visibility.Collapsed;
  1407. TipVisible = Visibility.Collapsed;
  1408. break;
  1409. default: break;
  1410. }
  1411. }
  1412. /// <summary>
  1413. /// 右键菜单创建链接
  1414. /// </summary>
  1415. /// <param name="obj"></param>
  1416. private void CreateLinkEvent(object obj)
  1417. {
  1418. if (obj is object[] objArry)
  1419. {
  1420. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  1421. {
  1422. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  1423. linkArgs.URI = string.Empty;
  1424. linkArgs.LinkType = LINK_TYPE.GOTO;
  1425. linkArgs.PageIndex = annotCommand.PageIndex;
  1426. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  1427. this.IsRightMenuCreateLink = true;
  1428. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  1429. lists.Add(linkArgs);
  1430. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  1431. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1432. PDFViewer.SetToolParam(annotArgs);
  1433. this.IsPropertyOpen = true;
  1434. }
  1435. }
  1436. }
  1437. private void CloseProperty()
  1438. {
  1439. FromClick = true;
  1440. IsPropertyOpen = false;
  1441. FromClick = false;
  1442. }
  1443. /// <summary>
  1444. /// 在文件资源管理器中显示
  1445. /// </summary>
  1446. private void ShowInFolder()
  1447. {
  1448. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  1449. }
  1450. private void property()
  1451. {
  1452. DialogParameters valuePairs = new DialogParameters();
  1453. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1454. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  1455. }
  1456. private async void share()
  1457. {
  1458. if (IsPopupInProgress)
  1459. {
  1460. return;
  1461. }
  1462. IsPopupInProgress = true;
  1463. try
  1464. {
  1465. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Share");
  1466. //分享前自动保存
  1467. if (!await SaveBeforeOption(true))
  1468. {
  1469. IsPopupInProgress = false;
  1470. return;
  1471. }
  1472. IsPopupInProgress = false;
  1473. var path = PDFViewer.Document.FilePath;
  1474. string subject = "Share With" + " " + PDFViewer.Document.FileName;
  1475. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  1476. }
  1477. catch
  1478. {
  1479. IsPopupInProgress = false;
  1480. AlertsMessage alertsMessage = new AlertsMessage();
  1481. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Share_NoOutLookWarning"), App.ServiceLoader.GetString("Text_ok"));
  1482. }
  1483. IsPopupInProgress = false;
  1484. }
  1485. private void SettingsEvent()
  1486. {
  1487. DialogParameters value = new DialogParameters();
  1488. value.Add(ParameterNames.ViewContentViewModel, this);
  1489. AnnotToolContentViewModel annotToolContent = GetAnnotToolContentVM(); ;
  1490. dialogs.ShowDialog(DialogNames.SettingsDialog, null, e =>
  1491. {
  1492. var annotate = Settings.Default.AppProperties.Annotate;
  1493. if (annotToolContent != null)
  1494. {
  1495. IsSettingOut = true;
  1496. //与注释联动修改颜色
  1497. UpdateFreeHand(annotate, annotToolContent);
  1498. UpdateTextHighlight(annotate, annotToolContent);
  1499. UpdateUnderLine(annotate, annotToolContent);
  1500. UpdateStrikethrough(annotate, annotToolContent);
  1501. UpdateLine(annotate, annotToolContent);
  1502. UpdateArrow(annotate, annotToolContent);
  1503. //IsSettingOut =false;
  1504. }
  1505. });
  1506. if (PDFViewer != null)
  1507. {
  1508. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1509. }
  1510. if (Settings.Default.AppProperties.Description.AutoSave)
  1511. {
  1512. StartAutoSave();
  1513. }
  1514. else
  1515. {
  1516. CloseAutoSave();
  1517. }
  1518. }
  1519. private AnnotToolContentViewModel GetAnnotToolContentVM()
  1520. {
  1521. AnnotToolContentViewModel annotToolContent = null;
  1522. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1523. {
  1524. var views = region.Regions[ToolsBarContentRegionName].Views;
  1525. var isHas = views.FindFirst(q => q is AnnotToolContent);
  1526. if (isHas is AnnotToolContent annotTool)
  1527. {
  1528. annotToolContent = (AnnotToolContentViewModel)annotTool.DataContext;
  1529. }
  1530. }
  1531. return annotToolContent;
  1532. }
  1533. private void UpdateArrow(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1534. {
  1535. Color color2 = annotate.ArrowColor;
  1536. Color color1 = (annotToolContent.ArrowColor as SolidColorBrush).Color;
  1537. bool flag = ColorComparison(color2, color1);
  1538. if (flag)
  1539. {
  1540. annotToolContent.ArrowColor = new SolidColorBrush(color2);
  1541. if (annotToolContent.PropertyPanel.LastArrowAnnot != null)
  1542. {
  1543. if (annotToolContent.PropertyPanel.LastArrowAnnot is LineAnnotArgs annotArgs)
  1544. {
  1545. annotArgs.LineColor = color2;
  1546. }
  1547. }
  1548. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1549. {
  1550. CreateRefreshComment(annotToolContent);
  1551. }
  1552. }
  1553. }
  1554. private void UpdateLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1555. {
  1556. Color color2 = annotate.LineColor;
  1557. Color color1 = (annotToolContent.LineColor as SolidColorBrush).Color;
  1558. bool flag = ColorComparison(color2, color1);
  1559. if (flag)
  1560. {
  1561. annotToolContent.LineColor = new SolidColorBrush(color2);
  1562. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null)
  1563. {
  1564. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] is LineAnnotArgs annotArgs)
  1565. {
  1566. annotArgs.LineColor = color2;
  1567. }
  1568. }
  1569. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1570. {
  1571. CreateRefreshComment(annotToolContent);
  1572. }
  1573. }
  1574. }
  1575. private void UpdateStrikethrough(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1576. {
  1577. Color color2 = annotate.StrikethroughColor;
  1578. Color color1 = (annotToolContent.StrikeoutColor as SolidColorBrush).Color;
  1579. bool flag = ColorComparison(color2, color1);
  1580. if (flag)
  1581. {
  1582. annotToolContent.StrikeoutColor = new SolidColorBrush(color2);
  1583. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1584. {
  1585. CreateRefreshComment(annotToolContent);
  1586. }
  1587. }
  1588. }
  1589. private void UpdateUnderLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1590. {
  1591. Color color2 = annotate.UnderLineColor;
  1592. Color color1 = (annotToolContent.UnderLineColor as SolidColorBrush).Color;
  1593. bool flag = ColorComparison(color2, color1);
  1594. if (flag)
  1595. {
  1596. annotToolContent.UnderLineColor = new SolidColorBrush(color2);
  1597. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1598. {
  1599. CreateRefreshComment(annotToolContent);
  1600. }
  1601. }
  1602. }
  1603. private void UpdateTextHighlight(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1604. {
  1605. Color color2 = annotate.HighLightColor;
  1606. Color color1 = (annotToolContent.HighLightColor as SolidColorBrush).Color;
  1607. bool flag = ColorComparison(color2, color1);
  1608. if (flag)
  1609. {
  1610. annotToolContent.HighLightColor = new SolidColorBrush(color2);
  1611. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1612. {
  1613. CreateRefreshComment(annotToolContent);
  1614. }
  1615. }
  1616. }
  1617. private void UpdateFreeHand(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1618. {
  1619. Color color2 = annotate.FreeHandColor;
  1620. Color color1 = (annotToolContent.FreeHandColor as SolidColorBrush).Color;
  1621. bool flag = ColorComparison(color2, color1);
  1622. if (flag)
  1623. {
  1624. annotToolContent.FreeHandColor = new SolidColorBrush(color2);
  1625. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] != null)
  1626. {
  1627. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] is FreehandAnnotArgs freehandAnnotArgs)
  1628. {
  1629. freehandAnnotArgs.InkColor = color2;
  1630. }
  1631. }
  1632. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1633. {
  1634. CreateRefreshComment(annotToolContent);
  1635. }
  1636. }
  1637. }
  1638. private void CreateRefreshComment(AnnotToolContentViewModel annotToolContent)
  1639. {
  1640. AnnotHandlerEventArgs annotArgs = null;
  1641. string tag = annotToolContent.StrAnnotToolChecked;
  1642. annotToolContent.FindAnnotTypeKey(tag, ref annotArgs);
  1643. if (annotArgs != null)
  1644. {
  1645. //设置点击页面会创建对应选中注释工具的注释
  1646. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1647. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1648. PDFViewer.SetToolParam(annotArgs);
  1649. }
  1650. }
  1651. private bool ColorComparison(Color color2, Color color1)
  1652. {
  1653. if (color1.R == color2.R && color1.G == color2.G && color1.B == color2.B
  1654. && color1.A == color2.A)
  1655. {
  1656. return false;
  1657. }
  1658. else
  1659. {
  1660. return true;
  1661. }
  1662. }
  1663. private bool CanSaveExcute()
  1664. {
  1665. return CanSave;
  1666. }
  1667. private void MenuEnterReadModeEvent(object obj)
  1668. {
  1669. }
  1670. public void ShowAITranslationDialog()
  1671. {
  1672. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_AITranslate");
  1673. DialogParameters printValue = new DialogParameters();
  1674. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1675. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1676. printValue.Add(ParameterNames.ViewContentViewModel, this);
  1677. printValue.Add(ParameterNames.Unicode, unicode);
  1678. dialogs.ShowDialog(DialogNames.DocumentaryTranslation, printValue, e => { });
  1679. }
  1680. public void ShowPrintDialog()
  1681. {
  1682. //保存并继续,使用了高级功能则弹窗权益弹窗
  1683. if (!saveFile(true))
  1684. {
  1685. return;
  1686. }
  1687. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Print");
  1688. DialogParameters printValue = new DialogParameters();
  1689. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1690. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1691. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  1692. printValue.Add(ParameterNames.Unicode, unicode);
  1693. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  1694. }
  1695. public void SelectClick()
  1696. {
  1697. if (OpenBOTA == false)
  1698. {
  1699. OpenBOTA = true;
  1700. }
  1701. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1702. if (isBook == false)
  1703. {
  1704. bOTAContent.TabItemSearch.IsSelected = true;
  1705. }
  1706. }
  1707. public bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1708. {
  1709. bool isTabItem = false;
  1710. bOTAContentViewModel = null;
  1711. bOTAContent = null;
  1712. if (region.Regions.ContainsRegionWithName(this.BOTARegionName))
  1713. {
  1714. var views = region.Regions[this.BOTARegionName].Views;
  1715. var model = views.FirstOrDefault(q => q is BOTAContent);
  1716. if (model is BOTAContent bOTAContent1)
  1717. {
  1718. bOTAContent = bOTAContent1;
  1719. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1720. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1721. {
  1722. isTabItem = true;
  1723. }
  1724. }
  1725. }
  1726. return isTabItem;
  1727. }
  1728. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  1729. {
  1730. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  1731. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  1732. //其他工具菜单栏共用一个ToolsBarContentRegionName
  1733. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  1734. dictionary.Add("TabItemConvert", ToolsBarContentRegionName);
  1735. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  1736. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  1737. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  1738. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  1739. }
  1740. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  1741. {
  1742. dictionary.Add("TabItemPageEdit", "PageEditContent");
  1743. dictionary.Add("TabItemTool", "ToolsBarContent");
  1744. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  1745. dictionary.Add("TabItemConvert", "ConverterBarContent");
  1746. dictionary.Add("TabItemScan", "ScanContent");
  1747. dictionary.Add("TabItemEdit", "TextEditToolContent");
  1748. dictionary.Add("TabItemForm", "FormsToolContent");
  1749. dictionary.Add("TabItemFill", "FillAndSignContent");
  1750. }
  1751. private void UpdateShowContent(string currentBar)
  1752. {
  1753. ToolContentVisible = Visibility.Collapsed;
  1754. ToolsBarContentVisible = Visibility.Collapsed;
  1755. ToolsBarContentVisible = Visibility.Collapsed;
  1756. TextEditToolContentVisible = Visibility.Collapsed;
  1757. OCRContentVisible = Visibility.Collapsed;
  1758. switch (currentBar)
  1759. {
  1760. case "TabItemAnnotation":
  1761. case "TabItemTool":
  1762. case "TabItemForm":
  1763. case "TabItemFill":
  1764. ToolsBarContentVisible = Visibility.Visible;
  1765. //当退出页面编辑后
  1766. //缩略图选中页面,要和当前显示的页面,一致
  1767. if (PDFViewer != null)
  1768. {
  1769. //防止部分情况PDFViewer.CurrentIndex获取异常问题
  1770. if (PDFViewer.Document.PageCount > 0)
  1771. {
  1772. events.GetEvent<PageEditSelectedItemEvent>().Publish(new PageEditSelectedItemEventArgs() { Unicode = unicode, SelectedItemIndex = PDFViewer.CurrentIndex, IsSingle = true });
  1773. }
  1774. }
  1775. #region 方案一,比较耗时,需要遍历
  1776. //bool isTabItemThumbnail = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemThumbnail");
  1777. //if (isTabItemThumbnail)
  1778. //{
  1779. // Views.PageEdit.PageEditContent pageEditContent = null;
  1780. // PageEditContentViewModel viewModel = GetPageEditContentVM(bOTAContentViewModel, out pageEditContent);
  1781. // if (viewModel != null)
  1782. // {
  1783. // viewModel.ListSelectedIndex = PDFViewer.CurrentIndex;
  1784. // pageEditContent.ListPageEdit.ScrollIntoView(pageEditContent.ListPageEdit.SelectedItem);
  1785. // }
  1786. //}
  1787. #endregion 方案一,比较耗时,需要遍历
  1788. break;
  1789. case "TabItemScan":
  1790. ToolsBarContentVisible = Visibility.Visible;
  1791. OCRContentVisible = Visibility.Visible;
  1792. break;
  1793. case "TabItemEdit":
  1794. TextEditToolContentVisible = Visibility.Visible;
  1795. break;
  1796. case "TabItemConvert":
  1797. ToolsBarContentVisible = Visibility.Visible;
  1798. //当退出页面编辑后
  1799. //缩略图选中页面,要和当前显示的页面,一致
  1800. if (PDFViewer != null)
  1801. {
  1802. events.GetEvent<PageEditSelectedItemEvent>().Publish(new PageEditSelectedItemEventArgs() { Unicode = unicode, SelectedItemIndex = PDFViewer.CurrentIndex, IsSingle = true });
  1803. }
  1804. break;
  1805. case "TabItemPageEdit":
  1806. case "HeaderFooterContent":
  1807. case "BatesContent":
  1808. case "WatermarkContent":
  1809. case "BackgroundContent":
  1810. case "RedactionContent":
  1811. ToolContentVisible = Visibility.Visible;
  1812. break;
  1813. default:
  1814. break;
  1815. }
  1816. PDFEditMode(currentBar);
  1817. FormMode(currentBar);
  1818. }
  1819. private void PDFEditMode(string currentBar)
  1820. {
  1821. if (currentBar == "TabItemEdit")
  1822. {
  1823. if (PDFViewer != null)
  1824. {
  1825. SolidColorBrush brush = new SolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString("#18A0FB"));
  1826. brush.Opacity = 0.2;
  1827. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  1828. CommonDrawData.PDFEditCoverBrush = brush;
  1829. CommonDrawData.PDFEditCoverPen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1);
  1830. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
  1831. PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
  1832. //SelectedPrpoertyPanel("TextEditProperty", null);
  1833. //IsPropertyOpen = true;
  1834. }
  1835. }
  1836. else
  1837. {
  1838. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  1839. {
  1840. IsPropertyOpen = false;
  1841. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1842. }
  1843. }
  1844. }
  1845. private void FormMode(string currentBar)
  1846. {
  1847. if (currentBar == "TabItemForm")
  1848. {
  1849. if (PDFViewer != null)
  1850. {
  1851. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  1852. }
  1853. }
  1854. else
  1855. {
  1856. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  1857. {
  1858. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1859. }
  1860. }
  1861. }
  1862. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  1863. {
  1864. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  1865. if (e.PropertyName == "CanUndo")
  1866. {
  1867. CanUndo = PDFViewer.UndoManager.CanUndo;
  1868. }
  1869. if (e.PropertyName == "CanRedo")
  1870. {
  1871. CanRedo = PDFViewer.UndoManager.CanRedo;
  1872. }
  1873. if (e.PropertyName == "CanSave")
  1874. {
  1875. CanSave = PDFViewer.UndoManager.CanSave;
  1876. }
  1877. }
  1878. /// <summary>
  1879. /// 选项卡切换事件
  1880. /// </summary>
  1881. /// <param name="e"></param>
  1882. private void TabControlSelectonChangedEvent(object e)
  1883. {
  1884. var args = e as SelectionChangedEventArgs;
  1885. if (args != null && args.AddedItems.Count > 0)
  1886. {
  1887. var item = args.AddedItems[0] as TabItem;
  1888. CurrentBar = item.Name;
  1889. TabControlSelectonDataTracking(item.Name);
  1890. if (previousBar != CurrentBar)
  1891. {
  1892. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  1893. {
  1894. EnterPageEdit();
  1895. searchContent = CleanSearch();
  1896. }
  1897. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  1898. {
  1899. EnterSelectedBar(CurrentBar);
  1900. isInPageEdit = false;
  1901. SearchTextFocus(searchContent);
  1902. }
  1903. previousBar = CurrentBar;
  1904. }
  1905. }
  1906. }
  1907. public void SearchTextFocus(SearchContent searchContent)
  1908. {
  1909. if (searchContent!=null&&searchContent.SearchText!=null&& string.IsNullOrEmpty(searchContent.SearchText.Text) == false)
  1910. {
  1911. searchContent.SearchText.Dispatcher.BeginInvoke(new Action(() =>
  1912. {
  1913. searchContent.SearchText.Focus();
  1914. searchContent.SearchText.SelectAll();
  1915. }));
  1916. }
  1917. }
  1918. private SearchContent CleanSearch()
  1919. {
  1920. SearchContent searchContent = null;
  1921. if (this.OpenBOTA)
  1922. {
  1923. bool isTabItemSearch = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1924. if (bOTAContent.TabItemSearch.IsSelected)
  1925. {
  1926. SearchContentViewModel viewModel = GetSearchContentVM(bOTAContentViewModel, out searchContent);
  1927. if (viewModel.SearchItemList.Count > 0)
  1928. {
  1929. PDFViewer.ClearPageSelectText();
  1930. viewModel.SearchItemList.Clear();
  1931. }
  1932. }
  1933. }
  1934. return searchContent;
  1935. }
  1936. private SearchContentViewModel GetSearchContentVM(BOTAContentViewModel bOTAContentViewModel, out SearchContent searchContent)
  1937. {
  1938. SearchContentViewModel viewModel = null;
  1939. searchContent = null;
  1940. if (bOTAContentViewModel != null)
  1941. {
  1942. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  1943. {
  1944. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  1945. foreach (var item in views)
  1946. {
  1947. if (item is SearchContent search)
  1948. {
  1949. searchContent = search;
  1950. viewModel = search.DataContext as SearchContentViewModel;
  1951. break;
  1952. }
  1953. }
  1954. }
  1955. }
  1956. return viewModel;
  1957. }
  1958. /// <summary>
  1959. /// 选项卡切换事件埋点
  1960. /// </summary>
  1961. /// <param name="e"></param>
  1962. private void TabControlSelectonDataTracking(string currentBar)
  1963. {
  1964. switch (currentBar)
  1965. {
  1966. case "TabItemAnnotation":
  1967. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Annotation");
  1968. break;
  1969. case "TabItemEdit":
  1970. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_EditPDF");
  1971. break;
  1972. case "TabItemPageEdit":
  1973. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_PageEdit");
  1974. break;
  1975. case "TabItemConvert":
  1976. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Converter");
  1977. break;
  1978. case "TabItemTool":
  1979. DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Tools");
  1980. break;
  1981. }
  1982. }
  1983. /// <summary>
  1984. /// 进入页面编辑模式
  1985. /// </summary>
  1986. //工具栏添加功能应注意自处
  1987. public void EnterPageEdit()
  1988. {
  1989. if (TabSelectedIndex != 2)
  1990. {
  1991. TabSelectedIndex = 2;
  1992. }
  1993. CurrentBar = "TabItemPageEdit";
  1994. EnterToolMode(barContentByTabItem[CurrentBar]);
  1995. isInPageEdit = true;
  1996. }
  1997. /// <summary>
  1998. /// 阅读模式
  1999. /// </summary>
  2000. /// <param name="viewContent"></param>
  2001. public async void On_ReadMode()
  2002. {
  2003. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  2004. mainViewModel.IsBookMode = true;
  2005. IsLoading = Visibility.Visible;
  2006. await Task.Delay(1);
  2007. PDFViewer.DisableClearSelectAnnot(false);
  2008. PDFViewer.ClearSelectAnnots();
  2009. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  2010. var annotArgs = new SelectToolArgs();
  2011. PDFViewer.SetToolParam(annotArgs);
  2012. #region 旧版本
  2013. //NavigationParameters param = new NavigationParameters();
  2014. //param.Add(ParameterNames.PDFViewer, PDFViewer);
  2015. //param.Add(ParameterNames.ViewContentViewModel, this);
  2016. //region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  2017. ////ShowContent(CurrentBar, true);
  2018. //if (GridToolRow != 0)
  2019. //{
  2020. // GridToolRow = 0;
  2021. //}
  2022. //if (GridToolRowSpan != 4)
  2023. //{
  2024. // GridToolRowSpan = 4;
  2025. //}
  2026. ////isInPageEdit = true;
  2027. //UpdateShowContent("TabItemPageEdit");
  2028. #endregion 旧版本
  2029. //5.15
  2030. //15722 【视图-阅读模式】退出阅读模式,页面应保持原来的视图结构
  2031. botaState = OpenBOTA;
  2032. propertyOpenState = IsPropertyOpen;
  2033. //5.6注释
  2034. //已调整左右侧边栏层级,暂时注释掉,修复展开BOTA,进入阅读模式再退出后,BOTA保持展开,但没有选中的问题
  2035. //留意测试阶段是否会有问题,如果没问题,在上线前删除
  2036. //OpenBOTA = false;
  2037. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = true });
  2038. //模拟一次用户点击 关闭属性面板
  2039. //如果直接设置属性可能因为偏好设置设置成手动的原因 无法生效
  2040. FromClick = true;
  2041. IsPropertyOpen = false;
  2042. FromClick = false;
  2043. AnnotToolContentViewModel annotToolContent = GetAnnotToolContentVM();
  2044. if (annotToolContent != null)
  2045. {
  2046. annotToolContent.StrAnnotToolChecked = "";
  2047. }
  2048. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  2049. {
  2050. var views = region.Regions[TipContentRegionName].Views;
  2051. var isHasView = views.FindFirst(q => q is Views.TipContent.EnterReadModeTip);
  2052. if (isHasView == null)
  2053. {
  2054. region.RequestNavigate(TipContentRegionName, "EnterReadModeTip");
  2055. }
  2056. else
  2057. {
  2058. region.Regions[TipContentRegionName].Activate(isHasView);
  2059. }
  2060. }
  2061. IsLoading = Visibility.Collapsed;
  2062. ShowTip(true);
  2063. await Task.Delay(3000);
  2064. TipVisible = Visibility.Collapsed;
  2065. }
  2066. /// <summary>
  2067. /// 退出阅读模式
  2068. /// </summary>
  2069. public async void Off_ReadModel()
  2070. {
  2071. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  2072. mainViewModel.IsBookMode = false;
  2073. IsLoading = Visibility.Visible;
  2074. await Task.Delay(1);
  2075. //PDFViewer.MouseMode = MouseModes.None;
  2076. #region 旧版本
  2077. //if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  2078. //{
  2079. // if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  2080. // {
  2081. // var contentRegion = region.Regions[ViwerRegionName];
  2082. // contentRegion.Remove(PDFViewer);
  2083. // }
  2084. // //还原背景色
  2085. // PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  2086. // region.AddToRegion(ViwerRegionName, PDFViewer);
  2087. //}
  2088. //if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  2089. //{
  2090. // EnterSelectedBar("TabItemAnnotation");
  2091. //}
  2092. //else
  2093. //{
  2094. // EnterSelectedBar(CurrentBar);
  2095. //}
  2096. #endregion 旧版本
  2097. //还原背景色
  2098. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  2099. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = false });
  2100. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  2101. {
  2102. var views = region.Regions[TipContentRegionName].Views;
  2103. var isHasView = views.FindFirst(q => q is Views.TipContent.ReadModelTip);
  2104. if (isHasView == null)
  2105. {
  2106. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  2107. }
  2108. else
  2109. {
  2110. region.Regions[TipContentRegionName].Activate(isHasView);
  2111. }
  2112. }
  2113. ///退出阅读模式 显示视图面板
  2114. BottomToolContent bottomTool = null;
  2115. BottomToolContentViewModel bottomToolVM = GetBottomToolContentVM(ref bottomTool);
  2116. if (bottomToolVM != null)
  2117. {
  2118. bottomToolVM.IsShowViewModular = propertyOpenState;
  2119. IsPropertyOpen = propertyOpenState;
  2120. if (bottomToolVM.IsShowViewModular && bottomTool != null)
  2121. {
  2122. bottomToolVM.ShowViewModularCommand.Execute(true);
  2123. }
  2124. }
  2125. //if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
  2126. //{
  2127. // var views = region.Regions[BottomToolRegionName].Views;
  2128. // var isHasView = views.FindFirst(q => q is BottomToolContent);
  2129. // if (isHasView is BottomToolContent bottomToolContent)
  2130. // {
  2131. // BottomToolContentViewModel toolContentViewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
  2132. // toolContentViewModel.IsShowViewModular = propertyOpenState;
  2133. // IsPropertyOpen = propertyOpenState;
  2134. // }
  2135. //}
  2136. IsLoading = Visibility.Collapsed;
  2137. //5.6注释
  2138. //已调整左右侧边栏层级,暂时注释掉,修复展开BOTA,进入阅读模式再退出后,BOTA保持展开,但没有选中的问题
  2139. //留意测试阶段是否会有问题,如果没问题,在上线前删除
  2140. //5.15
  2141. //15722 【视图-阅读模式】退出阅读模式,页面应保持原来的视图结构
  2142. OpenBOTA = botaState;
  2143. PDFViewer.DisableClearSelectAnnot(false);
  2144. PDFViewer.ClearSelectAnnots();
  2145. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  2146. var annotArgs = new SelectToolArgs();
  2147. PDFViewer.SetToolParam(annotArgs);
  2148. ShowTip(true);
  2149. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  2150. await Task.Delay(3000);
  2151. //ReadModelTip = Visibility.Collapsed;
  2152. TipVisible = Visibility.Collapsed;
  2153. }
  2154. public BottomToolContentViewModel GetBottomToolContentVM(ref BottomToolContent bottomTool)
  2155. {
  2156. BottomToolContentViewModel viewModel = null;
  2157. if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
  2158. {
  2159. var views = region.Regions[BottomToolRegionName].Views;
  2160. var isHasView = views.FindFirst(q => q is BottomToolContent);
  2161. if (isHasView is BottomToolContent bottomToolContent)
  2162. {
  2163. bottomTool = bottomToolContent;
  2164. viewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
  2165. }
  2166. }
  2167. return viewModel;
  2168. }
  2169. #region PDFViewer鼠标滚轮缩放事件
  2170. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  2171. {
  2172. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  2173. PDFViewer.Zoom(newZoom);
  2174. }
  2175. public double CheckZoomLevel(double zoom, bool IsGrowth)
  2176. {
  2177. double standardZoom = 100;
  2178. //最小缩放倍数 0.01倍
  2179. double minrate = 0.01;
  2180. //最大缩放倍数 100倍
  2181. double maxrate = 100;
  2182. if (zoom <= minrate)
  2183. {
  2184. return minrate;
  2185. }
  2186. //最大缩放倍数 100倍
  2187. if (zoom >= maxrate)
  2188. {
  2189. return maxrate;
  2190. }
  2191. zoom *= 100;
  2192. for (int i = 0; i < zoomLevel.Length - 1; i++)
  2193. {
  2194. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  2195. {
  2196. standardZoom = zoomLevel[i + 1];
  2197. break;
  2198. }
  2199. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  2200. {
  2201. standardZoom = zoomLevel[i];
  2202. break;
  2203. }
  2204. }
  2205. return standardZoom / 100;
  2206. }
  2207. #endregion PDFViewer鼠标滚轮缩放事件
  2208. #region 方法
  2209. /// <summary>
  2210. /// 快捷键
  2211. /// </summary>
  2212. /// <param name="sender"></param>
  2213. /// <param name="e"></param>
  2214. /// <exception cref="NotImplementedException"></exception>
  2215. private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  2216. {
  2217. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
  2218. {
  2219. //判断是不是不是注释工具下
  2220. bool isunannotTool = true;
  2221. //内容选择 退出
  2222. if (PDFViewer.MouseMode != MouseModes.PanTool)
  2223. {
  2224. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  2225. if (annotToolContent != null && toolContentViewModel != null)
  2226. {
  2227. if (annotToolContent.BtnSelecttool.IsChecked == true)
  2228. {
  2229. if (toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs != null)
  2230. {
  2231. toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  2232. annotToolContent.BtnSelecttool.IsChecked = false;
  2233. PDFViewer.SetMouseMode(MouseModes.PanTool);
  2234. isunannotTool = false;
  2235. }
  2236. }
  2237. else
  2238. {
  2239. //如果注释是在拖拉创建中 或者 选中 了图片 不退出阅读模式
  2240. if (toolContentViewModel != null)
  2241. {
  2242. if (toolContentViewModel.IsCreateAnnot)
  2243. {
  2244. isunannotTool = false;
  2245. toolContentViewModel.IsCreateAnnot = false;
  2246. }
  2247. if (toolContentViewModel.IsSelectImage)
  2248. {
  2249. isunannotTool = false;
  2250. toolContentViewModel.IsSelectImage = false;
  2251. }
  2252. }
  2253. }
  2254. }
  2255. }
  2256. if (mainViewModel.IsBookMode == true && isunannotTool)
  2257. {
  2258. Off_ReadModel();
  2259. }
  2260. }
  2261. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.C))
  2262. {
  2263. //内容选择 复制 快捷键
  2264. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  2265. if (annotToolContent != null && toolContentViewModel != null)
  2266. {
  2267. if (annotToolContent.BtnSelecttool.IsChecked == true)
  2268. {
  2269. toolContentViewModel.SnapshotEditMenuViewModel.SnapCopyCommand.Execute();
  2270. }
  2271. }
  2272. }
  2273. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.P))
  2274. {
  2275. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  2276. if (annotToolContent != null && toolContentViewModel != null)
  2277. {
  2278. if (annotToolContent.BtnSelecttool.IsChecked == true)
  2279. {
  2280. toolContentViewModel.SnapshotEditMenuViewModel.PrintCommand.Execute();
  2281. }
  2282. }
  2283. }
  2284. }
  2285. private AnnotToolContent GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel)
  2286. {
  2287. AnnotToolContent toolContent = null;
  2288. toolContentViewModel = null;
  2289. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  2290. {
  2291. var views = region.Regions[ToolsBarContentRegionName].Views;
  2292. var model = views.FirstOrDefault(q => q is AnnotToolContent);
  2293. if (model is AnnotToolContent annotToolContent)
  2294. {
  2295. toolContent = annotToolContent;
  2296. toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
  2297. }
  2298. }
  2299. return toolContent;
  2300. }
  2301. /// <summary>
  2302. /// 视图面板 切换分屏模式
  2303. /// </summary>
  2304. /// <param name="mode"></param>
  2305. public void EnterSplitMode(SplitMode mode)
  2306. {
  2307. ///通知UI层更改布局
  2308. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  2309. }
  2310. private void Undo()
  2311. {
  2312. PDFViewer.UndoManager.Undo();
  2313. PDFViewer.DisableClearSelectAnnot(false);
  2314. PDFViewer.ClearSelectAnnots();
  2315. //使用编辑功能时Undo刷新缩略图
  2316. if (PDFViewer.MouseMode == MouseModes.PDFEdit)
  2317. {
  2318. events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode));
  2319. }
  2320. }
  2321. private void Redo()
  2322. {
  2323. PDFViewer.UndoManager.Redo();
  2324. //使用编辑功能时Redo刷新缩略图
  2325. if (PDFViewer.MouseMode == MouseModes.PDFEdit)
  2326. {
  2327. events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode));
  2328. }
  2329. }
  2330. /// <summary>
  2331. /// 加载阅读页必要组件,BOTA,底部工具栏等
  2332. /// </summary>
  2333. /// <param name="fromSaveAs"></param>
  2334. private void LoadControl(bool fromSaveAs = false)
  2335. {
  2336. NavigationParameters parameters = new NavigationParameters();
  2337. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  2338. parameters.Add(ParameterNames.ViewContentViewModel, this);
  2339. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  2340. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  2341. region.RequestNavigate(ReadModeRegionName, "PageContent", parameters);
  2342. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  2343. //TODO 根据上一次关闭记录的菜单,选中顶部TabItem
  2344. if (!fromSaveAs)
  2345. {
  2346. EnterSelectedBar("TabItemAnnotation");
  2347. }
  2348. }
  2349. /// <summary>
  2350. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  2351. /// </summary>
  2352. /// <param name="Content"></param>
  2353. /// <param name="annotPropertyPanel"></param>
  2354. public void SelectedPrpoertyPanel(string Content, AnnotTransfer annotPropertyPanel)
  2355. {
  2356. if (Content == "PropertyPanelContent")
  2357. {
  2358. IsPropertyOpen = false;
  2359. }
  2360. else
  2361. {
  2362. IsPropertyOpen = true;
  2363. }
  2364. NavigationParameters parameters = new NavigationParameters();
  2365. //传其他参数:文档类,空注释面板;
  2366. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  2367. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  2368. parameters.Add(ParameterNames.ViewContentViewModel, this);
  2369. region.RequestNavigate(PropertyRegionName, Content, parameters);
  2370. }
  2371. /// <summary>
  2372. /// 将PDFViwer添加到Region
  2373. /// </summary>
  2374. private bool loadFile()
  2375. {
  2376. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  2377. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  2378. CanSave = PDFViewer.UndoManager.CanSave;
  2379. CanUndo = PDFViewer.UndoManager.CanUndo;
  2380. CanRedo = PDFViewer.UndoManager.CanRedo;
  2381. if (!CheckPassword())
  2382. {
  2383. return false;
  2384. }
  2385. PDFViewer.Load();
  2386. PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  2387. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  2388. //设置移动注释参考线
  2389. ComPDFKitViewer.CommonDrawData.MovePen = new System.Windows.Media.Pen((System.Windows.Media.Brush)new BrushConverter().ConvertFromString("#1770F4"), 1);
  2390. ComPDFKitViewer.CommonDrawData.DrawAnnotGuidesLine = true;
  2391. //还原上一次关闭前的视图设置
  2392. GetOpenFileInfo();
  2393. if (!string.IsNullOrEmpty(PassWord))
  2394. {
  2395. //加密文档解密后刷新底部工具栏页码总数
  2396. NavigationParameters parameters = new NavigationParameters();
  2397. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  2398. parameters.Add(ParameterNames.ViewContentViewModel, this);
  2399. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  2400. //解密后,刷新侧边栏逻辑
  2401. botaViewModel.OpenBOTA();
  2402. }
  2403. PDFViewer.SnapsToDevicePixels = true;
  2404. PDFViewer.UseLayoutRounding = true;
  2405. RenderOptions.SetBitmapScalingMode(PDFViewer, BitmapScalingMode.Fant);
  2406. region.AddToRegion(ViwerRegionName, PDFViewer);
  2407. if (App.mainWindowViewModel != null)
  2408. {
  2409. //更新CurrentPDFViewer对象
  2410. App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
  2411. }
  2412. if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
  2413. {
  2414. App.OpenedFileList.Add(PDFViewer.Document.FilePath);
  2415. }
  2416. return true;
  2417. }
  2418. /// <summary>
  2419. /// 处理密码相关的内容
  2420. /// </summary>
  2421. private bool CheckPassword()
  2422. {
  2423. if (passwordInfo != null && (!string.IsNullOrEmpty(passwordInfo.OpenPassword) || !string.IsNullOrEmpty(passwordInfo.PermissionsPassword)))
  2424. {
  2425. if (!string.IsNullOrEmpty(passwordInfo.OpenPassword))
  2426. {
  2427. PDFViewer.Document.UnlockWithPassword(passwordInfo.OpenPassword);
  2428. }
  2429. if (!string.IsNullOrEmpty(passwordInfo.PermissionsPassword) && passwordInfo.PermissionsPassword != passwordInfo.OpenPassword)
  2430. {
  2431. IsFileLocked = true;
  2432. NavigationParameters param = new NavigationParameters();
  2433. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2434. param.Add(ParameterNames.ViewContentViewModel, this);
  2435. ShowLeftTip(true);
  2436. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  2437. }
  2438. }
  2439. else
  2440. {
  2441. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
  2442. if (result.IsDiscryptied)
  2443. {
  2444. if (result.Password != null)
  2445. {
  2446. string filePath = PDFViewer.Document.FilePath;
  2447. PDFViewer.Document.UnlockWithPassword(result.Password);
  2448. PDFViewer.Tag = result.Password;
  2449. //记录密码到内存
  2450. this.PassWord = result.Password;
  2451. }
  2452. }
  2453. if (result.IsDiscryptied == false)
  2454. {
  2455. //未成功解密文档时,释放Document对象,返回
  2456. PDFViewer.Document.Release();
  2457. //取消解密时关闭当前页签
  2458. App.mainWindowViewModel.CloseTabItem(App.mainWindowViewModel.SelectedItem);
  2459. return false;
  2460. }
  2461. }
  2462. return true;
  2463. }
  2464. /// <summary>
  2465. /// 还原上一次浏览的视图相关设置
  2466. /// </summary>
  2467. private void GetOpenFileInfo()
  2468. {
  2469. OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  2470. //偏好设置里设置了记录上次视图设置时
  2471. if (OpenFileInfo != null && Settings.Default.AppProperties.Description.RecoveryViewWhenOpen)
  2472. {
  2473. if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
  2474. {
  2475. PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
  2476. }
  2477. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  2478. {
  2479. PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
  2480. }
  2481. if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
  2482. {
  2483. PDFViewer.Zoom(OpenFileInfo.LastZoom);
  2484. }
  2485. PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
  2486. PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
  2487. if (OpenFileInfo.LastPageSpace)
  2488. {
  2489. PDFViewer.SetPageSpacing(8);
  2490. }
  2491. else
  2492. {
  2493. PDFViewer.SetPageSpacing(0);
  2494. }
  2495. if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
  2496. {
  2497. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
  2498. }
  2499. else
  2500. {
  2501. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
  2502. }
  2503. if (OpenFileInfo.LastPageIndex == 0 && PDFViewer.GetVerticalOffset() != 0)
  2504. {
  2505. PDFViewer.ScrollToVerticalOffset(0);
  2506. }
  2507. }
  2508. else
  2509. {
  2510. //新文档应用默认设置
  2511. PDFViewer.ChangeViewMode(Settings.Default.AppProperties.InitialVIew.PageView);
  2512. PDFViewer.ChangeFitMode(Settings.Default.AppProperties.InitialVIew.ZoomMode);
  2513. PDFViewer.SetShowLink(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  2514. }
  2515. }
  2516. /// <summary>
  2517. /// 已有路径文档的保存逻辑
  2518. /// </summary>
  2519. public bool saveFile(bool autosave = false)
  2520. {
  2521. try
  2522. {
  2523. //是否取消了水印保存步骤
  2524. bool flg = false;
  2525. //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
  2526. if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && ((App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP == true || PDFViewer.UndoManager.PDFEditChanged == true))
  2527. {
  2528. DialogParameters value = new DialogParameters();
  2529. value.Add(ParameterNames.ViewContentViewModel, this);
  2530. if (autosave)
  2531. {
  2532. value.Add(ParameterNames.Open, "Auto");
  2533. }
  2534. dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
  2535. {
  2536. if (dialogResult.Result == ButtonResult.OK)
  2537. {
  2538. flg = true;
  2539. }
  2540. else
  2541. {
  2542. flg = false;
  2543. }
  2544. });
  2545. return flg;
  2546. }
  2547. if ((string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile) && !autosave)
  2548. {
  2549. return saveAsFile();
  2550. }
  2551. //文档已被修复时 提示另存为
  2552. if (PDFViewer.Document.HasRepaired)
  2553. {
  2554. AlertsMessage alertsMessage = new AlertsMessage();
  2555. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileRepairedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2556. if (alertsMessage.result == ContentResult.Ok)
  2557. return saveAsFile();
  2558. else
  2559. return false;
  2560. }
  2561. //文件路径无法存在时
  2562. if (!File.Exists(PDFViewer.Document.FilePath))
  2563. {
  2564. AlertsMessage alertsMessage = new AlertsMessage();
  2565. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileNotExistWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2566. if (alertsMessage.result == ContentResult.Ok)
  2567. return saveAsFile();
  2568. else
  2569. return false;
  2570. }
  2571. //只读文件无法写入时,提示另存为
  2572. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  2573. if (fileInfo.IsReadOnly)
  2574. {
  2575. AlertsMessage alertsMessage = new AlertsMessage();
  2576. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileReadonlyWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2577. if (alertsMessage.result == ContentResult.Ok)
  2578. return saveAsFile();
  2579. else
  2580. return false;
  2581. }
  2582. //记录保存前的当前页
  2583. int pageindex = PDFViewer.CurrentIndex;
  2584. //Security Fixed:
  2585. //修改密码后原文档保存的步骤:
  2586. //在设置密码窗口传出“已修改”信号,并允许延迟保存
  2587. //
  2588. if (SecurityInfo.IsPasswordChanged)
  2589. {
  2590. string currentFilePath = PDFViewer.Document.FilePath;
  2591. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  2592. string openPassword = string.Empty;
  2593. string permissionsPassword = string.Empty;
  2594. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2595. if (SecurityInfo.NeedOpenPassword)
  2596. {
  2597. openPassword = SecurityInfo.OpenPassword;
  2598. }
  2599. if (SecurityInfo.NeedPermissionsPassword)
  2600. {
  2601. permissionsPassword = SecurityInfo.PermissionsPassword;
  2602. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2603. }
  2604. try
  2605. {
  2606. string currentPath = PDFViewer.Document.FilePath;
  2607. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2608. if (PDFViewer.Document.Decrypt(tempPath))
  2609. {
  2610. PDFViewer.CloseDocument();
  2611. PDFViewer.InitDocument(tempPath);
  2612. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2613. if (PDFViewer.Document.WriteToFilePath(currentPath))
  2614. {
  2615. PDFViewer.CloseDocument();
  2616. PDFViewer.InitDocument(currentPath);
  2617. if (!string.IsNullOrEmpty(openPassword))
  2618. {
  2619. PDFViewer.Document.UnlockWithPassword(openPassword);
  2620. }
  2621. if (!string.IsNullOrEmpty(permissionsPassword) && openPassword != permissionsPassword)
  2622. {
  2623. //PDFViewer.Document.CheckOwnerPassword(permissionsPassword);
  2624. IsFileLocked = true;
  2625. NavigationParameters param = new NavigationParameters();
  2626. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2627. param.Add(ParameterNames.ViewContentViewModel, this);
  2628. ShowLeftTip(true);
  2629. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  2630. }
  2631. try
  2632. {
  2633. PDFViewer.Load();
  2634. //跳转到保存前的页面
  2635. PDFViewer.GoToPage(pageindex);
  2636. }
  2637. catch
  2638. {
  2639. }
  2640. if (!autosave)
  2641. {
  2642. PDFViewer.UndoManager.CanSave = false;
  2643. }
  2644. SecurityInfo.IsPasswordChanged = false;
  2645. }
  2646. else
  2647. {
  2648. return false;
  2649. }
  2650. System.IO.File.Delete(tempPath);
  2651. }
  2652. else
  2653. {
  2654. return false;
  2655. }
  2656. return true;
  2657. }
  2658. catch
  2659. {
  2660. return false;
  2661. }
  2662. }
  2663. else if (SecurityInfo.IsPasswordRemoved)
  2664. {
  2665. try
  2666. {
  2667. string currentPath = PDFViewer.Document.FilePath;
  2668. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2669. PDFViewer.Document.Decrypt(tempPath);
  2670. PDFViewer.CloseDocument();
  2671. PDFViewer.InitDocument(tempPath);
  2672. PDFViewer.Document.WriteToFilePath(currentPath);
  2673. PDFViewer.CloseDocument();
  2674. PDFViewer.InitDocument(currentPath);
  2675. PDFViewer.Load();
  2676. //跳转到保存前的页面
  2677. PDFViewer.GoToPage(pageindex);
  2678. System.IO.File.Delete(tempPath);
  2679. }
  2680. catch
  2681. {
  2682. return false;
  2683. }
  2684. }
  2685. //自动裁剪保存
  2686. List<int> cropPageList = new List<int>();
  2687. for (int i = 0; i < PDFViewer.Document.PageCount; i++)
  2688. {
  2689. cropPageList.Clear();
  2690. cropPageList.Add(i);
  2691. CPDFPage cPDFPage = PDFViewer.Document.PageAtIndex(i);
  2692. if (PDFViewer.IsCropMode(i) == true)
  2693. {
  2694. Rect rect = cPDFPage.GetCropBounds();
  2695. PDFViewer?.CropPage(CPDFDisplayBox.CropBox, rect, cropPageList);
  2696. }
  2697. }
  2698. bool result = PDFViewer.Document.WriteToLoadedPath();
  2699. if (result)
  2700. {
  2701. if (!autosave)
  2702. {
  2703. PDFViewer.UndoManager.CanSave = false;
  2704. }
  2705. App.Current.Dispatcher.Invoke(() =>
  2706. {
  2707. //保存时更新缩略图
  2708. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  2709. try
  2710. {
  2711. if (info != null && !string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  2712. {
  2713. var size = PDFViewer.Document.GetPageSize(0);
  2714. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  2715. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  2716. if (File.Exists(folderPath))
  2717. File.Delete(folderPath);
  2718. DirectoryInfo folder = new DirectoryInfo(folderPath);
  2719. if (!folder.Exists)
  2720. folder.Create();
  2721. string imagePath = info.ThumbImgPath;
  2722. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  2723. {
  2724. string imageName = Guid.NewGuid().ToString();
  2725. imagePath = System.IO.Path.Combine(folderPath, imageName);
  2726. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  2727. {
  2728. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2729. }
  2730. }
  2731. else
  2732. {
  2733. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  2734. {
  2735. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2736. }
  2737. }
  2738. info.ThumbImgPath = imagePath;
  2739. SettingHelper.SetFileInfo(info);
  2740. }
  2741. }
  2742. catch
  2743. {
  2744. info.ThumbImgPath = null;
  2745. SettingHelper.SetFileInfo(info);
  2746. }
  2747. });
  2748. //编辑不要刷新,否则保存时会崩溃
  2749. if (PDFViewer.GetPDFEditCreateType() == ComPDFKit.PDFPage.CPDFEditType.None)
  2750. {
  2751. PDFViewer.ReloadDocument();
  2752. }
  2753. //PDFViewer.ReloadDocument();
  2754. }
  2755. else
  2756. {
  2757. //弹窗前 激活主窗体
  2758. //App.Current.MainWindow.Activate();
  2759. AlertsMessage alertsMessage = new AlertsMessage();
  2760. //文件被占用 保存失败时
  2761. alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2762. //显示当前窗体,防止窗口置底
  2763. App.Current.MainWindow.Activate();
  2764. if (alertsMessage.result == ContentResult.Ok)
  2765. return saveAsFile();
  2766. else
  2767. return false;
  2768. }
  2769. return result;
  2770. }
  2771. catch { return false; }
  2772. finally
  2773. {
  2774. if (!IsFileLocked)
  2775. {
  2776. ShowLeftTip(false);
  2777. }
  2778. }
  2779. }
  2780. /// <summary>
  2781. /// 另存为或新文档保存逻辑
  2782. /// </summary>
  2783. public bool saveAsFile(Action RedactionAction = null, String IsFormSave = null)
  2784. {
  2785. //是否来自savefile方法
  2786. if (IsFormSave == "FormSave")
  2787. {
  2788. var dlg = new Microsoft.Win32.SaveFileDialog();
  2789. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2790. dlg.FileName = PDFViewer.Document.FileName;
  2791. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2792. {
  2793. bool result = false;
  2794. if (RedactionAction != null)
  2795. {
  2796. //保存前进行标记密文处理应用或擦除
  2797. RedactionAction.Invoke();
  2798. }
  2799. if (App.OpenedFileList.Contains(dlg.FileName))
  2800. {
  2801. //文件已经被打开
  2802. AlertsMessage alertsMessage = new AlertsMessage();
  2803. alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2804. }
  2805. else
  2806. {
  2807. string oldpath = PDFViewer.Document.FilePath;
  2808. string openPassword = string.Empty;
  2809. string permissionsPassword = string.Empty;
  2810. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2811. if (SecurityInfo.NeedOpenPassword)
  2812. {
  2813. openPassword = SecurityInfo.OpenPassword;
  2814. passwordInfo.OpenPassword = openPassword;
  2815. }
  2816. if (SecurityInfo.NeedPermissionsPassword)
  2817. {
  2818. permissionsPassword = SecurityInfo.PermissionsPassword;
  2819. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2820. passwordInfo.PermissionsPassword = permissionsPassword;
  2821. }
  2822. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2823. Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
  2824. StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
  2825. if (resourceInfo != null)
  2826. {
  2827. using (Stream stream = resourceInfo.Stream)
  2828. {
  2829. BitmapFrame frame = null;
  2830. int width = 0;
  2831. int height = 0;
  2832. BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
  2833. if (decoder != null && decoder.Frames.Count > 0)
  2834. {
  2835. frame = decoder.Frames[0];
  2836. }
  2837. if (frame != null)
  2838. {
  2839. var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  2840. width = frame.PixelWidth;
  2841. height = frame.PixelHeight;
  2842. frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
  2843. watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
  2844. watermark.SetImage(ImageArray, width, height);
  2845. watermark.SetScale(1);
  2846. watermark.SetRotation(0);
  2847. watermark.SetOpacity(255);
  2848. watermark.SetFront(true);
  2849. watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
  2850. watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
  2851. watermark.SetFullScreen(false);
  2852. watermark.SetVertOffset(0);
  2853. watermark.SetHorizOffset(0);
  2854. watermark.SetHorizontalSpacing(0);
  2855. watermark.SetVerticalSpacing(0);
  2856. string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
  2857. watermark.SetPages(setpages);
  2858. watermark.UpdateWatermark();
  2859. PDFViewer.Document.ReleasePages();
  2860. PDFViewer.ReloadDocument();
  2861. }
  2862. }
  2863. }
  2864. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  2865. if (result)
  2866. {
  2867. mainViewModel.NewFile = false;
  2868. App.OpenedFileList.Remove(oldpath);
  2869. DoAfterSaveAs(dlg.FileName);
  2870. }
  2871. else
  2872. { //提示文件被其他软件占用 无法保存
  2873. AlertsMessage alertsMessage = new AlertsMessage();
  2874. alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2875. }
  2876. }
  2877. return result;
  2878. }
  2879. else
  2880. return false;
  2881. }
  2882. else
  2883. {
  2884. bool flg = false;
  2885. //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
  2886. if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && ((App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP == true || PDFViewer.UndoManager.PDFEditChanged == true))
  2887. {
  2888. DialogParameters value = new DialogParameters();
  2889. value.Add(ParameterNames.ViewContentViewModel, this);
  2890. value.Add(ParameterNames.Open, "saveAs");
  2891. dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
  2892. {
  2893. if (dialogResult.Result == ButtonResult.OK)
  2894. {
  2895. flg = true;
  2896. }
  2897. else
  2898. {
  2899. flg = false;
  2900. }
  2901. });
  2902. if (flg == false)
  2903. {
  2904. return false;
  2905. }
  2906. }
  2907. var dlg = new Microsoft.Win32.SaveFileDialog();
  2908. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2909. dlg.FileName = PDFViewer.Document.FileName;
  2910. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2911. {
  2912. bool result = false;
  2913. if (RedactionAction != null)
  2914. {
  2915. //保存前进行标记密文处理应用或擦除
  2916. RedactionAction.Invoke();
  2917. }
  2918. if (App.OpenedFileList.Contains(dlg.FileName))
  2919. {
  2920. //文件已经被占用
  2921. AlertsMessage alertsMessage = new AlertsMessage();
  2922. alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2923. }
  2924. else
  2925. {
  2926. string oldpath = PDFViewer.Document.FilePath;
  2927. string openPassword = string.Empty;
  2928. string permissionsPassword = string.Empty;
  2929. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2930. if (SecurityInfo.NeedOpenPassword)
  2931. {
  2932. openPassword = SecurityInfo.OpenPassword;
  2933. passwordInfo.OpenPassword = openPassword;
  2934. }
  2935. if (SecurityInfo.NeedPermissionsPassword)
  2936. {
  2937. permissionsPassword = SecurityInfo.PermissionsPassword;
  2938. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2939. passwordInfo.PermissionsPassword = permissionsPassword;
  2940. }
  2941. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2942. //是否需要加水印
  2943. if (flg == true)
  2944. {
  2945. Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
  2946. StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
  2947. if (resourceInfo != null)
  2948. {
  2949. using (Stream stream = resourceInfo.Stream)
  2950. {
  2951. BitmapFrame frame = null;
  2952. int width = 0;
  2953. int height = 0;
  2954. BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
  2955. if (decoder != null && decoder.Frames.Count > 0)
  2956. {
  2957. frame = decoder.Frames[0];
  2958. }
  2959. if (frame != null)
  2960. {
  2961. var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  2962. width = frame.PixelWidth;
  2963. height = frame.PixelHeight;
  2964. frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
  2965. watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
  2966. watermark.SetImage(ImageArray, width, height);
  2967. watermark.SetScale(1);
  2968. watermark.SetRotation(0);
  2969. watermark.SetOpacity(255);
  2970. watermark.SetFront(true);
  2971. watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
  2972. watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
  2973. watermark.SetFullScreen(false);
  2974. watermark.SetVertOffset(0);
  2975. watermark.SetHorizOffset(0);
  2976. watermark.SetHorizontalSpacing(0);
  2977. watermark.SetVerticalSpacing(0);
  2978. string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
  2979. watermark.SetPages(setpages);
  2980. watermark.UpdateWatermark();
  2981. PDFViewer.Document.ReleasePages();
  2982. PDFViewer.ReloadDocument();
  2983. }
  2984. }
  2985. }
  2986. }
  2987. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  2988. if (result)
  2989. {
  2990. mainViewModel.NewFile = false;
  2991. App.OpenedFileList.Remove(oldpath);
  2992. DoAfterSaveAs(dlg.FileName);
  2993. }
  2994. else
  2995. {
  2996. //文件已经被占用
  2997. AlertsMessage alertsMessage = new AlertsMessage();
  2998. alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2999. }
  3000. }
  3001. return result;
  3002. }
  3003. else
  3004. return false;
  3005. }
  3006. }
  3007. /// <summary>
  3008. /// 转档、压缩、合并、分享前自动保存
  3009. /// </summary>
  3010. public async Task<bool> SaveBeforeOption(bool NoIAP = false)
  3011. {
  3012. if (NoIAP == false)
  3013. { //添加付费拦截锁
  3014. if (!ServiceHelper.IAPBeforeFunction())
  3015. {
  3016. return false;
  3017. }
  3018. }
  3019. bool result = true;
  3020. //因配合权益弹窗弹出,暂时移除可保存条件判断
  3021. //if (PDFViewer.UndoManager.CanSave)
  3022. {
  3023. string title = "Saving File";
  3024. App.mainWindowViewModel.SetProcessValue(title, 80, 100, false);
  3025. //让保存的效果更明显
  3026. await Task.Delay(200);
  3027. //合并前自动保存一次
  3028. result = saveFile(true);
  3029. App.mainWindowViewModel.SetProcessValue(title, 100, 100, false);
  3030. }
  3031. //方便其他调用的地方可以异步 await调用,增加显示保存过程的效果
  3032. return result;
  3033. }
  3034. /// <summary>
  3035. /// 另存为Flatten
  3036. /// </summary>
  3037. private void saveAsFlatten()
  3038. {
  3039. //添加付费拦截锁
  3040. if (!ServiceHelper.IAPBeforeFunction())
  3041. {
  3042. return;
  3043. }
  3044. bool flg = false;
  3045. //权益弹窗
  3046. //PDFViewer.UndoManager.PDFEditChanged为是否在编辑中对文档进行了改动
  3047. if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && ((App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP == true || PDFViewer.UndoManager.PDFEditChanged == true))
  3048. {
  3049. DialogParameters value = new DialogParameters();
  3050. value.Add(ParameterNames.ViewContentViewModel, this);
  3051. dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
  3052. {
  3053. if (dialogResult.Result == ButtonResult.OK)
  3054. {
  3055. flg = true;
  3056. }
  3057. else
  3058. {
  3059. flg = false;
  3060. }
  3061. });
  3062. if (flg == false)
  3063. {
  3064. return;
  3065. }
  3066. }
  3067. var dlg = new SaveFileDialog();
  3068. dlg.Filter = Properties.Resources.OpenDialogFilter;
  3069. dlg.FileName = PDFViewer.Document.FileName + "_Flattened.pdf";
  3070. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  3071. {
  3072. saveFile();
  3073. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FilePath);
  3074. if (kmdoc == null)
  3075. {
  3076. return;
  3077. }
  3078. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  3079. if (result)
  3080. {
  3081. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  3082. }
  3083. kmdoc.Release();
  3084. }
  3085. }
  3086. /// <summary>
  3087. /// 另存为后进行的操作
  3088. /// 重新打开新文档
  3089. /// </summary>
  3090. /// <param name="targetPath"></param>
  3091. public void DoAfterSaveAs(string targetPath)
  3092. {
  3093. PDFViewer.UndoManager.CanSave = false;
  3094. //从新路径重新加载
  3095. //用mianviewmodel.openfile的方法会有其他模块的pdfview更新不过来的情况,需要调整成现有的方法
  3096. PDFViewer.CloseDocument();
  3097. PDFViewer.InitDocument(targetPath);
  3098. //处理解密相关的逻辑 现在的逻辑另存为自动打开后会需要重新输入密码
  3099. CheckPassword();
  3100. PDFViewer.Load();
  3101. //更新打开文件列表
  3102. if (App.OpenedFileList.Contains(targetPath) == false)
  3103. {
  3104. App.OpenedFileList.Add(targetPath);
  3105. }
  3106. //打开文件后,不管是新文件还是旧文件都需要更新排序
  3107. SettingHelper.SortRecentOpenFiles(targetPath);
  3108. //更新页签文件名
  3109. mainViewModel.FilePath = PDFViewer.Document.FilePath;
  3110. App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
  3111. //刷新Bota 和底部工具栏的PDFviwer对象,不需要重新刷新注释工具栏
  3112. LoadControl(true);
  3113. }
  3114. /// <summary>
  3115. /// 显示前添加内容到Region
  3116. /// </summary>
  3117. /// <param name="isPageEdit"></param>
  3118. private void ShowContent(string currentBar, bool isToolMode = false)
  3119. {
  3120. GridVisibility = Visibility.Visible;
  3121. //显示页面编辑或其他工具
  3122. if (currentBar == "TabItemPageEdit" || isToolMode)
  3123. {
  3124. if (currentBar == "TabItemPageEdit")//进入页面编辑
  3125. {
  3126. if (GridToolRow != 1)
  3127. {
  3128. GridToolRow = 1;
  3129. }
  3130. if (GridToolRowSpan != 3)
  3131. {
  3132. GridToolRowSpan = 3;
  3133. }
  3134. }
  3135. else//进入水印等其他工具模式
  3136. {
  3137. GridVisibility = Visibility.Collapsed;
  3138. if (GridToolRow != 0)
  3139. {
  3140. GridToolRow = 0;
  3141. }
  3142. if (GridToolRowSpan != 4)
  3143. {
  3144. GridToolRowSpan = 4;
  3145. }
  3146. }
  3147. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  3148. UpdateShowContent(currentBar);
  3149. }
  3150. else
  3151. {
  3152. if (GridToolRow != 1)
  3153. {
  3154. GridToolRow = 1;
  3155. }
  3156. UpdateShowContent(currentBar);
  3157. }
  3158. }
  3159. /// <summary>
  3160. /// 从二级工具栏进入需要修改界面布局的场景
  3161. /// </summary>
  3162. /// <param name="EditToolName"></param>
  3163. private void EnterEditTools(StringWithUnicode EditToolName)
  3164. {
  3165. EnterSelectedEditTool(EditToolName);
  3166. }
  3167. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  3168. {
  3169. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  3170. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  3171. {
  3172. PDFViewer.Document.ReleasePages();
  3173. PDFViewer.ReloadDocument();
  3174. }
  3175. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  3176. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  3177. {
  3178. region.AddToRegion(ViwerRegionName, PDFViewer);
  3179. }
  3180. CurrentBar = "TabItemTool";
  3181. EnterSelectedBar(CurrentBar);
  3182. }
  3183. /// <summary>
  3184. /// 二级菜单指定目标处理
  3185. /// </summary>
  3186. /// <param name="e"></param>
  3187. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  3188. {
  3189. CurrentBar = EditToolName.EditToolsContentName;
  3190. EnterToolMode(CurrentBar);
  3191. }
  3192. /// <summary>
  3193. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  3194. /// </summary>
  3195. /// <param name="targetToolMode">要导航过去的控件名称</param>
  3196. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  3197. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  3198. {
  3199. IsLoading = Visibility.Visible;
  3200. await Task.Delay(3);
  3201. NavigationParameters param = new NavigationParameters();
  3202. if (valuePairs == null)
  3203. {
  3204. param.Add(ParameterNames.PDFViewer, PDFViewer);
  3205. param.Add(ParameterNames.ViewContentViewModel, this);
  3206. }
  3207. else//有传入其他内容的参数时
  3208. {
  3209. param = valuePairs;
  3210. }
  3211. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  3212. ShowContent(CurrentBar, true);
  3213. IsLoading = Visibility.Collapsed;
  3214. }
  3215. private void EnterSelectedBar(string currentBar)
  3216. {
  3217. NavigationParameters param = new NavigationParameters();
  3218. param.Add(ParameterNames.PDFViewer, PDFViewer);
  3219. param.Add(ParameterNames.ViewContentViewModel, this);
  3220. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  3221. if (currentBar == "TabItemScan")
  3222. {
  3223. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  3224. }
  3225. ShowContent(currentBar);
  3226. }
  3227. /// <summary>
  3228. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  3229. /// </summary>
  3230. public void ExitToolMode()
  3231. {
  3232. ToolContentVisible = Visibility.Collapsed;
  3233. if (isInPageEdit)
  3234. {
  3235. TabSelectedIndex = 0;
  3236. isInPageEdit = false;
  3237. }
  3238. }
  3239. /// <summary>
  3240. /// 刷新账号信息
  3241. /// </summary>
  3242. public void Refresh()
  3243. {
  3244. ServiceHelper.GetUser();
  3245. }
  3246. #endregion 方法
  3247. #region Navigate
  3248. public void OnNavigatedTo(NavigationContext navigationContext)
  3249. {
  3250. navigationContext.Parameters.TryGetValue(ParameterNames.PasswordInfo, out PasswordInfo);
  3251. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  3252. if (mainVM != null)
  3253. {
  3254. mainViewModel = mainVM;
  3255. mainViewModel.viewContentViewModel = this;
  3256. }
  3257. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  3258. if (pdfview != null)
  3259. {
  3260. PDFViewer = pdfview;
  3261. if (loadFile())
  3262. {
  3263. CheckHaveAllPermission();
  3264. }
  3265. }
  3266. //快捷键
  3267. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  3268. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  3269. //弹窗需要放到最后(确保在各字段赋值语句的后面),弹窗显示会触发控件的Loaded事件,会导致后续段没有赋值,而加载等事件继续往后跑了
  3270. //例如这里的问题 会因为显示注册弹窗,导致其他模块没有接受到正常的PDFviewer对象
  3271. Settings.Default.UserDate.CheckRegisterStatus();
  3272. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  3273. if (Settings.Default.UserDate.TodayRegister == false && App.IsLogin == false)
  3274. {
  3275. Settings.Default.UserDate.TodayRegister = true;
  3276. DateTime currentTime = DateTime.Now;
  3277. Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
  3278. Settings.Default.Save();
  3279. App.mainWindowViewModel.OpenRegister();
  3280. }
  3281. //需要在pdfview赋值后绑定
  3282. GlobalCommands.FullWindowCommand.RegisterCommand(new DelegateCommand(() => { OpenFullWindow(); }));
  3283. }
  3284. public bool IsNavigationTarget(NavigationContext navigationContext)
  3285. {
  3286. if (navigationContext != null)
  3287. {
  3288. //另存为打开导航进来时 不能新建一个实例
  3289. return true;
  3290. }
  3291. else
  3292. {
  3293. //一次性打开多个文件时,需要新建实例
  3294. return false;
  3295. }
  3296. }
  3297. public void OnNavigatedFrom(NavigationContext navigationContext)
  3298. {
  3299. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  3300. }
  3301. internal void FindPageEditContent(out Views.PageEdit.PageEditContent pageEditContent)
  3302. {
  3303. pageEditContent = null;
  3304. if (region.Regions.ContainsRegionWithName(ToolContentRegionName))
  3305. {
  3306. var views = region.Regions[ToolContentRegionName].Views;
  3307. var model = views.FirstOrDefault(q => q is Views.PageEdit.PageEditContent);
  3308. if (model is Views.PageEdit.PageEditContent page)
  3309. {
  3310. pageEditContent = page;
  3311. }
  3312. }
  3313. }
  3314. #endregion Navigate
  3315. }
  3316. }