ViewContentViewModel.cs 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577
  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. namespace PDF_Master.ViewModels
  45. {
  46. public class ViewContentViewModel : BindableBase, INavigationAware
  47. {
  48. #region 文案
  49. private string T_file;
  50. public string T_File
  51. {
  52. get { return T_file; }
  53. set
  54. {
  55. SetProperty(ref T_file, value);
  56. }
  57. }
  58. private string T_save;
  59. public string T_Save
  60. {
  61. get { return T_save; }
  62. set
  63. {
  64. SetProperty(ref T_save, value);
  65. }
  66. }
  67. private string T_undo;
  68. public string T_Undo
  69. {
  70. get { return T_undo; }
  71. set
  72. {
  73. SetProperty(ref T_undo, value);
  74. }
  75. }
  76. private string T_redo;
  77. public string T_Redo
  78. {
  79. get { return T_redo; }
  80. set
  81. {
  82. SetProperty(ref T_redo, value);
  83. }
  84. }
  85. private string T_annotation;
  86. public string T_Annotation
  87. {
  88. get { return T_annotation; }
  89. set
  90. {
  91. SetProperty(ref T_annotation, value);
  92. }
  93. }
  94. private string T_pageEdit;
  95. public string T_PageEdit
  96. {
  97. get { return T_pageEdit; }
  98. set
  99. {
  100. SetProperty(ref T_pageEdit, value);
  101. }
  102. }
  103. private string T_converter;
  104. public string T_Converter
  105. {
  106. get { return T_converter; }
  107. set
  108. {
  109. SetProperty(ref T_converter, value);
  110. }
  111. }
  112. private string T_fillSign;
  113. public string T_FillSign
  114. {
  115. get { return T_fillSign; }
  116. set
  117. {
  118. SetProperty(ref T_fillSign, value);
  119. }
  120. }
  121. private string T_tools;
  122. public string T_Tools
  123. {
  124. get { return T_tools; }
  125. set
  126. {
  127. SetProperty(ref T_tools, value);
  128. }
  129. }
  130. private string T_print;
  131. public string T_Print
  132. {
  133. get { return T_print; }
  134. set
  135. {
  136. SetProperty(ref T_print, value);
  137. }
  138. }
  139. private string T_share;
  140. public string T_Share
  141. {
  142. get { return T_share; }
  143. set
  144. {
  145. SetProperty(ref T_share, value);
  146. }
  147. }
  148. private string T_properties;
  149. public string T_Properties
  150. {
  151. get { return T_properties; }
  152. set
  153. {
  154. SetProperty(ref T_properties, value);
  155. }
  156. }
  157. private void InitStirng()
  158. {
  159. T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
  160. T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
  161. T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
  162. T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
  163. T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
  164. T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
  165. T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
  166. T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
  167. T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
  168. T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
  169. T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
  170. T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
  171. }
  172. #endregion 文案
  173. #region 属性、变量
  174. public OpenFileInfo OpenFileInfo = null;
  175. public CPDFViewer PDFViewer { get; set; }
  176. public MainContentViewModel mainViewModel { get; set; }
  177. public IRegionManager region;
  178. public IDialogService dialogs;
  179. public IEventAggregator events;
  180. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  181. public string ViwerRegionName { get; set; }
  182. /// <summary>
  183. /// 分屏视图的region名称
  184. /// </summary>
  185. public string SplitViewerRegionName { get; set; }
  186. /// <summary>
  187. /// OCR视图名称
  188. /// </summary>
  189. public string OCRViewerRegionName { get; set; }
  190. public string BOTARegionName { get; set; }
  191. public string PropertyRegionName { get; set; }
  192. public string ToolContentRegionName { get; set; }
  193. public string ToolsBarContentRegionName { get; set; }
  194. /// <summary>
  195. /// 顶部提示的Content
  196. /// </summary>
  197. public string TipContentRegionName { get; set; }
  198. public string LeftTipContentRegionName { get; set; }
  199. //便签弹窗
  200. public string NotePopupRegionName { get; set; }
  201. public string ReadModeRegionName { get; set; }
  202. public string ConverterBarContentRegionName { get; set; }
  203. public string TextEditContentRegionName { get; set; }
  204. public string BackgroundContentRegionName { get; set; }
  205. public PasswordInfo PasswordInfo = new PasswordInfo();
  206. //若point不赋值或从列表中找不到point,系统会提供默认值为(0,0)的新point,所以改用Tuple<int,int>
  207. public List<FillAndSignIsShape> FillAndSign = new List<FillAndSignIsShape>();
  208. /// <summary>
  209. /// 签名列表
  210. /// </summary>
  211. public List<Tuple<int, int>> AnnotSignatures = new List<Tuple<int, int>>();
  212. /// <summary>
  213. /// 文档的密码
  214. /// </summary>
  215. public string PassWord { get; set; }
  216. public PasswordInfo passwordInfo = new PasswordInfo();
  217. private Visibility tipVisible = Visibility.Collapsed;
  218. /// <summary>
  219. /// 顶部提示栏的显示状态
  220. /// </summary>
  221. public Visibility TipVisible
  222. {
  223. get { return tipVisible; }
  224. set
  225. {
  226. SetProperty(ref tipVisible, value);
  227. }
  228. }
  229. private Visibility leftTipVisible = Visibility.Collapsed;
  230. public Visibility LeftTipVisible
  231. {
  232. get { return leftTipVisible; }
  233. set
  234. {
  235. SetProperty(ref leftTipVisible, value);
  236. }
  237. }
  238. private Visibility notePopupVisible = Visibility.Collapsed;
  239. public Visibility NotePopupVisible
  240. {
  241. get { return notePopupVisible; }
  242. set
  243. {
  244. SetProperty(ref notePopupVisible, value);
  245. }
  246. }
  247. public bool IsNoteAdd = false;
  248. private double canvasNoteLeft;
  249. public double CanvasNoteLeft
  250. {
  251. get { return canvasNoteLeft; }
  252. set
  253. {
  254. SetProperty(ref canvasNoteLeft, value);
  255. }
  256. }
  257. private double canvasNoteBottom;
  258. public double CanvasNoteBottom
  259. {
  260. get { return canvasNoteBottom; }
  261. set
  262. {
  263. SetProperty(ref canvasNoteBottom, value);
  264. }
  265. }
  266. /// <summary>
  267. /// 底部工具栏 RegionName
  268. /// </summary>
  269. public string BottomToolRegionName { get; set; }
  270. private bool _isInPageEdit = false;
  271. /// <summary>
  272. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  273. /// </summary>
  274. public bool isInPageEdit
  275. {
  276. get { return _isInPageEdit; }
  277. set
  278. {
  279. SetProperty(ref _isInPageEdit, value);
  280. //if (!value)
  281. //{
  282. // CanRedo = PDFViewer.UndoManager.CanRedo;
  283. // CanUndo = PDFViewer.UndoManager.CanUndo;
  284. //}
  285. }
  286. }
  287. public Action PageEditUndo { get; set; }
  288. public Action PageEditRedo { get; set; }
  289. /// <summary>
  290. ///工具条
  291. ///0:收起
  292. ///40:显示
  293. /// </summary>
  294. private int toolRowHeight = 40;
  295. public int ToolRowHeight
  296. {
  297. get { return toolRowHeight; }
  298. set
  299. {
  300. SetProperty(ref toolRowHeight, value);
  301. }
  302. }
  303. /// <summary>
  304. /// 水印,背景侧边栏宽度
  305. /// 0:收起
  306. /// 260:显示
  307. /// </summary>
  308. private int propertyColumnWidth = 0;
  309. public int PropertyColumnWidth
  310. {
  311. get { return propertyColumnWidth; }
  312. set
  313. {
  314. SetProperty(ref propertyColumnWidth, value);
  315. }
  316. }
  317. private int gridToolRow = 1;
  318. /// <summary>
  319. /// 控制ToolContent的Row
  320. /// </summary>
  321. public int GridToolRow
  322. {
  323. get { return gridToolRow; }
  324. set
  325. {
  326. SetProperty(ref gridToolRow, value);
  327. }
  328. }
  329. private int gridToolRowSpan = 3;
  330. /// <summary>
  331. /// 控制ToolContent的RowSpan
  332. /// </summary>
  333. public int GridToolRowSpan
  334. {
  335. get { return gridToolRowSpan; }
  336. set
  337. {
  338. SetProperty(ref gridToolRowSpan, value);
  339. }
  340. }
  341. private Visibility toolContentVisible = Visibility.Collapsed;
  342. /// <summary>
  343. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  344. /// 留意:显示前需要先注入内容、设置好行和跨行数
  345. /// </summary>
  346. public Visibility ToolContentVisible
  347. {
  348. get { return toolContentVisible; }
  349. set
  350. {
  351. SetProperty(ref toolContentVisible, value);
  352. }
  353. }
  354. private Visibility gridVisibility = Visibility.Visible;
  355. /// <summary>
  356. /// 是否正在加载中
  357. /// </summary>
  358. public Visibility GridVisibility
  359. {
  360. get { return gridVisibility; }
  361. set
  362. {
  363. SetProperty(ref gridVisibility, value);
  364. }
  365. }
  366. private Visibility isLoading = Visibility.Collapsed;
  367. private Visibility ocrContentVisible = Visibility.Collapsed;
  368. public Visibility OCRContentVisible
  369. {
  370. get { return ocrContentVisible; }
  371. set
  372. {
  373. SetProperty(ref ocrContentVisible, value);
  374. }
  375. }
  376. /// <summary>
  377. /// 是否正在加载中
  378. /// </summary>
  379. public Visibility IsLoading
  380. {
  381. get { return isLoading; }
  382. set
  383. {
  384. SetProperty(ref isLoading, value);
  385. }
  386. }
  387. private Visibility converterBarContentVisible = Visibility.Collapsed;
  388. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  389. /// <summary>
  390. /// 控制ToolsBarContent的显示
  391. /// 留意:显示前需要先注入内容、设置好行和跨行数
  392. /// </summary>
  393. public Visibility ConverterBarContentVisible
  394. {
  395. get { return converterBarContentVisible; }
  396. set
  397. {
  398. SetProperty(ref converterBarContentVisible, value);
  399. }
  400. }
  401. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  402. /// <summary>
  403. /// 控制ToolsBarContent的显示
  404. /// 留意:显示前需要先注入内容、设置好行和跨行数
  405. /// </summary>
  406. public Visibility ToolsBarContentVisible
  407. {
  408. get { return toolsBarContentVisible; }
  409. set
  410. {
  411. SetProperty(ref toolsBarContentVisible, value);
  412. }
  413. }
  414. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  415. /// <summary>
  416. /// 控制ToolsBarContent的显示
  417. /// 留意:显示前需要先注入内容、设置好行和跨行数
  418. /// </summary>
  419. public Visibility TextEditToolContentVisible
  420. {
  421. get { return textEditToolContentVisible; }
  422. set
  423. {
  424. SetProperty(ref textEditToolContentVisible, value);
  425. }
  426. }
  427. private bool isPorpertyOpen = false;
  428. /// <summary>
  429. /// 属性栏是否展开
  430. /// </summary>
  431. public bool IsPropertyOpen
  432. {
  433. get { return isPorpertyOpen; }
  434. set
  435. {
  436. //如果设置为手动展开属性面板时,则不响应代码控制的展开
  437. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty)
  438. {
  439. if (mainViewModel.IsBookMode)
  440. {
  441. this.events.GetEvent<ReadModePropertyOpenEvent>().Publish(new ReadModePropertyOpenArgs() { Unicode = unicode });
  442. }
  443. SetProperty(ref isPorpertyOpen, value);
  444. }
  445. }
  446. }
  447. private Visibility isReadMode = Visibility.Visible;
  448. /// <summary>
  449. ///是否为阅读模式
  450. /// </summary>
  451. public Visibility IsReadMode
  452. {
  453. get { return isReadMode; }
  454. set
  455. {
  456. SetProperty(ref isReadMode, value);
  457. }
  458. }
  459. private bool canSave;
  460. /// <summary>
  461. /// 是否可以保存
  462. /// </summary>
  463. public bool CanSave
  464. {
  465. get { return canSave; }
  466. set
  467. {
  468. if (events != null && canSave == false)
  469. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = "Clear", AppUnicode = unicode });
  470. SetProperty(ref canSave, value);
  471. }
  472. }
  473. private bool canUndo;
  474. /// <summary>
  475. /// 是否可以进行Undo
  476. /// </summary>
  477. public bool CanUndo
  478. {
  479. get { return canUndo; }
  480. set
  481. {
  482. SetProperty(ref canUndo, value);
  483. }
  484. }
  485. private bool canRedo;
  486. /// <summary>
  487. /// 是否可以进行Redo
  488. /// </summary>
  489. public bool CanRedo
  490. {
  491. get { return canRedo; }
  492. set
  493. {
  494. SetProperty(ref canRedo, value);
  495. }
  496. }
  497. private GridLength botaWidth = new GridLength(48);
  498. /// <summary>
  499. /// BOTA栏的宽度
  500. /// </summary>
  501. public GridLength BOTAWidth
  502. {
  503. get { return botaWidth; }
  504. set
  505. {
  506. SetProperty(ref botaWidth, value);
  507. if (botaWidth.Value <= 48)
  508. {
  509. OpenBOTA = false;
  510. }
  511. }
  512. }
  513. private int selectedIndex;
  514. /// <summary>
  515. /// 工具栏选中项的索引
  516. /// </summary>
  517. public int TabSelectedIndex
  518. {
  519. get { return selectedIndex; }
  520. set
  521. {
  522. SetProperty(ref selectedIndex, value);
  523. }
  524. }
  525. private bool openBOTA = false;
  526. /// <summary>
  527. /// 是否展开BOTA
  528. /// </summary>
  529. public bool OpenBOTA
  530. {
  531. get { return openBOTA; }
  532. set
  533. {
  534. SetProperty(ref openBOTA, value);
  535. if (openBOTA && BOTAWidth.Value <= 48)
  536. {
  537. BOTAWidth = new GridLength(260);
  538. }
  539. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  540. }
  541. }
  542. public SecurityInfo SecurityInfo = new SecurityInfo();
  543. private Dictionary<string, string> regionNameByTabItem;
  544. private Dictionary<string, string> barContentByTabItem;
  545. private string previousBar = "";
  546. public string CurrentBar = "";
  547. public string unicode = null;
  548. /// <summary>
  549. /// 自动保存的定时器
  550. /// </summary>
  551. private DispatcherTimer autoSaveTimer = new DispatcherTimer();
  552. /// <summary>
  553. /// 用来避免重复触发导航事件的标志符
  554. /// </summary>
  555. private bool isOpenFile = false;
  556. /// <summary>
  557. /// 鼠标滚轮缩放的缩放值
  558. /// </summary>
  559. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  560. /// <summary>
  561. /// 注释-链接,提示语
  562. /// </summary>
  563. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  564. public Visibility LinkAnnotTipVisibility
  565. {
  566. get { return linkAnnotTipVisibility; }
  567. set
  568. {
  569. SetProperty(ref linkAnnotTipVisibility, value);
  570. }
  571. }
  572. private string linkAnnotTipText = "Please use the scroll bar, thumbnail tool to locate the target page, click or box the area to select the target range";
  573. private bool isCreateLink = false;
  574. public string LinkAnnotTipText
  575. {
  576. get { return linkAnnotTipText; }
  577. set
  578. {
  579. SetProperty(ref linkAnnotTipText, value);
  580. }
  581. }
  582. #endregion 属性、变量
  583. #region 命令
  584. public DelegateCommand Load { get; set; }
  585. public DelegateCommand MouseDown { get; set; }
  586. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  587. public DelegateCommand SaveFile { get; set; }
  588. public DelegateCommand SaveAsFile { get; set; }
  589. public DelegateCommand SaveAsFlattenCommand { get; set; }
  590. public DelegateCommand UndoCommand { get; set; }
  591. public DelegateCommand RedoCommand { get; set; }
  592. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  593. public DelegateCommand PrintCommand { get; set; }
  594. public DelegateCommand SelectCommand { get; set; }
  595. public DelegateCommand SettingsCommand { get; set; }
  596. public DelegateCommand ShareCommand { get; set; }
  597. public DelegateCommand<object> CreateLinkCommand { get; set; }
  598. public DelegateCommand PropertyCommand { get; set; }
  599. public DelegateCommand ShowInFolderCommand { get; set; }
  600. public DelegateCommand CompressCommand { get; set; }
  601. public DelegateCommand MergeFileCommand { get; set; }
  602. public DelegateCommand EncryptCommand { get; set; }
  603. public DelegateCommand DecryptCommand { get; set; }
  604. public DelegateCommand<string> ConvertCommand { get; set; }
  605. public DelegateCommand CloseWindowCommand { get; set; }
  606. public DelegateCommand OpenFileCommand { get; set; }
  607. public DelegateCommand<string> HelpCommand { get; set; }
  608. public DelegateCommand CreateBlankFileCommand { get; set; }
  609. public DelegateCommand CreateFromFile { get; set; }
  610. public DelegateCommand ClosePropertyCommand { get; set; }
  611. #endregion 命令
  612. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  613. {
  614. InitStirng();
  615. region = regionManager;
  616. dialogs = dialogService;
  617. events = eventAggregator;
  618. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  619. Load = new DelegateCommand(LoadControl);
  620. MouseDown = new DelegateCommand(MouseDownEvent);
  621. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  622. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  623. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  624. UndoCommand = new DelegateCommand(Undo);
  625. RedoCommand = new DelegateCommand(Redo);
  626. ShareCommand = new DelegateCommand(share);
  627. PropertyCommand = new DelegateCommand(property);
  628. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  629. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  630. CompressCommand = new DelegateCommand(compress);
  631. MergeFileCommand = new DelegateCommand(mergeFile);
  632. EncryptCommand = new DelegateCommand(encrypt);
  633. DecryptCommand = new DelegateCommand(decrypt);
  634. ConvertCommand = new DelegateCommand<string>(convert);
  635. CloseWindowCommand = new DelegateCommand(closeWindow);
  636. OpenFileCommand = new DelegateCommand(openfile);
  637. HelpCommand = new DelegateCommand<string>(help);
  638. CreateBlankFileCommand = new DelegateCommand(createBlankFile);
  639. CreateFromFile = new DelegateCommand(createfromFile);
  640. ViwerRegionName = RegionNames.ViwerRegionName;
  641. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  642. BOTARegionName = RegionNames.BOTARegionName;
  643. PropertyRegionName = RegionNames.PropertyRegionName;
  644. BottomToolRegionName = RegionNames.BottomToolRegionName;
  645. ReadModeRegionName = RegionNames.ReadModeRegionName;
  646. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  647. PrintCommand = new DelegateCommand(ShowPrintDialog);
  648. SelectCommand = new DelegateCommand(SelectClick);
  649. SettingsCommand = new DelegateCommand(SettingsEvent);
  650. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  651. ClosePropertyCommand = new DelegateCommand(CloseProperty);
  652. //未显示时无法注册上Region名称
  653. ToolContentVisible = Visibility.Visible;
  654. ToolsBarContentVisible = Visibility.Visible;
  655. OCRContentVisible = Visibility.Visible;
  656. TipVisible = Visibility.Visible;
  657. TipContentRegionName = RegionNames.TipContentRegionName;
  658. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  659. NotePopupRegionName = RegionNames.NotePopupRegionName;
  660. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  661. ToolContentRegionName = Guid.NewGuid().ToString();
  662. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  663. ConverterBarContentRegionName = Guid.NewGuid().ToString();
  664. TextEditContentRegionName = Guid.NewGuid().ToString();
  665. ToolContentVisible = Visibility.Collapsed;
  666. ToolsBarContentVisible = Visibility.Collapsed;
  667. OCRContentVisible = Visibility.Collapsed;
  668. TipVisible = Visibility.Collapsed;
  669. regionNameByTabItem = new Dictionary<string, string>();
  670. barContentByTabItem = new Dictionary<string, string>();
  671. InitialregionNameByTabItem(ref regionNameByTabItem);
  672. InitialbarContentByTabItem(ref barContentByTabItem);
  673. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  674. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  675. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTipAsync, e => e.Unicode == unicode);
  676. //TODO:根据缓存 选择用户上次选择的菜单
  677. CurrentBar = "TabItemAnnotation";
  678. EnterSelectedBar("TabItemAnnotation");
  679. StartAutoSave();
  680. }
  681. /// <summary>
  682. /// 开始自动保存
  683. /// </summary>
  684. public void StartAutoSave()
  685. {
  686. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  687. if(autoSave)
  688. {
  689. var interval = Settings.Default.AppProperties.Description.AutoSaveInterval;
  690. if(autoSaveTimer==null)
  691. {
  692. autoSaveTimer = new DispatcherTimer();
  693. }
  694. autoSaveTimer.Stop();
  695. autoSaveTimer.Interval = TimeSpan.FromMinutes(interval);
  696. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  697. autoSaveTimer.Tick += AutoSaveTimer_Tick;
  698. autoSaveTimer.Start();
  699. }
  700. }
  701. /// <summary>
  702. /// 释放定时器
  703. /// 不释放定时器可能会一直运行并占用内存,导致内存泄露
  704. /// </summary>
  705. public void CloseAutoSave()
  706. {
  707. autoSaveTimer.Stop();
  708. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  709. autoSaveTimer = null;
  710. }
  711. private void AutoSaveTimer_Tick(object sender, EventArgs e)
  712. {
  713. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  714. if (autoSave&&!mainViewModel.NewFile)
  715. {
  716. //自动保存仅针对已经有文件路径的文档
  717. saveFile();
  718. }
  719. }
  720. private void MouseDownEvent()
  721. {
  722. if (NotePopupVisible == Visibility.Visible && IsNoteAdd == false)
  723. {
  724. NotePopupVisible = Visibility.Collapsed;
  725. if (region.Regions.ContainsRegionWithName(NotePopupRegionName))
  726. {
  727. var views = region.Regions[NotePopupRegionName].Views;
  728. foreach (var item in views)
  729. {
  730. if (item is StickyNotePopup sticky)
  731. {
  732. var contentRegion = region.Regions[NotePopupRegionName];
  733. contentRegion.Remove(sticky);
  734. break;
  735. }
  736. }
  737. }
  738. }
  739. }
  740. private async void createfromFile()
  741. {
  742. string txt = Properties.Resources.txtex;
  743. string word = Properties.Resources.wordex;
  744. string ppt = Properties.Resources.pptex;
  745. string excel = Properties.Resources.excelex;
  746. string html = Properties.Resources.htmlex;
  747. string image = Properties.Resources.imageex;
  748. string allfiles = txt + word + excel + ppt + image + html;
  749. OpenFileDialog dialog = new OpenFileDialog();
  750. dialog.Multiselect = true;
  751. dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
  752. $"Microsoft Office Word({word})|{word}|" +
  753. $"Microsoft Office Excel({excel})|{excel}|" +
  754. $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
  755. $"Txt({txt})|{txt}|" +
  756. $"Picture({image})|{image}|" +
  757. $"Html({html})|{html}");
  758. if ((bool)dialog.ShowDialog())
  759. {
  760. for (int i = 0; i < dialog.FileNames.Length; i++)
  761. {
  762. if (App.OpenedFileList.Contains(dialog.FileNames[i]))
  763. {
  764. App.mainWindowViewModel.SelectItem(dialog.FileNames[i]);
  765. }
  766. else
  767. {
  768. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  769. {
  770. App.mainWindowViewModel.AddTabItem(dialog.FileNames[i]);
  771. }));
  772. await Task.Delay(20);
  773. ToolMethod.SetFileThumbImg(dialog.FileNames[i]);
  774. }
  775. }
  776. }
  777. }
  778. /// <summary>
  779. ///创建空白文档
  780. /// </summary>
  781. private async void createBlankFile()
  782. {
  783. App.mainWindowViewModel.AddTab.Execute();
  784. await Task.Delay(30);
  785. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
  786. }
  787. private void help(string args)
  788. {
  789. string url = "";
  790. switch (args)
  791. {
  792. case "Guid":
  793. //打开内嵌文档
  794. if (App.OpenedFileList.Contains(App.GuidPDFPath))
  795. {
  796. //如果已经打开时,则选中内嵌文档
  797. App.mainWindowViewModel.SelectItem(App.GuidPDFPath);
  798. return;
  799. }
  800. if (File.Exists(App.GuidPDFPath))
  801. {
  802. App.mainWindowViewModel.AddTabItem(App.GuidPDFPath);
  803. }
  804. break;
  805. case "Online":
  806. url = @"https://www.pdfreaderpro.com/windows/help";
  807. break;
  808. case "More":
  809. url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
  810. break;
  811. case "Template":
  812. url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
  813. break;
  814. case "Blog":
  815. //TODO:显示订阅电子报弹窗
  816. break;
  817. case "ComPDF":
  818. url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
  819. break;
  820. case "FeedBack":
  821. //调用邮箱 发送邮件
  822. StringBuilder sr = new StringBuilder();
  823. sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
  824. System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
  825. break;
  826. default:
  827. break;
  828. }
  829. if (!string.IsNullOrEmpty(url))
  830. {
  831. //需要跳转网页的情况
  832. System.Diagnostics.Process.Start(url);
  833. }
  834. }
  835. /// <summary>
  836. /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
  837. /// </summary>
  838. private void openfile()
  839. {
  840. OpenFileDialog openFileDialog = new OpenFileDialog();
  841. openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
  842. openFileDialog.Multiselect = true;
  843. if ((bool)openFileDialog.ShowDialog())
  844. {
  845. if (openFileDialog.FileNames.Count() == 1)
  846. {
  847. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  848. {
  849. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  850. }
  851. else
  852. {
  853. App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
  854. }
  855. ToolMethod.SetFileThumbImg(openFileDialog.FileName);
  856. }
  857. else
  858. {
  859. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  860. if (fileList.Count <= 0)
  861. {
  862. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  863. return;
  864. }
  865. mainViewModel.OpenFile(fileList[0]);
  866. for (int i = 1; i < fileList.Count(); i++)
  867. {
  868. if (!App.OpenedFileList.Contains(fileList[i]))
  869. {
  870. App.mainWindowViewModel.AddTabItem(fileList[i]);
  871. }
  872. ToolMethod.SetFileThumbImg(fileList[i]);
  873. }
  874. }
  875. }
  876. }
  877. /// <summary>
  878. /// 关闭当前窗体
  879. /// </summary>
  880. private void closeWindow()
  881. {
  882. App.Current.MainWindow.Close();
  883. }
  884. /// <summary>
  885. /// 转档
  886. /// </summary>
  887. /// <param name="obj"></param>
  888. private void convert(string obj)
  889. {
  890. if (!string.IsNullOrEmpty(obj))
  891. {
  892. DialogParameters value = new DialogParameters();
  893. value.Add(ParameterNames.PDFViewer, PDFViewer);
  894. switch (obj)
  895. {
  896. case "Word":
  897. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  898. {
  899. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  900. converterDialogsModel.OnOpened((DialogResult)e);
  901. });
  902. break;
  903. case "Excel":
  904. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  905. {
  906. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  907. converterDialogsModel.OnOpened((DialogResult)e);
  908. });
  909. break;
  910. case "PPT":
  911. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  912. {
  913. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  914. converterDialogsModel.OnOpened((DialogResult)e);
  915. });
  916. break;
  917. case "RTF":
  918. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  919. {
  920. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  921. converterDialogsModel.OnOpened((DialogResult)e);
  922. });
  923. break;
  924. case "CSV":
  925. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  926. {
  927. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  928. converterDialogsModel.OnOpened((DialogResult)e);
  929. });
  930. break;
  931. case "HTML":
  932. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  933. {
  934. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  935. converterDialogsModel.OnOpened((DialogResult)e);
  936. });
  937. break;
  938. case "Text":
  939. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  940. {
  941. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  942. converterDialogsModel.OnOpened((DialogResult)e);
  943. });
  944. break;
  945. case "Image":
  946. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  947. {
  948. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  949. converterDialogsModel.OnOpened((DialogResult)e);
  950. });
  951. break;
  952. default:
  953. break;
  954. }
  955. }
  956. }
  957. /// <summary>
  958. /// 解密
  959. /// </summary>
  960. private void decrypt()
  961. {
  962. if (!PDFViewer.Document.IsEncrypted)
  963. {
  964. MessageBoxEx.Show("No security settings available ");
  965. }
  966. else
  967. {
  968. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  969. if (result.IsDiscryptied)
  970. {
  971. if (result.Password != null)
  972. {
  973. string filePath = PDFViewer.Document.FilePath;
  974. PDFViewer.Document.Release();
  975. PDFViewer.InitDocument(filePath);
  976. PDFViewer.Document.UnlockWithPassword(result.Password);
  977. }
  978. DialogParameters value = new DialogParameters();
  979. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  980. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });
  981. }
  982. }
  983. }
  984. /// <summary>
  985. /// 加密
  986. /// </summary>
  987. private void encrypt()
  988. {
  989. if (!this.SecurityInfo.IsPasswordChanged)
  990. {
  991. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  992. if (result.IsDiscryptied)
  993. {
  994. if (result.Password != null)
  995. {
  996. string filePath = PDFViewer.Document.FilePath;
  997. PDFViewer.Document.Release();
  998. PDFViewer.InitDocument(filePath);
  999. PDFViewer.Document.UnlockWithPassword(result.Password);
  1000. }
  1001. }
  1002. }
  1003. DialogParameters value = new DialogParameters();
  1004. value.Add(ParameterNames.PDFViewer, this.PDFViewer);
  1005. value.Add(ParameterNames.ViewContentViewModel, this);
  1006. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
  1007. {
  1008. if (e.Result == ButtonResult.OK)
  1009. {
  1010. SecurityHelper.IsPasswordChanged = true;
  1011. if (this.SecurityInfo.IsPasswordChanged)
  1012. {
  1013. this.PDFViewer.UndoManager.CanSave = true;
  1014. }
  1015. this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
  1016. }
  1017. });
  1018. }
  1019. /// <summary>
  1020. /// 合并
  1021. /// </summary>
  1022. private void mergeFile()
  1023. {
  1024. DialogParameters value = new DialogParameters();
  1025. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1026. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  1027. }
  1028. /// <summary>
  1029. /// 压缩
  1030. /// </summary>
  1031. private void compress()
  1032. {
  1033. DialogParameters value = new DialogParameters();
  1034. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1035. dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
  1036. {
  1037. CompressDialogModel compressDialogModel = new CompressDialogModel();
  1038. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  1039. });
  1040. }
  1041. /// <summary>
  1042. /// 设置Tip状态栏的显示状态
  1043. /// </summary>
  1044. /// <param name="show">是否显示</param>
  1045. public void ShowTip(bool show)
  1046. {
  1047. if (show)
  1048. {
  1049. TipVisible = Visibility.Visible;
  1050. }
  1051. else
  1052. {
  1053. TipVisible = Visibility.Collapsed;
  1054. }
  1055. }
  1056. /// <summary>
  1057. /// 设置LeftTip状态栏的显示状态
  1058. /// </summary>
  1059. /// <param name="show">是否显示</param>
  1060. public void ShowLeftTip(bool show)
  1061. {
  1062. if (show)
  1063. {
  1064. LeftTipVisible = Visibility.Visible;
  1065. }
  1066. else
  1067. {
  1068. LeftTipVisible = Visibility.Collapsed;
  1069. }
  1070. }
  1071. public void CheckHaveAllPermission()
  1072. {
  1073. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  1074. {
  1075. ShowLeftTip(true);
  1076. NavigationParameters param = new NavigationParameters();
  1077. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1078. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  1079. }
  1080. }
  1081. public async void ShowSelectedTipAsync(ShowTipEventArgs showTipEventArgs)
  1082. {
  1083. switch (showTipEventArgs.enumTipKind)
  1084. {
  1085. case EnumTipKind.StatusNone:
  1086. ShowLeftTip(false);
  1087. break;
  1088. case EnumTipKind.StatusSetPasswordSuccessfully:
  1089. ShowLeftTip(true);
  1090. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  1091. break;
  1092. case EnumTipKind.StatusRemoveSecuritySuccessfully:
  1093. ShowLeftTip(false);
  1094. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1095. IsLoading = Visibility.Collapsed;
  1096. ShowTip(true);
  1097. await Task.Delay(3000);
  1098. //ReadModelTip = Visibility.Collapsed;
  1099. TipVisible = Visibility.Collapsed;
  1100. break;
  1101. default: break;
  1102. }
  1103. }
  1104. /// <summary>
  1105. /// 右键菜单创建链接
  1106. /// </summary>
  1107. /// <param name="obj"></param>
  1108. private void CreateLinkEvent(object obj)
  1109. {
  1110. if (obj is object[] objArry)
  1111. {
  1112. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  1113. {
  1114. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  1115. linkArgs.URI = string.Empty;
  1116. linkArgs.LinkType = LINK_TYPE.GOTO;
  1117. linkArgs.PageIndex = annotCommand.PageIndex;
  1118. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  1119. this.IsRightMenuCreateLink = true;
  1120. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  1121. lists.Add(linkArgs);
  1122. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  1123. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1124. PDFViewer.SetToolParam(annotArgs);
  1125. this.IsPropertyOpen = true;
  1126. }
  1127. }
  1128. }
  1129. private void CloseProperty()
  1130. {
  1131. IsPropertyOpen = false;
  1132. }
  1133. /// <summary>
  1134. /// 在文件资源管理器中显示
  1135. /// </summary>
  1136. private void ShowInFolder()
  1137. {
  1138. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  1139. }
  1140. private void property()
  1141. {
  1142. DialogParameters valuePairs = new DialogParameters();
  1143. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1144. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  1145. }
  1146. private void share()
  1147. {
  1148. try
  1149. {
  1150. var path = PDFViewer.Document.FilePath;
  1151. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  1152. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  1153. }
  1154. catch
  1155. {
  1156. AlertsMessage alertsMessage = new AlertsMessage();
  1157. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  1158. }
  1159. }
  1160. private void SettingsEvent()
  1161. {
  1162. dialogs.ShowDialog(DialogNames.SettingsDialog, null, null);
  1163. if (PDFViewer != null)
  1164. {
  1165. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1166. }
  1167. if(Settings.Default.AppProperties.Description.AutoSave)
  1168. {
  1169. StartAutoSave();
  1170. }
  1171. else
  1172. {
  1173. CloseAutoSave();
  1174. }
  1175. }
  1176. private bool CanSaveExcute()
  1177. {
  1178. return CanSave;
  1179. }
  1180. private void MenuEnterReadModeEvent(object obj)
  1181. {
  1182. }
  1183. public void ShowPrintDialog()
  1184. {
  1185. DialogParameters printValue = new DialogParameters();
  1186. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1187. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1188. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  1189. printValue.Add(ParameterNames.Unicode, unicode);
  1190. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  1191. }
  1192. public void SelectClick()
  1193. {
  1194. if (OpenBOTA == false)
  1195. {
  1196. OpenBOTA = true;
  1197. }
  1198. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1199. if (isBook == false)
  1200. {
  1201. bOTAContent.TabItemSearch.IsSelected = true;
  1202. }
  1203. }
  1204. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1205. {
  1206. bool isTabItem = false;
  1207. bOTAContentViewModel = null;
  1208. bOTAContent = null;
  1209. if (region.Regions.ContainsRegionWithName(this.BOTARegionName))
  1210. {
  1211. var views = region.Regions[this.BOTARegionName].Views;
  1212. var model = views.FirstOrDefault(q => q is BOTAContent);
  1213. if (model is BOTAContent bOTAContent1)
  1214. {
  1215. bOTAContent = bOTAContent1;
  1216. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1217. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1218. {
  1219. isTabItem = true;
  1220. }
  1221. }
  1222. }
  1223. return isTabItem;
  1224. }
  1225. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  1226. {
  1227. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  1228. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  1229. //其他工具菜单栏共用一个ToolsBarContentRegionName
  1230. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  1231. dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
  1232. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  1233. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  1234. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  1235. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  1236. }
  1237. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  1238. {
  1239. dictionary.Add("TabItemPageEdit", "PageEditContent");
  1240. dictionary.Add("TabItemTool", "ToolsBarContent");
  1241. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  1242. dictionary.Add("TabItemConvert", "ConverterBarContent");
  1243. dictionary.Add("TabItemScan", "ScanContent");
  1244. dictionary.Add("TabItemEdit", "TextEditToolContent");
  1245. dictionary.Add("TabItemForm", "FormsToolContent");
  1246. dictionary.Add("TabItemFill", "FillAndSignContent");
  1247. }
  1248. private void UpdateShowContent(string currentBar)
  1249. {
  1250. ToolContentVisible = Visibility.Collapsed;
  1251. ToolsBarContentVisible = Visibility.Collapsed;
  1252. ConverterBarContentVisible = Visibility.Collapsed;
  1253. TextEditToolContentVisible = Visibility.Collapsed;
  1254. OCRContentVisible = Visibility.Collapsed;
  1255. switch (currentBar)
  1256. {
  1257. case "TabItemAnnotation":
  1258. case "TabItemTool":
  1259. case "TabItemForm":
  1260. case "TabItemFill":
  1261. ToolsBarContentVisible = Visibility.Visible;
  1262. break;
  1263. case "TabItemScan":
  1264. ToolsBarContentVisible = Visibility.Visible;
  1265. OCRContentVisible = Visibility.Visible;
  1266. break;
  1267. case "TabItemEdit":
  1268. TextEditToolContentVisible = Visibility.Visible;
  1269. break;
  1270. case "TabItemConvert":
  1271. ConverterBarContentVisible = Visibility.Visible;
  1272. break;
  1273. case "TabItemPageEdit":
  1274. case "HeaderFooterContent":
  1275. case "BatesContent":
  1276. case "WatermarkContent":
  1277. case "BackgroundContent":
  1278. case "RedactionContent":
  1279. ToolContentVisible = Visibility.Visible;
  1280. break;
  1281. default:
  1282. break;
  1283. }
  1284. PDFEditMode(currentBar);
  1285. FormMode(currentBar);
  1286. }
  1287. private void PDFEditMode(string currentBar)
  1288. {
  1289. if (currentBar == "TabItemEdit")
  1290. {
  1291. if (PDFViewer != null)
  1292. {
  1293. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  1294. //SelectedPrpoertyPanel("TextEditProperty", null);
  1295. //IsPropertyOpen = true;
  1296. }
  1297. }
  1298. else
  1299. {
  1300. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  1301. {
  1302. IsPropertyOpen = false;
  1303. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1304. }
  1305. }
  1306. }
  1307. private void FormMode(string currentBar)
  1308. {
  1309. if (currentBar == "TabItemForm")
  1310. {
  1311. if (PDFViewer != null)
  1312. {
  1313. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  1314. }
  1315. }
  1316. else
  1317. {
  1318. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  1319. {
  1320. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1321. }
  1322. }
  1323. }
  1324. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  1325. {
  1326. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  1327. if (e.PropertyName == "CanUndo")
  1328. {
  1329. CanUndo = PDFViewer.UndoManager.CanUndo;
  1330. }
  1331. if (e.PropertyName == "CanRedo")
  1332. {
  1333. CanRedo = PDFViewer.UndoManager.CanRedo;
  1334. }
  1335. if (e.PropertyName == "CanSave")
  1336. {
  1337. CanSave = PDFViewer.UndoManager.CanSave;
  1338. }
  1339. }
  1340. /// <summary>
  1341. /// 选项卡切换事件
  1342. /// </summary>
  1343. /// <param name="e"></param>
  1344. private void TabControlSelectonChangedEvent(object e)
  1345. {
  1346. var args = e as SelectionChangedEventArgs;
  1347. if (args != null)
  1348. {
  1349. var item = args.AddedItems[0] as TabItem;
  1350. CurrentBar = item.Name;
  1351. if (previousBar != CurrentBar)
  1352. {
  1353. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  1354. {
  1355. EnterPageEdit();
  1356. }
  1357. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  1358. {
  1359. EnterSelectedBar(CurrentBar);
  1360. isInPageEdit = false;
  1361. }
  1362. previousBar = CurrentBar;
  1363. }
  1364. }
  1365. }
  1366. /// <summary>
  1367. /// 进入页面编辑模式
  1368. /// </summary>
  1369. public void EnterPageEdit()
  1370. {
  1371. if (TabSelectedIndex != 1)
  1372. {
  1373. TabSelectedIndex = 1;
  1374. }
  1375. CurrentBar = "TabItemPageEdit";
  1376. EnterToolMode(barContentByTabItem[CurrentBar]);
  1377. isInPageEdit = true;
  1378. }
  1379. /// <summary>
  1380. /// 阅读模式
  1381. /// </summary>
  1382. /// <param name="viewContent"></param>
  1383. public async void On_ReadMode()
  1384. {
  1385. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  1386. mainViewModel.IsBookMode = true;
  1387. IsLoading = Visibility.Visible;
  1388. await Task.Delay(1);
  1389. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1390. #region 旧版本
  1391. //NavigationParameters param = new NavigationParameters();
  1392. //param.Add(ParameterNames.PDFViewer, PDFViewer);
  1393. //param.Add(ParameterNames.ViewContentViewModel, this);
  1394. //region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  1395. ////ShowContent(CurrentBar, true);
  1396. //if (GridToolRow != 0)
  1397. //{
  1398. // GridToolRow = 0;
  1399. //}
  1400. //if (GridToolRowSpan != 4)
  1401. //{
  1402. // GridToolRowSpan = 4;
  1403. //}
  1404. ////isInPageEdit = true;
  1405. //UpdateShowContent("TabItemPageEdit");
  1406. #endregion 旧版本
  1407. OpenBOTA = false;
  1408. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = true });
  1409. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1410. {
  1411. var views = region.Regions[TipContentRegionName].Views;
  1412. var isHasView = views.FindFirst(q => q is Views.TipContent.EnterReadModeTip);
  1413. if (isHasView == null)
  1414. {
  1415. region.RequestNavigate(TipContentRegionName, "EnterReadModeTip");
  1416. }
  1417. else
  1418. {
  1419. region.Regions[TipContentRegionName].Activate(isHasView);
  1420. }
  1421. }
  1422. IsLoading = Visibility.Collapsed;
  1423. ShowTip(true);
  1424. await Task.Delay(3000);
  1425. TipVisible = Visibility.Collapsed;
  1426. }
  1427. /// <summary>
  1428. /// 退出阅读模式
  1429. /// </summary>
  1430. public async void Off_ReadModel()
  1431. {
  1432. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  1433. mainViewModel.IsBookMode = false;
  1434. IsLoading = Visibility.Visible;
  1435. await Task.Delay(1);
  1436. //PDFViewer.MouseMode = MouseModes.None;
  1437. #region 旧版本
  1438. //if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  1439. //{
  1440. // if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1441. // {
  1442. // var contentRegion = region.Regions[ViwerRegionName];
  1443. // contentRegion.Remove(PDFViewer);
  1444. // }
  1445. // //还原背景色
  1446. // PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1447. // region.AddToRegion(ViwerRegionName, PDFViewer);
  1448. //}
  1449. //if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  1450. //{
  1451. // EnterSelectedBar("TabItemAnnotation");
  1452. //}
  1453. //else
  1454. //{
  1455. // EnterSelectedBar(CurrentBar);
  1456. //}
  1457. #endregion 旧版本
  1458. //还原背景色
  1459. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1460. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = false });
  1461. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1462. {
  1463. var views = region.Regions[TipContentRegionName].Views;
  1464. var isHasView = views.FindFirst(q => q is Views.TipContent.ReadModelTip);
  1465. if (isHasView == null)
  1466. {
  1467. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  1468. }
  1469. else
  1470. {
  1471. region.Regions[TipContentRegionName].Activate(isHasView);
  1472. }
  1473. }
  1474. ///退出阅读模式 显示视图面板
  1475. IsPropertyOpen = true;
  1476. if (region.Regions.ContainsRegionWithName(PropertyRegionName))
  1477. {
  1478. var views = region.Regions[PropertyRegionName].Views;
  1479. var item = views.FindFirst(p => p is ViewModularContent);
  1480. if (item == null)
  1481. {
  1482. NavigationParameters param = new NavigationParameters();
  1483. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1484. param.Add(ParameterNames.BottomToolContentViewModel, this);
  1485. region.RequestNavigate(RegionNames.PropertyRegionName, "ViewModularContent", param);
  1486. }
  1487. else
  1488. {
  1489. if (item is ViewModularContent viewModular)
  1490. {
  1491. var contentRegion = region.Regions[PropertyRegionName];
  1492. contentRegion.Activate(viewModular);
  1493. }
  1494. }
  1495. }
  1496. IsLoading = Visibility.Collapsed;
  1497. ShowTip(true);
  1498. await Task.Delay(3000);
  1499. //ReadModelTip = Visibility.Collapsed;
  1500. TipVisible = Visibility.Collapsed;
  1501. }
  1502. #region PDFViewer鼠标滚轮缩放事件
  1503. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  1504. {
  1505. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  1506. PDFViewer.Zoom(newZoom);
  1507. }
  1508. public double CheckZoomLevel(double zoom, bool IsGrowth)
  1509. {
  1510. double standardZoom = 100;
  1511. if (zoom <= 0.01)
  1512. {
  1513. return 0.01;
  1514. }
  1515. if (zoom >= 10)
  1516. {
  1517. return 10;
  1518. }
  1519. zoom *= 100;
  1520. for (int i = 0; i < zoomLevel.Length - 1; i++)
  1521. {
  1522. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  1523. {
  1524. standardZoom = zoomLevel[i + 1];
  1525. break;
  1526. }
  1527. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  1528. {
  1529. standardZoom = zoomLevel[i];
  1530. break;
  1531. }
  1532. }
  1533. return standardZoom / 100;
  1534. }
  1535. #endregion PDFViewer鼠标滚轮缩放事件
  1536. #region Navigate
  1537. public void OnNavigatedTo(NavigationContext navigationContext)
  1538. {
  1539. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  1540. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  1541. if (mainVM != null)
  1542. {
  1543. mainViewModel = mainVM;
  1544. mainViewModel.viewContentViewModel = this;
  1545. }
  1546. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  1547. if (pdfview != null)
  1548. {
  1549. PDFViewer = pdfview;
  1550. if (loadFile())
  1551. {
  1552. CheckHaveAllPermission();
  1553. }
  1554. }
  1555. navigationContext.Parameters.TryGetValue(ParameterNames.PasswordInfo, out PasswordInfo);
  1556. //快捷键
  1557. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1558. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  1559. }
  1560. public bool IsNavigationTarget(NavigationContext navigationContext)
  1561. {
  1562. if (navigationContext != null)
  1563. {
  1564. //另存为打开导航进来时 不能新建一个实例
  1565. return true;
  1566. }
  1567. else
  1568. {
  1569. //一次性打开多个文件时,需要新建实例
  1570. return false;
  1571. }
  1572. }
  1573. public void OnNavigatedFrom(NavigationContext navigationContext)
  1574. {
  1575. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1576. }
  1577. #endregion Navigate
  1578. #region 方法
  1579. /// <summary>
  1580. /// 快捷键
  1581. /// </summary>
  1582. /// <param name="sender"></param>
  1583. /// <param name="e"></param>
  1584. /// <exception cref="NotImplementedException"></exception>
  1585. private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  1586. {
  1587. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
  1588. {
  1589. if (mainViewModel.IsBookMode == true)
  1590. {
  1591. Off_ReadModel();
  1592. }
  1593. //内容选择 退出
  1594. if (PDFViewer.MouseMode != MouseModes.PanTool)
  1595. {
  1596. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1597. if (annotToolContent != null && toolContentViewModel != null)
  1598. {
  1599. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1600. {
  1601. if (toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs != null)
  1602. {
  1603. toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  1604. annotToolContent.BtnSelecttool.IsChecked = false;
  1605. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1606. }
  1607. }
  1608. }
  1609. }
  1610. }
  1611. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.C))
  1612. {
  1613. //内容选择 复制 快捷键
  1614. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1615. if (annotToolContent != null && toolContentViewModel != null)
  1616. {
  1617. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1618. {
  1619. toolContentViewModel.SnapshotEditMenuViewModel.SnapCopyCommand.Execute();
  1620. }
  1621. }
  1622. }
  1623. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.P))
  1624. {
  1625. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1626. if (annotToolContent != null && toolContentViewModel != null)
  1627. {
  1628. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1629. {
  1630. toolContentViewModel.SnapshotEditMenuViewModel.PrintCommand.Execute();
  1631. }
  1632. }
  1633. }
  1634. }
  1635. private AnnotToolContent GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel)
  1636. {
  1637. AnnotToolContent toolContent = null;
  1638. toolContentViewModel = null;
  1639. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1640. {
  1641. var views = region.Regions[ToolsBarContentRegionName].Views;
  1642. var model = views.FirstOrDefault(q => q is AnnotToolContent);
  1643. if (model is AnnotToolContent annotToolContent)
  1644. {
  1645. toolContent = annotToolContent;
  1646. toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
  1647. }
  1648. }
  1649. return toolContent;
  1650. }
  1651. /// <summary>
  1652. /// 视图面板 切换分屏模式
  1653. /// </summary>
  1654. /// <param name="mode"></param>
  1655. public void EnterSplitMode(SplitMode mode)
  1656. {
  1657. ///通知UI层更改布局
  1658. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  1659. }
  1660. private void Undo()
  1661. {
  1662. PDFViewer.UndoManager.Undo();
  1663. }
  1664. private void Redo()
  1665. {
  1666. PDFViewer.UndoManager.Redo();
  1667. }
  1668. private void LoadControl()
  1669. {
  1670. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  1671. // 非必要情况不要使用该异步方法,可能会导致一次性加载多个文件时出现因异步引起的regionname 错乱问题
  1672. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1673. // {
  1674. NavigationParameters parameters = new NavigationParameters();
  1675. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1676. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1677. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  1678. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  1679. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  1680. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  1681. //TODO 根据上一次关闭记录的菜单,选中TabItem
  1682. EnterSelectedBar("TabItemAnnotation");
  1683. //}
  1684. //));
  1685. //if (App.IsBookMode)
  1686. //{
  1687. // RbtnReadMode();
  1688. //}
  1689. //else
  1690. //{
  1691. // UnReadModel();
  1692. //}
  1693. }
  1694. /// <summary>
  1695. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  1696. /// </summary>
  1697. /// <param name="Content"></param>
  1698. /// <param name="annotPropertyPanel"></param>
  1699. public void SelectedPrpoertyPanel(string Content, AnnotTransfer annotPropertyPanel)
  1700. {
  1701. if (Content == "PropertyPanelContent")
  1702. {
  1703. IsPropertyOpen = false;
  1704. }
  1705. else
  1706. {
  1707. IsPropertyOpen = true;
  1708. }
  1709. NavigationParameters parameters = new NavigationParameters();
  1710. //传其他参数:文档类,空注释面板;
  1711. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1712. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  1713. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1714. region.RequestNavigate(PropertyRegionName, Content, parameters);
  1715. }
  1716. /// <summary>
  1717. /// 将PDFViwer添加到Region
  1718. /// </summary>
  1719. private bool loadFile()
  1720. {
  1721. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  1722. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  1723. CanSave = PDFViewer.UndoManager.CanSave;
  1724. CanUndo = PDFViewer.UndoManager.CanUndo;
  1725. CanRedo = PDFViewer.UndoManager.CanRedo;
  1726. if (passwordInfo != null && (!string.IsNullOrEmpty(passwordInfo.OpenPassword) || !string.IsNullOrEmpty(passwordInfo.PermissionsPassword)))
  1727. {
  1728. if (!string.IsNullOrEmpty(passwordInfo.OpenPassword))
  1729. {
  1730. PDFViewer.Document.UnlockWithPassword(passwordInfo.OpenPassword);
  1731. }
  1732. if (!string.IsNullOrEmpty(passwordInfo.PermissionsPassword))
  1733. {
  1734. PDFViewer.Document.UnlockWithPassword(passwordInfo.PermissionsPassword);
  1735. }
  1736. }
  1737. else
  1738. {
  1739. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
  1740. if (result.IsDiscryptied)
  1741. {
  1742. if (result.Password != null)
  1743. {
  1744. string filePath = PDFViewer.Document.FilePath;
  1745. PDFViewer.Document.UnlockWithPassword(result.Password);
  1746. PDFViewer.Tag = result.Password;
  1747. //记录密码到内存
  1748. this.PassWord = result.Password;
  1749. }
  1750. }
  1751. if (result.IsDiscryptied == false)
  1752. {
  1753. //未成功解密文档时,释放Document对象,返回
  1754. PDFViewer.Document.Release();
  1755. //取消解密时关闭当前页签
  1756. App.mainWindowViewModel.CloseTabItem(App.mainWindowViewModel.SelectedItem);
  1757. return false;
  1758. }
  1759. }
  1760. PDFViewer.Load();
  1761. PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  1762. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1763. //还原上一次关闭前的视图设置
  1764. GetOpenFileInfo();
  1765. region.AddToRegion(ViwerRegionName, PDFViewer);
  1766. if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
  1767. {
  1768. App.OpenedFileList.Add(PDFViewer.Document.FilePath);
  1769. }
  1770. return true;
  1771. }
  1772. /// <summary>
  1773. /// 还原上一次浏览的视图相关设置
  1774. /// </summary>
  1775. private void GetOpenFileInfo()
  1776. {
  1777. OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1778. //偏好设置里设置了记录上次视图设置时
  1779. if (OpenFileInfo != null && Settings.Default.AppProperties.Description.RecoveryViewWhenOpen)
  1780. {
  1781. if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
  1782. {
  1783. PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
  1784. }
  1785. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  1786. {
  1787. PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
  1788. }
  1789. if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
  1790. {
  1791. PDFViewer.Zoom(OpenFileInfo.LastZoom);
  1792. }
  1793. if (OpenFileInfo.LastPageIndex != PDFViewer.CurrentIndex)
  1794. {
  1795. PDFViewer.GoToPage(OpenFileInfo.LastPageIndex);
  1796. }
  1797. PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
  1798. PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
  1799. if (OpenFileInfo.LastPageSpace)
  1800. {
  1801. PDFViewer.SetPageSpacing(8);
  1802. }
  1803. else
  1804. {
  1805. PDFViewer.SetPageSpacing(0);
  1806. }
  1807. if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
  1808. {
  1809. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
  1810. }
  1811. else
  1812. {
  1813. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
  1814. }
  1815. }
  1816. else
  1817. {
  1818. //新文档应用默认设置
  1819. PDFViewer.ChangeViewMode(Settings.Default.AppProperties.InitialVIew.PageView);
  1820. PDFViewer.ChangeFitMode(Settings.Default.AppProperties.InitialVIew.ZoomMode);
  1821. PDFViewer.SetShowLink(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  1822. }
  1823. }
  1824. /// <summary>
  1825. /// 已有路径文档的保存逻辑
  1826. /// </summary>
  1827. public bool saveFile()
  1828. {
  1829. try
  1830. {
  1831. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile)
  1832. return saveAsFile();
  1833. //文档已被修复时 提示另存为
  1834. if (PDFViewer.Document.HasRepaired)
  1835. {
  1836. AlertsMessage alertsMessage = new AlertsMessage();
  1837. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  1838. if (alertsMessage.result == ContentResult.Ok)
  1839. return saveAsFile();
  1840. else
  1841. return false;
  1842. }
  1843. //文件路径无法存在时
  1844. if (!File.Exists(PDFViewer.Document.FilePath))
  1845. {
  1846. AlertsMessage alertsMessage = new AlertsMessage();
  1847. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  1848. if (alertsMessage.result == ContentResult.Ok)
  1849. return saveAsFile();
  1850. else
  1851. return false;
  1852. }
  1853. //只读文件无法写入时,提示另存为
  1854. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  1855. if (fileInfo.IsReadOnly)
  1856. {
  1857. AlertsMessage alertsMessage = new AlertsMessage();
  1858. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  1859. if (alertsMessage.result == ContentResult.Ok)
  1860. return saveAsFile();
  1861. else
  1862. return false;
  1863. }
  1864. //Security Fixed:
  1865. //修改密码后原文档保存的步骤:
  1866. //在设置密码窗口传出“已修改”信号,并允许延迟保存
  1867. //
  1868. if (SecurityInfo.IsPasswordChanged)
  1869. {
  1870. string currentFilePath = PDFViewer.Document.FilePath;
  1871. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  1872. string openPassword = string.Empty;
  1873. string permissionsPassword = string.Empty;
  1874. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  1875. if (SecurityInfo.NeedOpenPassword)
  1876. {
  1877. openPassword = SecurityInfo.OpenPassword;
  1878. }
  1879. if (SecurityInfo.NeedPermissionsPassword)
  1880. {
  1881. permissionsPassword = SecurityInfo.PermissionsPassword;
  1882. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  1883. }
  1884. try
  1885. {
  1886. string currentPath = PDFViewer.Document.FilePath;
  1887. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  1888. if (PDFViewer.Document.Descrypt(tempPath))
  1889. {
  1890. PDFViewer.CloseDocument();
  1891. PDFViewer.InitDocument(tempPath);
  1892. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1893. if (PDFViewer.Document.WriteToFilePath(currentPath))
  1894. {
  1895. PDFViewer.CloseDocument();
  1896. PDFViewer.InitDocument(currentPath);
  1897. if (!string.IsNullOrEmpty(openPassword))
  1898. {
  1899. PDFViewer.Document.UnlockWithPassword(openPassword);
  1900. }
  1901. if (!string.IsNullOrEmpty(permissionsPassword))
  1902. {
  1903. PDFViewer.Document.CheckOwnerPassword(permissionsPassword);
  1904. }
  1905. try
  1906. {
  1907. PDFViewer.Load();
  1908. }
  1909. catch
  1910. {
  1911. }
  1912. PDFViewer.UndoManager.CanSave = false;
  1913. SecurityInfo.IsPasswordChanged = false;
  1914. }
  1915. else
  1916. {
  1917. return false;
  1918. }
  1919. System.IO.File.Delete(tempPath);
  1920. }
  1921. else
  1922. {
  1923. return false;
  1924. }
  1925. return true;
  1926. }
  1927. catch
  1928. {
  1929. return false;
  1930. }
  1931. }
  1932. else if (SecurityInfo.IsPasswordRemoved)
  1933. {
  1934. try
  1935. {
  1936. string currentPath = PDFViewer.Document.FilePath;
  1937. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  1938. PDFViewer.Document.Descrypt(tempPath);
  1939. PDFViewer.CloseDocument();
  1940. PDFViewer.InitDocument(tempPath);
  1941. PDFViewer.Document.WriteToFilePath(currentPath);
  1942. PDFViewer.CloseDocument();
  1943. PDFViewer.InitDocument(currentPath);
  1944. PDFViewer.Load();
  1945. System.IO.File.Delete(tempPath);
  1946. }
  1947. catch
  1948. {
  1949. return false;
  1950. }
  1951. }
  1952. bool result = PDFViewer.Document.WriteToLoadedPath();
  1953. if (result)
  1954. {
  1955. PDFViewer.UndoManager.CanSave = false;
  1956. App.Current.Dispatcher.Invoke(() =>
  1957. {
  1958. //保存时更新缩略图
  1959. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1960. try
  1961. {
  1962. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  1963. {
  1964. var size = PDFViewer.Document.GetPageSize(0);
  1965. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  1966. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  1967. if (File.Exists(folderPath))
  1968. File.Delete(folderPath);
  1969. DirectoryInfo folder = new DirectoryInfo(folderPath);
  1970. if (!folder.Exists)
  1971. folder.Create();
  1972. string imagePath = info.ThumbImgPath;
  1973. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  1974. {
  1975. string imageName = Guid.NewGuid().ToString();
  1976. imagePath = System.IO.Path.Combine(folderPath, imageName);
  1977. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  1978. {
  1979. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1980. }
  1981. }
  1982. else
  1983. {
  1984. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  1985. {
  1986. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1987. }
  1988. }
  1989. info.ThumbImgPath = imagePath;
  1990. SettingHelper.SetFileInfo(info);
  1991. }
  1992. }
  1993. catch
  1994. {
  1995. info.ThumbImgPath = null;
  1996. SettingHelper.SetFileInfo(info);
  1997. }
  1998. });
  1999. PDFViewer.ReloadDocument();
  2000. }
  2001. else
  2002. {
  2003. //文件被占用 保存失败时
  2004. AlertsMessage alertsMessage = new AlertsMessage();
  2005. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  2006. if (alertsMessage.result == ContentResult.Ok)
  2007. return saveAsFile();
  2008. else
  2009. return false;
  2010. }
  2011. return result;
  2012. }
  2013. catch { return false; }
  2014. finally
  2015. {
  2016. ShowLeftTip(false);
  2017. }
  2018. }
  2019. /// <summary>
  2020. /// 另存为或新文档保存逻辑
  2021. /// </summary>
  2022. public bool saveAsFile(Action RedactionAction = null)
  2023. {
  2024. var dlg = new Microsoft.Win32.SaveFileDialog();
  2025. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2026. dlg.FileName = PDFViewer.Document.FileName;
  2027. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2028. {
  2029. bool result = false;
  2030. if (RedactionAction != null)
  2031. {
  2032. //保存前进行标记密文处理应用或擦除
  2033. RedactionAction.Invoke();
  2034. }
  2035. if (App.OpenedFileList.Contains(dlg.FileName))
  2036. {
  2037. //提示文件已经被打开
  2038. }
  2039. else
  2040. {
  2041. string oldpath = PDFViewer.Document.FilePath;
  2042. string openPassword = string.Empty;
  2043. string permissionsPassword = string.Empty;
  2044. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2045. if (SecurityInfo.NeedOpenPassword)
  2046. {
  2047. openPassword = SecurityInfo.OpenPassword;
  2048. passwordInfo.OpenPassword = openPassword;
  2049. }
  2050. if (SecurityInfo.NeedPermissionsPassword)
  2051. {
  2052. permissionsPassword = SecurityInfo.PermissionsPassword;
  2053. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2054. passwordInfo.PermissionsPassword = permissionsPassword;
  2055. }
  2056. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2057. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  2058. if (result)
  2059. {
  2060. mainViewModel.NewFile = false;
  2061. App.OpenedFileList.Remove(oldpath);
  2062. DoAfterSaveAs(dlg.FileName);
  2063. }
  2064. else
  2065. {
  2066. //提示文件被其他软件占用 无法保存
  2067. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") });
  2068. }
  2069. }
  2070. return result;
  2071. }
  2072. else
  2073. return false;
  2074. }
  2075. /// <summary>
  2076. /// 另存为Flatten
  2077. /// </summary>
  2078. private void saveAsFlatten()
  2079. {
  2080. var dlg = new SaveFileDialog();
  2081. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2082. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  2083. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2084. {
  2085. saveFile();
  2086. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  2087. if (kmdoc == null)
  2088. return;
  2089. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  2090. if (result)
  2091. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  2092. kmdoc.Release();
  2093. }
  2094. }
  2095. /// <summary>
  2096. /// 另存为后进行的操作
  2097. /// 重新打开新文档
  2098. /// </summary>
  2099. /// <param name="targetPath"></param>
  2100. public void DoAfterSaveAs(string targetPath)
  2101. {
  2102. string oldFilePath = targetPath;
  2103. PDFViewer.UndoManager.CanSave = false;
  2104. mainViewModel.OpenFile(targetPath, passwordInfo);
  2105. //TODO:通知各模块更新PDFview对象
  2106. //var result = OpenFile(targetPath, true);
  2107. //if (result)
  2108. //{
  2109. // FileChanged.Invoke(this, null);
  2110. // Zoomer.PdfViewer = PdfViewer;
  2111. // PageSelector.PdfViewer = PdfViewer;
  2112. // ViewModeSelector.PdfViewer = PdfViewer;
  2113. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  2114. // if (fileInfo != null)
  2115. // {
  2116. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  2117. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  2118. // if (fileInfo.LastFitMode == FitMode.FitFree)
  2119. // PdfViewer.Zoom(fileInfo.LastZoom);
  2120. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  2121. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  2122. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  2123. // else
  2124. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  2125. // }
  2126. //}
  2127. }
  2128. /// <summary>
  2129. /// 显示前添加内容到Region
  2130. /// </summary>
  2131. /// <param name="isPageEdit"></param>
  2132. private void ShowContent(string currentBar, bool isToolMode = false)
  2133. {
  2134. GridVisibility = Visibility.Visible;
  2135. //显示页面编辑或其他工具
  2136. if (currentBar == "TabItemPageEdit" || isToolMode)
  2137. {
  2138. if (currentBar == "TabItemPageEdit")//进入页面编辑
  2139. {
  2140. if (GridToolRow != 1)
  2141. {
  2142. GridToolRow = 1;
  2143. }
  2144. if (GridToolRowSpan != 3)
  2145. {
  2146. GridToolRowSpan = 3;
  2147. }
  2148. }
  2149. else//进入水印等其他工具模式
  2150. {
  2151. GridVisibility = Visibility.Collapsed;
  2152. if (GridToolRow != 0)
  2153. {
  2154. GridToolRow = 0;
  2155. }
  2156. if (GridToolRowSpan != 4)
  2157. {
  2158. GridToolRowSpan = 4;
  2159. }
  2160. }
  2161. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  2162. UpdateShowContent(currentBar);
  2163. }
  2164. else
  2165. {
  2166. if (GridToolRow != 1)
  2167. {
  2168. GridToolRow = 1;
  2169. }
  2170. UpdateShowContent(currentBar);
  2171. }
  2172. }
  2173. /// <summary>
  2174. /// 从二级工具栏进入需要修改界面布局的场景
  2175. /// </summary>
  2176. /// <param name="EditToolName"></param>
  2177. private void EnterEditTools(StringWithUnicode EditToolName)
  2178. {
  2179. EnterSelectedEditTool(EditToolName);
  2180. }
  2181. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  2182. {
  2183. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  2184. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  2185. {
  2186. PDFViewer.Document.ReleasePages();
  2187. PDFViewer.ReloadDocument();
  2188. }
  2189. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  2190. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  2191. {
  2192. region.AddToRegion(ViwerRegionName, PDFViewer);
  2193. }
  2194. CurrentBar = "TabItemTool";
  2195. EnterSelectedBar(CurrentBar);
  2196. }
  2197. /// <summary>
  2198. /// 二级菜单指定目标处理
  2199. /// </summary>
  2200. /// <param name="e"></param>
  2201. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  2202. {
  2203. CurrentBar = EditToolName.EditToolsContentName;
  2204. EnterToolMode(CurrentBar);
  2205. }
  2206. /// <summary>
  2207. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  2208. /// </summary>
  2209. /// <param name="targetToolMode">要导航过去的控件名称</param>
  2210. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  2211. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  2212. {
  2213. IsLoading = Visibility.Visible;
  2214. await Task.Delay(3);
  2215. NavigationParameters param = new NavigationParameters();
  2216. if (valuePairs == null)
  2217. {
  2218. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2219. param.Add(ParameterNames.ViewContentViewModel, this);
  2220. }
  2221. else//有传入其他内容的参数时
  2222. {
  2223. param = valuePairs;
  2224. }
  2225. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  2226. ShowContent(CurrentBar, true);
  2227. IsLoading = Visibility.Collapsed;
  2228. }
  2229. private void EnterSelectedBar(string currentBar)
  2230. {
  2231. NavigationParameters param = new NavigationParameters();
  2232. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2233. param.Add(ParameterNames.ViewContentViewModel, this);
  2234. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  2235. if (currentBar == "TabItemScan")
  2236. {
  2237. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  2238. }
  2239. ShowContent(currentBar);
  2240. }
  2241. /// <summary>
  2242. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  2243. /// </summary>
  2244. public void ExitToolMode()
  2245. {
  2246. ToolContentVisible = Visibility.Collapsed;
  2247. if (isInPageEdit)
  2248. {
  2249. TabSelectedIndex = 0;
  2250. isInPageEdit = false;
  2251. }
  2252. }
  2253. #endregion 方法
  2254. }
  2255. }