ViewContentViewModel.cs 77 KB

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