ViewContentViewModel.cs 94 KB

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