ViewContentViewModel.cs 144 KB

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