ViewContentViewModel.cs 110 KB

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