ViewContentViewModel.cs 124 KB

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