ViewContentViewModel.cs 118 KB

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