ViewContentViewModel.cs 132 KB

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