ViewContentViewModel.cs 120 KB

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