ViewContentViewModel.cs 115 KB

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