ViewContentViewModel.cs 96 KB

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