ViewContentViewModel.cs 118 KB

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