ViewContentViewModel.cs 50 KB

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