ViewContentViewModel.cs 50 KB

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