ViewContentViewModel.cs 98 KB

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