ViewContentViewModel.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. using Microsoft.Win32;
  2. using Prism.Commands;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using ComPDFKitViewer.PdfViewer;
  10. using Prism.Regions;
  11. using DryIoc;
  12. using System.Diagnostics;
  13. using Prism.Services.Dialogs;
  14. using PDF_Office.CustomControl;
  15. using PDF_Office.Model;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.IO;
  19. using PDFSettings;
  20. using ComPDFKitViewer.AnnotEvent;
  21. using PDF_Office.ViewModels.Tools;
  22. using PDF_Office.Views;
  23. using Prism.Events;
  24. using PDF_Office.EventAggregators;
  25. using PDF_Office.Views.EditTools.Background;
  26. using PDF_Office.Views.Dialog;
  27. using PDF_Office.Helper;
  28. using System.Security.Policy;
  29. using System.Windows.Documents;
  30. using ComPDFKit.PDFDocument;
  31. using PDFSettings.Settings;
  32. namespace PDF_Office.ViewModels
  33. {
  34. public class ViewContentViewModel : BindableBase, INavigationAware
  35. {
  36. #region 属性、变量
  37. public CPDFViewer PDFViewer { get; set; }
  38. public MainContentViewModel mainViewModel { get; set; }
  39. public IRegionManager region;
  40. public IDialogService dialogs;
  41. public IEventAggregator events;
  42. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  43. public string ViwerRegionName { get; set; }
  44. /// <summary>
  45. /// 分屏视图的region名称
  46. /// </summary>
  47. public string SplitViewerRegionName { get; set; }
  48. /// <summary>
  49. /// OCR视图名称
  50. /// </summary>
  51. public string OCRViewerRegionName { get; set; }
  52. public string BOTARegionName { get; set; }
  53. public string PropertyRegionName { get; set; }
  54. public string ToolContentRegionName { get; set; }
  55. public string ToolsBarContentRegionName { get; set; }
  56. /// <summary>
  57. /// 顶部提示的Content
  58. /// </summary>
  59. public string TipContentRegionName { get; set; }
  60. public string LeftTipContentRegionName { get; set; }
  61. public string ReadModeRegionName { get; set; }
  62. public string ConverterBarContentRegionName { get; set; }
  63. public string TextEditContentRegionName { get; set; }
  64. public string BackgroundContentRegionName { get; set; }
  65. public List<Point>FillAndSign=new List<Point>();
  66. /// <summary>
  67. /// 文档的密码
  68. /// </summary>
  69. public string PassWord { get; set; }
  70. private Visibility tipVisible = Visibility.Collapsed;
  71. /// <summary>
  72. /// 顶部提示栏的显示状态
  73. /// </summary>
  74. public Visibility TipVisible
  75. {
  76. get { return tipVisible; }
  77. set
  78. {
  79. SetProperty(ref tipVisible, value);
  80. }
  81. }
  82. private Visibility leftTipVisible = Visibility.Collapsed;
  83. public Visibility LeftTipVisible
  84. {
  85. get { return leftTipVisible; }
  86. set
  87. {
  88. SetProperty(ref leftTipVisible, value);
  89. }
  90. }
  91. private Visibility readModelTip = Visibility.Collapsed;
  92. public Visibility ReadModelTip
  93. {
  94. get { return readModelTip; }
  95. set
  96. {
  97. SetProperty(ref readModelTip, value);
  98. }
  99. }
  100. /// <summary>
  101. /// 底部工具栏 RegionName
  102. /// </summary>
  103. public string BottomToolRegionName { get; set; }
  104. private bool _isInPageEdit = false;
  105. /// <summary>
  106. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  107. /// </summary>
  108. public bool isInPageEdit
  109. {
  110. get { return _isInPageEdit; }
  111. set
  112. {
  113. _isInPageEdit = value;
  114. if (!value)
  115. {
  116. CanRedo = PDFViewer.UndoManager.CanRedo;
  117. CanUndo = PDFViewer.UndoManager.CanUndo;
  118. }
  119. }
  120. }
  121. public Action PageEditUndo { get; set; }
  122. public Action PageEditRedo { get; set; }
  123. /// <summary>
  124. ///工具条
  125. ///0:收起
  126. ///40:显示
  127. /// </summary>
  128. private int toolRowHeight = 40;
  129. public int ToolRowHeight
  130. {
  131. get { return toolRowHeight; }
  132. set
  133. {
  134. SetProperty(ref toolRowHeight, value);
  135. }
  136. }
  137. /// <summary>
  138. /// 水印,背景侧边栏宽度
  139. /// 0:收起
  140. /// 260:显示
  141. /// </summary>
  142. private int propertyColumnWidth = 0;
  143. public int PropertyColumnWidth
  144. {
  145. get { return propertyColumnWidth; }
  146. set
  147. {
  148. SetProperty(ref propertyColumnWidth, value);
  149. }
  150. }
  151. private int gridToolRow = 1;
  152. /// <summary>
  153. /// 控制ToolContent的Row
  154. /// </summary>
  155. public int GridToolRow
  156. {
  157. get { return gridToolRow; }
  158. set
  159. {
  160. SetProperty(ref gridToolRow, value);
  161. }
  162. }
  163. private int gridToolRowSpan = 3;
  164. /// <summary>
  165. /// 控制ToolContent的RowSpan
  166. /// </summary>
  167. public int GridToolRowSpan
  168. {
  169. get { return gridToolRowSpan; }
  170. set
  171. {
  172. SetProperty(ref gridToolRowSpan, value);
  173. }
  174. }
  175. private Visibility toolContentVisible = Visibility.Collapsed;
  176. /// <summary>
  177. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  178. /// 留意:显示前需要先注入内容、设置好行和跨行数
  179. /// </summary>
  180. public Visibility ToolContentVisible
  181. {
  182. get { return toolContentVisible; }
  183. set
  184. {
  185. SetProperty(ref toolContentVisible, value);
  186. }
  187. }
  188. private Visibility gridVisibility = Visibility.Visible;
  189. /// <summary>
  190. /// 是否正在加载中
  191. /// </summary>
  192. public Visibility GridVisibility
  193. {
  194. get { return gridVisibility; }
  195. set
  196. {
  197. SetProperty(ref gridVisibility, value);
  198. }
  199. }
  200. private Visibility isLoading = Visibility.Collapsed;
  201. private Visibility ocrContentVisible = Visibility.Collapsed;
  202. public Visibility OCRContentVisible
  203. {
  204. get { return ocrContentVisible; }
  205. set
  206. {
  207. SetProperty(ref ocrContentVisible, value);
  208. }
  209. }
  210. /// <summary>
  211. /// 是否正在加载中
  212. /// </summary>
  213. public Visibility IsLoading
  214. {
  215. get { return isLoading; }
  216. set
  217. {
  218. SetProperty(ref isLoading, value);
  219. }
  220. }
  221. private Visibility converterBarContentVisible = Visibility.Collapsed;
  222. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  223. /// <summary>
  224. /// 控制ToolsBarContent的显示
  225. /// 留意:显示前需要先注入内容、设置好行和跨行数
  226. /// </summary>
  227. public Visibility ConverterBarContentVisible
  228. {
  229. get { return converterBarContentVisible; }
  230. set
  231. {
  232. SetProperty(ref converterBarContentVisible, value);
  233. }
  234. }
  235. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  236. /// <summary>
  237. /// 控制ToolsBarContent的显示
  238. /// 留意:显示前需要先注入内容、设置好行和跨行数
  239. /// </summary>
  240. public Visibility ToolsBarContentVisible
  241. {
  242. get { return toolsBarContentVisible; }
  243. set
  244. {
  245. SetProperty(ref toolsBarContentVisible, value);
  246. }
  247. }
  248. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  249. /// <summary>
  250. /// 控制ToolsBarContent的显示
  251. /// 留意:显示前需要先注入内容、设置好行和跨行数
  252. /// </summary>
  253. public Visibility TextEditToolContentVisible
  254. {
  255. get { return textEditToolContentVisible; }
  256. set
  257. {
  258. SetProperty(ref textEditToolContentVisible, value);
  259. }
  260. }
  261. private bool isPorpertyOpen = false;
  262. /// <summary>
  263. /// 属性栏是否展开
  264. /// </summary>
  265. public bool IsPropertyOpen
  266. {
  267. get { return isPorpertyOpen; }
  268. set
  269. {
  270. SetProperty(ref isPorpertyOpen, value);
  271. }
  272. }
  273. private Visibility isReadMode = Visibility.Visible;
  274. /// <summary>
  275. ///是否为阅读模式
  276. /// </summary>
  277. public Visibility IsReadMode
  278. {
  279. get { return isReadMode; }
  280. set
  281. {
  282. SetProperty(ref isReadMode, value);
  283. }
  284. }
  285. private bool canSave;
  286. /// <summary>
  287. /// 是否可以保存
  288. /// </summary>
  289. public bool CanSave
  290. {
  291. get { return canSave; }
  292. set
  293. {
  294. SetProperty(ref canSave, value);
  295. }
  296. }
  297. private bool canUndo;
  298. /// <summary>
  299. /// 是否可以进行Undo
  300. /// </summary>
  301. public bool CanUndo
  302. {
  303. get { return canUndo; }
  304. set
  305. {
  306. SetProperty(ref canUndo, value);
  307. }
  308. }
  309. private bool canRedo;
  310. /// <summary>
  311. /// 是否可以进行Redo
  312. /// </summary>
  313. public bool CanRedo
  314. {
  315. get { return canRedo; }
  316. set
  317. {
  318. SetProperty(ref canRedo, value);
  319. }
  320. }
  321. private GridLength botaWidth = new GridLength(48);
  322. /// <summary>
  323. /// BOTA栏的宽度
  324. /// </summary>
  325. public GridLength BOTAWidth
  326. {
  327. get { return botaWidth; }
  328. set
  329. {
  330. SetProperty(ref botaWidth, value);
  331. if (botaWidth.Value <= 48)
  332. {
  333. OpenBOTA = false;
  334. }
  335. }
  336. }
  337. private int selectedIndex;
  338. /// <summary>
  339. /// 工具栏选中项的索引
  340. /// </summary>
  341. public int TabSelectedIndex
  342. {
  343. get { return selectedIndex; }
  344. set
  345. {
  346. SetProperty(ref selectedIndex, value);
  347. }
  348. }
  349. private bool openBOTA = false;
  350. /// <summary>
  351. /// 是否展开BOTA
  352. /// </summary>
  353. public bool OpenBOTA
  354. {
  355. get { return openBOTA; }
  356. set
  357. {
  358. SetProperty(ref openBOTA, value);
  359. if (openBOTA && BOTAWidth.Value <= 48)
  360. {
  361. BOTAWidth = new GridLength(260);
  362. }
  363. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  364. }
  365. }
  366. private Dictionary<string, string> regionNameByTabItem;
  367. private Dictionary<string, string> barContentByTabItem;
  368. private string previousBar = "";
  369. public string CurrentBar = "";
  370. public string unicode = null;
  371. /// <summary>
  372. /// 用来避免重复触发导航事件的标志符
  373. /// </summary>
  374. private bool isOpenFile = false;
  375. /// <summary>
  376. /// 鼠标滚轮缩放的缩放值
  377. /// </summary>
  378. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  379. /// <summary>
  380. /// 注释-链接,提示语
  381. /// </summary>
  382. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  383. public Visibility LinkAnnotTipVisibility
  384. {
  385. get { return linkAnnotTipVisibility; }
  386. set
  387. {
  388. SetProperty(ref linkAnnotTipVisibility, value);
  389. }
  390. }
  391. 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";
  392. private bool isCreateLink = false;
  393. public string LinkAnnotTipText
  394. {
  395. get { return linkAnnotTipText; }
  396. set
  397. {
  398. SetProperty(ref linkAnnotTipText, value);
  399. }
  400. }
  401. #endregion 属性、变量
  402. #region 命令
  403. public DelegateCommand LoadFile { get; set; }
  404. public DelegateCommand Load { get; set; }
  405. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  406. public DelegateCommand SaveFile { get; set; }
  407. public DelegateCommand SaveAsFile { get; set; }
  408. public DelegateCommand SaveAsFlattenCommand { get; set; }
  409. public DelegateCommand UndoCommand { get; set; }
  410. public DelegateCommand RedoCommand { get; set; }
  411. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  412. public DelegateCommand PrintCommand { get; set; }
  413. public DelegateCommand SettingsCommand { get; set; }
  414. public DelegateCommand ShareCommand { get; set; }
  415. public DelegateCommand<object> CreateLinkCommand { get; set; }
  416. public DelegateCommand PropertyCommand { get; set; }
  417. public DelegateCommand ShowInFolderCommand { get; set; }
  418. #endregion 命令
  419. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  420. {
  421. region = regionManager;
  422. dialogs = dialogService;
  423. events = eventAggregator;
  424. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  425. LoadFile = new DelegateCommand(loadFile);
  426. Load = new DelegateCommand(LoadControl);
  427. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  428. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  429. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  430. UndoCommand = new DelegateCommand(Undo);
  431. RedoCommand = new DelegateCommand(Redo);
  432. ShareCommand = new DelegateCommand(share);
  433. PropertyCommand = new DelegateCommand(property);
  434. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  435. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  436. ViwerRegionName = RegionNames.ViwerRegionName;
  437. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  438. BOTARegionName = RegionNames.BOTARegionName;
  439. PropertyRegionName = RegionNames.PropertyRegionName;
  440. BottomToolRegionName = RegionNames.BottomToolRegionName;
  441. ReadModeRegionName = RegionNames.ReadModeRegionName;
  442. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  443. PrintCommand = new DelegateCommand(ShowPrintDialog);
  444. SettingsCommand = new DelegateCommand(SettingsEvent);
  445. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  446. //未显示时无法注册上Region名称
  447. ToolContentVisible = Visibility.Visible;
  448. ToolsBarContentVisible = Visibility.Visible;
  449. OCRContentVisible = Visibility.Visible;
  450. TipVisible = Visibility.Visible;
  451. TipContentRegionName = RegionNames.TipContentRegionName;
  452. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  453. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  454. ToolContentRegionName = Guid.NewGuid().ToString();
  455. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  456. ConverterBarContentRegionName = Guid.NewGuid().ToString();
  457. TextEditContentRegionName = Guid.NewGuid().ToString();
  458. ToolContentVisible = Visibility.Collapsed;
  459. ToolsBarContentVisible = Visibility.Collapsed;
  460. OCRContentVisible = Visibility.Collapsed;
  461. TipVisible = Visibility.Collapsed;
  462. regionNameByTabItem = new Dictionary<string, string>();
  463. barContentByTabItem = new Dictionary<string, string>();
  464. InitialregionNameByTabItem(ref regionNameByTabItem);
  465. InitialbarContentByTabItem(ref barContentByTabItem);
  466. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  467. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  468. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTip, e => e.Unicode == unicode);
  469. //TODO:根据缓存 选择用户上次选择的菜单
  470. EnterSelectedBar("TabItemAnnotation");
  471. }
  472. /// <summary>
  473. /// 设置Tip状态栏的显示状态
  474. /// </summary>
  475. /// <param name="show">是否显示</param>
  476. public void ShowTip(bool show)
  477. {
  478. if (show)
  479. {
  480. TipVisible = Visibility.Visible;
  481. }
  482. else
  483. {
  484. TipVisible = Visibility.Collapsed;
  485. }
  486. }
  487. /// <summary>
  488. /// 设置LeftTip状态栏的显示状态
  489. /// </summary>
  490. /// <param name="show">是否显示</param>
  491. public void ShowLeftTip(bool show)
  492. {
  493. if (show)
  494. {
  495. LeftTipVisible = Visibility.Visible;
  496. }
  497. else
  498. {
  499. LeftTipVisible = Visibility.Collapsed;
  500. }
  501. }
  502. public void CheckHaveAllPermission()
  503. {
  504. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  505. {
  506. ShowLeftTip(true);
  507. NavigationParameters param = new NavigationParameters();
  508. param.Add(ParameterNames.PDFViewer, PDFViewer);
  509. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  510. }
  511. }
  512. public void ShowSelectedTip(ShowTipEventArgs showTipEventArgs)
  513. {
  514. switch (showTipEventArgs.enumTipKind)
  515. {
  516. case EnumTipKind.StatusNone:
  517. ShowLeftTip(false);
  518. break;
  519. case EnumTipKind.StatusSetPasswordSuccessfully:
  520. ShowLeftTip(true);
  521. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  522. break;
  523. default: break;
  524. }
  525. }
  526. /// <summary>
  527. /// 右键菜单创建链接
  528. /// </summary>
  529. /// <param name="obj"></param>
  530. private void CreateLinkEvent(object obj)
  531. {
  532. if (obj is object[] objArry)
  533. {
  534. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  535. {
  536. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  537. linkArgs.URI = string.Empty;
  538. linkArgs.LinkType = LINK_TYPE.GOTO;
  539. linkArgs.PageIndex = annotCommand.PageIndex;
  540. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  541. this.IsRightMenuCreateLink = true;
  542. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  543. lists.Add(linkArgs);
  544. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  545. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  546. PDFViewer.SetToolParam(annotArgs);
  547. this.IsPropertyOpen = true;
  548. }
  549. }
  550. }
  551. /// <summary>
  552. /// 在文件资源管理器中显示
  553. /// </summary>
  554. private void ShowInFolder()
  555. {
  556. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  557. }
  558. private void property()
  559. {
  560. DialogParameters valuePairs = new DialogParameters();
  561. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  562. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  563. }
  564. private void share()
  565. {
  566. try
  567. {
  568. var path = PDFViewer.Document.FilePath;
  569. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  570. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  571. }
  572. catch
  573. {
  574. AlertsMessage alertsMessage = new AlertsMessage();
  575. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  576. }
  577. }
  578. private void SettingsEvent()
  579. {
  580. dialogs.ShowDialog(DialogNames.SettingsDialog, null, null);
  581. }
  582. private bool CanSaveExcute()
  583. {
  584. return CanSave;
  585. }
  586. private void MenuEnterReadModeEvent(object obj)
  587. {
  588. }
  589. public void ShowPrintDialog()
  590. {
  591. DialogParameters printValue = new DialogParameters();
  592. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  593. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  594. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  595. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  596. }
  597. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  598. {
  599. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  600. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  601. //其他工具菜单栏共用一个ToolsBarContentRegionName
  602. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  603. dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
  604. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  605. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  606. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  607. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  608. }
  609. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  610. {
  611. dictionary.Add("TabItemPageEdit", "PageEditContent");
  612. dictionary.Add("TabItemTool", "ToolsBarContent");
  613. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  614. dictionary.Add("TabItemConvert", "ConverterBarContent");
  615. dictionary.Add("TabItemScan", "ScanContent");
  616. dictionary.Add("TabItemEdit", "TextEditToolContent");
  617. dictionary.Add("TabItemForm", "FormsToolContent");
  618. dictionary.Add("TabItemFill", "FillAndSignContent");
  619. }
  620. private void UpdateShowContent(string currentBar)
  621. {
  622. ToolContentVisible = Visibility.Collapsed;
  623. ToolsBarContentVisible = Visibility.Collapsed;
  624. ConverterBarContentVisible = Visibility.Collapsed;
  625. TextEditToolContentVisible = Visibility.Collapsed;
  626. OCRContentVisible = Visibility.Collapsed;
  627. switch (currentBar)
  628. {
  629. case "TabItemAnnotation":
  630. case "TabItemTool":
  631. case "TabItemForm":
  632. case "TabItemFill":
  633. ToolsBarContentVisible = Visibility.Visible;
  634. break;
  635. case "TabItemScan":
  636. ToolsBarContentVisible = Visibility.Visible;
  637. OCRContentVisible = Visibility.Visible;
  638. break;
  639. case "TabItemEdit":
  640. TextEditToolContentVisible = Visibility.Visible;
  641. break;
  642. case "TabItemConvert":
  643. ConverterBarContentVisible = Visibility.Visible;
  644. break;
  645. case "TabItemPageEdit":
  646. case "HeaderFooterContent":
  647. case "BatesContent":
  648. case "WatermarkContent":
  649. case "BackgroundContent":
  650. case "RedactionContent":
  651. ToolContentVisible = Visibility.Visible;
  652. break;
  653. default:
  654. break;
  655. }
  656. PDFEditMode(currentBar);
  657. FormMode(currentBar);
  658. }
  659. private void PDFEditMode(string currentBar)
  660. {
  661. if (currentBar == "TabItemEdit")
  662. {
  663. if (PDFViewer != null)
  664. {
  665. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  666. //SelectedPrpoertyPanel("TextEditProperty", null);
  667. //IsPropertyOpen = true;
  668. }
  669. }
  670. else
  671. {
  672. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  673. {
  674. IsPropertyOpen = false;
  675. PDFViewer.SetMouseMode(MouseModes.PanTool);
  676. }
  677. }
  678. }
  679. private void FormMode(string currentBar)
  680. {
  681. if (currentBar == "TabItemForm")
  682. {
  683. if (PDFViewer != null)
  684. {
  685. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  686. }
  687. }
  688. else
  689. {
  690. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  691. {
  692. PDFViewer.SetMouseMode(MouseModes.PanTool);
  693. }
  694. }
  695. }
  696. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  697. {
  698. if (!isInPageEdit)
  699. {
  700. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  701. //页面编辑模式下,按钮状态根据页面编辑的undo redo来显示
  702. if (e.PropertyName == "CanUndo")
  703. {
  704. CanUndo = PDFViewer.UndoManager.CanUndo;
  705. }
  706. if (e.PropertyName == "CanRedo")
  707. {
  708. CanRedo = PDFViewer.UndoManager.CanRedo;
  709. }
  710. }
  711. if (e.PropertyName == "CanSave")
  712. {
  713. CanSave = PDFViewer.UndoManager.CanSave;
  714. }
  715. }
  716. /// <summary>
  717. /// 选项卡切换事件
  718. /// </summary>
  719. /// <param name="e"></param>
  720. private void TabControlSelectonChangedEvent(object e)
  721. {
  722. var args = e as SelectionChangedEventArgs;
  723. if (args != null)
  724. {
  725. var item = args.AddedItems[0] as TabItem;
  726. CurrentBar = item.Name;
  727. if (previousBar != CurrentBar)
  728. {
  729. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  730. {
  731. EnterToolMode(barContentByTabItem[CurrentBar]);
  732. isInPageEdit = true;
  733. }
  734. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  735. {
  736. EnterSelectedBar(CurrentBar);
  737. isInPageEdit = false;
  738. }
  739. previousBar = CurrentBar;
  740. }
  741. }
  742. }
  743. /// <summary>
  744. /// 阅读模式
  745. /// </summary>
  746. /// <param name="viewContent"></param>
  747. public async void RbtnReadMode()
  748. {
  749. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  750. App.IsBookMode = true;
  751. IsLoading = Visibility.Visible;
  752. await Task.Delay(1);
  753. NavigationParameters param = new NavigationParameters();
  754. param.Add(ParameterNames.PDFViewer, PDFViewer);
  755. param.Add(ParameterNames.ViewContentViewModel, this);
  756. region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  757. //ShowContent(CurrentBar, true);
  758. if (GridToolRow != 0)
  759. {
  760. GridToolRow = 0;
  761. }
  762. if (GridToolRowSpan != 4)
  763. {
  764. GridToolRowSpan = 4;
  765. }
  766. //isInPageEdit = true;
  767. UpdateShowContent("TabItemPageEdit");
  768. IsLoading = Visibility.Collapsed;
  769. }
  770. /// <summary>
  771. /// 退出阅读模式
  772. /// </summary>
  773. public async void UnReadModel()
  774. {
  775. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  776. App.IsBookMode = false;
  777. IsLoading = Visibility.Visible;
  778. await Task.Delay(1);
  779. //PDFViewer.MouseMode = MouseModes.None;
  780. if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  781. {
  782. if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  783. {
  784. var contentRegion = region.Regions[ViwerRegionName];
  785. contentRegion.Remove(PDFViewer);
  786. }
  787. region.AddToRegion(ViwerRegionName, PDFViewer);
  788. }
  789. if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  790. {
  791. EnterSelectedBar("TabItemAnnotation");
  792. }
  793. else
  794. {
  795. EnterSelectedBar(CurrentBar);
  796. }
  797. //isInPageEdit = false;
  798. //ShowContent(CurrentBar, false);
  799. //isInPageEdit = false;
  800. IsLoading = Visibility.Collapsed;
  801. ReadModelTip = Visibility.Visible;
  802. await Task.Delay(3000);
  803. ReadModelTip = Visibility.Collapsed;
  804. }
  805. #region PDFViewer鼠标滚轮缩放事件
  806. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  807. {
  808. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  809. PDFViewer.Zoom(newZoom);
  810. }
  811. public double CheckZoomLevel(double zoom, bool IsGrowth)
  812. {
  813. double standardZoom = 100;
  814. if (zoom <= 0.01)
  815. {
  816. return 0.01;
  817. }
  818. if (zoom >= 10)
  819. {
  820. return 10;
  821. }
  822. zoom *= 100;
  823. for (int i = 0; i < zoomLevel.Length - 1; i++)
  824. {
  825. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  826. {
  827. standardZoom = zoomLevel[i + 1];
  828. break;
  829. }
  830. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  831. {
  832. standardZoom = zoomLevel[i];
  833. break;
  834. }
  835. }
  836. return standardZoom / 100;
  837. }
  838. #endregion PDFViewer鼠标滚轮缩放事件
  839. #region Navigate
  840. public void OnNavigatedTo(NavigationContext navigationContext)
  841. {
  842. if (isOpenFile)
  843. return;
  844. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  845. if (mainVM != null)
  846. {
  847. mainViewModel = mainVM;
  848. mainViewModel.viewContentViewModel = this;
  849. }
  850. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  851. if (pdfview != null)
  852. {
  853. PDFViewer = pdfview;
  854. if(pdfview.Tag!=null)
  855. {
  856. //保存密码
  857. PassWord = pdfview.Tag.ToString();
  858. }
  859. loadFile();
  860. CheckHaveAllPermission();
  861. }
  862. isOpenFile = true;
  863. }
  864. public bool IsNavigationTarget(NavigationContext navigationContext)
  865. {
  866. return false;
  867. }
  868. public void OnNavigatedFrom(NavigationContext navigationContext)
  869. {
  870. }
  871. #endregion Navigate
  872. #region 方法
  873. /// <summary>
  874. /// 视图面板 切换分屏模式
  875. /// </summary>
  876. /// <param name="mode"></param>
  877. public void EnterSplitMode(SplitMode mode)
  878. {
  879. ///通知UI层更改布局
  880. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  881. }
  882. private void Undo()
  883. {
  884. if (isInPageEdit)
  885. {
  886. //执行页面编辑的Undo
  887. PageEditUndo?.Invoke();
  888. }
  889. else
  890. {
  891. PDFViewer.UndoManager.Undo();
  892. }
  893. }
  894. private void Redo()
  895. {
  896. if (isInPageEdit)
  897. {
  898. //执行页面编辑的Redo
  899. PageEditRedo?.Invoke();
  900. }
  901. else
  902. {
  903. PDFViewer.UndoManager.Redo();
  904. }
  905. }
  906. private void LoadControl()
  907. {
  908. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  909. // 非必要情况不要使用该异步方法,可能会导致一次性加载多个文件时出现因异步引起的regionname 错乱问题
  910. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  911. // {
  912. NavigationParameters parameters = new NavigationParameters();
  913. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  914. parameters.Add(ParameterNames.ViewContentViewModel, this);
  915. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  916. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  917. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  918. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  919. //TODO 根据上一次关闭记录的菜单,选中TabItem
  920. EnterSelectedBar("TabItemAnnotation");
  921. //}
  922. //));
  923. }
  924. /// <summary>
  925. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  926. /// </summary>
  927. /// <param name="Content"></param>
  928. /// <param name="annotPropertyPanel"></param>
  929. public void SelectedPrpoertyPanel(string Content, AnnotPropertyPanel annotPropertyPanel)
  930. {
  931. NavigationParameters parameters = new NavigationParameters();
  932. //传其他参数:文档类,空注释面板;
  933. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  934. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  935. parameters.Add(ParameterNames.ViewContentViewModel, this);
  936. region.RequestNavigate(PropertyRegionName, Content, parameters);
  937. }
  938. /// <summary>
  939. /// 将PDFViwer添加到Region
  940. /// </summary>
  941. private void loadFile()
  942. {
  943. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  944. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  945. CanSave = PDFViewer.UndoManager.CanSave;
  946. CanUndo = PDFViewer.UndoManager.CanUndo;
  947. CanRedo = PDFViewer.UndoManager.CanRedo;
  948. region.AddToRegion(ViwerRegionName, PDFViewer);
  949. }
  950. /// <summary>
  951. /// 已有路径文档的保存逻辑
  952. /// </summary>
  953. public bool saveFile()
  954. {
  955. try
  956. {
  957. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
  958. return saveAsFile();
  959. //文档已被修复时 提示另存为
  960. if (PDFViewer.Document.HasRepaired)
  961. {
  962. AlertsMessage alertsMessage = new AlertsMessage();
  963. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  964. if (alertsMessage.result == ContentResult.Ok)
  965. return saveAsFile();
  966. else
  967. return false;
  968. }
  969. //文件路径无法存在时
  970. if (!File.Exists(PDFViewer.Document.FilePath))
  971. {
  972. AlertsMessage alertsMessage = new AlertsMessage();
  973. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  974. if (alertsMessage.result == ContentResult.Ok)
  975. return saveAsFile();
  976. else
  977. return false;
  978. }
  979. //只读文件无法写入时,提示另存为
  980. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  981. if (fileInfo.IsReadOnly)
  982. {
  983. AlertsMessage alertsMessage = new AlertsMessage();
  984. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  985. if (alertsMessage.result == ContentResult.Ok)
  986. return saveAsFile();
  987. else
  988. return false;
  989. }
  990. bool result = PDFViewer.Document.WriteToLoadedPath();
  991. if (result)
  992. {
  993. PDFViewer.UndoManager.CanSave = false;
  994. App.Current.Dispatcher.Invoke(() =>
  995. {
  996. //保存时更新缩略图
  997. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  998. try
  999. {
  1000. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  1001. {
  1002. var size = PDFViewer.Document.GetPageSize(0);
  1003. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  1004. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  1005. if (File.Exists(folderPath))
  1006. File.Delete(folderPath);
  1007. DirectoryInfo folder = new DirectoryInfo(folderPath);
  1008. if (!folder.Exists)
  1009. folder.Create();
  1010. string imagePath = info.ThumbImgPath;
  1011. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  1012. {
  1013. string imageName = Guid.NewGuid().ToString();
  1014. imagePath = System.IO.Path.Combine(folderPath, imageName);
  1015. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  1016. {
  1017. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1018. }
  1019. }
  1020. else
  1021. {
  1022. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  1023. {
  1024. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1025. }
  1026. }
  1027. info.ThumbImgPath = imagePath;
  1028. SettingHelper.SetFileInfo(info);
  1029. }
  1030. }
  1031. catch
  1032. {
  1033. info.ThumbImgPath = null;
  1034. SettingHelper.SetFileInfo(info);
  1035. }
  1036. });
  1037. }
  1038. else
  1039. {
  1040. //文件被占用 保存失败时
  1041. AlertsMessage alertsMessage = new AlertsMessage();
  1042. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  1043. if (alertsMessage.result == ContentResult.Ok)
  1044. return saveAsFile();
  1045. else
  1046. return false;
  1047. }
  1048. return result;
  1049. }
  1050. catch { return false; }
  1051. }
  1052. /// <summary>
  1053. /// 另存为或新文档保存逻辑
  1054. /// </summary>
  1055. public bool saveAsFile(Action RedactionAction = null)
  1056. {
  1057. var dlg = new Microsoft.Win32.SaveFileDialog();
  1058. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1059. dlg.FileName = PDFViewer.Document.FileName;
  1060. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1061. {
  1062. bool result = false;
  1063. if (RedactionAction != null)
  1064. {
  1065. //保存前进行标记密文处理应用或擦除
  1066. RedactionAction.Invoke();
  1067. }
  1068. if (App.OpenedFileList.Contains(dlg.FileName))
  1069. {
  1070. //提示文件已经被打开
  1071. }
  1072. else
  1073. {
  1074. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  1075. if (result)
  1076. {
  1077. DoAfterSaveAs(dlg.FileName);
  1078. }
  1079. else
  1080. {
  1081. //提示文件被其他软件占用 无法保存
  1082. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
  1083. }
  1084. ;
  1085. }
  1086. return result;
  1087. }
  1088. else
  1089. return false;
  1090. }
  1091. /// <summary>
  1092. /// 另存为Flatten
  1093. /// </summary>
  1094. private void saveAsFlatten()
  1095. {
  1096. var dlg = new SaveFileDialog();
  1097. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1098. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  1099. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1100. {
  1101. saveFile();
  1102. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  1103. if (kmdoc == null)
  1104. return;
  1105. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  1106. if (result)
  1107. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  1108. kmdoc.Release();
  1109. }
  1110. }
  1111. /// <summary>
  1112. /// 另存为后进行的操作
  1113. /// 重新打开新文档
  1114. /// </summary>
  1115. /// <param name="targetPath"></param>
  1116. public void DoAfterSaveAs(string targetPath)
  1117. {
  1118. App.OpenedFileList.Remove(targetPath);
  1119. string oldFilePath = targetPath;
  1120. PDFViewer.UndoManager.CanSave = false;
  1121. mainViewModel.OpenFile(targetPath);
  1122. //TODO:通知各模块更新PDFview对象
  1123. //var result = OpenFile(targetPath, true);
  1124. //if (result)
  1125. //{
  1126. // FileChanged.Invoke(this, null);
  1127. // Zoomer.PdfViewer = PdfViewer;
  1128. // PageSelector.PdfViewer = PdfViewer;
  1129. // ViewModeSelector.PdfViewer = PdfViewer;
  1130. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  1131. // if (fileInfo != null)
  1132. // {
  1133. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  1134. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  1135. // if (fileInfo.LastFitMode == FitMode.FitFree)
  1136. // PdfViewer.Zoom(fileInfo.LastZoom);
  1137. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  1138. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  1139. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  1140. // else
  1141. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  1142. // }
  1143. //}
  1144. }
  1145. /// <summary>
  1146. /// 显示前添加内容到Region
  1147. /// </summary>
  1148. /// <param name="isPageEdit"></param>
  1149. private void ShowContent(string currentBar, bool isToolMode = false)
  1150. {
  1151. GridVisibility = Visibility.Visible;
  1152. //显示页面编辑或其他工具
  1153. if (currentBar == "TabItemPageEdit" || isToolMode)
  1154. {
  1155. if (currentBar == "TabItemPageEdit")//进入页面编辑
  1156. {
  1157. if (GridToolRow != 1)
  1158. {
  1159. GridToolRow = 1;
  1160. }
  1161. if (GridToolRowSpan != 3)
  1162. {
  1163. GridToolRowSpan = 3;
  1164. }
  1165. }
  1166. else//进入水印等其他工具模式
  1167. {
  1168. GridVisibility = Visibility.Collapsed;
  1169. if (GridToolRow != 0)
  1170. {
  1171. GridToolRow = 0;
  1172. }
  1173. if (GridToolRowSpan != 4)
  1174. {
  1175. GridToolRowSpan = 4;
  1176. }
  1177. }
  1178. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  1179. UpdateShowContent(currentBar);
  1180. }
  1181. else
  1182. {
  1183. if (GridToolRow != 1)
  1184. {
  1185. GridToolRow = 1;
  1186. }
  1187. UpdateShowContent(currentBar);
  1188. }
  1189. }
  1190. /// <summary>
  1191. /// 从二级工具栏进入需要修改界面布局的场景
  1192. /// </summary>
  1193. /// <param name="EditToolName"></param>
  1194. private void EnterEditTools(StringWithUnicode EditToolName)
  1195. {
  1196. EnterSelectedEditTool(EditToolName);
  1197. }
  1198. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  1199. {
  1200. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  1201. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  1202. {
  1203. PDFViewer.Document.ReleasePages();
  1204. PDFViewer.ReloadDocument();
  1205. }
  1206. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  1207. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1208. {
  1209. region.AddToRegion(ViwerRegionName, PDFViewer);
  1210. }
  1211. CurrentBar = "TabItemTool";
  1212. EnterSelectedBar(CurrentBar);
  1213. }
  1214. /// <summary>
  1215. /// 二级菜单指定目标处理
  1216. /// </summary>
  1217. /// <param name="e"></param>
  1218. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  1219. {
  1220. CurrentBar = EditToolName.EditToolsContentName;
  1221. EnterToolMode(CurrentBar);
  1222. }
  1223. /// <summary>
  1224. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  1225. /// </summary>
  1226. /// <param name="targetToolMode">要导航过去的控件名称</param>
  1227. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  1228. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  1229. {
  1230. IsLoading = Visibility.Visible;
  1231. await Task.Delay(3);
  1232. NavigationParameters param = new NavigationParameters();
  1233. if (valuePairs == null)
  1234. {
  1235. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1236. param.Add(ParameterNames.ViewContentViewModel, this);
  1237. }
  1238. else//有传入其他内容的参数时
  1239. {
  1240. param = valuePairs;
  1241. }
  1242. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  1243. ShowContent(CurrentBar, true);
  1244. IsLoading = Visibility.Collapsed;
  1245. }
  1246. private void EnterSelectedBar(string currentBar)
  1247. {
  1248. NavigationParameters param = new NavigationParameters();
  1249. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1250. param.Add(ParameterNames.ViewContentViewModel, this);
  1251. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  1252. if (currentBar == "TabItemScan")
  1253. {
  1254. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  1255. }
  1256. ShowContent(currentBar);
  1257. }
  1258. /// <summary>
  1259. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  1260. /// </summary>
  1261. public void ExitToolMode()
  1262. {
  1263. ToolContentVisible = Visibility.Collapsed;
  1264. if (isInPageEdit)
  1265. {
  1266. TabSelectedIndex = 0;
  1267. isInPageEdit = false;
  1268. }
  1269. }
  1270. #endregion 方法
  1271. }
  1272. }