ViewContentViewModel.cs 119 KB

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