ViewContentViewModel.cs 115 KB

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