ViewContentViewModel.cs 119 KB

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