ViewContentViewModel.cs 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077
  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_Office.CustomControl;
  11. using PDF_Office.Model;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.IO;
  15. using ComPDFKitViewer.AnnotEvent;
  16. using PDF_Office.ViewModels.Tools;
  17. using Prism.Events;
  18. using PDF_Office.EventAggregators;
  19. using PDF_Office.Helper;
  20. using ComPDFKit.PDFDocument;
  21. using PDFSettings.Settings;
  22. using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
  23. using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
  24. using PDF_Office.Model.Dialog.ToolsDialogs;
  25. using DryIoc;
  26. using PDF_Office.Model.Dialog.ConverterDialogs;
  27. using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  28. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  29. using System.Linq;
  30. using System.Text;
  31. namespace PDF_Office.ViewModels
  32. {
  33. public class ViewContentViewModel : BindableBase, INavigationAware
  34. {
  35. #region 文案
  36. private string T_file;
  37. public string T_File
  38. {
  39. get { return T_file; }
  40. set
  41. {
  42. SetProperty(ref T_file, value);
  43. }
  44. }
  45. private string T_save;
  46. public string T_Save
  47. {
  48. get { return T_save; }
  49. set
  50. {
  51. SetProperty(ref T_save, value);
  52. }
  53. }
  54. private string T_undo;
  55. public string T_Undo
  56. {
  57. get { return T_undo; }
  58. set
  59. {
  60. SetProperty(ref T_undo, value);
  61. }
  62. }
  63. private string T_redo;
  64. public string T_Redo
  65. {
  66. get { return T_redo; }
  67. set
  68. {
  69. SetProperty(ref T_redo, value);
  70. }
  71. }
  72. private string T_annotation;
  73. public string T_Annotation
  74. {
  75. get { return T_annotation; }
  76. set
  77. {
  78. SetProperty(ref T_annotation, value);
  79. }
  80. }
  81. private string T_pageEdit;
  82. public string T_PageEdit
  83. {
  84. get { return T_pageEdit; }
  85. set
  86. {
  87. SetProperty(ref T_pageEdit, value);
  88. }
  89. }
  90. private string T_converter;
  91. public string T_Converter
  92. {
  93. get { return T_converter; }
  94. set
  95. {
  96. SetProperty(ref T_converter, value);
  97. }
  98. }
  99. private string T_fillSign;
  100. public string T_FillSign
  101. {
  102. get { return T_fillSign; }
  103. set
  104. {
  105. SetProperty(ref T_fillSign, value);
  106. }
  107. }
  108. private string T_tools;
  109. public string T_Tools
  110. {
  111. get { return T_tools; }
  112. set
  113. {
  114. SetProperty(ref T_tools, value);
  115. }
  116. }
  117. private string T_print;
  118. public string T_Print
  119. {
  120. get { return T_print; }
  121. set
  122. {
  123. SetProperty(ref T_print, value);
  124. }
  125. }
  126. private string T_share;
  127. public string T_Share
  128. {
  129. get { return T_share; }
  130. set
  131. {
  132. SetProperty(ref T_share, value);
  133. }
  134. }
  135. private string T_properties;
  136. public string T_Properties
  137. {
  138. get { return T_properties; }
  139. set
  140. {
  141. SetProperty(ref T_properties, value);
  142. }
  143. }
  144. private void InitStirng()
  145. {
  146. T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
  147. T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
  148. T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
  149. T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
  150. T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
  151. T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
  152. T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
  153. T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
  154. T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
  155. T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
  156. T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
  157. T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
  158. }
  159. #endregion
  160. #region 属性、变量
  161. public OpenFileInfo OpenFileInfo = null;
  162. public CPDFViewer PDFViewer { get; set; }
  163. public MainContentViewModel mainViewModel { get; set; }
  164. public IRegionManager region;
  165. public IDialogService dialogs;
  166. public IEventAggregator events;
  167. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  168. public string ViwerRegionName { get; set; }
  169. /// <summary>
  170. /// 分屏视图的region名称
  171. /// </summary>
  172. public string SplitViewerRegionName { get; set; }
  173. /// <summary>
  174. /// OCR视图名称
  175. /// </summary>
  176. public string OCRViewerRegionName { get; set; }
  177. public string BOTARegionName { get; set; }
  178. public string PropertyRegionName { get; set; }
  179. public string ToolContentRegionName { get; set; }
  180. public string ToolsBarContentRegionName { get; set; }
  181. /// <summary>
  182. /// 顶部提示的Content
  183. /// </summary>
  184. public string TipContentRegionName { get; set; }
  185. public string LeftTipContentRegionName { get; set; }
  186. public string ReadModeRegionName { get; set; }
  187. public string ConverterBarContentRegionName { get; set; }
  188. public string TextEditContentRegionName { get; set; }
  189. public string BackgroundContentRegionName { get; set; }
  190. public List<Point> FillAndSign = new List<Point>();
  191. /// <summary>
  192. /// 文档的密码
  193. /// </summary>
  194. public string PassWord { get; set; }
  195. private Visibility tipVisible = Visibility.Collapsed;
  196. /// <summary>
  197. /// 顶部提示栏的显示状态
  198. /// </summary>
  199. public Visibility TipVisible
  200. {
  201. get { return tipVisible; }
  202. set
  203. {
  204. SetProperty(ref tipVisible, value);
  205. }
  206. }
  207. private Visibility leftTipVisible = Visibility.Collapsed;
  208. public Visibility LeftTipVisible
  209. {
  210. get { return leftTipVisible; }
  211. set
  212. {
  213. SetProperty(ref leftTipVisible, value);
  214. }
  215. }
  216. private Visibility readModelTip = Visibility.Collapsed;
  217. public Visibility ReadModelTip
  218. {
  219. get { return readModelTip; }
  220. set
  221. {
  222. SetProperty(ref readModelTip, value);
  223. }
  224. }
  225. /// <summary>
  226. /// 底部工具栏 RegionName
  227. /// </summary>
  228. public string BottomToolRegionName { get; set; }
  229. private bool _isInPageEdit = false;
  230. /// <summary>
  231. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  232. /// </summary>
  233. public bool isInPageEdit
  234. {
  235. get { return _isInPageEdit; }
  236. set
  237. {
  238. SetProperty(ref _isInPageEdit, value);
  239. if (!value)
  240. {
  241. CanRedo = PDFViewer.UndoManager.CanRedo;
  242. CanUndo = PDFViewer.UndoManager.CanUndo;
  243. }
  244. }
  245. }
  246. public Action PageEditUndo { get; set; }
  247. public Action PageEditRedo { get; set; }
  248. /// <summary>
  249. ///工具条
  250. ///0:收起
  251. ///40:显示
  252. /// </summary>
  253. private int toolRowHeight = 40;
  254. public int ToolRowHeight
  255. {
  256. get { return toolRowHeight; }
  257. set
  258. {
  259. SetProperty(ref toolRowHeight, value);
  260. }
  261. }
  262. /// <summary>
  263. /// 水印,背景侧边栏宽度
  264. /// 0:收起
  265. /// 260:显示
  266. /// </summary>
  267. private int propertyColumnWidth = 0;
  268. public int PropertyColumnWidth
  269. {
  270. get { return propertyColumnWidth; }
  271. set
  272. {
  273. SetProperty(ref propertyColumnWidth, value);
  274. }
  275. }
  276. private int gridToolRow = 1;
  277. /// <summary>
  278. /// 控制ToolContent的Row
  279. /// </summary>
  280. public int GridToolRow
  281. {
  282. get { return gridToolRow; }
  283. set
  284. {
  285. SetProperty(ref gridToolRow, value);
  286. }
  287. }
  288. private int gridToolRowSpan = 3;
  289. /// <summary>
  290. /// 控制ToolContent的RowSpan
  291. /// </summary>
  292. public int GridToolRowSpan
  293. {
  294. get { return gridToolRowSpan; }
  295. set
  296. {
  297. SetProperty(ref gridToolRowSpan, value);
  298. }
  299. }
  300. private Visibility toolContentVisible = Visibility.Collapsed;
  301. /// <summary>
  302. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  303. /// 留意:显示前需要先注入内容、设置好行和跨行数
  304. /// </summary>
  305. public Visibility ToolContentVisible
  306. {
  307. get { return toolContentVisible; }
  308. set
  309. {
  310. SetProperty(ref toolContentVisible, value);
  311. }
  312. }
  313. private Visibility gridVisibility = Visibility.Visible;
  314. /// <summary>
  315. /// 是否正在加载中
  316. /// </summary>
  317. public Visibility GridVisibility
  318. {
  319. get { return gridVisibility; }
  320. set
  321. {
  322. SetProperty(ref gridVisibility, value);
  323. }
  324. }
  325. private Visibility isLoading = Visibility.Collapsed;
  326. private Visibility ocrContentVisible = Visibility.Collapsed;
  327. public Visibility OCRContentVisible
  328. {
  329. get { return ocrContentVisible; }
  330. set
  331. {
  332. SetProperty(ref ocrContentVisible, value);
  333. }
  334. }
  335. /// <summary>
  336. /// 是否正在加载中
  337. /// </summary>
  338. public Visibility IsLoading
  339. {
  340. get { return isLoading; }
  341. set
  342. {
  343. SetProperty(ref isLoading, value);
  344. }
  345. }
  346. private Visibility converterBarContentVisible = Visibility.Collapsed;
  347. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  348. /// <summary>
  349. /// 控制ToolsBarContent的显示
  350. /// 留意:显示前需要先注入内容、设置好行和跨行数
  351. /// </summary>
  352. public Visibility ConverterBarContentVisible
  353. {
  354. get { return converterBarContentVisible; }
  355. set
  356. {
  357. SetProperty(ref converterBarContentVisible, value);
  358. }
  359. }
  360. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  361. /// <summary>
  362. /// 控制ToolsBarContent的显示
  363. /// 留意:显示前需要先注入内容、设置好行和跨行数
  364. /// </summary>
  365. public Visibility ToolsBarContentVisible
  366. {
  367. get { return toolsBarContentVisible; }
  368. set
  369. {
  370. SetProperty(ref toolsBarContentVisible, value);
  371. }
  372. }
  373. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  374. /// <summary>
  375. /// 控制ToolsBarContent的显示
  376. /// 留意:显示前需要先注入内容、设置好行和跨行数
  377. /// </summary>
  378. public Visibility TextEditToolContentVisible
  379. {
  380. get { return textEditToolContentVisible; }
  381. set
  382. {
  383. SetProperty(ref textEditToolContentVisible, value);
  384. }
  385. }
  386. private bool isPorpertyOpen = false;
  387. /// <summary>
  388. /// 属性栏是否展开
  389. /// </summary>
  390. public bool IsPropertyOpen
  391. {
  392. get { return isPorpertyOpen; }
  393. set
  394. {
  395. SetProperty(ref isPorpertyOpen, value);
  396. }
  397. }
  398. private Visibility isReadMode = Visibility.Visible;
  399. /// <summary>
  400. ///是否为阅读模式
  401. /// </summary>
  402. public Visibility IsReadMode
  403. {
  404. get { return isReadMode; }
  405. set
  406. {
  407. SetProperty(ref isReadMode, value);
  408. }
  409. }
  410. private bool canSave;
  411. /// <summary>
  412. /// 是否可以保存
  413. /// </summary>
  414. public bool CanSave
  415. {
  416. get { return canSave; }
  417. set
  418. {
  419. SetProperty(ref canSave, value);
  420. }
  421. }
  422. private bool canUndo;
  423. /// <summary>
  424. /// 是否可以进行Undo
  425. /// </summary>
  426. public bool CanUndo
  427. {
  428. get { return canUndo; }
  429. set
  430. {
  431. SetProperty(ref canUndo, value);
  432. }
  433. }
  434. private bool canRedo;
  435. /// <summary>
  436. /// 是否可以进行Redo
  437. /// </summary>
  438. public bool CanRedo
  439. {
  440. get { return canRedo; }
  441. set
  442. {
  443. SetProperty(ref canRedo, value);
  444. }
  445. }
  446. private GridLength botaWidth = new GridLength(48);
  447. /// <summary>
  448. /// BOTA栏的宽度
  449. /// </summary>
  450. public GridLength BOTAWidth
  451. {
  452. get { return botaWidth; }
  453. set
  454. {
  455. SetProperty(ref botaWidth, value);
  456. if (botaWidth.Value <= 48)
  457. {
  458. OpenBOTA = false;
  459. }
  460. }
  461. }
  462. private int selectedIndex;
  463. /// <summary>
  464. /// 工具栏选中项的索引
  465. /// </summary>
  466. public int TabSelectedIndex
  467. {
  468. get { return selectedIndex; }
  469. set
  470. {
  471. SetProperty(ref selectedIndex, value);
  472. }
  473. }
  474. private bool openBOTA = false;
  475. /// <summary>
  476. /// 是否展开BOTA
  477. /// </summary>
  478. public bool OpenBOTA
  479. {
  480. get { return openBOTA; }
  481. set
  482. {
  483. SetProperty(ref openBOTA, value);
  484. if (openBOTA && BOTAWidth.Value <= 48)
  485. {
  486. BOTAWidth = new GridLength(260);
  487. }
  488. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  489. }
  490. }
  491. public SecurityInfo SecurityInfo = new SecurityInfo();
  492. private Dictionary<string, string> regionNameByTabItem;
  493. private Dictionary<string, string> barContentByTabItem;
  494. private string previousBar = "";
  495. public string CurrentBar = "";
  496. public string unicode = null;
  497. /// <summary>
  498. /// 用来避免重复触发导航事件的标志符
  499. /// </summary>
  500. private bool isOpenFile = false;
  501. /// <summary>
  502. /// 鼠标滚轮缩放的缩放值
  503. /// </summary>
  504. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  505. /// <summary>
  506. /// 注释-链接,提示语
  507. /// </summary>
  508. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  509. public Visibility LinkAnnotTipVisibility
  510. {
  511. get { return linkAnnotTipVisibility; }
  512. set
  513. {
  514. SetProperty(ref linkAnnotTipVisibility, value);
  515. }
  516. }
  517. 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";
  518. private bool isCreateLink = false;
  519. public string LinkAnnotTipText
  520. {
  521. get { return linkAnnotTipText; }
  522. set
  523. {
  524. SetProperty(ref linkAnnotTipText, value);
  525. }
  526. }
  527. #endregion 属性、变量
  528. #region 命令
  529. public DelegateCommand LoadFile { get; set; }
  530. public DelegateCommand Load { get; set; }
  531. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  532. public DelegateCommand SaveFile { get; set; }
  533. public DelegateCommand SaveAsFile { get; set; }
  534. public DelegateCommand SaveAsFlattenCommand { get; set; }
  535. public DelegateCommand UndoCommand { get; set; }
  536. public DelegateCommand RedoCommand { get; set; }
  537. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  538. public DelegateCommand PrintCommand { get; set; }
  539. public DelegateCommand SettingsCommand { get; set; }
  540. public DelegateCommand ShareCommand { get; set; }
  541. public DelegateCommand<object> CreateLinkCommand { get; set; }
  542. public DelegateCommand PropertyCommand { get; set; }
  543. public DelegateCommand ShowInFolderCommand { get; set; }
  544. public DelegateCommand CompressCommand { get; set; }
  545. public DelegateCommand MergeFileCommand { get; set; }
  546. public DelegateCommand EncryptCommand { get; set; }
  547. public DelegateCommand DecryptCommand { get; set; }
  548. public DelegateCommand<string> ConvertCommand { get; set; }
  549. public DelegateCommand CloseWindowCommand { get; set; }
  550. public DelegateCommand OpenFileCommand { get; set; }
  551. public DelegateCommand<string> HelpCommand { get; set; }
  552. public DelegateCommand CreateBlankFileCommand { get; set; }
  553. #endregion 命令
  554. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  555. {
  556. InitStirng();
  557. region = regionManager;
  558. dialogs = dialogService;
  559. events = eventAggregator;
  560. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  561. LoadFile = new DelegateCommand(loadFile);
  562. Load = new DelegateCommand(LoadControl);
  563. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  564. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  565. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  566. UndoCommand = new DelegateCommand(Undo);
  567. RedoCommand = new DelegateCommand(Redo);
  568. ShareCommand = new DelegateCommand(share);
  569. PropertyCommand = new DelegateCommand(property);
  570. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  571. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  572. CompressCommand = new DelegateCommand(compress);
  573. MergeFileCommand = new DelegateCommand(mergeFile);
  574. EncryptCommand = new DelegateCommand(encrypt);
  575. DecryptCommand = new DelegateCommand(decrypt);
  576. ConvertCommand = new DelegateCommand<string>(convert);
  577. CloseWindowCommand = new DelegateCommand(closeWindow);
  578. OpenFileCommand = new DelegateCommand(openfile);
  579. HelpCommand = new DelegateCommand<string>(help);
  580. CreateBlankFileCommand = new DelegateCommand(createBlankFile);
  581. ViwerRegionName = RegionNames.ViwerRegionName;
  582. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  583. BOTARegionName = RegionNames.BOTARegionName;
  584. PropertyRegionName = RegionNames.PropertyRegionName;
  585. BottomToolRegionName = RegionNames.BottomToolRegionName;
  586. ReadModeRegionName = RegionNames.ReadModeRegionName;
  587. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  588. PrintCommand = new DelegateCommand(ShowPrintDialog);
  589. SettingsCommand = new DelegateCommand(SettingsEvent);
  590. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  591. //未显示时无法注册上Region名称
  592. ToolContentVisible = Visibility.Visible;
  593. ToolsBarContentVisible = Visibility.Visible;
  594. OCRContentVisible = Visibility.Visible;
  595. TipVisible = Visibility.Visible;
  596. TipContentRegionName = RegionNames.TipContentRegionName;
  597. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  598. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  599. ToolContentRegionName = Guid.NewGuid().ToString();
  600. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  601. ConverterBarContentRegionName = Guid.NewGuid().ToString();
  602. TextEditContentRegionName = Guid.NewGuid().ToString();
  603. ToolContentVisible = Visibility.Collapsed;
  604. ToolsBarContentVisible = Visibility.Collapsed;
  605. OCRContentVisible = Visibility.Collapsed;
  606. TipVisible = Visibility.Collapsed;
  607. regionNameByTabItem = new Dictionary<string, string>();
  608. barContentByTabItem = new Dictionary<string, string>();
  609. InitialregionNameByTabItem(ref regionNameByTabItem);
  610. InitialbarContentByTabItem(ref barContentByTabItem);
  611. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  612. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  613. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTip, e => e.Unicode == unicode);
  614. //TODO:根据缓存 选择用户上次选择的菜单
  615. EnterSelectedBar("TabItemAnnotation");
  616. }
  617. /// <summary>
  618. ///创建空白文档
  619. /// </summary>
  620. private async void createBlankFile()
  621. {
  622. App.mainWindowViewModel.AddTab.Execute();
  623. await Task.Delay(30);
  624. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
  625. }
  626. private void help(string args)
  627. {
  628. string url = "";
  629. switch (args)
  630. {
  631. case "Guid":
  632. //TODO 打开内嵌文档
  633. break;
  634. case "Online":
  635. url = @"https://www.pdfreaderpro.com/windows/help";
  636. break;
  637. case "More":
  638. url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
  639. break;
  640. case "Template":
  641. url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
  642. break;
  643. case "Blog":
  644. //TODO:显示订阅电子报弹窗
  645. break;
  646. case "ComPDF":
  647. url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
  648. break;
  649. case "FeedBack":
  650. //调用邮箱 发送邮件
  651. StringBuilder sr = new StringBuilder();
  652. sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
  653. System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
  654. break;
  655. default:
  656. break;
  657. }
  658. if (!string.IsNullOrEmpty(url))
  659. {
  660. //需要跳转网页的情况
  661. System.Diagnostics.Process.Start(url);
  662. }
  663. }
  664. /// <summary>
  665. /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
  666. /// </summary>
  667. private void openfile()
  668. {
  669. OpenFileDialog openFileDialog = new OpenFileDialog();
  670. openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
  671. openFileDialog.Multiselect = true;
  672. if ((bool)openFileDialog.ShowDialog())
  673. {
  674. if (openFileDialog.FileNames.Count() == 1)
  675. {
  676. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  677. {
  678. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  679. }
  680. else
  681. {
  682. App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
  683. }
  684. ToolMethod.SetFileThumbImg(openFileDialog.FileName);
  685. }
  686. else
  687. {
  688. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  689. if (fileList.Count <= 0)
  690. {
  691. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  692. return;
  693. }
  694. mainViewModel.OpenFile(fileList[0]);
  695. for (int i = 1; i < fileList.Count(); i++)
  696. {
  697. if (!App.OpenedFileList.Contains(fileList[i]))
  698. {
  699. App.mainWindowViewModel.AddTabItem(fileList[i]);
  700. }
  701. ToolMethod.SetFileThumbImg(fileList[i]);
  702. }
  703. }
  704. }
  705. }
  706. /// <summary>
  707. /// 关闭当前窗体
  708. /// </summary>
  709. private void closeWindow()
  710. {
  711. App.Current.MainWindow.Close();
  712. }
  713. /// <summary>
  714. /// 转档
  715. /// </summary>
  716. /// <param name="obj"></param>
  717. private void convert(string obj)
  718. {
  719. if (!string.IsNullOrEmpty(obj))
  720. {
  721. DialogParameters value = new DialogParameters();
  722. value.Add(ParameterNames.PDFViewer, PDFViewer);
  723. switch (obj)
  724. {
  725. case "Word":
  726. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  727. {
  728. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  729. converterDialogsModel.OnOpened((DialogResult)e);
  730. });
  731. break;
  732. case "Excel":
  733. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  734. {
  735. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  736. converterDialogsModel.OnOpened((DialogResult)e);
  737. });
  738. break;
  739. case "PPT":
  740. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  741. {
  742. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  743. converterDialogsModel.OnOpened((DialogResult)e);
  744. });
  745. break;
  746. case "RTF":
  747. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  748. {
  749. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  750. converterDialogsModel.OnOpened((DialogResult)e);
  751. });
  752. break;
  753. case "CSV":
  754. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  755. {
  756. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  757. converterDialogsModel.OnOpened((DialogResult)e);
  758. });
  759. break;
  760. case "HTML":
  761. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  762. {
  763. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  764. converterDialogsModel.OnOpened((DialogResult)e);
  765. });
  766. break;
  767. case "Text":
  768. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  769. {
  770. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  771. converterDialogsModel.OnOpened((DialogResult)e);
  772. });
  773. break;
  774. case "Image":
  775. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  776. {
  777. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  778. converterDialogsModel.OnOpened((DialogResult)e);
  779. });
  780. break;
  781. default:
  782. break;
  783. }
  784. }
  785. }
  786. /// <summary>
  787. /// 解密
  788. /// </summary>
  789. private void decrypt()
  790. {
  791. if (!PDFViewer.Document.IsEncrypted)
  792. {
  793. MessageBoxEx.Show("No security settings available ");
  794. }
  795. else
  796. {
  797. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  798. if (result.IsDiscryptied)
  799. {
  800. if (result.Password != null)
  801. {
  802. string filePath = PDFViewer.Document.FilePath;
  803. PDFViewer.Document.Release();
  804. PDFViewer.InitDocument(filePath);
  805. PDFViewer.Document.UnlockWithPassword(result.Password);
  806. }
  807. DialogParameters value = new DialogParameters();
  808. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  809. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });
  810. }
  811. }
  812. }
  813. /// <summary>
  814. /// 加密
  815. /// </summary>
  816. private void encrypt()
  817. {
  818. if (!this.SecurityInfo.IsPasswordChanged)
  819. {
  820. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  821. if (result.IsDiscryptied)
  822. {
  823. if (result.Password != null)
  824. {
  825. string filePath = PDFViewer.Document.FilePath;
  826. PDFViewer.Document.Release();
  827. PDFViewer.InitDocument(filePath);
  828. PDFViewer.Document.UnlockWithPassword(result.Password);
  829. }
  830. }
  831. }
  832. DialogParameters value = new DialogParameters();
  833. value.Add(ParameterNames.PDFViewer, this.PDFViewer);
  834. value.Add(ParameterNames.ViewContentViewModel, this);
  835. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
  836. {
  837. if (e.Result == ButtonResult.OK)
  838. {
  839. SecurityHelper.IsPasswordChanged = true;
  840. if (this.SecurityInfo.IsPasswordChanged)
  841. {
  842. this.PDFViewer.UndoManager.CanSave = true;
  843. }
  844. this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
  845. }
  846. });
  847. }
  848. /// <summary>
  849. /// 合并
  850. /// </summary>
  851. private void mergeFile()
  852. {
  853. DialogParameters value = new DialogParameters();
  854. value.Add(ParameterNames.PDFViewer, PDFViewer);
  855. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  856. }
  857. /// <summary>
  858. /// 压缩
  859. /// </summary>
  860. private void compress()
  861. {
  862. DialogParameters value = new DialogParameters();
  863. value.Add(ParameterNames.PDFViewer, PDFViewer);
  864. dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
  865. {
  866. CompressDialogModel compressDialogModel = new CompressDialogModel();
  867. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  868. });
  869. }
  870. /// <summary>
  871. /// 设置Tip状态栏的显示状态
  872. /// </summary>
  873. /// <param name="show">是否显示</param>
  874. public void ShowTip(bool show)
  875. {
  876. if (show)
  877. {
  878. TipVisible = Visibility.Visible;
  879. }
  880. else
  881. {
  882. TipVisible = Visibility.Collapsed;
  883. }
  884. }
  885. /// <summary>
  886. /// 设置LeftTip状态栏的显示状态
  887. /// </summary>
  888. /// <param name="show">是否显示</param>
  889. public void ShowLeftTip(bool show)
  890. {
  891. if (show)
  892. {
  893. LeftTipVisible = Visibility.Visible;
  894. }
  895. else
  896. {
  897. LeftTipVisible = Visibility.Collapsed;
  898. }
  899. }
  900. public void CheckHaveAllPermission()
  901. {
  902. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  903. {
  904. ShowLeftTip(true);
  905. NavigationParameters param = new NavigationParameters();
  906. param.Add(ParameterNames.PDFViewer, PDFViewer);
  907. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  908. }
  909. }
  910. public void ShowSelectedTip(ShowTipEventArgs showTipEventArgs)
  911. {
  912. switch (showTipEventArgs.enumTipKind)
  913. {
  914. case EnumTipKind.StatusNone:
  915. ShowLeftTip(false);
  916. break;
  917. case EnumTipKind.StatusSetPasswordSuccessfully:
  918. ShowLeftTip(true);
  919. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  920. break;
  921. default: break;
  922. }
  923. }
  924. /// <summary>
  925. /// 右键菜单创建链接
  926. /// </summary>
  927. /// <param name="obj"></param>
  928. private void CreateLinkEvent(object obj)
  929. {
  930. if (obj is object[] objArry)
  931. {
  932. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  933. {
  934. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  935. linkArgs.URI = string.Empty;
  936. linkArgs.LinkType = LINK_TYPE.GOTO;
  937. linkArgs.PageIndex = annotCommand.PageIndex;
  938. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  939. this.IsRightMenuCreateLink = true;
  940. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  941. lists.Add(linkArgs);
  942. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  943. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  944. PDFViewer.SetToolParam(annotArgs);
  945. this.IsPropertyOpen = true;
  946. }
  947. }
  948. }
  949. /// <summary>
  950. /// 在文件资源管理器中显示
  951. /// </summary>
  952. private void ShowInFolder()
  953. {
  954. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  955. }
  956. private void property()
  957. {
  958. DialogParameters valuePairs = new DialogParameters();
  959. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  960. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  961. }
  962. private void share()
  963. {
  964. try
  965. {
  966. var path = PDFViewer.Document.FilePath;
  967. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  968. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  969. }
  970. catch
  971. {
  972. AlertsMessage alertsMessage = new AlertsMessage();
  973. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  974. }
  975. }
  976. private void SettingsEvent()
  977. {
  978. dialogs.ShowDialog(DialogNames.SettingsDialog, null, null);
  979. }
  980. private bool CanSaveExcute()
  981. {
  982. return CanSave;
  983. }
  984. private void MenuEnterReadModeEvent(object obj)
  985. {
  986. }
  987. public void ShowPrintDialog()
  988. {
  989. DialogParameters printValue = new DialogParameters();
  990. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  991. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  992. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  993. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  994. }
  995. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  996. {
  997. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  998. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  999. //其他工具菜单栏共用一个ToolsBarContentRegionName
  1000. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  1001. dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
  1002. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  1003. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  1004. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  1005. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  1006. }
  1007. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  1008. {
  1009. dictionary.Add("TabItemPageEdit", "PageEditContent");
  1010. dictionary.Add("TabItemTool", "ToolsBarContent");
  1011. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  1012. dictionary.Add("TabItemConvert", "ConverterBarContent");
  1013. dictionary.Add("TabItemScan", "ScanContent");
  1014. dictionary.Add("TabItemEdit", "TextEditToolContent");
  1015. dictionary.Add("TabItemForm", "FormsToolContent");
  1016. dictionary.Add("TabItemFill", "FillAndSignContent");
  1017. }
  1018. private void UpdateShowContent(string currentBar)
  1019. {
  1020. ToolContentVisible = Visibility.Collapsed;
  1021. ToolsBarContentVisible = Visibility.Collapsed;
  1022. ConverterBarContentVisible = Visibility.Collapsed;
  1023. TextEditToolContentVisible = Visibility.Collapsed;
  1024. OCRContentVisible = Visibility.Collapsed;
  1025. switch (currentBar)
  1026. {
  1027. case "TabItemAnnotation":
  1028. case "TabItemTool":
  1029. case "TabItemForm":
  1030. case "TabItemFill":
  1031. ToolsBarContentVisible = Visibility.Visible;
  1032. break;
  1033. case "TabItemScan":
  1034. ToolsBarContentVisible = Visibility.Visible;
  1035. OCRContentVisible = Visibility.Visible;
  1036. break;
  1037. case "TabItemEdit":
  1038. TextEditToolContentVisible = Visibility.Visible;
  1039. break;
  1040. case "TabItemConvert":
  1041. ConverterBarContentVisible = Visibility.Visible;
  1042. break;
  1043. case "TabItemPageEdit":
  1044. case "HeaderFooterContent":
  1045. case "BatesContent":
  1046. case "WatermarkContent":
  1047. case "BackgroundContent":
  1048. case "RedactionContent":
  1049. ToolContentVisible = Visibility.Visible;
  1050. break;
  1051. default:
  1052. break;
  1053. }
  1054. PDFEditMode(currentBar);
  1055. FormMode(currentBar);
  1056. }
  1057. private void PDFEditMode(string currentBar)
  1058. {
  1059. if (currentBar == "TabItemEdit")
  1060. {
  1061. if (PDFViewer != null)
  1062. {
  1063. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  1064. //SelectedPrpoertyPanel("TextEditProperty", null);
  1065. //IsPropertyOpen = true;
  1066. }
  1067. }
  1068. else
  1069. {
  1070. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  1071. {
  1072. IsPropertyOpen = false;
  1073. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1074. }
  1075. }
  1076. }
  1077. private void FormMode(string currentBar)
  1078. {
  1079. if (currentBar == "TabItemForm")
  1080. {
  1081. if (PDFViewer != null)
  1082. {
  1083. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  1084. }
  1085. }
  1086. else
  1087. {
  1088. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  1089. {
  1090. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1091. }
  1092. }
  1093. }
  1094. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  1095. {
  1096. if (!isInPageEdit)
  1097. {
  1098. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  1099. //页面编辑模式下,按钮状态根据页面编辑的undo redo来显示
  1100. if (e.PropertyName == "CanUndo")
  1101. {
  1102. CanUndo = PDFViewer.UndoManager.CanUndo;
  1103. }
  1104. if (e.PropertyName == "CanRedo")
  1105. {
  1106. CanRedo = PDFViewer.UndoManager.CanRedo;
  1107. }
  1108. }
  1109. if (e.PropertyName == "CanSave")
  1110. {
  1111. CanSave = PDFViewer.UndoManager.CanSave;
  1112. }
  1113. }
  1114. /// <summary>
  1115. /// 选项卡切换事件
  1116. /// </summary>
  1117. /// <param name="e"></param>
  1118. private void TabControlSelectonChangedEvent(object e)
  1119. {
  1120. var args = e as SelectionChangedEventArgs;
  1121. if (args != null)
  1122. {
  1123. var item = args.AddedItems[0] as TabItem;
  1124. CurrentBar = item.Name;
  1125. if (previousBar != CurrentBar)
  1126. {
  1127. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  1128. {
  1129. EnterToolMode(barContentByTabItem[CurrentBar]);
  1130. isInPageEdit = true;
  1131. }
  1132. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  1133. {
  1134. EnterSelectedBar(CurrentBar);
  1135. isInPageEdit = false;
  1136. }
  1137. previousBar = CurrentBar;
  1138. }
  1139. }
  1140. }
  1141. /// <summary>
  1142. /// 阅读模式
  1143. /// </summary>
  1144. /// <param name="viewContent"></param>
  1145. public async void RbtnReadMode()
  1146. {
  1147. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  1148. mainViewModel.IsBookMode = true;
  1149. IsLoading = Visibility.Visible;
  1150. await Task.Delay(1);
  1151. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1152. NavigationParameters param = new NavigationParameters();
  1153. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1154. param.Add(ParameterNames.ViewContentViewModel, this);
  1155. region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  1156. //ShowContent(CurrentBar, true);
  1157. if (GridToolRow != 0)
  1158. {
  1159. GridToolRow = 0;
  1160. }
  1161. if (GridToolRowSpan != 4)
  1162. {
  1163. GridToolRowSpan = 4;
  1164. }
  1165. //isInPageEdit = true;
  1166. UpdateShowContent("TabItemPageEdit");
  1167. IsLoading = Visibility.Collapsed;
  1168. }
  1169. /// <summary>
  1170. /// 退出阅读模式
  1171. /// </summary>
  1172. public async void UnReadModel()
  1173. {
  1174. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  1175. mainViewModel.IsBookMode = false;
  1176. IsLoading = Visibility.Visible;
  1177. await Task.Delay(1);
  1178. //PDFViewer.MouseMode = MouseModes.None;
  1179. if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  1180. {
  1181. if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1182. {
  1183. var contentRegion = region.Regions[ViwerRegionName];
  1184. contentRegion.Remove(PDFViewer);
  1185. }
  1186. region.AddToRegion(ViwerRegionName, PDFViewer);
  1187. }
  1188. if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  1189. {
  1190. EnterSelectedBar("TabItemAnnotation");
  1191. }
  1192. else
  1193. {
  1194. EnterSelectedBar(CurrentBar);
  1195. }
  1196. bool isExist = false;
  1197. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1198. {
  1199. var views = region.Regions[TipContentRegionName].Views;
  1200. foreach (var item in views)
  1201. {
  1202. if (item is Views.TipContent.ReadModelTip readModelTip)
  1203. {
  1204. isExist = true;
  1205. break;
  1206. }
  1207. }
  1208. }
  1209. if (isExist == false)
  1210. {
  1211. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  1212. }
  1213. IsLoading = Visibility.Collapsed;
  1214. ShowTip(true);
  1215. await Task.Delay(3000);
  1216. //ReadModelTip = Visibility.Collapsed;
  1217. TipVisible = Visibility.Collapsed;
  1218. }
  1219. #region PDFViewer鼠标滚轮缩放事件
  1220. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  1221. {
  1222. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  1223. PDFViewer.Zoom(newZoom);
  1224. }
  1225. public double CheckZoomLevel(double zoom, bool IsGrowth)
  1226. {
  1227. double standardZoom = 100;
  1228. if (zoom <= 0.01)
  1229. {
  1230. return 0.01;
  1231. }
  1232. if (zoom >= 10)
  1233. {
  1234. return 10;
  1235. }
  1236. zoom *= 100;
  1237. for (int i = 0; i < zoomLevel.Length - 1; i++)
  1238. {
  1239. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  1240. {
  1241. standardZoom = zoomLevel[i + 1];
  1242. break;
  1243. }
  1244. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  1245. {
  1246. standardZoom = zoomLevel[i];
  1247. break;
  1248. }
  1249. }
  1250. return standardZoom / 100;
  1251. }
  1252. #endregion PDFViewer鼠标滚轮缩放事件
  1253. #region Navigate
  1254. public void OnNavigatedTo(NavigationContext navigationContext)
  1255. {
  1256. if (isOpenFile)
  1257. return;
  1258. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  1259. if (mainVM != null)
  1260. {
  1261. mainViewModel = mainVM;
  1262. mainViewModel.viewContentViewModel = this;
  1263. }
  1264. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  1265. if (pdfview != null)
  1266. {
  1267. PDFViewer = pdfview;
  1268. if (pdfview.Tag != null)
  1269. {
  1270. //保存密码
  1271. PassWord = pdfview.Tag.ToString();
  1272. }
  1273. loadFile();
  1274. CheckHaveAllPermission();
  1275. }
  1276. isOpenFile = true;
  1277. }
  1278. public bool IsNavigationTarget(NavigationContext navigationContext)
  1279. {
  1280. if (navigationContext != null)
  1281. {
  1282. //另存为打开导航进来时 不能新建一个实例
  1283. return true;
  1284. }
  1285. else
  1286. {
  1287. //一次性打开多个文件时,需要新建实例
  1288. return false;
  1289. }
  1290. }
  1291. public void OnNavigatedFrom(NavigationContext navigationContext)
  1292. {
  1293. }
  1294. #endregion Navigate
  1295. #region 方法
  1296. /// <summary>
  1297. /// 视图面板 切换分屏模式
  1298. /// </summary>
  1299. /// <param name="mode"></param>
  1300. public void EnterSplitMode(SplitMode mode)
  1301. {
  1302. ///通知UI层更改布局
  1303. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  1304. }
  1305. private void Undo()
  1306. {
  1307. if (isInPageEdit)
  1308. {
  1309. //执行页面编辑的Undo
  1310. PageEditUndo?.Invoke();
  1311. }
  1312. else
  1313. {
  1314. PDFViewer.UndoManager.Undo();
  1315. }
  1316. }
  1317. private void Redo()
  1318. {
  1319. if (isInPageEdit)
  1320. {
  1321. //执行页面编辑的Redo
  1322. PageEditRedo?.Invoke();
  1323. }
  1324. else
  1325. {
  1326. PDFViewer.UndoManager.Redo();
  1327. }
  1328. }
  1329. private void LoadControl()
  1330. {
  1331. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  1332. // 非必要情况不要使用该异步方法,可能会导致一次性加载多个文件时出现因异步引起的regionname 错乱问题
  1333. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1334. // {
  1335. NavigationParameters parameters = new NavigationParameters();
  1336. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1337. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1338. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  1339. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  1340. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  1341. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  1342. //TODO 根据上一次关闭记录的菜单,选中TabItem
  1343. EnterSelectedBar("TabItemAnnotation");
  1344. //}
  1345. //));
  1346. //if (App.IsBookMode)
  1347. //{
  1348. // RbtnReadMode();
  1349. //}
  1350. //else
  1351. //{
  1352. // UnReadModel();
  1353. //}
  1354. }
  1355. /// <summary>
  1356. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  1357. /// </summary>
  1358. /// <param name="Content"></param>
  1359. /// <param name="annotPropertyPanel"></param>
  1360. public void SelectedPrpoertyPanel(string Content, AnnotPropertyPanel annotPropertyPanel)
  1361. {
  1362. NavigationParameters parameters = new NavigationParameters();
  1363. //传其他参数:文档类,空注释面板;
  1364. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1365. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  1366. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1367. region.RequestNavigate(PropertyRegionName, Content, parameters);
  1368. }
  1369. /// <summary>
  1370. /// 将PDFViwer添加到Region
  1371. /// </summary>
  1372. private void loadFile()
  1373. {
  1374. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  1375. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  1376. CanSave = PDFViewer.UndoManager.CanSave;
  1377. CanUndo = PDFViewer.UndoManager.CanUndo;
  1378. CanRedo = PDFViewer.UndoManager.CanRedo;
  1379. region.Regions[ViwerRegionName].RemoveAll();
  1380. //OpenFileInfo 内容赋值给PDFViewer
  1381. GetOpenFileInfo();
  1382. region.AddToRegion(ViwerRegionName, PDFViewer);
  1383. }
  1384. private void GetOpenFileInfo()
  1385. {
  1386. OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1387. if (OpenFileInfo != null)
  1388. {
  1389. if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
  1390. {
  1391. PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
  1392. }
  1393. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  1394. {
  1395. PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
  1396. }
  1397. if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
  1398. {
  1399. PDFViewer.Zoom(OpenFileInfo.LastZoom);
  1400. }
  1401. if (OpenFileInfo.LastPageIndex != PDFViewer.CurrentIndex)
  1402. {
  1403. PDFViewer.GoToPage(OpenFileInfo.LastPageIndex);
  1404. }
  1405. PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
  1406. PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
  1407. if (OpenFileInfo.LastPageSpace)
  1408. {
  1409. PDFViewer.SetPageSpacing(8);
  1410. }
  1411. else
  1412. {
  1413. PDFViewer.SetPageSpacing(0);
  1414. }
  1415. if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
  1416. {
  1417. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
  1418. }
  1419. else
  1420. {
  1421. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
  1422. }
  1423. }
  1424. }
  1425. /// <summary>
  1426. /// 已有路径文档的保存逻辑
  1427. /// </summary>
  1428. public bool saveFile()
  1429. {
  1430. try
  1431. {
  1432. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
  1433. return saveAsFile();
  1434. //文档已被修复时 提示另存为
  1435. if (PDFViewer.Document.HasRepaired)
  1436. {
  1437. AlertsMessage alertsMessage = new AlertsMessage();
  1438. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  1439. if (alertsMessage.result == ContentResult.Ok)
  1440. return saveAsFile();
  1441. else
  1442. return false;
  1443. }
  1444. //文件路径无法存在时
  1445. if (!File.Exists(PDFViewer.Document.FilePath))
  1446. {
  1447. AlertsMessage alertsMessage = new AlertsMessage();
  1448. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  1449. if (alertsMessage.result == ContentResult.Ok)
  1450. return saveAsFile();
  1451. else
  1452. return false;
  1453. }
  1454. //只读文件无法写入时,提示另存为
  1455. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  1456. if (fileInfo.IsReadOnly)
  1457. {
  1458. AlertsMessage alertsMessage = new AlertsMessage();
  1459. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  1460. if (alertsMessage.result == ContentResult.Ok)
  1461. return saveAsFile();
  1462. else
  1463. return false;
  1464. }
  1465. //Security Fixed:
  1466. //修改密码后原文档保存的步骤:
  1467. //在设置密码窗口传出“已修改”信号,并允许延迟保存
  1468. //延迟保存方式:
  1469. //
  1470. //
  1471. if (SecurityInfo.IsPasswordChanged)
  1472. {
  1473. string currentFilePath = PDFViewer.Document.FilePath;
  1474. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  1475. string openPassword = null;
  1476. string permissionsPassword = null;
  1477. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  1478. if (SecurityInfo.NeedOpenPassword)
  1479. {
  1480. openPassword = SecurityInfo.OpenPassword;
  1481. }
  1482. if (SecurityInfo.NeedPermissionsPassword)
  1483. {
  1484. permissionsPassword = SecurityInfo.PermissionsPassword;
  1485. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  1486. }
  1487. try
  1488. {
  1489. string currentPath = PDFViewer.Document.FilePath;
  1490. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  1491. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1492. PDFViewer.Document.WriteToFilePath(tempPath);
  1493. PDFViewer.CloseDocument();
  1494. PDFViewer.InitDocument(tempPath);
  1495. if (!string.IsNullOrEmpty(permissionsPassword))
  1496. {
  1497. PDFViewer.Document.UnlockWithPassword(permissionsPassword);
  1498. }
  1499. else if (!string.IsNullOrEmpty(openPassword))
  1500. {
  1501. PDFViewer.Document.UnlockWithPassword(openPassword);
  1502. }
  1503. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1504. PDFViewer.Document.WriteToFilePath(currentPath);
  1505. PDFViewer.CloseDocument();
  1506. PDFViewer.InitDocument(currentPath);
  1507. //System.IO.File.Delete(tempPath);
  1508. if (!string.IsNullOrEmpty(permissionsPassword))
  1509. {
  1510. PDFViewer.Document.UnlockWithPassword(permissionsPassword);
  1511. }
  1512. else if (!string.IsNullOrEmpty(openPassword))
  1513. {
  1514. PDFViewer.Document.UnlockWithPassword(openPassword);
  1515. }
  1516. try
  1517. {
  1518. PDFViewer.Load();
  1519. }
  1520. catch
  1521. {
  1522. }
  1523. PDFViewer.UndoManager.CanSave = false;
  1524. SecurityInfo.IsPasswordChanged = false;
  1525. return true;
  1526. }
  1527. catch
  1528. {
  1529. return false;
  1530. }
  1531. }
  1532. bool result = PDFViewer.Document.WriteToLoadedPath();
  1533. if (result)
  1534. {
  1535. PDFViewer.UndoManager.CanSave = false;
  1536. App.Current.Dispatcher.Invoke(() =>
  1537. {
  1538. //保存时更新缩略图
  1539. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1540. try
  1541. {
  1542. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  1543. {
  1544. var size = PDFViewer.Document.GetPageSize(0);
  1545. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  1546. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  1547. if (File.Exists(folderPath))
  1548. File.Delete(folderPath);
  1549. DirectoryInfo folder = new DirectoryInfo(folderPath);
  1550. if (!folder.Exists)
  1551. folder.Create();
  1552. string imagePath = info.ThumbImgPath;
  1553. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  1554. {
  1555. string imageName = Guid.NewGuid().ToString();
  1556. imagePath = System.IO.Path.Combine(folderPath, imageName);
  1557. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  1558. {
  1559. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1560. }
  1561. }
  1562. else
  1563. {
  1564. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  1565. {
  1566. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1567. }
  1568. }
  1569. info.ThumbImgPath = imagePath;
  1570. SettingHelper.SetFileInfo(info);
  1571. }
  1572. }
  1573. catch
  1574. {
  1575. info.ThumbImgPath = null;
  1576. SettingHelper.SetFileInfo(info);
  1577. }
  1578. });
  1579. PDFViewer.ReloadDocument();
  1580. }
  1581. else
  1582. {
  1583. //文件被占用 保存失败时
  1584. AlertsMessage alertsMessage = new AlertsMessage();
  1585. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  1586. if (alertsMessage.result == ContentResult.Ok)
  1587. return saveAsFile();
  1588. else
  1589. return false;
  1590. }
  1591. return result;
  1592. }
  1593. catch { return false; }
  1594. }
  1595. /// <summary>
  1596. /// 另存为或新文档保存逻辑
  1597. /// </summary>
  1598. public bool saveAsFile(Action RedactionAction = null)
  1599. {
  1600. var dlg = new Microsoft.Win32.SaveFileDialog();
  1601. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1602. dlg.FileName = PDFViewer.Document.FileName;
  1603. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1604. {
  1605. bool result = false;
  1606. if (RedactionAction != null)
  1607. {
  1608. //保存前进行标记密文处理应用或擦除
  1609. RedactionAction.Invoke();
  1610. }
  1611. if (App.OpenedFileList.Contains(dlg.FileName))
  1612. {
  1613. //提示文件已经被打开
  1614. }
  1615. else
  1616. {
  1617. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  1618. if (result)
  1619. {
  1620. DoAfterSaveAs(dlg.FileName);
  1621. }
  1622. else
  1623. {
  1624. //提示文件被其他软件占用 无法保存
  1625. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
  1626. }
  1627. ;
  1628. }
  1629. return result;
  1630. }
  1631. else
  1632. return false;
  1633. }
  1634. /// <summary>
  1635. /// 另存为Flatten
  1636. /// </summary>
  1637. private void saveAsFlatten()
  1638. {
  1639. var dlg = new SaveFileDialog();
  1640. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1641. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  1642. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1643. {
  1644. saveFile();
  1645. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  1646. if (kmdoc == null)
  1647. return;
  1648. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  1649. if (result)
  1650. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  1651. kmdoc.Release();
  1652. }
  1653. }
  1654. /// <summary>
  1655. /// 另存为后进行的操作
  1656. /// 重新打开新文档
  1657. /// </summary>
  1658. /// <param name="targetPath"></param>
  1659. public void DoAfterSaveAs(string targetPath)
  1660. {
  1661. App.OpenedFileList.Remove(targetPath);
  1662. string oldFilePath = targetPath;
  1663. PDFViewer.UndoManager.CanSave = false;
  1664. mainViewModel.OpenFile(targetPath);
  1665. //TODO:通知各模块更新PDFview对象
  1666. //var result = OpenFile(targetPath, true);
  1667. //if (result)
  1668. //{
  1669. // FileChanged.Invoke(this, null);
  1670. // Zoomer.PdfViewer = PdfViewer;
  1671. // PageSelector.PdfViewer = PdfViewer;
  1672. // ViewModeSelector.PdfViewer = PdfViewer;
  1673. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  1674. // if (fileInfo != null)
  1675. // {
  1676. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  1677. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  1678. // if (fileInfo.LastFitMode == FitMode.FitFree)
  1679. // PdfViewer.Zoom(fileInfo.LastZoom);
  1680. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  1681. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  1682. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  1683. // else
  1684. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  1685. // }
  1686. //}
  1687. }
  1688. /// <summary>
  1689. /// 显示前添加内容到Region
  1690. /// </summary>
  1691. /// <param name="isPageEdit"></param>
  1692. private void ShowContent(string currentBar, bool isToolMode = false)
  1693. {
  1694. GridVisibility = Visibility.Visible;
  1695. //显示页面编辑或其他工具
  1696. if (currentBar == "TabItemPageEdit" || isToolMode)
  1697. {
  1698. if (currentBar == "TabItemPageEdit")//进入页面编辑
  1699. {
  1700. if (GridToolRow != 1)
  1701. {
  1702. GridToolRow = 1;
  1703. }
  1704. if (GridToolRowSpan != 3)
  1705. {
  1706. GridToolRowSpan = 3;
  1707. }
  1708. }
  1709. else//进入水印等其他工具模式
  1710. {
  1711. GridVisibility = Visibility.Collapsed;
  1712. if (GridToolRow != 0)
  1713. {
  1714. GridToolRow = 0;
  1715. }
  1716. if (GridToolRowSpan != 4)
  1717. {
  1718. GridToolRowSpan = 4;
  1719. }
  1720. }
  1721. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  1722. UpdateShowContent(currentBar);
  1723. }
  1724. else
  1725. {
  1726. if (GridToolRow != 1)
  1727. {
  1728. GridToolRow = 1;
  1729. }
  1730. UpdateShowContent(currentBar);
  1731. }
  1732. }
  1733. /// <summary>
  1734. /// 从二级工具栏进入需要修改界面布局的场景
  1735. /// </summary>
  1736. /// <param name="EditToolName"></param>
  1737. private void EnterEditTools(StringWithUnicode EditToolName)
  1738. {
  1739. EnterSelectedEditTool(EditToolName);
  1740. }
  1741. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  1742. {
  1743. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  1744. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  1745. {
  1746. PDFViewer.Document.ReleasePages();
  1747. PDFViewer.ReloadDocument();
  1748. }
  1749. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  1750. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1751. {
  1752. region.AddToRegion(ViwerRegionName, PDFViewer);
  1753. }
  1754. CurrentBar = "TabItemTool";
  1755. EnterSelectedBar(CurrentBar);
  1756. }
  1757. /// <summary>
  1758. /// 二级菜单指定目标处理
  1759. /// </summary>
  1760. /// <param name="e"></param>
  1761. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  1762. {
  1763. CurrentBar = EditToolName.EditToolsContentName;
  1764. EnterToolMode(CurrentBar);
  1765. }
  1766. /// <summary>
  1767. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  1768. /// </summary>
  1769. /// <param name="targetToolMode">要导航过去的控件名称</param>
  1770. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  1771. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  1772. {
  1773. IsLoading = Visibility.Visible;
  1774. await Task.Delay(3);
  1775. NavigationParameters param = new NavigationParameters();
  1776. if (valuePairs == null)
  1777. {
  1778. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1779. param.Add(ParameterNames.ViewContentViewModel, this);
  1780. }
  1781. else//有传入其他内容的参数时
  1782. {
  1783. param = valuePairs;
  1784. }
  1785. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  1786. ShowContent(CurrentBar, true);
  1787. IsLoading = Visibility.Collapsed;
  1788. }
  1789. private void EnterSelectedBar(string currentBar)
  1790. {
  1791. NavigationParameters param = new NavigationParameters();
  1792. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1793. param.Add(ParameterNames.ViewContentViewModel, this);
  1794. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  1795. if (currentBar == "TabItemScan")
  1796. {
  1797. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  1798. }
  1799. ShowContent(currentBar);
  1800. }
  1801. /// <summary>
  1802. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  1803. /// </summary>
  1804. public void ExitToolMode()
  1805. {
  1806. ToolContentVisible = Visibility.Collapsed;
  1807. if (isInPageEdit)
  1808. {
  1809. TabSelectedIndex = 0;
  1810. isInPageEdit = false;
  1811. }
  1812. }
  1813. #endregion 方法
  1814. }
  1815. }