ViewContentViewModel.cs 107 KB

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