ViewContentViewModel.cs 122 KB

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