ViewContentViewModel.cs 105 KB

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