ViewContentViewModel.cs 108 KB

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