ViewContentViewModel.cs 49 KB

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