ViewContentViewModel.cs 98 KB

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