ViewContentViewModel.cs 115 KB

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