ViewContentViewModel.cs 105 KB

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