ViewContentViewModel.cs 79 KB

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