ViewContentViewModel.cs 125 KB

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