ViewContentViewModel.cs 123 KB

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