ViewContentViewModel.cs 139 KB

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