ViewContentViewModel.cs 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856
  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.Settings;
  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 PDFSettings;
  48. using PDF_Master.Views;
  49. namespace PDF_Master.ViewModels
  50. {
  51. public class ViewContentViewModel : BindableBase, INavigationAware
  52. {
  53. #region 文案
  54. private string T_file;
  55. public string T_File
  56. {
  57. get { return T_file; }
  58. set
  59. {
  60. SetProperty(ref T_file, value);
  61. }
  62. }
  63. private string T_save;
  64. public string T_Save
  65. {
  66. get { return T_save; }
  67. set
  68. {
  69. SetProperty(ref T_save, value);
  70. }
  71. }
  72. private string T_undo;
  73. public string T_Undo
  74. {
  75. get { return T_undo; }
  76. set
  77. {
  78. SetProperty(ref T_undo, value);
  79. }
  80. }
  81. private string T_redo;
  82. public string T_Redo
  83. {
  84. get { return T_redo; }
  85. set
  86. {
  87. SetProperty(ref T_redo, value);
  88. }
  89. }
  90. private string T_annotation;
  91. public string T_Annotation
  92. {
  93. get { return T_annotation; }
  94. set
  95. {
  96. SetProperty(ref T_annotation, value);
  97. }
  98. }
  99. private string T_pageEdit;
  100. public string T_PageEdit
  101. {
  102. get { return T_pageEdit; }
  103. set
  104. {
  105. SetProperty(ref T_pageEdit, value);
  106. }
  107. }
  108. private string T_converter;
  109. public string T_Converter
  110. {
  111. get { return T_converter; }
  112. set
  113. {
  114. SetProperty(ref T_converter, value);
  115. }
  116. }
  117. private string T_fillSign;
  118. public string T_FillSign
  119. {
  120. get { return T_fillSign; }
  121. set
  122. {
  123. SetProperty(ref T_fillSign, value);
  124. }
  125. }
  126. private string T_tools;
  127. public string T_Tools
  128. {
  129. get { return T_tools; }
  130. set
  131. {
  132. SetProperty(ref T_tools, value);
  133. }
  134. }
  135. private string T_print;
  136. public string T_Print
  137. {
  138. get { return T_print; }
  139. set
  140. {
  141. SetProperty(ref T_print, value);
  142. }
  143. }
  144. private string T_share;
  145. public string T_Share
  146. {
  147. get { return T_share; }
  148. set
  149. {
  150. SetProperty(ref T_share, value);
  151. }
  152. }
  153. private string T_properties;
  154. public string T_Properties
  155. {
  156. get { return T_properties; }
  157. set
  158. {
  159. SetProperty(ref T_properties, value);
  160. }
  161. }
  162. private void InitStirng()
  163. {
  164. T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
  165. T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
  166. T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
  167. T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
  168. T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
  169. T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
  170. T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
  171. T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
  172. T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
  173. T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
  174. T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
  175. T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
  176. }
  177. #endregion 文案
  178. #region 属性、变量
  179. public bool IsMultiSelected { get; set; } = false;
  180. public OpenFileInfo OpenFileInfo = null;
  181. public CPDFViewer PDFViewer { get; set; }
  182. public bool ReadModeIsShowProperty { get; set; } = false;
  183. public MainContentViewModel mainViewModel { get; set; }
  184. public IRegionManager region;
  185. public IDialogService dialogs;
  186. public IEventAggregator events;
  187. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  188. public string ViwerRegionName { get; set; }
  189. /// <summary>
  190. /// 分屏视图的region名称
  191. /// </summary>
  192. public string SplitViewerRegionName { get; set; }
  193. /// <summary>
  194. /// OCR视图名称
  195. /// </summary>
  196. public string OCRViewerRegionName { get; set; }
  197. public string BOTARegionName { get; set; }
  198. public string PropertyRegionName { get; set; }
  199. public string ToolContentRegionName { get; set; }
  200. public string ToolsBarContentRegionName { get; set; }
  201. /// <summary>
  202. /// 顶部提示的Content
  203. /// </summary>
  204. public string TipContentRegionName { get; set; }
  205. public string LeftTipContentRegionName { get; set; }
  206. //便签弹窗
  207. public string NotePopupRegionName { get; set; }
  208. public string ReadModeRegionName { get; set; }
  209. public string TextEditContentRegionName { get; set; }
  210. public string BackgroundContentRegionName { get; set; }
  211. public PasswordInfo PasswordInfo = new PasswordInfo();
  212. //若point不赋值或从列表中找不到point,系统会提供默认值为(0,0)的新point,所以改用Tuple<int,int>
  213. public List<FillAndSignIsShape> FillAndSign = new List<FillAndSignIsShape>();
  214. /// <summary>
  215. /// 签名列表
  216. /// </summary>
  217. public List<Tuple<int, int>> AnnotSignatures = new List<Tuple<int, int>>();
  218. /// <summary>
  219. /// 文档的密码
  220. /// </summary>
  221. public string PassWord { get; set; }
  222. public PasswordInfo passwordInfo = new PasswordInfo();
  223. private Visibility tipVisible = Visibility.Collapsed;
  224. /// <summary>
  225. /// 顶部提示栏的显示状态
  226. /// </summary>
  227. public bool IsFileLocked = false;
  228. public Visibility TipVisible
  229. {
  230. get { return tipVisible; }
  231. set
  232. {
  233. SetProperty(ref tipVisible, value);
  234. }
  235. }
  236. private Visibility leftTipVisible = Visibility.Collapsed;
  237. public Visibility LeftTipVisible
  238. {
  239. get { return leftTipVisible; }
  240. set
  241. {
  242. SetProperty(ref leftTipVisible, value);
  243. }
  244. }
  245. private Visibility notePopupVisible = Visibility.Collapsed;
  246. public Visibility NotePopupVisible
  247. {
  248. get { return notePopupVisible; }
  249. set
  250. {
  251. SetProperty(ref notePopupVisible, value);
  252. }
  253. }
  254. public bool IsNoteAdd = false;
  255. private double canvasNoteLeft;
  256. public double CanvasNoteLeft
  257. {
  258. get { return canvasNoteLeft; }
  259. set
  260. {
  261. SetProperty(ref canvasNoteLeft, value);
  262. }
  263. }
  264. private double canvasNoteBottom;
  265. public double CanvasNoteBottom
  266. {
  267. get { return canvasNoteBottom; }
  268. set
  269. {
  270. SetProperty(ref canvasNoteBottom, value);
  271. }
  272. }
  273. /// <summary>
  274. /// 底部工具栏 RegionName
  275. /// </summary>
  276. public string BottomToolRegionName { get; set; }
  277. private bool _isInPageEdit = false;
  278. /// <summary>
  279. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  280. /// </summary>
  281. public bool isInPageEdit
  282. {
  283. get { return _isInPageEdit; }
  284. set
  285. {
  286. SetProperty(ref _isInPageEdit, value);
  287. //if (!value)
  288. //{
  289. // CanRedo = PDFViewer.UndoManager.CanRedo;
  290. // CanUndo = PDFViewer.UndoManager.CanUndo;
  291. //}
  292. }
  293. }
  294. public Action PageEditUndo { get; set; }
  295. public Action PageEditRedo { get; set; }
  296. /// <summary>
  297. ///工具条
  298. ///0:收起
  299. ///40:显示
  300. /// </summary>
  301. private int toolRowHeight = 40;
  302. public int ToolRowHeight
  303. {
  304. get { return toolRowHeight; }
  305. set
  306. {
  307. SetProperty(ref toolRowHeight, value);
  308. }
  309. }
  310. /// <summary>
  311. /// 水印,背景侧边栏宽度
  312. /// 0:收起
  313. /// 260:显示
  314. /// </summary>
  315. private int propertyColumnWidth = 0;
  316. public int PropertyColumnWidth
  317. {
  318. get { return propertyColumnWidth; }
  319. set
  320. {
  321. SetProperty(ref propertyColumnWidth, value);
  322. }
  323. }
  324. private int gridToolRow = 1;
  325. /// <summary>
  326. /// 控制ToolContent的Row
  327. /// </summary>
  328. public int GridToolRow
  329. {
  330. get { return gridToolRow; }
  331. set
  332. {
  333. SetProperty(ref gridToolRow, value);
  334. }
  335. }
  336. private int gridToolRowSpan = 3;
  337. /// <summary>
  338. /// 控制ToolContent的RowSpan
  339. /// </summary>
  340. public int GridToolRowSpan
  341. {
  342. get { return gridToolRowSpan; }
  343. set
  344. {
  345. SetProperty(ref gridToolRowSpan, value);
  346. }
  347. }
  348. private Visibility toolContentVisible = Visibility.Collapsed;
  349. /// <summary>
  350. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  351. /// 留意:显示前需要先注入内容、设置好行和跨行数
  352. /// </summary>
  353. public Visibility ToolContentVisible
  354. {
  355. get { return toolContentVisible; }
  356. set
  357. {
  358. SetProperty(ref toolContentVisible, value);
  359. }
  360. }
  361. private Visibility gridVisibility = Visibility.Visible;
  362. /// <summary>
  363. /// 是否正在加载中
  364. /// </summary>
  365. public Visibility GridVisibility
  366. {
  367. get { return gridVisibility; }
  368. set
  369. {
  370. SetProperty(ref gridVisibility, value);
  371. }
  372. }
  373. private Visibility isLoading = Visibility.Collapsed;
  374. private Visibility ocrContentVisible = Visibility.Collapsed;
  375. public Visibility OCRContentVisible
  376. {
  377. get { return ocrContentVisible; }
  378. set
  379. {
  380. SetProperty(ref ocrContentVisible, value);
  381. }
  382. }
  383. /// <summary>
  384. /// 是否正在加载中
  385. /// </summary>
  386. public Visibility IsLoading
  387. {
  388. get { return isLoading; }
  389. set
  390. {
  391. SetProperty(ref isLoading, value);
  392. }
  393. }
  394. private Visibility converterBarContentVisible = Visibility.Collapsed;
  395. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  396. ///// <summary>
  397. ///// 控制ToolsBarContent的显示
  398. ///// 留意:显示前需要先注入内容、设置好行和跨行数
  399. ///// </summary>
  400. //public Visibility ConverterBarContentVisible
  401. //{
  402. // get { return converterBarContentVisible; }
  403. // set
  404. // {
  405. // SetProperty(ref converterBarContentVisible, value);
  406. // }
  407. //}
  408. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  409. /// <summary>
  410. /// 控制ToolsBarContent的显示
  411. /// 留意:显示前需要先注入内容、设置好行和跨行数
  412. /// </summary>
  413. public Visibility ToolsBarContentVisible
  414. {
  415. get { return toolsBarContentVisible; }
  416. set
  417. {
  418. SetProperty(ref toolsBarContentVisible, value);
  419. }
  420. }
  421. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  422. /// <summary>
  423. /// 控制ToolsBarContent的显示
  424. /// 留意:显示前需要先注入内容、设置好行和跨行数
  425. /// </summary>
  426. public Visibility TextEditToolContentVisible
  427. {
  428. get { return textEditToolContentVisible; }
  429. set
  430. {
  431. SetProperty(ref textEditToolContentVisible, value);
  432. }
  433. }
  434. private bool isPorpertyOpen = false;
  435. /// <summary>
  436. /// 属性栏是否展开
  437. /// </summary>
  438. public bool IsPropertyOpen
  439. {
  440. get { return isPorpertyOpen; }
  441. set
  442. {
  443. //如果设置为手动展开属性面板时,则不响应代码控制的展开
  444. //或者手动点击按钮时 也展开
  445. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty || FromClick)
  446. {
  447. if (mainViewModel.IsBookMode)
  448. {
  449. this.events.GetEvent<ReadModePropertyOpenEvent>().Publish(new ReadModePropertyOpenArgs() { Unicode = unicode });
  450. }
  451. SetProperty(ref isPorpertyOpen, value);
  452. }
  453. }
  454. }
  455. /// <summary>
  456. /// 是否是点击属性面板按钮
  457. /// </summary>
  458. private bool FromClick = false;
  459. private Visibility isReadMode = Visibility.Visible;
  460. /// <summary>
  461. ///是否为阅读模式
  462. /// </summary>
  463. public Visibility IsReadMode
  464. {
  465. get { return isReadMode; }
  466. set
  467. {
  468. SetProperty(ref isReadMode, value);
  469. }
  470. }
  471. private bool canSave;
  472. /// <summary>
  473. /// 是否可以保存
  474. /// </summary>
  475. public bool CanSave
  476. {
  477. get { return canSave; }
  478. set
  479. {
  480. if (events != null && canSave == false)
  481. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = "Clear", AppUnicode = unicode });
  482. SetProperty(ref canSave, value);
  483. }
  484. }
  485. private bool canUndo;
  486. /// <summary>
  487. /// 是否可以进行Undo
  488. /// </summary>
  489. public bool CanUndo
  490. {
  491. get { return canUndo; }
  492. set
  493. {
  494. SetProperty(ref canUndo, value);
  495. }
  496. }
  497. private bool canRedo;
  498. /// <summary>
  499. /// 是否可以进行Redo
  500. /// </summary>
  501. public bool CanRedo
  502. {
  503. get { return canRedo; }
  504. set
  505. {
  506. SetProperty(ref canRedo, value);
  507. }
  508. }
  509. private GridLength botaWidth = new GridLength(48);
  510. /// <summary>
  511. /// BOTA栏的宽度
  512. /// </summary>
  513. public GridLength BOTAWidth
  514. {
  515. get { return botaWidth; }
  516. set
  517. {
  518. SetProperty(ref botaWidth, value);
  519. if (botaWidth.Value <= 48)
  520. {
  521. OpenBOTA = false;
  522. }
  523. }
  524. }
  525. private int selectedIndex;
  526. /// <summary>
  527. /// 工具栏选中项的索引
  528. /// </summary>
  529. public int TabSelectedIndex
  530. {
  531. get { return selectedIndex; }
  532. set
  533. {
  534. SetProperty(ref selectedIndex, value);
  535. }
  536. }
  537. private bool openBOTA = false;
  538. /// <summary>
  539. /// 是否展开BOTA
  540. /// </summary>
  541. public bool OpenBOTA
  542. {
  543. get { return openBOTA; }
  544. set
  545. {
  546. SetProperty(ref openBOTA, value);
  547. if (openBOTA && BOTAWidth.Value <= 48)
  548. {
  549. BOTAWidth = new GridLength(260);
  550. }
  551. Settings.Default.AppProperties.InitialVIew.RememberBOTA = openBOTA;
  552. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  553. }
  554. }
  555. public SecurityInfo SecurityInfo = new SecurityInfo();
  556. private Dictionary<string, string> regionNameByTabItem;
  557. private Dictionary<string, string> barContentByTabItem;
  558. private string previousBar = "";
  559. public string CurrentBar = "";
  560. public string unicode = null;
  561. /// <summary>
  562. /// 自动保存的定时器
  563. /// </summary>
  564. private DispatcherTimer autoSaveTimer = new DispatcherTimer();
  565. /// <summary>
  566. /// 用来避免重复触发导航事件的标志符
  567. /// </summary>
  568. private bool isOpenFile = false;
  569. /// <summary>
  570. /// 鼠标滚轮缩放的缩放值
  571. /// </summary>
  572. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  573. /// <summary>
  574. /// 注释-链接,提示语
  575. /// </summary>
  576. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  577. public Visibility LinkAnnotTipVisibility
  578. {
  579. get { return linkAnnotTipVisibility; }
  580. set
  581. {
  582. SetProperty(ref linkAnnotTipVisibility, value);
  583. }
  584. }
  585. private string linkAnnotTipText = "Please use the scroll bar, thumbnail tool to locate the target page, click or box the area to select the target range";
  586. private bool isCreateLink = false;
  587. internal bool IsRightMenuSelectedTextAddLink = false;
  588. public string LinkAnnotTipText
  589. {
  590. get { return linkAnnotTipText; }
  591. set
  592. {
  593. SetProperty(ref linkAnnotTipText, value);
  594. }
  595. }
  596. #endregion 属性、变量
  597. #region 命令
  598. public DelegateCommand Load { get; set; }
  599. public DelegateCommand MouseDown { get; set; }
  600. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  601. public DelegateCommand SaveFile { get; set; }
  602. public DelegateCommand SaveAsFile { get; set; }
  603. public DelegateCommand SaveAsFlattenCommand { get; set; }
  604. public DelegateCommand UndoCommand { get; set; }
  605. public DelegateCommand RedoCommand { get; set; }
  606. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  607. public DelegateCommand PrintCommand { get; set; }
  608. public DelegateCommand SelectCommand { get; set; }
  609. public DelegateCommand SettingsCommand { get; set; }
  610. public DelegateCommand ShareCommand { get; set; }
  611. public DelegateCommand<object> CreateLinkCommand { get; set; }
  612. public DelegateCommand PropertyCommand { get; set; }
  613. public DelegateCommand ShowInFolderCommand { get; set; }
  614. public DelegateCommand CompressCommand { get; set; }
  615. public DelegateCommand MergeFileCommand { get; set; }
  616. public DelegateCommand EncryptCommand { get; set; }
  617. public DelegateCommand DecryptCommand { get; set; }
  618. public DelegateCommand<string> ConvertCommand { get; set; }
  619. public DelegateCommand CloseWindowCommand { get; set; }
  620. public DelegateCommand OpenFileCommand { get; set; }
  621. public DelegateCommand<string> HelpCommand { get; set; }
  622. public DelegateCommand CreateBlankFileCommand { get; set; }
  623. public DelegateCommand CreateFromFile { get; set; }
  624. public DelegateCommand ClosePropertyCommand { get; set; }
  625. public DelegateCommand<object> OpenPropertyCommand { get; set; }
  626. #endregion 命令
  627. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  628. {
  629. InitStirng();
  630. region = regionManager;
  631. dialogs = dialogService;
  632. events = eventAggregator;
  633. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  634. Load = new DelegateCommand(LoadControl);
  635. MouseDown = new DelegateCommand(MouseDownEvent);
  636. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  637. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  638. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  639. UndoCommand = new DelegateCommand(Undo);
  640. RedoCommand = new DelegateCommand(Redo);
  641. ShareCommand = new DelegateCommand(share);
  642. PropertyCommand = new DelegateCommand(property);
  643. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  644. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  645. CompressCommand = new DelegateCommand(compress);
  646. MergeFileCommand = new DelegateCommand(mergeFile);
  647. EncryptCommand = new DelegateCommand(encrypt);
  648. DecryptCommand = new DelegateCommand(decrypt);
  649. ConvertCommand = new DelegateCommand<string>(convert);
  650. CloseWindowCommand = new DelegateCommand(closeWindow);
  651. OpenFileCommand = new DelegateCommand(openfile);
  652. HelpCommand = new DelegateCommand<string>(help);
  653. CreateBlankFileCommand = new DelegateCommand(createBlankFile);
  654. CreateFromFile = new DelegateCommand(createfromFile);
  655. OpenPropertyCommand = new DelegateCommand<object>(openProperty);
  656. ViwerRegionName = RegionNames.ViwerRegionName;
  657. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  658. BOTARegionName = RegionNames.BOTARegionName;
  659. PropertyRegionName = RegionNames.PropertyRegionName;
  660. BottomToolRegionName = RegionNames.BottomToolRegionName;
  661. ReadModeRegionName = RegionNames.ReadModeRegionName;
  662. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  663. PrintCommand = new DelegateCommand(ShowPrintDialog);
  664. SelectCommand = new DelegateCommand(SelectClick);
  665. SettingsCommand = new DelegateCommand(SettingsEvent);
  666. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  667. ClosePropertyCommand = new DelegateCommand(CloseProperty);
  668. //未显示时无法注册上Region名称
  669. ToolContentVisible = Visibility.Visible;
  670. ToolsBarContentVisible = Visibility.Visible;
  671. OCRContentVisible = Visibility.Visible;
  672. TipVisible = Visibility.Visible;
  673. TipContentRegionName = RegionNames.TipContentRegionName;
  674. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  675. NotePopupRegionName = RegionNames.NotePopupRegionName;
  676. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  677. ToolContentRegionName = Guid.NewGuid().ToString();
  678. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  679. TextEditContentRegionName = Guid.NewGuid().ToString();
  680. ToolContentVisible = Visibility.Collapsed;
  681. ToolsBarContentVisible = Visibility.Collapsed;
  682. OCRContentVisible = Visibility.Collapsed;
  683. TipVisible = Visibility.Collapsed;
  684. regionNameByTabItem = new Dictionary<string, string>();
  685. barContentByTabItem = new Dictionary<string, string>();
  686. InitialregionNameByTabItem(ref regionNameByTabItem);
  687. InitialbarContentByTabItem(ref barContentByTabItem);
  688. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  689. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  690. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTipAsync, e => e.Unicode == unicode);
  691. //TODO:根据缓存 选择用户上次选择的菜单
  692. CurrentBar = "TabItemAnnotation";
  693. EnterSelectedBar("TabItemAnnotation");
  694. StartAutoSave();
  695. }
  696. /// <summary>
  697. /// 进入全屏模式
  698. /// </summary>
  699. private void OpenFullWindow()
  700. {
  701. DialogParameters parameters = new DialogParameters();
  702. //因为全屏模式可能需要设置特定的页面模式,所以只传文件路径,新建一个PDFview对象
  703. parameters.Add(ParameterNames.FilePath, PDFViewer.Document.FilePath);
  704. parameters.Add(ParameterNames.PassWord, PDFViewer.Tag == null ? "" : PDFViewer.Tag.ToString());
  705. dialogs.ShowDialog(DialogNames.FullScreenDialog, parameters, e =>
  706. {
  707. if (e.Result == ButtonResult.Cancel)
  708. {
  709. //TODO:弹窗提示打开全屏模式失败
  710. AlertsMessage alertsMessage = new AlertsMessage();
  711. alertsMessage.ShowDialog("", "Error", "OK");
  712. return;
  713. }
  714. });
  715. }
  716. /// <summary>
  717. /// 点击展开折叠属性面板
  718. /// </summary>
  719. /// <param name="obj"></param>
  720. private void openProperty(object obj)
  721. {
  722. FromClick = true;
  723. IsPropertyOpen = (bool)obj;
  724. FromClick = false;
  725. }
  726. /// <summary>
  727. /// 开始自动保存
  728. /// </summary>
  729. public void StartAutoSave()
  730. {
  731. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  732. if (autoSave)
  733. {
  734. var interval = Settings.Default.AppProperties.Description.AutoSaveInterval;
  735. if (autoSaveTimer == null)
  736. {
  737. autoSaveTimer = new DispatcherTimer();
  738. }
  739. autoSaveTimer.Stop();
  740. autoSaveTimer.Interval = TimeSpan.FromMinutes(interval);
  741. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  742. autoSaveTimer.Tick += AutoSaveTimer_Tick;
  743. autoSaveTimer.Start();
  744. }
  745. }
  746. /// <summary>
  747. /// 释放定时器
  748. /// 不释放定时器可能会一直运行并占用内存,导致内存泄露
  749. /// </summary>
  750. public void CloseAutoSave()
  751. {
  752. autoSaveTimer.Stop();
  753. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  754. autoSaveTimer = null;
  755. }
  756. private void AutoSaveTimer_Tick(object sender, EventArgs e)
  757. {
  758. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  759. if (autoSave && !mainViewModel.NewFile && PDFViewer.UndoManager.CanSave)
  760. {
  761. //自动保存仅针对已经有文件路径的文档
  762. saveFile();
  763. App.Current.MainWindow.Activate();
  764. }
  765. }
  766. private void MouseDownEvent()
  767. {
  768. if (NotePopupVisible == Visibility.Visible && IsNoteAdd == false)
  769. {
  770. NotePopupVisible = Visibility.Collapsed;
  771. if (region.Regions.ContainsRegionWithName(NotePopupRegionName))
  772. {
  773. var views = region.Regions[NotePopupRegionName].Views;
  774. foreach (var item in views)
  775. {
  776. if (item is StickyNotePopup sticky)
  777. {
  778. var contentRegion = region.Regions[NotePopupRegionName];
  779. contentRegion.Remove(sticky);
  780. break;
  781. }
  782. }
  783. }
  784. }
  785. }
  786. private async void createfromFile()
  787. {
  788. string txt = Properties.Resources.txtex;
  789. string word = Properties.Resources.wordex;
  790. string ppt = Properties.Resources.pptex;
  791. string excel = Properties.Resources.excelex;
  792. string html = Properties.Resources.htmlex;
  793. string image = Properties.Resources.imageex;
  794. string allfiles = txt + word + excel + ppt + image + html;
  795. OpenFileDialog dialog = new OpenFileDialog();
  796. dialog.Multiselect = true;
  797. dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
  798. $"Microsoft Office Word({word})|{word}|" +
  799. $"Microsoft Office Excel({excel})|{excel}|" +
  800. $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
  801. $"Txt({txt})|{txt}|" +
  802. $"Picture({image})|{image}|" +
  803. $"Html({html})|{html}");
  804. if ((bool)dialog.ShowDialog())
  805. {
  806. for (int i = 0; i < dialog.FileNames.Length; i++)
  807. {
  808. if (App.OpenedFileList.Contains(dialog.FileNames[i]))
  809. {
  810. App.mainWindowViewModel.SelectItem(dialog.FileNames[i]);
  811. }
  812. else
  813. {
  814. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  815. {
  816. App.mainWindowViewModel.AddTabItem(dialog.FileNames[i]);
  817. }));
  818. await Task.Delay(20);
  819. ToolMethod.SetFileThumbImg(dialog.FileNames[i]);
  820. }
  821. }
  822. }
  823. }
  824. /// <summary>
  825. ///创建空白文档
  826. /// </summary>
  827. private async void createBlankFile()
  828. {
  829. App.mainWindowViewModel.AddTab.Execute();
  830. await Task.Delay(30);
  831. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
  832. }
  833. private void help(string args)
  834. {
  835. string url = "";
  836. switch (args)
  837. {
  838. case "Guid":
  839. //打开内嵌文档
  840. if (App.OpenedFileList.Contains(App.GuidPDFPath))
  841. {
  842. //如果已经打开时,则选中内嵌文档
  843. App.mainWindowViewModel.SelectItem(App.GuidPDFPath);
  844. return;
  845. }
  846. if (File.Exists(App.GuidPDFPath))
  847. {
  848. App.mainWindowViewModel.AddTabItem(App.GuidPDFPath);
  849. }
  850. break;
  851. case "Online":
  852. url = @"https://www.pdfreaderpro.com/windows/help";
  853. break;
  854. case "More":
  855. url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
  856. break;
  857. case "Template":
  858. url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
  859. break;
  860. case "Blog":
  861. //TODO:显示订阅电子报弹窗
  862. break;
  863. case "ComPDF":
  864. url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
  865. break;
  866. case "FeedBack":
  867. //调用邮箱 发送邮件
  868. StringBuilder sr = new StringBuilder();
  869. sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
  870. System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
  871. break;
  872. default:
  873. break;
  874. }
  875. if (!string.IsNullOrEmpty(url))
  876. {
  877. //需要跳转网页的情况
  878. System.Diagnostics.Process.Start(url);
  879. }
  880. }
  881. /// <summary>
  882. /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
  883. /// </summary>
  884. private void openfile()
  885. {
  886. OpenFileDialog openFileDialog = new OpenFileDialog();
  887. openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
  888. openFileDialog.Multiselect = true;
  889. if ((bool)openFileDialog.ShowDialog())
  890. {
  891. if (openFileDialog.FileNames.Count() == 1)
  892. {
  893. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  894. {
  895. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  896. }
  897. else
  898. {
  899. App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
  900. }
  901. ToolMethod.SetFileThumbImg(openFileDialog.FileName);
  902. }
  903. else
  904. {
  905. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  906. if (fileList.Count <= 0)
  907. {
  908. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  909. return;
  910. }
  911. mainViewModel.OpenFile(fileList[0]);
  912. for (int i = 1; i < fileList.Count(); i++)
  913. {
  914. if (!App.OpenedFileList.Contains(fileList[i]))
  915. {
  916. App.mainWindowViewModel.AddTabItem(fileList[i]);
  917. }
  918. ToolMethod.SetFileThumbImg(fileList[i]);
  919. }
  920. }
  921. }
  922. }
  923. /// <summary>
  924. /// 关闭当前窗体
  925. /// </summary>
  926. private void closeWindow()
  927. {
  928. App.Current.MainWindow.Close();
  929. }
  930. /// <summary>
  931. /// 转档
  932. /// </summary>
  933. /// <param name="obj"></param>
  934. private void convert(string obj)
  935. {
  936. if (!string.IsNullOrEmpty(obj))
  937. {
  938. DialogParameters value = new DialogParameters();
  939. value.Add(ParameterNames.PDFViewer, PDFViewer);
  940. switch (obj)
  941. {
  942. case "Word":
  943. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  944. {
  945. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  946. converterDialogsModel.OnOpened((DialogResult)e);
  947. });
  948. break;
  949. case "Excel":
  950. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  951. {
  952. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  953. converterDialogsModel.OnOpened((DialogResult)e);
  954. });
  955. break;
  956. case "PPT":
  957. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  958. {
  959. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  960. converterDialogsModel.OnOpened((DialogResult)e);
  961. });
  962. break;
  963. case "RTF":
  964. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  965. {
  966. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  967. converterDialogsModel.OnOpened((DialogResult)e);
  968. });
  969. break;
  970. case "CSV":
  971. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  972. {
  973. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  974. converterDialogsModel.OnOpened((DialogResult)e);
  975. });
  976. break;
  977. case "HTML":
  978. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  979. {
  980. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  981. converterDialogsModel.OnOpened((DialogResult)e);
  982. });
  983. break;
  984. case "Text":
  985. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  986. {
  987. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  988. converterDialogsModel.OnOpened((DialogResult)e);
  989. });
  990. break;
  991. case "Image":
  992. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  993. {
  994. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  995. converterDialogsModel.OnOpened((DialogResult)e);
  996. });
  997. break;
  998. default:
  999. break;
  1000. }
  1001. }
  1002. }
  1003. /// <summary>
  1004. /// 解密
  1005. /// </summary>
  1006. private void decrypt()
  1007. {
  1008. ///无可用安全性设置的原因:
  1009. ///文件本身无安全性设置,且没有设置过密码
  1010. ///文件安全性已经被重置
  1011. ///
  1012. if ((!PDFViewer.Document.IsEncrypted && !SecurityInfo.IsPasswordChanged) || (SecurityInfo.IsPasswordRemoved))
  1013. {
  1014. AlertsMessage alertsMessage = new AlertsMessage();
  1015. alertsMessage.ShowDialog("", "No security settings available ", "OK");
  1016. }
  1017. else
  1018. {
  1019. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1020. if (result.IsDiscryptied)
  1021. {
  1022. if (result.Password != null)
  1023. {
  1024. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1025. }
  1026. ShowLeftTip(false);
  1027. DialogParameters value = new DialogParameters();
  1028. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1029. value.Add(ParameterNames.ViewContentViewModel, this);
  1030. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e =>
  1031. {
  1032. if (e.Result == ButtonResult.OK)
  1033. {
  1034. if (SecurityInfo.IsPasswordRemoved)
  1035. {
  1036. PDFViewer.UndoManager.CanSave = true;
  1037. }
  1038. ShowLeftTip(false);
  1039. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1040. }
  1041. });
  1042. }
  1043. }
  1044. }
  1045. /// <summary>
  1046. /// 加密
  1047. /// </summary>
  1048. private void encrypt()
  1049. {
  1050. if (!this.SecurityInfo.IsPasswordChanged)
  1051. {
  1052. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1053. if (result.IsDiscryptied)
  1054. {
  1055. if (result.Password != null)
  1056. {
  1057. if (PDFViewer.Document.UnlockWithPassword(result.Password))
  1058. {
  1059. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1060. }
  1061. }
  1062. }
  1063. }
  1064. DialogParameters value = new DialogParameters();
  1065. value.Add(ParameterNames.PDFViewer, this.PDFViewer);
  1066. value.Add(ParameterNames.ViewContentViewModel, this);
  1067. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
  1068. {
  1069. if (e.Result == ButtonResult.OK)
  1070. {
  1071. SecurityHelper.IsPasswordChanged = true;
  1072. if (this.SecurityInfo.IsPasswordChanged)
  1073. {
  1074. this.PDFViewer.UndoManager.CanSave = true;
  1075. }
  1076. this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
  1077. }
  1078. });
  1079. }
  1080. /// <summary>
  1081. /// 合并
  1082. /// </summary>
  1083. private void mergeFile()
  1084. {
  1085. DialogParameters value = new DialogParameters();
  1086. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1087. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  1088. }
  1089. /// <summary>
  1090. /// 压缩
  1091. /// </summary>
  1092. private void compress()
  1093. {
  1094. DialogParameters value = new DialogParameters();
  1095. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1096. dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
  1097. {
  1098. CompressDialogModel compressDialogModel = new CompressDialogModel();
  1099. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  1100. });
  1101. }
  1102. /// <summary>
  1103. /// 设置Tip状态栏的显示状态
  1104. /// </summary>
  1105. /// <param name="show">是否显示</param>
  1106. public void ShowTip(bool show)
  1107. {
  1108. if (show)
  1109. {
  1110. TipVisible = Visibility.Visible;
  1111. }
  1112. else
  1113. {
  1114. TipVisible = Visibility.Collapsed;
  1115. }
  1116. }
  1117. /// <summary>
  1118. /// 设置LeftTip状态栏的显示状态
  1119. /// </summary>
  1120. /// <param name="show">是否显示</param>
  1121. public void ShowLeftTip(bool show)
  1122. {
  1123. if (show)
  1124. {
  1125. LeftTipVisible = Visibility.Visible;
  1126. }
  1127. else
  1128. {
  1129. LeftTipVisible = Visibility.Collapsed;
  1130. }
  1131. }
  1132. public void CheckHaveAllPermission()
  1133. {
  1134. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  1135. {
  1136. ShowLeftTip(true);
  1137. NavigationParameters param = new NavigationParameters();
  1138. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1139. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  1140. }
  1141. }
  1142. public async void ShowSelectedTipAsync(ShowTipEventArgs showTipEventArgs)
  1143. {
  1144. switch (showTipEventArgs.enumTipKind)
  1145. {
  1146. case EnumTipKind.StatusNone:
  1147. ShowLeftTip(false);
  1148. break;
  1149. case EnumTipKind.StatusSetPasswordSuccessfully:
  1150. ShowLeftTip(true);
  1151. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  1152. break;
  1153. case EnumTipKind.StatusRemoveSecuritySuccessfully:
  1154. ShowLeftTip(false);
  1155. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1156. IsLoading = Visibility.Collapsed;
  1157. ShowTip(true);
  1158. await Task.Delay(3000);
  1159. //ReadModelTip = Visibility.Collapsed;
  1160. TipVisible = Visibility.Collapsed;
  1161. break;
  1162. default: break;
  1163. }
  1164. }
  1165. /// <summary>
  1166. /// 右键菜单创建链接
  1167. /// </summary>
  1168. /// <param name="obj"></param>
  1169. private void CreateLinkEvent(object obj)
  1170. {
  1171. if (obj is object[] objArry)
  1172. {
  1173. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  1174. {
  1175. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  1176. linkArgs.URI = string.Empty;
  1177. linkArgs.LinkType = LINK_TYPE.GOTO;
  1178. linkArgs.PageIndex = annotCommand.PageIndex;
  1179. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  1180. this.IsRightMenuCreateLink = true;
  1181. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  1182. lists.Add(linkArgs);
  1183. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  1184. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1185. PDFViewer.SetToolParam(annotArgs);
  1186. this.IsPropertyOpen = true;
  1187. }
  1188. }
  1189. }
  1190. private void CloseProperty()
  1191. {
  1192. FromClick = true;
  1193. IsPropertyOpen = false;
  1194. FromClick = false;
  1195. }
  1196. /// <summary>
  1197. /// 在文件资源管理器中显示
  1198. /// </summary>
  1199. private void ShowInFolder()
  1200. {
  1201. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  1202. }
  1203. private void property()
  1204. {
  1205. DialogParameters valuePairs = new DialogParameters();
  1206. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1207. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  1208. }
  1209. private void share()
  1210. {
  1211. try
  1212. {
  1213. var path = PDFViewer.Document.FilePath;
  1214. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  1215. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  1216. }
  1217. catch
  1218. {
  1219. AlertsMessage alertsMessage = new AlertsMessage();
  1220. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  1221. }
  1222. }
  1223. private void SettingsEvent()
  1224. {
  1225. DialogParameters value = new DialogParameters();
  1226. value.Add(ParameterNames.ViewContentViewModel, this);
  1227. AnnotToolContentViewModel annotToolContent = null;
  1228. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1229. {
  1230. var views = region.Regions[ToolsBarContentRegionName].Views;
  1231. var isHas = views.FindFirst(q => q is AnnotToolContent);
  1232. if (isHas is AnnotToolContent annotTool)
  1233. {
  1234. annotToolContent = (AnnotToolContentViewModel)annotTool.DataContext;
  1235. }
  1236. }
  1237. dialogs.ShowDialog(DialogNames.SettingsDialog, null, e =>
  1238. {
  1239. var annotate = Settings.Default.AppProperties.Annotate;
  1240. if (annotToolContent != null)
  1241. {
  1242. //与注释联动修改颜色
  1243. UpdateFreeHand(annotate, annotToolContent);
  1244. UpdateTextHighlight(annotate, annotToolContent);
  1245. UpdateUnderLine(annotate, annotToolContent);
  1246. UpdateStrikethrough(annotate, annotToolContent);
  1247. UpdateLine(annotate, annotToolContent);
  1248. UpdateArrow(annotate, annotToolContent);
  1249. }
  1250. });
  1251. if (PDFViewer != null)
  1252. {
  1253. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1254. }
  1255. if (Settings.Default.AppProperties.Description.AutoSave)
  1256. {
  1257. StartAutoSave();
  1258. }
  1259. else
  1260. {
  1261. CloseAutoSave();
  1262. }
  1263. }
  1264. private void UpdateArrow(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1265. {
  1266. Color color2 = annotate.ArrowColor;
  1267. Color color1 = (annotToolContent.ArrowColor as SolidColorBrush).Color;
  1268. bool flag = ColorComparison(color2, color1);
  1269. if (flag)
  1270. {
  1271. annotToolContent.ArrowColor = new SolidColorBrush(color2);
  1272. if (annotToolContent.PropertyPanel.LastArrowAnnot != null)
  1273. {
  1274. if (annotToolContent.PropertyPanel.LastArrowAnnot is LineAnnotArgs annotArgs)
  1275. {
  1276. annotArgs.LineColor = color2;
  1277. }
  1278. }
  1279. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1280. {
  1281. CreateRefreshComment(annotToolContent);
  1282. }
  1283. }
  1284. }
  1285. private void UpdateLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1286. {
  1287. Color color2 = annotate.LineColor;
  1288. Color color1 = (annotToolContent.LineColor as SolidColorBrush).Color;
  1289. bool flag = ColorComparison(color2, color1);
  1290. if (flag)
  1291. {
  1292. annotToolContent.LineColor = new SolidColorBrush(color2);
  1293. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null)
  1294. {
  1295. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] is LineAnnotArgs annotArgs)
  1296. {
  1297. annotArgs.LineColor = color2;
  1298. }
  1299. }
  1300. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1301. {
  1302. CreateRefreshComment(annotToolContent);
  1303. }
  1304. }
  1305. }
  1306. private void UpdateStrikethrough(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1307. {
  1308. Color color2 = annotate.StrikethroughColor;
  1309. Color color1 = (annotToolContent.StrikeoutColor as SolidColorBrush).Color;
  1310. bool flag = ColorComparison(color2, color1);
  1311. if (flag)
  1312. {
  1313. annotToolContent.StrikeoutColor = new SolidColorBrush(color2);
  1314. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1315. {
  1316. CreateRefreshComment(annotToolContent);
  1317. }
  1318. }
  1319. }
  1320. private void UpdateUnderLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1321. {
  1322. Color color2 = annotate.UnderLineColor;
  1323. Color color1 = (annotToolContent.UnderLineColor as SolidColorBrush).Color;
  1324. bool flag = ColorComparison(color2, color1);
  1325. if (flag)
  1326. {
  1327. annotToolContent.UnderLineColor = new SolidColorBrush(color2);
  1328. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1329. {
  1330. CreateRefreshComment(annotToolContent);
  1331. }
  1332. }
  1333. }
  1334. private void UpdateTextHighlight(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1335. {
  1336. Color color2 = annotate.HighLightColor;
  1337. Color color1 = (annotToolContent.HighLightColor as SolidColorBrush).Color;
  1338. bool flag = ColorComparison(color2, color1);
  1339. if (flag)
  1340. {
  1341. annotToolContent.HighLightColor = new SolidColorBrush(color2);
  1342. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1343. {
  1344. CreateRefreshComment(annotToolContent);
  1345. }
  1346. }
  1347. }
  1348. private void UpdateFreeHand(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1349. {
  1350. Color color2 = annotate.FreeHandColor;
  1351. Color color1 = (annotToolContent.FreeHandColor as SolidColorBrush).Color;
  1352. bool flag = ColorComparison(color2, color1);
  1353. if (flag)
  1354. {
  1355. annotToolContent.FreeHandColor = new SolidColorBrush(color2);
  1356. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] != null)
  1357. {
  1358. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] is FreehandAnnotArgs freehandAnnotArgs)
  1359. {
  1360. freehandAnnotArgs.InkColor = color2;
  1361. }
  1362. }
  1363. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1364. {
  1365. CreateRefreshComment(annotToolContent);
  1366. }
  1367. }
  1368. }
  1369. private void CreateRefreshComment(AnnotToolContentViewModel annotToolContent)
  1370. {
  1371. AnnotHandlerEventArgs annotArgs = null;
  1372. string tag = annotToolContent.StrAnnotToolChecked;
  1373. annotToolContent.FindAnnotTypeKey(tag, ref annotArgs);
  1374. if (annotArgs != null)
  1375. {
  1376. //设置点击页面会创建对应选中注释工具的注释
  1377. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1378. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1379. PDFViewer.SetToolParam(annotArgs);
  1380. }
  1381. }
  1382. private bool ColorComparison(Color color2, Color color1)
  1383. {
  1384. if (color1.R == color2.R && color1.G == color2.G && color1.B == color2.B
  1385. && color1.A == color2.A)
  1386. {
  1387. return false;
  1388. }
  1389. else
  1390. {
  1391. return true;
  1392. }
  1393. }
  1394. private bool CanSaveExcute()
  1395. {
  1396. return CanSave;
  1397. }
  1398. private void MenuEnterReadModeEvent(object obj)
  1399. {
  1400. }
  1401. public void ShowPrintDialog()
  1402. {
  1403. DialogParameters printValue = new DialogParameters();
  1404. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1405. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1406. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  1407. printValue.Add(ParameterNames.Unicode, unicode);
  1408. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  1409. }
  1410. public void SelectClick()
  1411. {
  1412. if (OpenBOTA == false)
  1413. {
  1414. OpenBOTA = true;
  1415. }
  1416. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1417. if (isBook == false)
  1418. {
  1419. bOTAContent.TabItemSearch.IsSelected = true;
  1420. }
  1421. }
  1422. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1423. {
  1424. bool isTabItem = false;
  1425. bOTAContentViewModel = null;
  1426. bOTAContent = null;
  1427. if (region.Regions.ContainsRegionWithName(this.BOTARegionName))
  1428. {
  1429. var views = region.Regions[this.BOTARegionName].Views;
  1430. var model = views.FirstOrDefault(q => q is BOTAContent);
  1431. if (model is BOTAContent bOTAContent1)
  1432. {
  1433. bOTAContent = bOTAContent1;
  1434. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1435. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1436. {
  1437. isTabItem = true;
  1438. }
  1439. }
  1440. }
  1441. return isTabItem;
  1442. }
  1443. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  1444. {
  1445. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  1446. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  1447. //其他工具菜单栏共用一个ToolsBarContentRegionName
  1448. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  1449. dictionary.Add("TabItemConvert", ToolsBarContentRegionName);
  1450. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  1451. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  1452. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  1453. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  1454. }
  1455. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  1456. {
  1457. dictionary.Add("TabItemPageEdit", "PageEditContent");
  1458. dictionary.Add("TabItemTool", "ToolsBarContent");
  1459. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  1460. dictionary.Add("TabItemConvert", "ConverterBarContent");
  1461. dictionary.Add("TabItemScan", "ScanContent");
  1462. dictionary.Add("TabItemEdit", "TextEditToolContent");
  1463. dictionary.Add("TabItemForm", "FormsToolContent");
  1464. dictionary.Add("TabItemFill", "FillAndSignContent");
  1465. }
  1466. private void UpdateShowContent(string currentBar)
  1467. {
  1468. ToolContentVisible = Visibility.Collapsed;
  1469. ToolsBarContentVisible = Visibility.Collapsed;
  1470. ToolsBarContentVisible = Visibility.Collapsed;
  1471. TextEditToolContentVisible = Visibility.Collapsed;
  1472. OCRContentVisible = Visibility.Collapsed;
  1473. switch (currentBar)
  1474. {
  1475. case "TabItemAnnotation":
  1476. case "TabItemTool":
  1477. case "TabItemForm":
  1478. case "TabItemFill":
  1479. ToolsBarContentVisible = Visibility.Visible;
  1480. break;
  1481. case "TabItemScan":
  1482. ToolsBarContentVisible = Visibility.Visible;
  1483. OCRContentVisible = Visibility.Visible;
  1484. break;
  1485. case "TabItemEdit":
  1486. TextEditToolContentVisible = Visibility.Visible;
  1487. break;
  1488. case "TabItemConvert":
  1489. ToolsBarContentVisible = Visibility.Visible;
  1490. break;
  1491. case "TabItemPageEdit":
  1492. case "HeaderFooterContent":
  1493. case "BatesContent":
  1494. case "WatermarkContent":
  1495. case "BackgroundContent":
  1496. case "RedactionContent":
  1497. ToolContentVisible = Visibility.Visible;
  1498. break;
  1499. default:
  1500. break;
  1501. }
  1502. PDFEditMode(currentBar);
  1503. FormMode(currentBar);
  1504. }
  1505. private void PDFEditMode(string currentBar)
  1506. {
  1507. if (currentBar == "TabItemEdit")
  1508. {
  1509. if (PDFViewer != null)
  1510. {
  1511. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  1512. //SelectedPrpoertyPanel("TextEditProperty", null);
  1513. //IsPropertyOpen = true;
  1514. }
  1515. }
  1516. else
  1517. {
  1518. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  1519. {
  1520. IsPropertyOpen = false;
  1521. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1522. }
  1523. }
  1524. }
  1525. private void FormMode(string currentBar)
  1526. {
  1527. if (currentBar == "TabItemForm")
  1528. {
  1529. if (PDFViewer != null)
  1530. {
  1531. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  1532. }
  1533. }
  1534. else
  1535. {
  1536. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  1537. {
  1538. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1539. }
  1540. }
  1541. }
  1542. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  1543. {
  1544. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  1545. if (e.PropertyName == "CanUndo")
  1546. {
  1547. CanUndo = PDFViewer.UndoManager.CanUndo;
  1548. }
  1549. if (e.PropertyName == "CanRedo")
  1550. {
  1551. CanRedo = PDFViewer.UndoManager.CanRedo;
  1552. }
  1553. if (e.PropertyName == "CanSave")
  1554. {
  1555. CanSave = PDFViewer.UndoManager.CanSave;
  1556. }
  1557. }
  1558. /// <summary>
  1559. /// 选项卡切换事件
  1560. /// </summary>
  1561. /// <param name="e"></param>
  1562. private void TabControlSelectonChangedEvent(object e)
  1563. {
  1564. var args = e as SelectionChangedEventArgs;
  1565. if (args != null)
  1566. {
  1567. var item = args.AddedItems[0] as TabItem;
  1568. CurrentBar = item.Name;
  1569. if (previousBar != CurrentBar)
  1570. {
  1571. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  1572. {
  1573. EnterPageEdit();
  1574. }
  1575. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  1576. {
  1577. EnterSelectedBar(CurrentBar);
  1578. isInPageEdit = false;
  1579. }
  1580. previousBar = CurrentBar;
  1581. }
  1582. }
  1583. }
  1584. /// <summary>
  1585. /// 进入页面编辑模式
  1586. /// </summary>
  1587. public void EnterPageEdit()
  1588. {
  1589. if (TabSelectedIndex != 1)
  1590. {
  1591. TabSelectedIndex = 1;
  1592. }
  1593. CurrentBar = "TabItemPageEdit";
  1594. EnterToolMode(barContentByTabItem[CurrentBar]);
  1595. isInPageEdit = true;
  1596. }
  1597. /// <summary>
  1598. /// 阅读模式
  1599. /// </summary>
  1600. /// <param name="viewContent"></param>
  1601. public async void On_ReadMode()
  1602. {
  1603. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  1604. mainViewModel.IsBookMode = true;
  1605. IsLoading = Visibility.Visible;
  1606. await Task.Delay(1);
  1607. PDFViewer.DisableClearSelectAnnot(false);
  1608. PDFViewer.ClearSelectAnnots();
  1609. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1610. #region 旧版本
  1611. //NavigationParameters param = new NavigationParameters();
  1612. //param.Add(ParameterNames.PDFViewer, PDFViewer);
  1613. //param.Add(ParameterNames.ViewContentViewModel, this);
  1614. //region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  1615. ////ShowContent(CurrentBar, true);
  1616. //if (GridToolRow != 0)
  1617. //{
  1618. // GridToolRow = 0;
  1619. //}
  1620. //if (GridToolRowSpan != 4)
  1621. //{
  1622. // GridToolRowSpan = 4;
  1623. //}
  1624. ////isInPageEdit = true;
  1625. //UpdateShowContent("TabItemPageEdit");
  1626. #endregion 旧版本
  1627. OpenBOTA = false;
  1628. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = true });
  1629. //模拟一次用户点击 关闭属性面板
  1630. //如果直接设置属性可能因为偏好设置设置成手动的原因 无法生效
  1631. FromClick = true;
  1632. IsPropertyOpen = false;
  1633. FromClick = false;
  1634. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1635. {
  1636. var views = region.Regions[TipContentRegionName].Views;
  1637. var isHasView = views.FindFirst(q => q is Views.TipContent.EnterReadModeTip);
  1638. if (isHasView == null)
  1639. {
  1640. region.RequestNavigate(TipContentRegionName, "EnterReadModeTip");
  1641. }
  1642. else
  1643. {
  1644. region.Regions[TipContentRegionName].Activate(isHasView);
  1645. }
  1646. }
  1647. IsLoading = Visibility.Collapsed;
  1648. ShowTip(true);
  1649. await Task.Delay(3000);
  1650. TipVisible = Visibility.Collapsed;
  1651. }
  1652. /// <summary>
  1653. /// 退出阅读模式
  1654. /// </summary>
  1655. public async void Off_ReadModel()
  1656. {
  1657. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  1658. mainViewModel.IsBookMode = false;
  1659. IsLoading = Visibility.Visible;
  1660. await Task.Delay(1);
  1661. //PDFViewer.MouseMode = MouseModes.None;
  1662. #region 旧版本
  1663. //if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  1664. //{
  1665. // if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1666. // {
  1667. // var contentRegion = region.Regions[ViwerRegionName];
  1668. // contentRegion.Remove(PDFViewer);
  1669. // }
  1670. // //还原背景色
  1671. // PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1672. // region.AddToRegion(ViwerRegionName, PDFViewer);
  1673. //}
  1674. //if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  1675. //{
  1676. // EnterSelectedBar("TabItemAnnotation");
  1677. //}
  1678. //else
  1679. //{
  1680. // EnterSelectedBar(CurrentBar);
  1681. //}
  1682. #endregion 旧版本
  1683. //还原背景色
  1684. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1685. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = false });
  1686. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1687. {
  1688. var views = region.Regions[TipContentRegionName].Views;
  1689. var isHasView = views.FindFirst(q => q is Views.TipContent.ReadModelTip);
  1690. if (isHasView == null)
  1691. {
  1692. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  1693. }
  1694. else
  1695. {
  1696. region.Regions[TipContentRegionName].Activate(isHasView);
  1697. }
  1698. }
  1699. ///退出阅读模式 显示视图面板
  1700. //IsPropertyOpen = true;
  1701. //if (region.Regions.ContainsRegionWithName(PropertyRegionName))
  1702. //{
  1703. // NavigationParameters param = new NavigationParameters();
  1704. // param.Add(ParameterNames.PDFViewer, PDFViewer);
  1705. // param.Add(ParameterNames.BottomToolContentViewModel, this);
  1706. // region.RequestNavigate(RegionNames.PropertyRegionName, "ViewModularContent", param);
  1707. //}
  1708. if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
  1709. {
  1710. var views = region.Regions[BottomToolRegionName].Views;
  1711. var isHasView = views.FindFirst(q => q is BottomToolContent);
  1712. if (isHasView is BottomToolContent bottomToolContent)
  1713. {
  1714. BottomToolContentViewModel toolContentViewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
  1715. toolContentViewModel.IsShowViewModular = false;
  1716. }
  1717. }
  1718. IsLoading = Visibility.Collapsed;
  1719. PDFViewer.DisableClearSelectAnnot(false);
  1720. PDFViewer.ClearSelectAnnots();
  1721. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1722. var annotArgs = new SelectToolArgs();
  1723. PDFViewer.SetToolParam(annotArgs);
  1724. ShowTip(true);
  1725. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  1726. await Task.Delay(3000);
  1727. //ReadModelTip = Visibility.Collapsed;
  1728. TipVisible = Visibility.Collapsed;
  1729. }
  1730. #region PDFViewer鼠标滚轮缩放事件
  1731. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  1732. {
  1733. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  1734. PDFViewer.Zoom(newZoom);
  1735. }
  1736. public double CheckZoomLevel(double zoom, bool IsGrowth)
  1737. {
  1738. double standardZoom = 100;
  1739. if (zoom <= 0.01)
  1740. {
  1741. return 0.01;
  1742. }
  1743. if (zoom >= 10)
  1744. {
  1745. return 10;
  1746. }
  1747. zoom *= 100;
  1748. for (int i = 0; i < zoomLevel.Length - 1; i++)
  1749. {
  1750. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  1751. {
  1752. standardZoom = zoomLevel[i + 1];
  1753. break;
  1754. }
  1755. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  1756. {
  1757. standardZoom = zoomLevel[i];
  1758. break;
  1759. }
  1760. }
  1761. return standardZoom / 100;
  1762. }
  1763. #endregion PDFViewer鼠标滚轮缩放事件
  1764. #region 方法
  1765. /// <summary>
  1766. /// 快捷键
  1767. /// </summary>
  1768. /// <param name="sender"></param>
  1769. /// <param name="e"></param>
  1770. /// <exception cref="NotImplementedException"></exception>
  1771. private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  1772. {
  1773. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
  1774. {
  1775. if (mainViewModel.IsBookMode == true)
  1776. {
  1777. Off_ReadModel();
  1778. }
  1779. //内容选择 退出
  1780. if (PDFViewer.MouseMode != MouseModes.PanTool)
  1781. {
  1782. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1783. if (annotToolContent != null && toolContentViewModel != null)
  1784. {
  1785. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1786. {
  1787. if (toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs != null)
  1788. {
  1789. toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  1790. annotToolContent.BtnSelecttool.IsChecked = false;
  1791. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1792. }
  1793. }
  1794. }
  1795. }
  1796. }
  1797. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.C))
  1798. {
  1799. //内容选择 复制 快捷键
  1800. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1801. if (annotToolContent != null && toolContentViewModel != null)
  1802. {
  1803. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1804. {
  1805. toolContentViewModel.SnapshotEditMenuViewModel.SnapCopyCommand.Execute();
  1806. }
  1807. }
  1808. }
  1809. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.P))
  1810. {
  1811. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1812. if (annotToolContent != null && toolContentViewModel != null)
  1813. {
  1814. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1815. {
  1816. toolContentViewModel.SnapshotEditMenuViewModel.PrintCommand.Execute();
  1817. }
  1818. }
  1819. }
  1820. }
  1821. private AnnotToolContent GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel)
  1822. {
  1823. AnnotToolContent toolContent = null;
  1824. toolContentViewModel = null;
  1825. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1826. {
  1827. var views = region.Regions[ToolsBarContentRegionName].Views;
  1828. var model = views.FirstOrDefault(q => q is AnnotToolContent);
  1829. if (model is AnnotToolContent annotToolContent)
  1830. {
  1831. toolContent = annotToolContent;
  1832. toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
  1833. }
  1834. }
  1835. return toolContent;
  1836. }
  1837. /// <summary>
  1838. /// 视图面板 切换分屏模式
  1839. /// </summary>
  1840. /// <param name="mode"></param>
  1841. public void EnterSplitMode(SplitMode mode)
  1842. {
  1843. ///通知UI层更改布局
  1844. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  1845. }
  1846. private void Undo()
  1847. {
  1848. PDFViewer.UndoManager.Undo();
  1849. }
  1850. private void Redo()
  1851. {
  1852. PDFViewer.UndoManager.Redo();
  1853. }
  1854. private void LoadControl()
  1855. {
  1856. NavigationParameters parameters = new NavigationParameters();
  1857. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1858. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1859. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  1860. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  1861. region.RequestNavigate(ReadModeRegionName, "PageContent", parameters);
  1862. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  1863. //TODO 根据上一次关闭记录的菜单,选中TabItem
  1864. EnterSelectedBar("TabItemAnnotation");
  1865. //}
  1866. //));
  1867. }
  1868. /// <summary>
  1869. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  1870. /// </summary>
  1871. /// <param name="Content"></param>
  1872. /// <param name="annotPropertyPanel"></param>
  1873. public void SelectedPrpoertyPanel(string Content, AnnotTransfer annotPropertyPanel)
  1874. {
  1875. if (Content == "PropertyPanelContent")
  1876. {
  1877. IsPropertyOpen = false;
  1878. }
  1879. else
  1880. {
  1881. IsPropertyOpen = true;
  1882. }
  1883. NavigationParameters parameters = new NavigationParameters();
  1884. //传其他参数:文档类,空注释面板;
  1885. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1886. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  1887. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1888. region.RequestNavigate(PropertyRegionName, Content, parameters);
  1889. }
  1890. /// <summary>
  1891. /// 将PDFViwer添加到Region
  1892. /// </summary>
  1893. private bool loadFile()
  1894. {
  1895. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  1896. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  1897. CanSave = PDFViewer.UndoManager.CanSave;
  1898. CanUndo = PDFViewer.UndoManager.CanUndo;
  1899. CanRedo = PDFViewer.UndoManager.CanRedo;
  1900. if (!CheckPassword())
  1901. {
  1902. return false;
  1903. }
  1904. PDFViewer.Load();
  1905. PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  1906. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1907. //设置移动注释参考线
  1908. ComPDFKitViewer.CommonDrawData.MovePen = new System.Windows.Media.Pen((System.Windows.Media.Brush)new BrushConverter().ConvertFromString("#1770F4"), 1);
  1909. //还原上一次关闭前的视图设置
  1910. GetOpenFileInfo();
  1911. if (!string.IsNullOrEmpty(PassWord))
  1912. {
  1913. //加密文档解密后刷新底部工具栏页码总数
  1914. NavigationParameters parameters = new NavigationParameters();
  1915. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1916. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1917. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  1918. }
  1919. region.AddToRegion(ViwerRegionName, PDFViewer);
  1920. if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
  1921. {
  1922. App.OpenedFileList.Add(PDFViewer.Document.FilePath);
  1923. }
  1924. return true;
  1925. }
  1926. /// <summary>
  1927. /// 处理密码相关的内容
  1928. /// </summary>
  1929. private bool CheckPassword()
  1930. {
  1931. if (passwordInfo != null && (!string.IsNullOrEmpty(passwordInfo.OpenPassword) || !string.IsNullOrEmpty(passwordInfo.PermissionsPassword)))
  1932. {
  1933. if (!string.IsNullOrEmpty(passwordInfo.OpenPassword))
  1934. {
  1935. PDFViewer.Document.UnlockWithPassword(passwordInfo.OpenPassword);
  1936. }
  1937. if (!string.IsNullOrEmpty(passwordInfo.PermissionsPassword) && passwordInfo.PermissionsPassword != passwordInfo.OpenPassword)
  1938. {
  1939. IsFileLocked = true;
  1940. NavigationParameters param = new NavigationParameters();
  1941. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1942. param.Add(ParameterNames.ViewContentViewModel, this);
  1943. ShowLeftTip(true);
  1944. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  1945. }
  1946. }
  1947. else
  1948. {
  1949. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
  1950. if (result.IsDiscryptied)
  1951. {
  1952. if (result.Password != null)
  1953. {
  1954. string filePath = PDFViewer.Document.FilePath;
  1955. PDFViewer.Document.UnlockWithPassword(result.Password);
  1956. PDFViewer.Tag = result.Password;
  1957. //记录密码到内存
  1958. this.PassWord = result.Password;
  1959. }
  1960. }
  1961. if (result.IsDiscryptied == false)
  1962. {
  1963. //未成功解密文档时,释放Document对象,返回
  1964. PDFViewer.Document.Release();
  1965. //取消解密时关闭当前页签
  1966. App.mainWindowViewModel.CloseTabItem(App.mainWindowViewModel.SelectedItem);
  1967. return false;
  1968. }
  1969. }
  1970. return true;
  1971. }
  1972. /// <summary>
  1973. /// 还原上一次浏览的视图相关设置
  1974. /// </summary>
  1975. private void GetOpenFileInfo()
  1976. {
  1977. OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1978. //偏好设置里设置了记录上次视图设置时
  1979. if (OpenFileInfo != null && Settings.Default.AppProperties.Description.RecoveryViewWhenOpen)
  1980. {
  1981. if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
  1982. {
  1983. PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
  1984. }
  1985. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  1986. {
  1987. PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
  1988. }
  1989. if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
  1990. {
  1991. PDFViewer.Zoom(OpenFileInfo.LastZoom);
  1992. }
  1993. if (OpenFileInfo.LastPageIndex != PDFViewer.CurrentIndex)
  1994. {
  1995. PDFViewer.GoToPage(OpenFileInfo.LastPageIndex);
  1996. }
  1997. PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
  1998. PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
  1999. if (OpenFileInfo.LastPageSpace)
  2000. {
  2001. PDFViewer.SetPageSpacing(8);
  2002. }
  2003. else
  2004. {
  2005. PDFViewer.SetPageSpacing(0);
  2006. }
  2007. if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
  2008. {
  2009. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
  2010. }
  2011. else
  2012. {
  2013. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
  2014. }
  2015. }
  2016. else
  2017. {
  2018. //新文档应用默认设置
  2019. PDFViewer.ChangeViewMode(Settings.Default.AppProperties.InitialVIew.PageView);
  2020. PDFViewer.ChangeFitMode(Settings.Default.AppProperties.InitialVIew.ZoomMode);
  2021. PDFViewer.SetShowLink(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  2022. }
  2023. }
  2024. /// <summary>
  2025. /// 已有路径文档的保存逻辑
  2026. /// </summary>
  2027. public bool saveFile()
  2028. {
  2029. try
  2030. {
  2031. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile)
  2032. return saveAsFile();
  2033. //文档已被修复时 提示另存为
  2034. if (PDFViewer.Document.HasRepaired)
  2035. {
  2036. AlertsMessage alertsMessage = new AlertsMessage();
  2037. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  2038. if (alertsMessage.result == ContentResult.Ok)
  2039. return saveAsFile();
  2040. else
  2041. return false;
  2042. }
  2043. //文件路径无法存在时
  2044. if (!File.Exists(PDFViewer.Document.FilePath))
  2045. {
  2046. AlertsMessage alertsMessage = new AlertsMessage();
  2047. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  2048. if (alertsMessage.result == ContentResult.Ok)
  2049. return saveAsFile();
  2050. else
  2051. return false;
  2052. }
  2053. //只读文件无法写入时,提示另存为
  2054. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  2055. if (fileInfo.IsReadOnly)
  2056. {
  2057. AlertsMessage alertsMessage = new AlertsMessage();
  2058. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  2059. if (alertsMessage.result == ContentResult.Ok)
  2060. return saveAsFile();
  2061. else
  2062. return false;
  2063. }
  2064. //Security Fixed:
  2065. //修改密码后原文档保存的步骤:
  2066. //在设置密码窗口传出“已修改”信号,并允许延迟保存
  2067. //
  2068. if (SecurityInfo.IsPasswordChanged)
  2069. {
  2070. string currentFilePath = PDFViewer.Document.FilePath;
  2071. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  2072. string openPassword = string.Empty;
  2073. string permissionsPassword = string.Empty;
  2074. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2075. if (SecurityInfo.NeedOpenPassword)
  2076. {
  2077. openPassword = SecurityInfo.OpenPassword;
  2078. }
  2079. if (SecurityInfo.NeedPermissionsPassword)
  2080. {
  2081. permissionsPassword = SecurityInfo.PermissionsPassword;
  2082. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2083. }
  2084. try
  2085. {
  2086. string currentPath = PDFViewer.Document.FilePath;
  2087. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2088. if (PDFViewer.Document.Descrypt(tempPath))
  2089. {
  2090. PDFViewer.CloseDocument();
  2091. PDFViewer.InitDocument(tempPath);
  2092. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2093. if (PDFViewer.Document.WriteToFilePath(currentPath))
  2094. {
  2095. PDFViewer.CloseDocument();
  2096. PDFViewer.InitDocument(currentPath);
  2097. if (!string.IsNullOrEmpty(openPassword))
  2098. {
  2099. PDFViewer.Document.UnlockWithPassword(openPassword);
  2100. }
  2101. if (!string.IsNullOrEmpty(permissionsPassword) && openPassword != permissionsPassword)
  2102. {
  2103. //PDFViewer.Document.CheckOwnerPassword(permissionsPassword);
  2104. IsFileLocked = true;
  2105. NavigationParameters param = new NavigationParameters();
  2106. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2107. param.Add(ParameterNames.ViewContentViewModel, this);
  2108. ShowLeftTip(true);
  2109. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  2110. }
  2111. try
  2112. {
  2113. PDFViewer.Load();
  2114. }
  2115. catch
  2116. {
  2117. }
  2118. PDFViewer.UndoManager.CanSave = false;
  2119. SecurityInfo.IsPasswordChanged = false;
  2120. }
  2121. else
  2122. {
  2123. return false;
  2124. }
  2125. System.IO.File.Delete(tempPath);
  2126. }
  2127. else
  2128. {
  2129. return false;
  2130. }
  2131. return true;
  2132. }
  2133. catch
  2134. {
  2135. return false;
  2136. }
  2137. }
  2138. else if (SecurityInfo.IsPasswordRemoved)
  2139. {
  2140. try
  2141. {
  2142. string currentPath = PDFViewer.Document.FilePath;
  2143. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2144. PDFViewer.Document.Descrypt(tempPath);
  2145. PDFViewer.CloseDocument();
  2146. PDFViewer.InitDocument(tempPath);
  2147. PDFViewer.Document.WriteToFilePath(currentPath);
  2148. PDFViewer.CloseDocument();
  2149. PDFViewer.InitDocument(currentPath);
  2150. PDFViewer.Load();
  2151. System.IO.File.Delete(tempPath);
  2152. }
  2153. catch
  2154. {
  2155. return false;
  2156. }
  2157. }
  2158. bool result = PDFViewer.Document.WriteToLoadedPath();
  2159. if (result)
  2160. {
  2161. PDFViewer.UndoManager.CanSave = false;
  2162. App.Current.Dispatcher.Invoke(() =>
  2163. {
  2164. //保存时更新缩略图
  2165. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  2166. try
  2167. {
  2168. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  2169. {
  2170. var size = PDFViewer.Document.GetPageSize(0);
  2171. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  2172. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  2173. if (File.Exists(folderPath))
  2174. File.Delete(folderPath);
  2175. DirectoryInfo folder = new DirectoryInfo(folderPath);
  2176. if (!folder.Exists)
  2177. folder.Create();
  2178. string imagePath = info.ThumbImgPath;
  2179. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  2180. {
  2181. string imageName = Guid.NewGuid().ToString();
  2182. imagePath = System.IO.Path.Combine(folderPath, imageName);
  2183. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  2184. {
  2185. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2186. }
  2187. }
  2188. else
  2189. {
  2190. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  2191. {
  2192. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2193. }
  2194. }
  2195. info.ThumbImgPath = imagePath;
  2196. SettingHelper.SetFileInfo(info);
  2197. }
  2198. }
  2199. catch
  2200. {
  2201. info.ThumbImgPath = null;
  2202. SettingHelper.SetFileInfo(info);
  2203. }
  2204. });
  2205. PDFViewer.ReloadDocument();
  2206. }
  2207. else
  2208. {
  2209. //文件被占用 保存失败时
  2210. AlertsMessage alertsMessage = new AlertsMessage();
  2211. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  2212. if (alertsMessage.result == ContentResult.Ok)
  2213. return saveAsFile();
  2214. else
  2215. return false;
  2216. }
  2217. return result;
  2218. }
  2219. catch { return false; }
  2220. finally
  2221. {
  2222. if (!IsFileLocked)
  2223. {
  2224. ShowLeftTip(false);
  2225. }
  2226. }
  2227. }
  2228. /// <summary>
  2229. /// 另存为或新文档保存逻辑
  2230. /// </summary>
  2231. public bool saveAsFile(Action RedactionAction = null)
  2232. {
  2233. var dlg = new Microsoft.Win32.SaveFileDialog();
  2234. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2235. dlg.FileName = PDFViewer.Document.FileName;
  2236. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2237. {
  2238. bool result = false;
  2239. if (RedactionAction != null)
  2240. {
  2241. //保存前进行标记密文处理应用或擦除
  2242. RedactionAction.Invoke();
  2243. }
  2244. if (App.OpenedFileList.Contains(dlg.FileName))
  2245. {
  2246. //提示文件已经被打开
  2247. }
  2248. else
  2249. {
  2250. string oldpath = PDFViewer.Document.FilePath;
  2251. string openPassword = string.Empty;
  2252. string permissionsPassword = string.Empty;
  2253. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2254. if (SecurityInfo.NeedOpenPassword)
  2255. {
  2256. openPassword = SecurityInfo.OpenPassword;
  2257. passwordInfo.OpenPassword = openPassword;
  2258. }
  2259. if (SecurityInfo.NeedPermissionsPassword)
  2260. {
  2261. permissionsPassword = SecurityInfo.PermissionsPassword;
  2262. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2263. passwordInfo.PermissionsPassword = permissionsPassword;
  2264. }
  2265. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2266. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  2267. if (result)
  2268. {
  2269. mainViewModel.NewFile = false;
  2270. App.OpenedFileList.Remove(oldpath);
  2271. DoAfterSaveAs(dlg.FileName);
  2272. }
  2273. else
  2274. {
  2275. //提示文件被其他软件占用 无法保存
  2276. //
  2277. //Ex.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") });
  2278. }
  2279. }
  2280. return result;
  2281. }
  2282. else
  2283. return false;
  2284. }
  2285. /// <summary>
  2286. /// 另存为Flatten
  2287. /// </summary>
  2288. private void saveAsFlatten()
  2289. {
  2290. var dlg = new SaveFileDialog();
  2291. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2292. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  2293. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2294. {
  2295. saveFile();
  2296. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  2297. if (kmdoc == null)
  2298. return;
  2299. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  2300. if (result)
  2301. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  2302. kmdoc.Release();
  2303. }
  2304. }
  2305. /// <summary>
  2306. /// 另存为后进行的操作
  2307. /// 重新打开新文档
  2308. /// </summary>
  2309. /// <param name="targetPath"></param>
  2310. public void DoAfterSaveAs(string targetPath)
  2311. {
  2312. PDFViewer.UndoManager.CanSave = false;
  2313. //从新路径重新加载
  2314. //用mianviewmodel.openfile的方法会有其他模块的pdfview更新不过来的情况,需要调整成现有的方法
  2315. PDFViewer.CloseDocument();
  2316. PDFViewer.InitDocument(targetPath);
  2317. //处理解密相关的逻辑 现在的逻辑另存为自动打开后会需要重新输入密码
  2318. CheckPassword();
  2319. PDFViewer.Load();
  2320. //刷新最近文件列表
  2321. OpenFileInfo isnew = SettingHelper.GetFileInfo(targetPath);
  2322. if (isnew == null)
  2323. {
  2324. if (App.OpenedFileList.Contains(targetPath) == false)
  2325. {
  2326. App.OpenedFileList.Add(targetPath);
  2327. }
  2328. }
  2329. //打开文件后,不管是新文件还是旧文件都需要更新排序
  2330. SettingHelper.SortRecentOpenFiles(targetPath);
  2331. //更新页签文件名
  2332. mainViewModel.FilePath = PDFViewer.Document.FilePath;
  2333. App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
  2334. //刷新Bota 和底部工具栏的PDFviwer对象
  2335. LoadControl();
  2336. }
  2337. /// <summary>
  2338. /// 显示前添加内容到Region
  2339. /// </summary>
  2340. /// <param name="isPageEdit"></param>
  2341. private void ShowContent(string currentBar, bool isToolMode = false)
  2342. {
  2343. GridVisibility = Visibility.Visible;
  2344. //显示页面编辑或其他工具
  2345. if (currentBar == "TabItemPageEdit" || isToolMode)
  2346. {
  2347. if (currentBar == "TabItemPageEdit")//进入页面编辑
  2348. {
  2349. if (GridToolRow != 1)
  2350. {
  2351. GridToolRow = 1;
  2352. }
  2353. if (GridToolRowSpan != 3)
  2354. {
  2355. GridToolRowSpan = 3;
  2356. }
  2357. }
  2358. else//进入水印等其他工具模式
  2359. {
  2360. GridVisibility = Visibility.Collapsed;
  2361. if (GridToolRow != 0)
  2362. {
  2363. GridToolRow = 0;
  2364. }
  2365. if (GridToolRowSpan != 4)
  2366. {
  2367. GridToolRowSpan = 4;
  2368. }
  2369. }
  2370. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  2371. UpdateShowContent(currentBar);
  2372. }
  2373. else
  2374. {
  2375. if (GridToolRow != 1)
  2376. {
  2377. GridToolRow = 1;
  2378. }
  2379. UpdateShowContent(currentBar);
  2380. }
  2381. }
  2382. /// <summary>
  2383. /// 从二级工具栏进入需要修改界面布局的场景
  2384. /// </summary>
  2385. /// <param name="EditToolName"></param>
  2386. private void EnterEditTools(StringWithUnicode EditToolName)
  2387. {
  2388. EnterSelectedEditTool(EditToolName);
  2389. }
  2390. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  2391. {
  2392. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  2393. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  2394. {
  2395. PDFViewer.Document.ReleasePages();
  2396. PDFViewer.ReloadDocument();
  2397. }
  2398. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  2399. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  2400. {
  2401. region.AddToRegion(ViwerRegionName, PDFViewer);
  2402. }
  2403. CurrentBar = "TabItemTool";
  2404. EnterSelectedBar(CurrentBar);
  2405. }
  2406. /// <summary>
  2407. /// 二级菜单指定目标处理
  2408. /// </summary>
  2409. /// <param name="e"></param>
  2410. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  2411. {
  2412. CurrentBar = EditToolName.EditToolsContentName;
  2413. EnterToolMode(CurrentBar);
  2414. }
  2415. /// <summary>
  2416. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  2417. /// </summary>
  2418. /// <param name="targetToolMode">要导航过去的控件名称</param>
  2419. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  2420. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  2421. {
  2422. IsLoading = Visibility.Visible;
  2423. await Task.Delay(3);
  2424. NavigationParameters param = new NavigationParameters();
  2425. if (valuePairs == null)
  2426. {
  2427. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2428. param.Add(ParameterNames.ViewContentViewModel, this);
  2429. }
  2430. else//有传入其他内容的参数时
  2431. {
  2432. param = valuePairs;
  2433. }
  2434. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  2435. ShowContent(CurrentBar, true);
  2436. IsLoading = Visibility.Collapsed;
  2437. }
  2438. private void EnterSelectedBar(string currentBar)
  2439. {
  2440. NavigationParameters param = new NavigationParameters();
  2441. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2442. param.Add(ParameterNames.ViewContentViewModel, this);
  2443. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  2444. if (currentBar == "TabItemScan")
  2445. {
  2446. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  2447. }
  2448. ShowContent(currentBar);
  2449. }
  2450. /// <summary>
  2451. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  2452. /// </summary>
  2453. public void ExitToolMode()
  2454. {
  2455. ToolContentVisible = Visibility.Collapsed;
  2456. if (isInPageEdit)
  2457. {
  2458. TabSelectedIndex = 0;
  2459. isInPageEdit = false;
  2460. }
  2461. }
  2462. #endregion 方法
  2463. #region Navigate
  2464. public void OnNavigatedTo(NavigationContext navigationContext)
  2465. {
  2466. navigationContext.Parameters.TryGetValue(ParameterNames.PasswordInfo, out PasswordInfo);
  2467. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  2468. if (mainVM != null)
  2469. {
  2470. mainViewModel = mainVM;
  2471. mainViewModel.viewContentViewModel = this;
  2472. }
  2473. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  2474. if (pdfview != null)
  2475. {
  2476. PDFViewer = pdfview;
  2477. if (loadFile())
  2478. {
  2479. CheckHaveAllPermission();
  2480. }
  2481. }
  2482. //快捷键
  2483. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  2484. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  2485. //弹窗需要放到最后(确保在各字段赋值语句的后面),弹窗显示会触发控件的Loaded事件,会导致后续段没有赋值,而加载等事件继续往后跑了
  2486. //例如这里的问题 会因为显示注册弹窗,导致其他模块没有接受到正常的PDFviewer对象
  2487. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  2488. if (Settings.Default.IsNewInViewContent == true && App.IsLogin == false)
  2489. {
  2490. App.mainWindowViewModel.OpenRegister();
  2491. Settings.Default.IsNewInViewContent = false;
  2492. Settings.Default.Save();
  2493. }
  2494. //需要在pdfview赋值后绑定
  2495. GlobalCommands.FullWindowCommand.RegisterCommand(new DelegateCommand(() => { OpenFullWindow(); }));
  2496. }
  2497. public bool IsNavigationTarget(NavigationContext navigationContext)
  2498. {
  2499. if (navigationContext != null)
  2500. {
  2501. //另存为打开导航进来时 不能新建一个实例
  2502. return true;
  2503. }
  2504. else
  2505. {
  2506. //一次性打开多个文件时,需要新建实例
  2507. return false;
  2508. }
  2509. }
  2510. public void OnNavigatedFrom(NavigationContext navigationContext)
  2511. {
  2512. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  2513. }
  2514. #endregion Navigate
  2515. }
  2516. }