ViewContentViewModel.cs 144 KB

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