ViewContentViewModel.cs 120 KB

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