ViewContentViewModel.cs 78 KB

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