ViewContentViewModel.cs 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190
  1. using Microsoft.Win32;
  2. using Prism.Commands;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. using ComPDFKitViewer.PdfViewer;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using PDF_Office.CustomControl;
  11. using PDF_Office.Model;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.IO;
  15. using ComPDFKitViewer.AnnotEvent;
  16. using PDF_Office.ViewModels.Tools;
  17. using Prism.Events;
  18. using PDF_Office.EventAggregators;
  19. using PDF_Office.Helper;
  20. using ComPDFKit.PDFDocument;
  21. using PDFSettings.Settings;
  22. using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
  23. using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
  24. using PDF_Office.Model.Dialog.ToolsDialogs;
  25. using DryIoc;
  26. using PDF_Office.Model.Dialog.ConverterDialogs;
  27. using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  28. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  29. using System.Linq;
  30. using System.Text;
  31. using PDF_Office.Views.Tools;
  32. using System.Windows.Input;
  33. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  34. namespace PDF_Office.ViewModels
  35. {
  36. public class ViewContentViewModel : BindableBase, INavigationAware
  37. {
  38. #region 文案
  39. private string T_file;
  40. public string T_File
  41. {
  42. get { return T_file; }
  43. set
  44. {
  45. SetProperty(ref T_file, value);
  46. }
  47. }
  48. private string T_save;
  49. public string T_Save
  50. {
  51. get { return T_save; }
  52. set
  53. {
  54. SetProperty(ref T_save, value);
  55. }
  56. }
  57. private string T_undo;
  58. public string T_Undo
  59. {
  60. get { return T_undo; }
  61. set
  62. {
  63. SetProperty(ref T_undo, value);
  64. }
  65. }
  66. private string T_redo;
  67. public string T_Redo
  68. {
  69. get { return T_redo; }
  70. set
  71. {
  72. SetProperty(ref T_redo, value);
  73. }
  74. }
  75. private string T_annotation;
  76. public string T_Annotation
  77. {
  78. get { return T_annotation; }
  79. set
  80. {
  81. SetProperty(ref T_annotation, value);
  82. }
  83. }
  84. private string T_pageEdit;
  85. public string T_PageEdit
  86. {
  87. get { return T_pageEdit; }
  88. set
  89. {
  90. SetProperty(ref T_pageEdit, value);
  91. }
  92. }
  93. private string T_converter;
  94. public string T_Converter
  95. {
  96. get { return T_converter; }
  97. set
  98. {
  99. SetProperty(ref T_converter, value);
  100. }
  101. }
  102. private string T_fillSign;
  103. public string T_FillSign
  104. {
  105. get { return T_fillSign; }
  106. set
  107. {
  108. SetProperty(ref T_fillSign, value);
  109. }
  110. }
  111. private string T_tools;
  112. public string T_Tools
  113. {
  114. get { return T_tools; }
  115. set
  116. {
  117. SetProperty(ref T_tools, value);
  118. }
  119. }
  120. private string T_print;
  121. public string T_Print
  122. {
  123. get { return T_print; }
  124. set
  125. {
  126. SetProperty(ref T_print, value);
  127. }
  128. }
  129. private string T_share;
  130. public string T_Share
  131. {
  132. get { return T_share; }
  133. set
  134. {
  135. SetProperty(ref T_share, value);
  136. }
  137. }
  138. private string T_properties;
  139. public string T_Properties
  140. {
  141. get { return T_properties; }
  142. set
  143. {
  144. SetProperty(ref T_properties, value);
  145. }
  146. }
  147. private void InitStirng()
  148. {
  149. T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
  150. T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
  151. T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
  152. T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
  153. T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
  154. T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
  155. T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
  156. T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
  157. T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
  158. T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
  159. T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
  160. T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
  161. }
  162. #endregion 文案
  163. #region 属性、变量
  164. public OpenFileInfo OpenFileInfo = null;
  165. public CPDFViewer PDFViewer { get; set; }
  166. public MainContentViewModel mainViewModel { get; set; }
  167. public IRegionManager region;
  168. public IDialogService dialogs;
  169. public IEventAggregator events;
  170. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  171. public string ViwerRegionName { get; set; }
  172. /// <summary>
  173. /// 分屏视图的region名称
  174. /// </summary>
  175. public string SplitViewerRegionName { get; set; }
  176. /// <summary>
  177. /// OCR视图名称
  178. /// </summary>
  179. public string OCRViewerRegionName { get; set; }
  180. public string BOTARegionName { get; set; }
  181. public string PropertyRegionName { get; set; }
  182. public string ToolContentRegionName { get; set; }
  183. public string ToolsBarContentRegionName { get; set; }
  184. /// <summary>
  185. /// 顶部提示的Content
  186. /// </summary>
  187. public string TipContentRegionName { get; set; }
  188. public string LeftTipContentRegionName { get; set; }
  189. //便签弹窗
  190. public string NotePopupRegionName { get; set; }
  191. public string ReadModeRegionName { get; set; }
  192. public string ConverterBarContentRegionName { get; set; }
  193. public string TextEditContentRegionName { get; set; }
  194. public string BackgroundContentRegionName { get; set; }
  195. public List<Point> FillAndSign = new List<Point>();
  196. /// <summary>
  197. /// 文档的密码
  198. /// </summary>
  199. public string PassWord { get; set; }
  200. private Visibility tipVisible = Visibility.Collapsed;
  201. /// <summary>
  202. /// 顶部提示栏的显示状态
  203. /// </summary>
  204. public Visibility TipVisible
  205. {
  206. get { return tipVisible; }
  207. set
  208. {
  209. SetProperty(ref tipVisible, value);
  210. }
  211. }
  212. private Visibility leftTipVisible = Visibility.Collapsed;
  213. public Visibility LeftTipVisible
  214. {
  215. get { return leftTipVisible; }
  216. set
  217. {
  218. SetProperty(ref leftTipVisible, value);
  219. }
  220. }
  221. private Visibility notePopupVisible = Visibility.Collapsed;
  222. public Visibility NotePopupVisible
  223. {
  224. get { return notePopupVisible; }
  225. set
  226. {
  227. SetProperty(ref notePopupVisible, value);
  228. }
  229. }
  230. public bool IsNoteAdd = false;
  231. private double canvasNoteLeft;
  232. public double CanvasNoteLeft
  233. {
  234. get { return canvasNoteLeft; }
  235. set
  236. {
  237. SetProperty(ref canvasNoteLeft, value);
  238. }
  239. }
  240. private double canvasNoteTop;
  241. public double CanvasNoteTop
  242. {
  243. get { return canvasNoteTop; }
  244. set
  245. {
  246. SetProperty(ref canvasNoteTop, value);
  247. }
  248. }
  249. /// <summary>
  250. /// 底部工具栏 RegionName
  251. /// </summary>
  252. public string BottomToolRegionName { get; set; }
  253. private bool _isInPageEdit = false;
  254. /// <summary>
  255. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  256. /// </summary>
  257. public bool isInPageEdit
  258. {
  259. get { return _isInPageEdit; }
  260. set
  261. {
  262. SetProperty(ref _isInPageEdit, value);
  263. if (!value)
  264. {
  265. CanRedo = PDFViewer.UndoManager.CanRedo;
  266. CanUndo = PDFViewer.UndoManager.CanUndo;
  267. }
  268. }
  269. }
  270. public Action PageEditUndo { get; set; }
  271. public Action PageEditRedo { get; set; }
  272. /// <summary>
  273. ///工具条
  274. ///0:收起
  275. ///40:显示
  276. /// </summary>
  277. private int toolRowHeight = 40;
  278. public int ToolRowHeight
  279. {
  280. get { return toolRowHeight; }
  281. set
  282. {
  283. SetProperty(ref toolRowHeight, value);
  284. }
  285. }
  286. /// <summary>
  287. /// 水印,背景侧边栏宽度
  288. /// 0:收起
  289. /// 260:显示
  290. /// </summary>
  291. private int propertyColumnWidth = 0;
  292. public int PropertyColumnWidth
  293. {
  294. get { return propertyColumnWidth; }
  295. set
  296. {
  297. SetProperty(ref propertyColumnWidth, value);
  298. }
  299. }
  300. private int gridToolRow = 1;
  301. /// <summary>
  302. /// 控制ToolContent的Row
  303. /// </summary>
  304. public int GridToolRow
  305. {
  306. get { return gridToolRow; }
  307. set
  308. {
  309. SetProperty(ref gridToolRow, value);
  310. }
  311. }
  312. private int gridToolRowSpan = 3;
  313. /// <summary>
  314. /// 控制ToolContent的RowSpan
  315. /// </summary>
  316. public int GridToolRowSpan
  317. {
  318. get { return gridToolRowSpan; }
  319. set
  320. {
  321. SetProperty(ref gridToolRowSpan, value);
  322. }
  323. }
  324. private Visibility toolContentVisible = Visibility.Collapsed;
  325. /// <summary>
  326. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  327. /// 留意:显示前需要先注入内容、设置好行和跨行数
  328. /// </summary>
  329. public Visibility ToolContentVisible
  330. {
  331. get { return toolContentVisible; }
  332. set
  333. {
  334. SetProperty(ref toolContentVisible, value);
  335. }
  336. }
  337. private Visibility gridVisibility = Visibility.Visible;
  338. /// <summary>
  339. /// 是否正在加载中
  340. /// </summary>
  341. public Visibility GridVisibility
  342. {
  343. get { return gridVisibility; }
  344. set
  345. {
  346. SetProperty(ref gridVisibility, value);
  347. }
  348. }
  349. private Visibility isLoading = Visibility.Collapsed;
  350. private Visibility ocrContentVisible = Visibility.Collapsed;
  351. public Visibility OCRContentVisible
  352. {
  353. get { return ocrContentVisible; }
  354. set
  355. {
  356. SetProperty(ref ocrContentVisible, value);
  357. }
  358. }
  359. /// <summary>
  360. /// 是否正在加载中
  361. /// </summary>
  362. public Visibility IsLoading
  363. {
  364. get { return isLoading; }
  365. set
  366. {
  367. SetProperty(ref isLoading, value);
  368. }
  369. }
  370. private Visibility converterBarContentVisible = Visibility.Collapsed;
  371. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  372. /// <summary>
  373. /// 控制ToolsBarContent的显示
  374. /// 留意:显示前需要先注入内容、设置好行和跨行数
  375. /// </summary>
  376. public Visibility ConverterBarContentVisible
  377. {
  378. get { return converterBarContentVisible; }
  379. set
  380. {
  381. SetProperty(ref converterBarContentVisible, value);
  382. }
  383. }
  384. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  385. /// <summary>
  386. /// 控制ToolsBarContent的显示
  387. /// 留意:显示前需要先注入内容、设置好行和跨行数
  388. /// </summary>
  389. public Visibility ToolsBarContentVisible
  390. {
  391. get { return toolsBarContentVisible; }
  392. set
  393. {
  394. SetProperty(ref toolsBarContentVisible, value);
  395. }
  396. }
  397. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  398. /// <summary>
  399. /// 控制ToolsBarContent的显示
  400. /// 留意:显示前需要先注入内容、设置好行和跨行数
  401. /// </summary>
  402. public Visibility TextEditToolContentVisible
  403. {
  404. get { return textEditToolContentVisible; }
  405. set
  406. {
  407. SetProperty(ref textEditToolContentVisible, value);
  408. }
  409. }
  410. private bool isPorpertyOpen = false;
  411. /// <summary>
  412. /// 属性栏是否展开
  413. /// </summary>
  414. public bool IsPropertyOpen
  415. {
  416. get { return isPorpertyOpen; }
  417. set
  418. {
  419. SetProperty(ref isPorpertyOpen, value);
  420. }
  421. }
  422. private Visibility isReadMode = Visibility.Visible;
  423. /// <summary>
  424. ///是否为阅读模式
  425. /// </summary>
  426. public Visibility IsReadMode
  427. {
  428. get { return isReadMode; }
  429. set
  430. {
  431. SetProperty(ref isReadMode, value);
  432. }
  433. }
  434. private bool canSave;
  435. /// <summary>
  436. /// 是否可以保存
  437. /// </summary>
  438. public bool CanSave
  439. {
  440. get { return canSave; }
  441. set
  442. {
  443. SetProperty(ref canSave, value);
  444. }
  445. }
  446. private bool canUndo;
  447. /// <summary>
  448. /// 是否可以进行Undo
  449. /// </summary>
  450. public bool CanUndo
  451. {
  452. get { return canUndo; }
  453. set
  454. {
  455. SetProperty(ref canUndo, value);
  456. }
  457. }
  458. private bool canRedo;
  459. /// <summary>
  460. /// 是否可以进行Redo
  461. /// </summary>
  462. public bool CanRedo
  463. {
  464. get { return canRedo; }
  465. set
  466. {
  467. SetProperty(ref canRedo, value);
  468. }
  469. }
  470. private GridLength botaWidth = new GridLength(48);
  471. /// <summary>
  472. /// BOTA栏的宽度
  473. /// </summary>
  474. public GridLength BOTAWidth
  475. {
  476. get { return botaWidth; }
  477. set
  478. {
  479. SetProperty(ref botaWidth, value);
  480. if (botaWidth.Value <= 48)
  481. {
  482. OpenBOTA = false;
  483. }
  484. }
  485. }
  486. private int selectedIndex;
  487. /// <summary>
  488. /// 工具栏选中项的索引
  489. /// </summary>
  490. public int TabSelectedIndex
  491. {
  492. get { return selectedIndex; }
  493. set
  494. {
  495. SetProperty(ref selectedIndex, value);
  496. }
  497. }
  498. private bool openBOTA = false;
  499. /// <summary>
  500. /// 是否展开BOTA
  501. /// </summary>
  502. public bool OpenBOTA
  503. {
  504. get { return openBOTA; }
  505. set
  506. {
  507. SetProperty(ref openBOTA, value);
  508. if (openBOTA && BOTAWidth.Value <= 48)
  509. {
  510. BOTAWidth = new GridLength(260);
  511. }
  512. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  513. }
  514. }
  515. public SecurityInfo SecurityInfo = new SecurityInfo();
  516. private Dictionary<string, string> regionNameByTabItem;
  517. private Dictionary<string, string> barContentByTabItem;
  518. private string previousBar = "";
  519. public string CurrentBar = "";
  520. public string unicode = null;
  521. /// <summary>
  522. /// 用来避免重复触发导航事件的标志符
  523. /// </summary>
  524. private bool isOpenFile = false;
  525. /// <summary>
  526. /// 鼠标滚轮缩放的缩放值
  527. /// </summary>
  528. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  529. /// <summary>
  530. /// 注释-链接,提示语
  531. /// </summary>
  532. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  533. public Visibility LinkAnnotTipVisibility
  534. {
  535. get { return linkAnnotTipVisibility; }
  536. set
  537. {
  538. SetProperty(ref linkAnnotTipVisibility, value);
  539. }
  540. }
  541. 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";
  542. private bool isCreateLink = false;
  543. public string LinkAnnotTipText
  544. {
  545. get { return linkAnnotTipText; }
  546. set
  547. {
  548. SetProperty(ref linkAnnotTipText, value);
  549. }
  550. }
  551. #endregion 属性、变量
  552. #region 命令
  553. public DelegateCommand LoadFile { get; set; }
  554. public DelegateCommand Load { get; set; }
  555. public DelegateCommand MouseDown { get; set; }
  556. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  557. public DelegateCommand SaveFile { get; set; }
  558. public DelegateCommand SaveAsFile { get; set; }
  559. public DelegateCommand SaveAsFlattenCommand { get; set; }
  560. public DelegateCommand UndoCommand { get; set; }
  561. public DelegateCommand RedoCommand { get; set; }
  562. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  563. public DelegateCommand PrintCommand { get; set; }
  564. public DelegateCommand SettingsCommand { get; set; }
  565. public DelegateCommand ShareCommand { get; set; }
  566. public DelegateCommand<object> CreateLinkCommand { get; set; }
  567. public DelegateCommand PropertyCommand { get; set; }
  568. public DelegateCommand ShowInFolderCommand { get; set; }
  569. public DelegateCommand CompressCommand { get; set; }
  570. public DelegateCommand MergeFileCommand { get; set; }
  571. public DelegateCommand EncryptCommand { get; set; }
  572. public DelegateCommand DecryptCommand { get; set; }
  573. public DelegateCommand<string> ConvertCommand { get; set; }
  574. public DelegateCommand CloseWindowCommand { get; set; }
  575. public DelegateCommand OpenFileCommand { get; set; }
  576. public DelegateCommand<string> HelpCommand { get; set; }
  577. public DelegateCommand CreateBlankFileCommand { get; set; }
  578. #endregion 命令
  579. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  580. {
  581. InitStirng();
  582. region = regionManager;
  583. dialogs = dialogService;
  584. events = eventAggregator;
  585. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  586. LoadFile = new DelegateCommand(loadFile);
  587. Load = new DelegateCommand(LoadControl);
  588. MouseDown = new DelegateCommand(MouseDownEvent);
  589. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  590. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  591. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  592. UndoCommand = new DelegateCommand(Undo);
  593. RedoCommand = new DelegateCommand(Redo);
  594. ShareCommand = new DelegateCommand(share);
  595. PropertyCommand = new DelegateCommand(property);
  596. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  597. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  598. CompressCommand = new DelegateCommand(compress);
  599. MergeFileCommand = new DelegateCommand(mergeFile);
  600. EncryptCommand = new DelegateCommand(encrypt);
  601. DecryptCommand = new DelegateCommand(decrypt);
  602. ConvertCommand = new DelegateCommand<string>(convert);
  603. CloseWindowCommand = new DelegateCommand(closeWindow);
  604. OpenFileCommand = new DelegateCommand(openfile);
  605. HelpCommand = new DelegateCommand<string>(help);
  606. CreateBlankFileCommand = new DelegateCommand(createBlankFile);
  607. ViwerRegionName = RegionNames.ViwerRegionName;
  608. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  609. BOTARegionName = RegionNames.BOTARegionName;
  610. PropertyRegionName = RegionNames.PropertyRegionName;
  611. BottomToolRegionName = RegionNames.BottomToolRegionName;
  612. ReadModeRegionName = RegionNames.ReadModeRegionName;
  613. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  614. PrintCommand = new DelegateCommand(ShowPrintDialog);
  615. SettingsCommand = new DelegateCommand(SettingsEvent);
  616. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  617. //未显示时无法注册上Region名称
  618. ToolContentVisible = Visibility.Visible;
  619. ToolsBarContentVisible = Visibility.Visible;
  620. OCRContentVisible = Visibility.Visible;
  621. TipVisible = Visibility.Visible;
  622. TipContentRegionName = RegionNames.TipContentRegionName;
  623. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  624. NotePopupRegionName = RegionNames.NotePopupRegionName;
  625. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  626. ToolContentRegionName = Guid.NewGuid().ToString();
  627. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  628. ConverterBarContentRegionName = Guid.NewGuid().ToString();
  629. TextEditContentRegionName = Guid.NewGuid().ToString();
  630. ToolContentVisible = Visibility.Collapsed;
  631. ToolsBarContentVisible = Visibility.Collapsed;
  632. OCRContentVisible = Visibility.Collapsed;
  633. TipVisible = Visibility.Collapsed;
  634. regionNameByTabItem = new Dictionary<string, string>();
  635. barContentByTabItem = new Dictionary<string, string>();
  636. InitialregionNameByTabItem(ref regionNameByTabItem);
  637. InitialbarContentByTabItem(ref barContentByTabItem);
  638. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  639. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  640. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTip, e => e.Unicode == unicode);
  641. //TODO:根据缓存 选择用户上次选择的菜单
  642. EnterSelectedBar("TabItemAnnotation");
  643. }
  644. private void MouseDownEvent()
  645. {
  646. if (NotePopupVisible == Visibility.Visible && IsNoteAdd == false)
  647. {
  648. NotePopupVisible = Visibility.Collapsed;
  649. }
  650. }
  651. /// <summary>
  652. ///创建空白文档
  653. /// </summary>
  654. private async void createBlankFile()
  655. {
  656. App.mainWindowViewModel.AddTab.Execute();
  657. await Task.Delay(30);
  658. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
  659. }
  660. private void help(string args)
  661. {
  662. string url = "";
  663. switch (args)
  664. {
  665. case "Guid":
  666. //打开内嵌文档
  667. if (File.Exists(App.GuidPDFPath))
  668. {
  669. App.mainWindowViewModel.AddTabItem(App.GuidPDFPath);
  670. }
  671. break;
  672. case "Online":
  673. url = @"https://www.pdfreaderpro.com/windows/help";
  674. break;
  675. case "More":
  676. url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
  677. break;
  678. case "Template":
  679. url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
  680. break;
  681. case "Blog":
  682. //TODO:显示订阅电子报弹窗
  683. break;
  684. case "ComPDF":
  685. url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
  686. break;
  687. case "FeedBack":
  688. //调用邮箱 发送邮件
  689. StringBuilder sr = new StringBuilder();
  690. sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
  691. System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
  692. break;
  693. default:
  694. break;
  695. }
  696. if (!string.IsNullOrEmpty(url))
  697. {
  698. //需要跳转网页的情况
  699. System.Diagnostics.Process.Start(url);
  700. }
  701. }
  702. /// <summary>
  703. /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
  704. /// </summary>
  705. private void openfile()
  706. {
  707. OpenFileDialog openFileDialog = new OpenFileDialog();
  708. openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
  709. openFileDialog.Multiselect = true;
  710. if ((bool)openFileDialog.ShowDialog())
  711. {
  712. if (openFileDialog.FileNames.Count() == 1)
  713. {
  714. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  715. {
  716. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  717. }
  718. else
  719. {
  720. App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
  721. }
  722. ToolMethod.SetFileThumbImg(openFileDialog.FileName);
  723. }
  724. else
  725. {
  726. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  727. if (fileList.Count <= 0)
  728. {
  729. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  730. return;
  731. }
  732. mainViewModel.OpenFile(fileList[0]);
  733. for (int i = 1; i < fileList.Count(); i++)
  734. {
  735. if (!App.OpenedFileList.Contains(fileList[i]))
  736. {
  737. App.mainWindowViewModel.AddTabItem(fileList[i]);
  738. }
  739. ToolMethod.SetFileThumbImg(fileList[i]);
  740. }
  741. }
  742. }
  743. }
  744. /// <summary>
  745. /// 关闭当前窗体
  746. /// </summary>
  747. private void closeWindow()
  748. {
  749. App.Current.MainWindow.Close();
  750. }
  751. /// <summary>
  752. /// 转档
  753. /// </summary>
  754. /// <param name="obj"></param>
  755. private void convert(string obj)
  756. {
  757. if (!string.IsNullOrEmpty(obj))
  758. {
  759. DialogParameters value = new DialogParameters();
  760. value.Add(ParameterNames.PDFViewer, PDFViewer);
  761. switch (obj)
  762. {
  763. case "Word":
  764. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  765. {
  766. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  767. converterDialogsModel.OnOpened((DialogResult)e);
  768. });
  769. break;
  770. case "Excel":
  771. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  772. {
  773. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  774. converterDialogsModel.OnOpened((DialogResult)e);
  775. });
  776. break;
  777. case "PPT":
  778. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  779. {
  780. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  781. converterDialogsModel.OnOpened((DialogResult)e);
  782. });
  783. break;
  784. case "RTF":
  785. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  786. {
  787. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  788. converterDialogsModel.OnOpened((DialogResult)e);
  789. });
  790. break;
  791. case "CSV":
  792. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  793. {
  794. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  795. converterDialogsModel.OnOpened((DialogResult)e);
  796. });
  797. break;
  798. case "HTML":
  799. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  800. {
  801. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  802. converterDialogsModel.OnOpened((DialogResult)e);
  803. });
  804. break;
  805. case "Text":
  806. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  807. {
  808. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  809. converterDialogsModel.OnOpened((DialogResult)e);
  810. });
  811. break;
  812. case "Image":
  813. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  814. {
  815. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  816. converterDialogsModel.OnOpened((DialogResult)e);
  817. });
  818. break;
  819. default:
  820. break;
  821. }
  822. }
  823. }
  824. /// <summary>
  825. /// 解密
  826. /// </summary>
  827. private void decrypt()
  828. {
  829. if (!PDFViewer.Document.IsEncrypted)
  830. {
  831. MessageBoxEx.Show("No security settings available ");
  832. }
  833. else
  834. {
  835. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  836. if (result.IsDiscryptied)
  837. {
  838. if (result.Password != null)
  839. {
  840. string filePath = PDFViewer.Document.FilePath;
  841. PDFViewer.Document.Release();
  842. PDFViewer.InitDocument(filePath);
  843. PDFViewer.Document.UnlockWithPassword(result.Password);
  844. }
  845. DialogParameters value = new DialogParameters();
  846. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  847. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });
  848. }
  849. }
  850. }
  851. /// <summary>
  852. /// 加密
  853. /// </summary>
  854. private void encrypt()
  855. {
  856. if (!this.SecurityInfo.IsPasswordChanged)
  857. {
  858. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  859. if (result.IsDiscryptied)
  860. {
  861. if (result.Password != null)
  862. {
  863. string filePath = PDFViewer.Document.FilePath;
  864. PDFViewer.Document.Release();
  865. PDFViewer.InitDocument(filePath);
  866. PDFViewer.Document.UnlockWithPassword(result.Password);
  867. }
  868. }
  869. }
  870. DialogParameters value = new DialogParameters();
  871. value.Add(ParameterNames.PDFViewer, this.PDFViewer);
  872. value.Add(ParameterNames.ViewContentViewModel, this);
  873. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
  874. {
  875. if (e.Result == ButtonResult.OK)
  876. {
  877. SecurityHelper.IsPasswordChanged = true;
  878. if (this.SecurityInfo.IsPasswordChanged)
  879. {
  880. this.PDFViewer.UndoManager.CanSave = true;
  881. }
  882. this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
  883. }
  884. });
  885. }
  886. /// <summary>
  887. /// 合并
  888. /// </summary>
  889. private void mergeFile()
  890. {
  891. DialogParameters value = new DialogParameters();
  892. value.Add(ParameterNames.PDFViewer, PDFViewer);
  893. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  894. }
  895. /// <summary>
  896. /// 压缩
  897. /// </summary>
  898. private void compress()
  899. {
  900. DialogParameters value = new DialogParameters();
  901. value.Add(ParameterNames.PDFViewer, PDFViewer);
  902. dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
  903. {
  904. CompressDialogModel compressDialogModel = new CompressDialogModel();
  905. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  906. });
  907. }
  908. /// <summary>
  909. /// 设置Tip状态栏的显示状态
  910. /// </summary>
  911. /// <param name="show">是否显示</param>
  912. public void ShowTip(bool show)
  913. {
  914. if (show)
  915. {
  916. TipVisible = Visibility.Visible;
  917. }
  918. else
  919. {
  920. TipVisible = Visibility.Collapsed;
  921. }
  922. }
  923. /// <summary>
  924. /// 设置LeftTip状态栏的显示状态
  925. /// </summary>
  926. /// <param name="show">是否显示</param>
  927. public void ShowLeftTip(bool show)
  928. {
  929. if (show)
  930. {
  931. LeftTipVisible = Visibility.Visible;
  932. }
  933. else
  934. {
  935. LeftTipVisible = Visibility.Collapsed;
  936. }
  937. }
  938. public void CheckHaveAllPermission()
  939. {
  940. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  941. {
  942. ShowLeftTip(true);
  943. NavigationParameters param = new NavigationParameters();
  944. param.Add(ParameterNames.PDFViewer, PDFViewer);
  945. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  946. }
  947. }
  948. public void ShowSelectedTip(ShowTipEventArgs showTipEventArgs)
  949. {
  950. switch (showTipEventArgs.enumTipKind)
  951. {
  952. case EnumTipKind.StatusNone:
  953. ShowLeftTip(false);
  954. break;
  955. case EnumTipKind.StatusSetPasswordSuccessfully:
  956. ShowLeftTip(true);
  957. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  958. break;
  959. default: break;
  960. }
  961. }
  962. /// <summary>
  963. /// 右键菜单创建链接
  964. /// </summary>
  965. /// <param name="obj"></param>
  966. private void CreateLinkEvent(object obj)
  967. {
  968. if (obj is object[] objArry)
  969. {
  970. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  971. {
  972. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  973. linkArgs.URI = string.Empty;
  974. linkArgs.LinkType = LINK_TYPE.GOTO;
  975. linkArgs.PageIndex = annotCommand.PageIndex;
  976. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  977. this.IsRightMenuCreateLink = true;
  978. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  979. lists.Add(linkArgs);
  980. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  981. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  982. PDFViewer.SetToolParam(annotArgs);
  983. this.IsPropertyOpen = true;
  984. }
  985. }
  986. }
  987. /// <summary>
  988. /// 在文件资源管理器中显示
  989. /// </summary>
  990. private void ShowInFolder()
  991. {
  992. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  993. }
  994. private void property()
  995. {
  996. DialogParameters valuePairs = new DialogParameters();
  997. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  998. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  999. }
  1000. private void share()
  1001. {
  1002. try
  1003. {
  1004. var path = PDFViewer.Document.FilePath;
  1005. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  1006. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  1007. }
  1008. catch
  1009. {
  1010. AlertsMessage alertsMessage = new AlertsMessage();
  1011. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  1012. }
  1013. }
  1014. private void SettingsEvent()
  1015. {
  1016. dialogs.ShowDialog(DialogNames.SettingsDialog, null, null);
  1017. }
  1018. private bool CanSaveExcute()
  1019. {
  1020. return CanSave;
  1021. }
  1022. private void MenuEnterReadModeEvent(object obj)
  1023. {
  1024. }
  1025. public void ShowPrintDialog()
  1026. {
  1027. DialogParameters printValue = new DialogParameters();
  1028. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1029. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1030. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  1031. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  1032. }
  1033. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  1034. {
  1035. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  1036. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  1037. //其他工具菜单栏共用一个ToolsBarContentRegionName
  1038. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  1039. dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
  1040. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  1041. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  1042. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  1043. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  1044. }
  1045. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  1046. {
  1047. dictionary.Add("TabItemPageEdit", "PageEditContent");
  1048. dictionary.Add("TabItemTool", "ToolsBarContent");
  1049. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  1050. dictionary.Add("TabItemConvert", "ConverterBarContent");
  1051. dictionary.Add("TabItemScan", "ScanContent");
  1052. dictionary.Add("TabItemEdit", "TextEditToolContent");
  1053. dictionary.Add("TabItemForm", "FormsToolContent");
  1054. dictionary.Add("TabItemFill", "FillAndSignContent");
  1055. }
  1056. private void UpdateShowContent(string currentBar)
  1057. {
  1058. ToolContentVisible = Visibility.Collapsed;
  1059. ToolsBarContentVisible = Visibility.Collapsed;
  1060. ConverterBarContentVisible = Visibility.Collapsed;
  1061. TextEditToolContentVisible = Visibility.Collapsed;
  1062. OCRContentVisible = Visibility.Collapsed;
  1063. switch (currentBar)
  1064. {
  1065. case "TabItemAnnotation":
  1066. case "TabItemTool":
  1067. case "TabItemForm":
  1068. case "TabItemFill":
  1069. ToolsBarContentVisible = Visibility.Visible;
  1070. break;
  1071. case "TabItemScan":
  1072. ToolsBarContentVisible = Visibility.Visible;
  1073. OCRContentVisible = Visibility.Visible;
  1074. break;
  1075. case "TabItemEdit":
  1076. TextEditToolContentVisible = Visibility.Visible;
  1077. break;
  1078. case "TabItemConvert":
  1079. ConverterBarContentVisible = Visibility.Visible;
  1080. break;
  1081. case "TabItemPageEdit":
  1082. case "HeaderFooterContent":
  1083. case "BatesContent":
  1084. case "WatermarkContent":
  1085. case "BackgroundContent":
  1086. case "RedactionContent":
  1087. ToolContentVisible = Visibility.Visible;
  1088. break;
  1089. default:
  1090. break;
  1091. }
  1092. PDFEditMode(currentBar);
  1093. FormMode(currentBar);
  1094. }
  1095. private void PDFEditMode(string currentBar)
  1096. {
  1097. if (currentBar == "TabItemEdit")
  1098. {
  1099. if (PDFViewer != null)
  1100. {
  1101. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  1102. //SelectedPrpoertyPanel("TextEditProperty", null);
  1103. //IsPropertyOpen = true;
  1104. }
  1105. }
  1106. else
  1107. {
  1108. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  1109. {
  1110. IsPropertyOpen = false;
  1111. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1112. }
  1113. }
  1114. }
  1115. private void FormMode(string currentBar)
  1116. {
  1117. if (currentBar == "TabItemForm")
  1118. {
  1119. if (PDFViewer != null)
  1120. {
  1121. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  1122. }
  1123. }
  1124. else
  1125. {
  1126. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  1127. {
  1128. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1129. }
  1130. }
  1131. }
  1132. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  1133. {
  1134. if (!isInPageEdit)
  1135. {
  1136. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  1137. //页面编辑模式下,按钮状态根据页面编辑的undo redo来显示
  1138. if (e.PropertyName == "CanUndo")
  1139. {
  1140. CanUndo = PDFViewer.UndoManager.CanUndo;
  1141. }
  1142. if (e.PropertyName == "CanRedo")
  1143. {
  1144. CanRedo = PDFViewer.UndoManager.CanRedo;
  1145. }
  1146. }
  1147. if (e.PropertyName == "CanSave")
  1148. {
  1149. CanSave = PDFViewer.UndoManager.CanSave;
  1150. }
  1151. }
  1152. /// <summary>
  1153. /// 选项卡切换事件
  1154. /// </summary>
  1155. /// <param name="e"></param>
  1156. private void TabControlSelectonChangedEvent(object e)
  1157. {
  1158. var args = e as SelectionChangedEventArgs;
  1159. if (args != null)
  1160. {
  1161. var item = args.AddedItems[0] as TabItem;
  1162. CurrentBar = item.Name;
  1163. if (previousBar != CurrentBar)
  1164. {
  1165. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  1166. {
  1167. EnterToolMode(barContentByTabItem[CurrentBar]);
  1168. isInPageEdit = true;
  1169. }
  1170. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  1171. {
  1172. EnterSelectedBar(CurrentBar);
  1173. isInPageEdit = false;
  1174. }
  1175. previousBar = CurrentBar;
  1176. }
  1177. }
  1178. }
  1179. /// <summary>
  1180. /// 阅读模式
  1181. /// </summary>
  1182. /// <param name="viewContent"></param>
  1183. public async void RbtnReadMode()
  1184. {
  1185. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  1186. mainViewModel.IsBookMode = true;
  1187. IsLoading = Visibility.Visible;
  1188. await Task.Delay(1);
  1189. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1190. NavigationParameters param = new NavigationParameters();
  1191. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1192. param.Add(ParameterNames.ViewContentViewModel, this);
  1193. region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  1194. //ShowContent(CurrentBar, true);
  1195. if (GridToolRow != 0)
  1196. {
  1197. GridToolRow = 0;
  1198. }
  1199. if (GridToolRowSpan != 4)
  1200. {
  1201. GridToolRowSpan = 4;
  1202. }
  1203. //isInPageEdit = true;
  1204. UpdateShowContent("TabItemPageEdit");
  1205. IsLoading = Visibility.Collapsed;
  1206. }
  1207. /// <summary>
  1208. /// 退出阅读模式
  1209. /// </summary>
  1210. public async void UnReadModel()
  1211. {
  1212. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  1213. mainViewModel.IsBookMode = false;
  1214. IsLoading = Visibility.Visible;
  1215. await Task.Delay(1);
  1216. //PDFViewer.MouseMode = MouseModes.None;
  1217. if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  1218. {
  1219. if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1220. {
  1221. var contentRegion = region.Regions[ViwerRegionName];
  1222. contentRegion.Remove(PDFViewer);
  1223. }
  1224. region.AddToRegion(ViwerRegionName, PDFViewer);
  1225. }
  1226. if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  1227. {
  1228. EnterSelectedBar("TabItemAnnotation");
  1229. }
  1230. else
  1231. {
  1232. EnterSelectedBar(CurrentBar);
  1233. }
  1234. bool isExist = false;
  1235. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1236. {
  1237. var views = region.Regions[TipContentRegionName].Views;
  1238. foreach (var item in views)
  1239. {
  1240. if (item is Views.TipContent.ReadModelTip readModelTip)
  1241. {
  1242. isExist = true;
  1243. break;
  1244. }
  1245. }
  1246. }
  1247. if (isExist == false)
  1248. {
  1249. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  1250. }
  1251. IsLoading = Visibility.Collapsed;
  1252. ShowTip(true);
  1253. await Task.Delay(3000);
  1254. //ReadModelTip = Visibility.Collapsed;
  1255. TipVisible = Visibility.Collapsed;
  1256. }
  1257. #region PDFViewer鼠标滚轮缩放事件
  1258. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  1259. {
  1260. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  1261. PDFViewer.Zoom(newZoom);
  1262. }
  1263. public double CheckZoomLevel(double zoom, bool IsGrowth)
  1264. {
  1265. double standardZoom = 100;
  1266. if (zoom <= 0.01)
  1267. {
  1268. return 0.01;
  1269. }
  1270. if (zoom >= 10)
  1271. {
  1272. return 10;
  1273. }
  1274. zoom *= 100;
  1275. for (int i = 0; i < zoomLevel.Length - 1; i++)
  1276. {
  1277. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  1278. {
  1279. standardZoom = zoomLevel[i + 1];
  1280. break;
  1281. }
  1282. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  1283. {
  1284. standardZoom = zoomLevel[i];
  1285. break;
  1286. }
  1287. }
  1288. return standardZoom / 100;
  1289. }
  1290. #endregion PDFViewer鼠标滚轮缩放事件
  1291. #region Navigate
  1292. public void OnNavigatedTo(NavigationContext navigationContext)
  1293. {
  1294. if (isOpenFile)
  1295. return;
  1296. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  1297. if (mainVM != null)
  1298. {
  1299. mainViewModel = mainVM;
  1300. mainViewModel.viewContentViewModel = this;
  1301. }
  1302. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  1303. if (pdfview != null)
  1304. {
  1305. PDFViewer = pdfview;
  1306. if (pdfview.Tag != null)
  1307. {
  1308. //保存密码
  1309. PassWord = pdfview.Tag.ToString();
  1310. }
  1311. loadFile();
  1312. CheckHaveAllPermission();
  1313. }
  1314. isOpenFile = true;
  1315. //快捷键
  1316. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1317. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  1318. }
  1319. public bool IsNavigationTarget(NavigationContext navigationContext)
  1320. {
  1321. if (navigationContext != null)
  1322. {
  1323. //另存为打开导航进来时 不能新建一个实例
  1324. return true;
  1325. }
  1326. else
  1327. {
  1328. //一次性打开多个文件时,需要新建实例
  1329. return false;
  1330. }
  1331. }
  1332. public void OnNavigatedFrom(NavigationContext navigationContext)
  1333. {
  1334. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1335. }
  1336. #endregion Navigate
  1337. #region 方法
  1338. /// <summary>
  1339. /// 快捷键
  1340. /// </summary>
  1341. /// <param name="sender"></param>
  1342. /// <param name="e"></param>
  1343. /// <exception cref="NotImplementedException"></exception>
  1344. private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  1345. {
  1346. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
  1347. {
  1348. if (mainViewModel.IsBookMode == true)
  1349. {
  1350. UnReadModel();
  1351. }
  1352. //内容选择 退出
  1353. if (PDFViewer.MouseMode != MouseModes.PanTool)
  1354. {
  1355. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1356. {
  1357. var views = region.Regions[ToolsBarContentRegionName].Views;
  1358. var model = views.FirstOrDefault(q => q is AnnotToolContent);
  1359. if (model is AnnotToolContent annotToolContent)
  1360. {
  1361. AnnotToolContentViewModel toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
  1362. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1363. {
  1364. if (toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs != null)
  1365. {
  1366. toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  1367. annotToolContent.BtnSelecttool.IsChecked = false;
  1368. }
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.C))
  1375. {
  1376. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1377. {
  1378. var views = region.Regions[ToolsBarContentRegionName].Views;
  1379. var model = views.FirstOrDefault(q => q is AnnotToolContent);
  1380. if (model is AnnotToolContent annotToolContent)
  1381. {
  1382. AnnotToolContentViewModel toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
  1383. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1384. {
  1385. toolContentViewModel.SnapshotEditMenuViewModel.SnapCopyCommand.Execute();
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. /// <summary>
  1392. /// 视图面板 切换分屏模式
  1393. /// </summary>
  1394. /// <param name="mode"></param>
  1395. public void EnterSplitMode(SplitMode mode)
  1396. {
  1397. ///通知UI层更改布局
  1398. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  1399. }
  1400. private void Undo()
  1401. {
  1402. if (isInPageEdit)
  1403. {
  1404. //执行页面编辑的Undo
  1405. PageEditUndo?.Invoke();
  1406. }
  1407. else
  1408. {
  1409. PDFViewer.UndoManager.Undo();
  1410. }
  1411. }
  1412. private void Redo()
  1413. {
  1414. if (isInPageEdit)
  1415. {
  1416. //执行页面编辑的Redo
  1417. PageEditRedo?.Invoke();
  1418. }
  1419. else
  1420. {
  1421. PDFViewer.UndoManager.Redo();
  1422. }
  1423. }
  1424. private void LoadControl()
  1425. {
  1426. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  1427. // 非必要情况不要使用该异步方法,可能会导致一次性加载多个文件时出现因异步引起的regionname 错乱问题
  1428. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1429. // {
  1430. NavigationParameters parameters = new NavigationParameters();
  1431. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1432. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1433. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  1434. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  1435. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  1436. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  1437. //TODO 根据上一次关闭记录的菜单,选中TabItem
  1438. EnterSelectedBar("TabItemAnnotation");
  1439. //}
  1440. //));
  1441. //if (App.IsBookMode)
  1442. //{
  1443. // RbtnReadMode();
  1444. //}
  1445. //else
  1446. //{
  1447. // UnReadModel();
  1448. //}
  1449. }
  1450. /// <summary>
  1451. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  1452. /// </summary>
  1453. /// <param name="Content"></param>
  1454. /// <param name="annotPropertyPanel"></param>
  1455. public void SelectedPrpoertyPanel(string Content, AnnotPropertyPanel annotPropertyPanel)
  1456. {
  1457. NavigationParameters parameters = new NavigationParameters();
  1458. //传其他参数:文档类,空注释面板;
  1459. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1460. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  1461. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1462. region.RequestNavigate(PropertyRegionName, Content, parameters);
  1463. }
  1464. /// <summary>
  1465. /// 将PDFViwer添加到Region
  1466. /// </summary>
  1467. private void loadFile()
  1468. {
  1469. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  1470. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  1471. CanSave = PDFViewer.UndoManager.CanSave;
  1472. CanUndo = PDFViewer.UndoManager.CanUndo;
  1473. CanRedo = PDFViewer.UndoManager.CanRedo;
  1474. //OpenFileInfo 内容赋值给PDFViewer
  1475. GetOpenFileInfo();
  1476. region.AddToRegion(ViwerRegionName, PDFViewer);
  1477. }
  1478. /// <summary>
  1479. /// 还原上一次浏览的视图相关设置
  1480. /// </summary>
  1481. private void GetOpenFileInfo()
  1482. {
  1483. OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1484. if (OpenFileInfo != null)
  1485. {
  1486. if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
  1487. {
  1488. PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
  1489. }
  1490. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  1491. {
  1492. PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
  1493. }
  1494. if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
  1495. {
  1496. PDFViewer.Zoom(OpenFileInfo.LastZoom);
  1497. }
  1498. if (OpenFileInfo.LastPageIndex != PDFViewer.CurrentIndex)
  1499. {
  1500. PDFViewer.GoToPage(OpenFileInfo.LastPageIndex);
  1501. }
  1502. PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
  1503. PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
  1504. if (OpenFileInfo.LastPageSpace)
  1505. {
  1506. PDFViewer.SetPageSpacing(8);
  1507. }
  1508. else
  1509. {
  1510. PDFViewer.SetPageSpacing(0);
  1511. }
  1512. if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
  1513. {
  1514. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
  1515. }
  1516. else
  1517. {
  1518. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
  1519. }
  1520. }
  1521. }
  1522. /// <summary>
  1523. /// 已有路径文档的保存逻辑
  1524. /// </summary>
  1525. public bool saveFile()
  1526. {
  1527. try
  1528. {
  1529. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
  1530. return saveAsFile();
  1531. //文档已被修复时 提示另存为
  1532. if (PDFViewer.Document.HasRepaired)
  1533. {
  1534. AlertsMessage alertsMessage = new AlertsMessage();
  1535. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  1536. if (alertsMessage.result == ContentResult.Ok)
  1537. return saveAsFile();
  1538. else
  1539. return false;
  1540. }
  1541. //文件路径无法存在时
  1542. if (!File.Exists(PDFViewer.Document.FilePath))
  1543. {
  1544. AlertsMessage alertsMessage = new AlertsMessage();
  1545. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  1546. if (alertsMessage.result == ContentResult.Ok)
  1547. return saveAsFile();
  1548. else
  1549. return false;
  1550. }
  1551. //只读文件无法写入时,提示另存为
  1552. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  1553. if (fileInfo.IsReadOnly)
  1554. {
  1555. AlertsMessage alertsMessage = new AlertsMessage();
  1556. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  1557. if (alertsMessage.result == ContentResult.Ok)
  1558. return saveAsFile();
  1559. else
  1560. return false;
  1561. }
  1562. //Security Fixed:
  1563. //修改密码后原文档保存的步骤:
  1564. //在设置密码窗口传出“已修改”信号,并允许延迟保存
  1565. //延迟保存方式:
  1566. //
  1567. //
  1568. if (SecurityInfo.IsPasswordChanged)
  1569. {
  1570. string currentFilePath = PDFViewer.Document.FilePath;
  1571. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  1572. string openPassword = null;
  1573. string permissionsPassword = null;
  1574. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  1575. if (SecurityInfo.NeedOpenPassword)
  1576. {
  1577. openPassword = SecurityInfo.OpenPassword;
  1578. }
  1579. if (SecurityInfo.NeedPermissionsPassword)
  1580. {
  1581. permissionsPassword = SecurityInfo.PermissionsPassword;
  1582. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  1583. }
  1584. try
  1585. {
  1586. string currentPath = PDFViewer.Document.FilePath;
  1587. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  1588. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1589. PDFViewer.Document.WriteToFilePath(tempPath);
  1590. PDFViewer.CloseDocument();
  1591. PDFViewer.InitDocument(tempPath);
  1592. if (!string.IsNullOrEmpty(permissionsPassword))
  1593. {
  1594. PDFViewer.Document.UnlockWithPassword(permissionsPassword);
  1595. }
  1596. else if (!string.IsNullOrEmpty(openPassword))
  1597. {
  1598. PDFViewer.Document.UnlockWithPassword(openPassword);
  1599. }
  1600. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1601. PDFViewer.Document.WriteToFilePath(currentPath);
  1602. PDFViewer.CloseDocument();
  1603. PDFViewer.InitDocument(currentPath);
  1604. //System.IO.File.Delete(tempPath);
  1605. if (!string.IsNullOrEmpty(permissionsPassword))
  1606. {
  1607. PDFViewer.Document.UnlockWithPassword(permissionsPassword);
  1608. }
  1609. else if (!string.IsNullOrEmpty(openPassword))
  1610. {
  1611. PDFViewer.Document.UnlockWithPassword(openPassword);
  1612. }
  1613. try
  1614. {
  1615. PDFViewer.Load();
  1616. }
  1617. catch
  1618. {
  1619. }
  1620. PDFViewer.UndoManager.CanSave = false;
  1621. SecurityInfo.IsPasswordChanged = false;
  1622. return true;
  1623. }
  1624. catch
  1625. {
  1626. return false;
  1627. }
  1628. }
  1629. bool result = PDFViewer.Document.WriteToLoadedPath();
  1630. if (result)
  1631. {
  1632. PDFViewer.UndoManager.CanSave = false;
  1633. App.Current.Dispatcher.Invoke(() =>
  1634. {
  1635. //保存时更新缩略图
  1636. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1637. try
  1638. {
  1639. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  1640. {
  1641. var size = PDFViewer.Document.GetPageSize(0);
  1642. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  1643. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  1644. if (File.Exists(folderPath))
  1645. File.Delete(folderPath);
  1646. DirectoryInfo folder = new DirectoryInfo(folderPath);
  1647. if (!folder.Exists)
  1648. folder.Create();
  1649. string imagePath = info.ThumbImgPath;
  1650. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  1651. {
  1652. string imageName = Guid.NewGuid().ToString();
  1653. imagePath = System.IO.Path.Combine(folderPath, imageName);
  1654. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  1655. {
  1656. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1657. }
  1658. }
  1659. else
  1660. {
  1661. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  1662. {
  1663. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1664. }
  1665. }
  1666. info.ThumbImgPath = imagePath;
  1667. SettingHelper.SetFileInfo(info);
  1668. }
  1669. }
  1670. catch
  1671. {
  1672. info.ThumbImgPath = null;
  1673. SettingHelper.SetFileInfo(info);
  1674. }
  1675. });
  1676. PDFViewer.ReloadDocument();
  1677. }
  1678. else
  1679. {
  1680. //文件被占用 保存失败时
  1681. AlertsMessage alertsMessage = new AlertsMessage();
  1682. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  1683. if (alertsMessage.result == ContentResult.Ok)
  1684. return saveAsFile();
  1685. else
  1686. return false;
  1687. }
  1688. return result;
  1689. }
  1690. catch { return false; }
  1691. }
  1692. /// <summary>
  1693. /// 另存为或新文档保存逻辑
  1694. /// </summary>
  1695. public bool saveAsFile(Action RedactionAction = null)
  1696. {
  1697. var dlg = new Microsoft.Win32.SaveFileDialog();
  1698. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1699. dlg.FileName = PDFViewer.Document.FileName;
  1700. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1701. {
  1702. bool result = false;
  1703. if (RedactionAction != null)
  1704. {
  1705. //保存前进行标记密文处理应用或擦除
  1706. RedactionAction.Invoke();
  1707. }
  1708. if (App.OpenedFileList.Contains(dlg.FileName))
  1709. {
  1710. //提示文件已经被打开
  1711. }
  1712. else
  1713. {
  1714. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  1715. if (result)
  1716. {
  1717. DoAfterSaveAs(dlg.FileName);
  1718. }
  1719. else
  1720. {
  1721. //提示文件被其他软件占用 无法保存
  1722. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
  1723. }
  1724. ;
  1725. }
  1726. return result;
  1727. }
  1728. else
  1729. return false;
  1730. }
  1731. /// <summary>
  1732. /// 另存为Flatten
  1733. /// </summary>
  1734. private void saveAsFlatten()
  1735. {
  1736. var dlg = new SaveFileDialog();
  1737. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1738. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  1739. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1740. {
  1741. saveFile();
  1742. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  1743. if (kmdoc == null)
  1744. return;
  1745. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  1746. if (result)
  1747. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  1748. kmdoc.Release();
  1749. }
  1750. }
  1751. /// <summary>
  1752. /// 另存为后进行的操作
  1753. /// 重新打开新文档
  1754. /// </summary>
  1755. /// <param name="targetPath"></param>
  1756. public void DoAfterSaveAs(string targetPath)
  1757. {
  1758. App.OpenedFileList.Remove(targetPath);
  1759. string oldFilePath = targetPath;
  1760. PDFViewer.UndoManager.CanSave = false;
  1761. mainViewModel.OpenFile(targetPath);
  1762. //TODO:通知各模块更新PDFview对象
  1763. //var result = OpenFile(targetPath, true);
  1764. //if (result)
  1765. //{
  1766. // FileChanged.Invoke(this, null);
  1767. // Zoomer.PdfViewer = PdfViewer;
  1768. // PageSelector.PdfViewer = PdfViewer;
  1769. // ViewModeSelector.PdfViewer = PdfViewer;
  1770. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  1771. // if (fileInfo != null)
  1772. // {
  1773. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  1774. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  1775. // if (fileInfo.LastFitMode == FitMode.FitFree)
  1776. // PdfViewer.Zoom(fileInfo.LastZoom);
  1777. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  1778. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  1779. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  1780. // else
  1781. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  1782. // }
  1783. //}
  1784. }
  1785. /// <summary>
  1786. /// 显示前添加内容到Region
  1787. /// </summary>
  1788. /// <param name="isPageEdit"></param>
  1789. private void ShowContent(string currentBar, bool isToolMode = false)
  1790. {
  1791. GridVisibility = Visibility.Visible;
  1792. //显示页面编辑或其他工具
  1793. if (currentBar == "TabItemPageEdit" || isToolMode)
  1794. {
  1795. if (currentBar == "TabItemPageEdit")//进入页面编辑
  1796. {
  1797. if (GridToolRow != 1)
  1798. {
  1799. GridToolRow = 1;
  1800. }
  1801. if (GridToolRowSpan != 3)
  1802. {
  1803. GridToolRowSpan = 3;
  1804. }
  1805. }
  1806. else//进入水印等其他工具模式
  1807. {
  1808. GridVisibility = Visibility.Collapsed;
  1809. if (GridToolRow != 0)
  1810. {
  1811. GridToolRow = 0;
  1812. }
  1813. if (GridToolRowSpan != 4)
  1814. {
  1815. GridToolRowSpan = 4;
  1816. }
  1817. }
  1818. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  1819. UpdateShowContent(currentBar);
  1820. }
  1821. else
  1822. {
  1823. if (GridToolRow != 1)
  1824. {
  1825. GridToolRow = 1;
  1826. }
  1827. UpdateShowContent(currentBar);
  1828. }
  1829. }
  1830. /// <summary>
  1831. /// 从二级工具栏进入需要修改界面布局的场景
  1832. /// </summary>
  1833. /// <param name="EditToolName"></param>
  1834. private void EnterEditTools(StringWithUnicode EditToolName)
  1835. {
  1836. EnterSelectedEditTool(EditToolName);
  1837. }
  1838. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  1839. {
  1840. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  1841. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  1842. {
  1843. PDFViewer.Document.ReleasePages();
  1844. PDFViewer.ReloadDocument();
  1845. }
  1846. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  1847. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1848. {
  1849. region.AddToRegion(ViwerRegionName, PDFViewer);
  1850. }
  1851. CurrentBar = "TabItemTool";
  1852. EnterSelectedBar(CurrentBar);
  1853. }
  1854. /// <summary>
  1855. /// 二级菜单指定目标处理
  1856. /// </summary>
  1857. /// <param name="e"></param>
  1858. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  1859. {
  1860. CurrentBar = EditToolName.EditToolsContentName;
  1861. EnterToolMode(CurrentBar);
  1862. }
  1863. /// <summary>
  1864. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  1865. /// </summary>
  1866. /// <param name="targetToolMode">要导航过去的控件名称</param>
  1867. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  1868. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  1869. {
  1870. IsLoading = Visibility.Visible;
  1871. await Task.Delay(3);
  1872. NavigationParameters param = new NavigationParameters();
  1873. if (valuePairs == null)
  1874. {
  1875. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1876. param.Add(ParameterNames.ViewContentViewModel, this);
  1877. }
  1878. else//有传入其他内容的参数时
  1879. {
  1880. param = valuePairs;
  1881. }
  1882. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  1883. ShowContent(CurrentBar, true);
  1884. IsLoading = Visibility.Collapsed;
  1885. }
  1886. private void EnterSelectedBar(string currentBar)
  1887. {
  1888. NavigationParameters param = new NavigationParameters();
  1889. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1890. param.Add(ParameterNames.ViewContentViewModel, this);
  1891. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  1892. if (currentBar == "TabItemScan")
  1893. {
  1894. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  1895. }
  1896. ShowContent(currentBar);
  1897. }
  1898. /// <summary>
  1899. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  1900. /// </summary>
  1901. public void ExitToolMode()
  1902. {
  1903. ToolContentVisible = Visibility.Collapsed;
  1904. if (isInPageEdit)
  1905. {
  1906. TabSelectedIndex = 0;
  1907. isInPageEdit = false;
  1908. }
  1909. }
  1910. #endregion 方法
  1911. }
  1912. }