ViewContentViewModel.cs 121 KB

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