using System; using System.ComponentModel; using System.Text.RegularExpressions; using System.Windows.Forms; using PDFPatcher.Common; using TheArtOfDev.HtmlRenderer.Core.Entities; namespace PDFPatcher { [ToolboxItem(false)] sealed partial class FrontPageControl : Functions.HtmlPageControl { readonly Regex __FrontPagePattern = new Regex ("
(.+);(.+);(.+);(.+)
", RegexOptions.CultureInvariant); public override string FunctionName => "主页"; public override System.Drawing.Bitmap IconImage => Properties.Resources.HomePage; public override void ExecuteCommand (string commandName, params string[] parameters) { if (commandName == Commands.Open) { var n = AppContext.MainForm.ShowPdfFileDialog (); if (n != null) { AppContext.MainForm.OpenFileWithEditor (n); } return; } else if (commandName == Commands.CleanUpInexistentFiles) { AppContext.CleanUpInexistentFiles (AppContext.Recent.SourcePdfFiles); AppContext.CleanUpInexistentFiles (AppContext.Recent.InfoDocuments); AppContext.CleanUpInexistentFolders (AppContext.Recent.Folders); RefreshContent (); return; } base.ExecuteCommand (commandName, parameters); } public FrontPageControl () { InitializeComponent (); Text = "主页"; RefreshContent (); RecentFileItemClicked = (s, args) => { AppContext.MainForm.OpenFileWithEditor (args.ClickedItem.ToolTipText); }; AllowDrop = true; } protected override void OnDragEnter (DragEventArgs drgevent) { base.OnDragEnter (drgevent); drgevent.FeedbackDragFileOver (Constants.FileExtensions.PdfAndAllBookmarkExtension); } protected override void OnDragDrop (DragEventArgs drgevent) { base.OnDragDrop (drgevent); foreach (var item in drgevent.DropFileOver (Constants.FileExtensions.PdfAndAllBookmarkExtension)) { AppContext.MainForm.OpenFileWithEditor (item); } } internal override void OnSelected () { base.OnSelected (); RefreshContent (); } public override void SetupCommand (ToolStripItem item) { switch (item.Name) { case Commands.Close: case Commands.Action: EnableCommand (item, false, true); break; } base.SetupCommand (item); } private void RefreshContent () { _FrontPageBox.Text = __FrontPagePattern .Replace (Properties.Resources.FrontPage, @"
$3
") .Replace ("$appName", Constants.AppName) .Replace ("$AppHomePage", Constants.AppHomePage) .Replace ("
  • ", GetLastFileList ()); } private string GetLastFileList () { var i = 0; return String.Concat (AppContext.Recent.SourcePdfFiles.ConvertAll ((s) => FileHelper.IsPathValid(s) && System.IO.File.Exists(s) ? String.Concat(@"
  • ", SubstringAfter(s, '\\'), "
  • ") : String.Concat(@"
  • ", SubstringAfter(s, '\\'), "
  • "))); } private void _FrontPageBox_LinkClicked (object sender, HtmlLinkClickedEventArgs e) { HandleLinkClicked (e.Link); e.Handled = true; } private void _FrontPageBox_ImageLoad (object sender, HtmlImageLoadEventArgs e) { LoadResourceImage (e); } } }