ViewContentViewModel.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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. namespace PDF_Office.ViewModels
  24. {
  25. public class ViewContentViewModel : BindableBase, INavigationAware
  26. {
  27. #region 属性、变量
  28. private CPDFViewer PDFViewer { get; set; }
  29. private MainContentViewModel mainViewModel { get; set; }
  30. public IRegionManager region;
  31. public IDialogService dialogs;
  32. public string ViwerRegionName { get; set; }
  33. public string BOTARegionName { get; set; }
  34. public string PropertyRegionName { get; set; }
  35. public string ToolContentRegionName { get; set; }
  36. public string ToolsBarContentRegionName { get; set; }
  37. public string ReadModeRegionName { get; set; }
  38. /// <summary>
  39. /// 底部工具栏 RegionName
  40. /// </summary>
  41. public string BottomToolRegionName { get; set; }
  42. /// <summary>
  43. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  44. /// </summary>
  45. public bool isInPageEdit = false;
  46. public Action PageEditUndo { get; set; }
  47. public Action PageEditRedo { get; set; }
  48. private int gridToolRow = 1;
  49. /// <summary>
  50. /// 控制ToolContent的Row
  51. /// </summary>
  52. public int GridToolRow
  53. {
  54. get { return gridToolRow; }
  55. set
  56. {
  57. SetProperty(ref gridToolRow, value);
  58. }
  59. }
  60. private int gridToolRowSpan = 3;
  61. /// <summary>
  62. /// 控制ToolContent的RowSpan
  63. /// </summary>
  64. public int GridToolRowSpan
  65. {
  66. get { return gridToolRowSpan; }
  67. set
  68. {
  69. SetProperty(ref gridToolRowSpan, value);
  70. }
  71. }
  72. private Visibility toolContentVisible = Visibility.Collapsed;
  73. /// <summary>
  74. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  75. /// 留意:显示前需要先注入内容、设置好行和跨行数
  76. /// </summary>
  77. public Visibility ToolContentVisible
  78. {
  79. get { return toolContentVisible; }
  80. set
  81. {
  82. SetProperty(ref toolContentVisible, value);
  83. }
  84. }
  85. private Visibility isLoading = Visibility.Collapsed;
  86. /// <summary>
  87. /// 是否正在加载中
  88. /// </summary>
  89. public Visibility IsLoading
  90. {
  91. get { return isLoading; }
  92. set
  93. {
  94. SetProperty(ref isLoading, value);
  95. }
  96. }
  97. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  98. /// <summary>
  99. /// 控制ToolsBarContent的显示
  100. /// 留意:显示前需要先注入内容、设置好行和跨行数
  101. /// </summary>
  102. public Visibility ToolsBarContentVisible
  103. {
  104. get { return toolsbarContentVisible; }
  105. set
  106. {
  107. SetProperty(ref toolsbarContentVisible, value);
  108. }
  109. }
  110. private bool isPorpertyOpen = false;
  111. /// <summary>
  112. /// 属性栏是否展开
  113. /// </summary>
  114. public bool IsPropertyOpen
  115. {
  116. get { return isPorpertyOpen; }
  117. set
  118. {
  119. SetProperty(ref isPorpertyOpen, value);
  120. }
  121. }
  122. private Visibility isReadMode = Visibility.Visible;
  123. /// <summary>
  124. ///是否为阅读模式
  125. /// </summary>
  126. public Visibility IsReadMode
  127. {
  128. get { return isReadMode; }
  129. set
  130. {
  131. SetProperty(ref isReadMode, value);
  132. }
  133. }
  134. private bool canSave;
  135. /// <summary>
  136. /// 是否可以保存
  137. /// </summary>
  138. public bool CanSave
  139. {
  140. get { return canSave; }
  141. set
  142. {
  143. SetProperty(ref canSave, value);
  144. }
  145. }
  146. private bool canUndo;
  147. /// <summary>
  148. /// 是否可以进行Undo
  149. /// </summary>
  150. public bool CanUndo
  151. {
  152. get { return canUndo; }
  153. set
  154. {
  155. SetProperty(ref canUndo, value);
  156. }
  157. }
  158. private bool canRedo;
  159. /// <summary>
  160. /// 是否可以进行Redo
  161. /// </summary>
  162. public bool CanRedo
  163. {
  164. get { return canRedo; }
  165. set
  166. {
  167. SetProperty(ref canRedo, value);
  168. }
  169. }
  170. private GridLength botaWidth = new GridLength(48);
  171. /// <summary>
  172. /// BOTA栏的宽度
  173. /// </summary>
  174. public GridLength BOTAWidth
  175. {
  176. get { return botaWidth; }
  177. set
  178. {
  179. SetProperty(ref botaWidth, value);
  180. if (botaWidth.Value <= 48)
  181. {
  182. OpenBOTA = false;
  183. }
  184. }
  185. }
  186. private int selectedIndex;
  187. /// <summary>
  188. /// 工具栏选中项的索引
  189. /// </summary>
  190. public int TabSelectedIndex
  191. {
  192. get { return selectedIndex; }
  193. set
  194. {
  195. SetProperty(ref selectedIndex, value);
  196. }
  197. }
  198. private bool openBOTA = false;
  199. /// <summary>
  200. /// 是否展开BOTA
  201. /// </summary>
  202. public bool OpenBOTA
  203. {
  204. get { return openBOTA; }
  205. set
  206. {
  207. openBOTA = value;
  208. if (openBOTA && BOTAWidth.Value <= 48)
  209. {
  210. BOTAWidth = new GridLength(256);
  211. }
  212. }
  213. }
  214. private Dictionary<string, string> regionNameByTabItem;
  215. private Dictionary<string, string> barContentByTabItem;
  216. private string previousBar = "";
  217. private string currentBar = "";
  218. /// <summary>
  219. /// 用来避免重复触发导航事件的标志符
  220. /// </summary>
  221. private bool isOpenFile = false;
  222. /// <summary>
  223. /// 鼠标滚轮缩放的缩放值
  224. /// </summary>
  225. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  226. #endregion 属性、变量
  227. #region 命令
  228. public DelegateCommand LoadFile { get; set; }
  229. public DelegateCommand Load { get; set; }
  230. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  231. public DelegateCommand SaveFile { get; set; }
  232. public DelegateCommand SaveAsFile { get; set; }
  233. public DelegateCommand UndoCommand { get; set; }
  234. public DelegateCommand RedoCommand { get; set; }
  235. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  236. #endregion 命令
  237. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService)
  238. {
  239. region = regionManager;
  240. dialogs = dialogService;
  241. LoadFile = new DelegateCommand(loadFile);
  242. Load = new DelegateCommand(LoadControl);
  243. SaveFile = new DelegateCommand(() => { saveFile(); });
  244. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  245. UndoCommand = new DelegateCommand(Undo);
  246. RedoCommand = new DelegateCommand(Redo);
  247. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  248. ViwerRegionName = RegionNames.ViwerRegionName;
  249. BOTARegionName = RegionNames.BOTARegionName;
  250. PropertyRegionName = RegionNames.PropertyRegionName;
  251. BottomToolRegionName = RegionNames.BottomToolRegionName;
  252. ReadModeRegionName = RegionNames.ReadModeRegionName;
  253. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  254. //未显示时无法注册上Region名称
  255. ToolContentVisible = Visibility.Visible;
  256. ToolContentRegionName = RegionNames.ToolContentRegionName;
  257. ToolsBarContentRegionName = RegionNames.ToolsBarContentRegionName;
  258. ToolContentVisible = Visibility.Collapsed;
  259. ToolsBarContentVisible = Visibility.Collapsed;
  260. regionNameByTabItem = new Dictionary<string, string>();
  261. barContentByTabItem = new Dictionary<string, string>();
  262. InitialregionNameByTabItem(ref regionNameByTabItem);
  263. InitialbarContentByTabItem(ref barContentByTabItem);
  264. }
  265. private void MenuEnterReadModeEvent(object obj)
  266. {
  267. }
  268. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  269. {
  270. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  271. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  272. //其他工具菜单栏共用一个ToolsBarContentRegionName
  273. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  274. dictionary.Add("TabItemConvert", ToolsBarContentRegionName);
  275. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  276. dictionary.Add("TabItemEdit", ToolsBarContentRegionName);
  277. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  278. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  279. }
  280. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  281. {
  282. dictionary.Add("TabItemPageEdit", "PageEditContent");
  283. dictionary.Add("TabItemTool", "ToolsBarContent");
  284. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  285. dictionary.Add("TabItemConvert", "");
  286. dictionary.Add("TabItemScan", "");
  287. dictionary.Add("TabItemEdit", "");
  288. dictionary.Add("TabItemForm", "");
  289. dictionary.Add("TabItemFill", "FillAndSignContent");
  290. }
  291. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  292. {
  293. if (e.PropertyName == "CanSave")
  294. {
  295. CanSave = PDFViewer.UndoManager.CanSave;
  296. }
  297. if (e.PropertyName == "CanUndo")
  298. {
  299. CanUndo = PDFViewer.UndoManager.CanUndo;
  300. }
  301. if (e.PropertyName == "CanRedo")
  302. {
  303. CanRedo = PDFViewer.UndoManager.CanRedo;
  304. }
  305. }
  306. /// <summary>
  307. /// 选项卡切换事件
  308. /// </summary>
  309. /// <param name="e"></param>
  310. private void TabControlSelectonChangedEvent(object e)
  311. {
  312. var args = e as SelectionChangedEventArgs;
  313. if (args != null)
  314. {
  315. var item = args.AddedItems[0] as TabItem;
  316. currentBar = item.Name;
  317. if (previousBar != currentBar)
  318. {
  319. if (currentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  320. {
  321. EnterToolMode(barContentByTabItem[currentBar]);
  322. isInPageEdit = true;
  323. }
  324. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  325. {
  326. EnterSelectedBar(currentBar);
  327. isInPageEdit = false;
  328. }
  329. previousBar = currentBar;
  330. }
  331. }
  332. }
  333. #region PDFViewer鼠标滚轮缩放事件
  334. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  335. {
  336. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  337. PDFViewer.Zoom(newZoom);
  338. }
  339. private double CheckZoomLevel(double zoom, bool IsGrowth)
  340. {
  341. double standardZoom = 100;
  342. if (zoom <= 0.01)
  343. {
  344. return 0.01;
  345. }
  346. if (zoom >= 10)
  347. {
  348. return 10;
  349. }
  350. zoom *= 100;
  351. for (int i = 0; i < zoomLevel.Length - 1; i++)
  352. {
  353. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  354. {
  355. standardZoom = zoomLevel[i + 1];
  356. break;
  357. }
  358. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  359. {
  360. standardZoom = zoomLevel[i];
  361. break;
  362. }
  363. }
  364. return standardZoom / 100;
  365. }
  366. #endregion PDFViewer鼠标滚轮缩放事件
  367. #region Navigate
  368. public void OnNavigatedTo(NavigationContext navigationContext)
  369. {
  370. if (isOpenFile)
  371. return;
  372. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  373. if (mainVM != null)
  374. {
  375. mainViewModel = mainVM;
  376. }
  377. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  378. if (pdfview != null)
  379. {
  380. PDFViewer = pdfview;
  381. loadFile();
  382. }
  383. isOpenFile = true;
  384. }
  385. public bool IsNavigationTarget(NavigationContext navigationContext)
  386. {
  387. return true;
  388. }
  389. public void OnNavigatedFrom(NavigationContext navigationContext)
  390. {
  391. }
  392. #endregion Navigate
  393. #region 方法
  394. private void Undo()
  395. {
  396. if (isInPageEdit)
  397. {
  398. //执行页面编辑的Undo
  399. PageEditUndo?.Invoke();
  400. }
  401. else
  402. {
  403. PDFViewer.UndoManager.Undo();
  404. }
  405. }
  406. private void Redo()
  407. {
  408. if (isInPageEdit)
  409. {
  410. //执行页面编辑的Redo
  411. PageEditRedo?.Invoke();
  412. }
  413. else
  414. {
  415. PDFViewer.UndoManager.Redo();
  416. }
  417. }
  418. private void LoadControl()
  419. {
  420. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  421. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  422. {
  423. NavigationParameters parameters = new NavigationParameters();
  424. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  425. parameters.Add(ParameterNames.ViewContentViewModel, this);
  426. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  427. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  428. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  429. //TODO 根据上一次关闭记录的菜单,选中TabItem
  430. EnterSelectedBar("TabItemAnnotation");
  431. }
  432. ));
  433. }
  434. public void SelectedPrpoertyPanel(string Content, AnnotPropertyPanel annotPropertyPanel)
  435. {
  436. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  437. {
  438. NavigationParameters parameters = new NavigationParameters();
  439. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  440. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  441. region.RequestNavigate(PropertyRegionName, Content, parameters);
  442. }
  443. ));
  444. }
  445. /// <summary>
  446. /// 将PDFViwer添加到Region
  447. /// </summary>
  448. private void loadFile()
  449. {
  450. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  451. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  452. CanSave = PDFViewer.UndoManager.CanSave;
  453. CanUndo = PDFViewer.UndoManager.CanUndo;
  454. CanRedo = PDFViewer.UndoManager.CanRedo;
  455. region.AddToRegion(ViwerRegionName, PDFViewer);
  456. }
  457. /// <summary>
  458. /// 已有路径文档的保存逻辑
  459. /// </summary>
  460. private bool saveFile()
  461. {
  462. try
  463. {
  464. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
  465. return saveAsFile();
  466. //文档已被修复时 提示另存为
  467. if (PDFViewer.Document.HasRepaired)
  468. {
  469. AlertsMessage alertsMessage = new AlertsMessage();
  470. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  471. if (alertsMessage.result == ContentResult.Ok)
  472. return saveAsFile();
  473. else
  474. return false;
  475. }
  476. //文件路径无法存在时
  477. if (!File.Exists(PDFViewer.Document.FilePath))
  478. {
  479. AlertsMessage alertsMessage = new AlertsMessage();
  480. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  481. if (alertsMessage.result == ContentResult.Ok)
  482. return saveAsFile();
  483. else
  484. return false;
  485. }
  486. //只读文件无法写入时,提示另存为
  487. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  488. if (fileInfo.IsReadOnly)
  489. {
  490. AlertsMessage alertsMessage = new AlertsMessage();
  491. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  492. if (alertsMessage.result == ContentResult.Ok)
  493. return saveAsFile();
  494. else
  495. return false;
  496. }
  497. bool result = PDFViewer.Document.WriteToLoadedPath();
  498. if (result)
  499. {
  500. PDFViewer.UndoManager.CanSave = false;
  501. App.Current.Dispatcher.Invoke(() =>
  502. {
  503. //TODO:更新缩略图
  504. //OpenFileInfo info = SettingHelper.GetFileInfo(PdfViewer.Document.FilePath);
  505. //try
  506. //{
  507. // if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PdfViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  508. // {
  509. // var size = PdfViewer.Document.GetPageSize(0);
  510. // System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PdfViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  511. // string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  512. // if (File.Exists(folderPath))
  513. // File.Delete(folderPath);
  514. // DirectoryInfo folder = new DirectoryInfo(folderPath);
  515. // if (!folder.Exists)
  516. // folder.Create();
  517. // string imagePath = info.ThumbImgPath;
  518. // if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  519. // {
  520. // string imageName = Guid.NewGuid().ToString();
  521. // imagePath = System.IO.Path.Combine(folderPath, imageName);
  522. // using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  523. // {
  524. // bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  525. // }
  526. // }
  527. // else
  528. // {
  529. // using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  530. // {
  531. // bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  532. // }
  533. // }
  534. // info.ThumbImgPath = imagePath;
  535. // SettingHelper.SetFileInfo(info);
  536. // }
  537. //}
  538. //catch
  539. //{
  540. // info.ThumbImgPath = null;
  541. // SettingHelper.SetFileInfo(info);
  542. //}
  543. });
  544. }
  545. else
  546. {
  547. //文件被占用 保存失败时
  548. AlertsMessage alertsMessage = new AlertsMessage();
  549. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  550. if (alertsMessage.result == ContentResult.Ok)
  551. return saveAsFile();
  552. else
  553. return false;
  554. }
  555. return result;
  556. }
  557. catch { return false; }
  558. }
  559. /// <summary>
  560. /// 另存为或新文档保存逻辑
  561. /// </summary>
  562. private bool saveAsFile()
  563. {
  564. var dlg = new SaveFileDialog();
  565. dlg.Filter = Properties.Resources.OpenDialogFilter;
  566. dlg.FileName = PDFViewer.Document.FileName;
  567. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  568. {
  569. bool result = false;
  570. if (App.OpenedFileList.Contains(dlg.FileName))
  571. {
  572. //提示文件已经被打开
  573. }
  574. else
  575. {
  576. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  577. if (result)
  578. {
  579. DoAfterSaveAs(dlg.FileName);
  580. }
  581. else
  582. {
  583. //提示文件被其他软件占用 无法保存
  584. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
  585. }
  586. ;
  587. }
  588. return result;
  589. }
  590. else
  591. return false;
  592. }
  593. /// <summary>
  594. /// 另存为后进行的操作
  595. /// 重新打开新文档
  596. /// </summary>
  597. /// <param name="targetPath"></param>
  598. public void DoAfterSaveAs(string targetPath)
  599. {
  600. App.OpenedFileList.Remove(targetPath);
  601. string oldFilePath = targetPath;
  602. PDFViewer.UndoManager.CanSave = false;
  603. mainViewModel.OpenFile(targetPath);
  604. //TODO:通知各模块更新PDFview对象
  605. //var result = OpenFile(targetPath, true);
  606. //if (result)
  607. //{
  608. // FileChanged.Invoke(this, null);
  609. // Zoomer.PdfViewer = PdfViewer;
  610. // PageSelector.PdfViewer = PdfViewer;
  611. // ViewModeSelector.PdfViewer = PdfViewer;
  612. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  613. // if (fileInfo != null)
  614. // {
  615. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  616. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  617. // if (fileInfo.LastFitMode == FitMode.FitFree)
  618. // PdfViewer.Zoom(fileInfo.LastZoom);
  619. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  620. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  621. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  622. // else
  623. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  624. // }
  625. //}
  626. }
  627. /// <summary>
  628. /// 显示前添加内容到Region
  629. /// </summary>
  630. /// <param name="isPageEdit"></param>
  631. private void ShowContent(string currentBar, bool isToolMode = false)
  632. {
  633. //显示页面编辑或其他工具
  634. if (currentBar == "TabItemPageEdit" || isToolMode)
  635. {
  636. if (currentBar == "TabItemPageEdit")//进入页面编辑
  637. {
  638. if (GridToolRow != 1)
  639. {
  640. GridToolRow = 1;
  641. }
  642. if (GridToolRowSpan != 3)
  643. {
  644. GridToolRowSpan = 3;
  645. }
  646. }
  647. else//进入水印等其他工具模式
  648. {
  649. if (GridToolRow != 0)
  650. {
  651. GridToolRow = 0;
  652. }
  653. if (GridToolRowSpan != 4)
  654. {
  655. GridToolRowSpan = 4;
  656. }
  657. }
  658. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  659. ToolContentVisible = Visibility.Visible;
  660. ToolsBarContentVisible = Visibility.Collapsed;
  661. }
  662. else
  663. {
  664. if (GridToolRow != 1)
  665. {
  666. GridToolRow = 1;
  667. }
  668. ToolContentVisible = Visibility.Collapsed;
  669. ToolsBarContentVisible = Visibility.Visible;
  670. }
  671. }
  672. /// <summary>
  673. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  674. /// </summary>
  675. /// <param name="targetToolMode">要导航过去的控件名称</param>
  676. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  677. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  678. {
  679. IsLoading = Visibility.Visible;
  680. await Task.Delay(3);
  681. NavigationParameters param = new NavigationParameters();
  682. if (valuePairs == null)
  683. {
  684. param.Add(ParameterNames.PDFViewer, PDFViewer);
  685. param.Add(ParameterNames.ViewContentViewModel, this);
  686. }
  687. else//有传入其他内容的参数时
  688. {
  689. param = valuePairs;
  690. }
  691. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  692. ShowContent(currentBar, true);
  693. IsLoading = Visibility.Collapsed;
  694. }
  695. private void EnterSelectedBar(string currentBar)
  696. {
  697. NavigationParameters param = new NavigationParameters();
  698. param.Add(ParameterNames.PDFViewer, PDFViewer);
  699. param.Add(ParameterNames.ViewContentViewModel, this);
  700. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  701. ShowContent(currentBar);
  702. }
  703. /// <summary>
  704. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  705. /// </summary>
  706. public void ExitToolMode()
  707. {
  708. ToolContentVisible = Visibility.Collapsed;
  709. if (isInPageEdit)
  710. {
  711. TabSelectedIndex = 0;
  712. isInPageEdit = false;
  713. }
  714. }
  715. #endregion 方法
  716. }
  717. }