ViewContentViewModel.cs 123 KB

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