ViewContentViewModel.cs 79 KB

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