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