ViewContentViewModel.cs 147 KB

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