ViewContentViewModel.cs 122 KB

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