ViewContentViewModel.cs 127 KB

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