ViewContentViewModel.cs 49 KB

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