ViewContentViewModel.cs 93 KB

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