ViewContentViewModel.cs 118 KB

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