ViewContentViewModel.cs 86 KB

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