ViewContentViewModel.cs 144 KB

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