ViewContentViewModel.cs 139 KB

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