| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 | using PaintDotNet.Actions;using PaintDotNet.Base.Functionodel;using PaintDotNet.Base.CommTool;using PaintDotNet.Data.Param;using PaintDotNet.Hardware;using System;using System.Collections.Generic;using System.Drawing;using System.Globalization;using System.IO;using System.Windows.Forms;using PaintDotNet.Base;namespace PaintDotNet.Menus{    /// <summary>    /// 帮助菜单    /// </summary>    internal sealed class HelpMenu : PdnMenuItem    {        private PdnMenuItem menuHelpHelpTopics;        private PdnMenuItem menuHelpHelpIndex;        private ToolStripSeparator menuHelpSeparator1;        //private PdnMenuItem menuHelpLanguage;        //private PdnMenuItem menuHelpLanguageSentinel;        //private ToolStripSeparator menuHelpSeparator2;        private PdnMenuItem menuHelpAbout;        private PdnMenuItem menuHelpSoftWareComposition;        public HelpMenu(int menuId)        {            InitializeComponent();            this.MenuId = menuId;            //在脚本中不显示            this.CanUseInScript = false;            this.AutomaticScript = false;        }        protected override void OnAppWorkspaceChanged()        {            base.OnAppWorkspaceChanged();        }        private void InitializeComponent()        {            this.menuHelpHelpTopics = new PdnMenuItem(ActionType.HelpTopics);            this.menuHelpHelpIndex = new PdnMenuItem(ActionType.HelpIndex);            this.menuHelpSeparator1 = new ToolStripSeparator();            //this.menuHelpLanguage = new PdnMenuItem();            //this.menuHelpLanguageSentinel = new PdnMenuItem();            //this.menuHelpSeparator2 = new ToolStripSeparator();            this.menuHelpAbout = new PdnMenuItem(ActionType.About);            this.menuHelpSoftWareComposition = new PdnMenuItem(ActionType.SoftWareComposition);            //            // HelpMenu            //            this.DropDownItems.AddRange(                new ToolStripItem[]                {                    this.menuHelpHelpTopics,                    this.menuHelpHelpIndex,                    this.menuHelpSeparator1,                    //this.menuHelpLanguage,                    //this.menuHelpSeparator2,                    this.menuHelpAbout,                    this.menuHelpSoftWareComposition                });            this.Name = "Menu.Help";            this.Text = PdnResources.GetString("Menu.Help.Text");            //             // 目录            //             this.menuHelpHelpTopics.Click += new EventHandler(this.MenuHelpHelpTopics_Click);            //            // 索引            //            this.menuHelpHelpIndex.Click += new EventHandler(this.MenuHelpHelpIndex_Click);            /*//            // menuHelpLanguage            //            this.menuHelpLanguage.Name = "Language";            this.menuHelpLanguage.DropDownItems.AddRange(                new ToolStripItem[]                {                    this.menuHelpLanguageSentinel                });            this.menuHelpLanguage.DropDownOpening += new EventHandler(MenuHelpLanguage_DropDownOpening);            //             // menuHelpLanguageSentinel            //            this.menuHelpLanguageSentinel.Text = "(sentinel)";*/            //             // 关于            //             this.menuHelpAbout.Click += new System.EventHandler(this.MenuHelpAbout_Click);            //            // 软件构成            //            this.menuHelpSoftWareComposition.Click += new EventHandler(this.MenuHelpSoftWareComposition_Click);            //            // 加载菜单的文字和icon            //            this.LoadNames(this.Name);            this.LoadIcons();        }        /// <summary>        /// 关于我们        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void MenuHelpAbout_Click(object sender, System.EventArgs e)        {            if (AppWorkspace.startScriptRecording)            {                AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());            }            using (AboutDialog af = new AboutDialog(AppWorkspace,1))            {                af.ShowDialog(AppWorkspace);            }        }        /// <summary>        /// 软件构成        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void MenuHelpSoftWareComposition_Click(object sender, System.EventArgs e)        {            if (AppWorkspace.startScriptRecording)            {                AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());            }            using (AboutDialog af = new AboutDialog(AppWorkspace, 2))            {                af.ShowDialog(AppWorkspace);            }        }        /// <summary>        /// 目录        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void MenuHelpHelpTopics_Click(object sender, System.EventArgs e)        {            if (AppWorkspace.startScriptRecording)            {                AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());            }            Utility.ShowHelp(AppWorkspace,1);        }        /// <summary>        /// 索引        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void MenuHelpHelpIndex_Click(object sender, System.EventArgs e)        {            if (AppWorkspace.startScriptRecording)            {                AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());            }            Utility.ShowHelp(AppWorkspace,2);        }        private class MenuTitleAndLocale        {            public string title;            public string locale;            public MenuTitleAndLocale(string title, string locale)            {                this.title = title;                this.locale = locale;            }        }        private string GetCultureInfoName(CultureInfo ci)        {            CultureInfo en_US = new CultureInfo("en-US");            // For "English (United States)" we'd rather just display "English"            if (ci.Equals(en_US))            {                return GetCultureInfoName(ci.Parent);            }            else            {                return ci.NativeName;            }        }        private void MenuHelpLanguage_DropDownOpening(object sender, EventArgs e)        {            //this.menuHelpLanguage.DropDownItems.Clear();            string[] locales = PdnResources.GetInstalledLocales();            MenuTitleAndLocale[] mtals = new MenuTitleAndLocale[locales.Length];            for (int i = 0; i < locales.Length; ++i)            {                string locale = locales[i];                CultureInfo ci = new CultureInfo(locale);                mtals[i] = new MenuTitleAndLocale(ci.DisplayName, locale);            }            Array.Sort(                mtals,                delegate (MenuTitleAndLocale x, MenuTitleAndLocale y)                {                    return string.Compare(x.title, y.title, StringComparison.InvariantCultureIgnoreCase);                });            foreach (MenuTitleAndLocale mtal in mtals)            {                ToolStripMenuItem menuItem = new ToolStripMenuItem();                menuItem.Text = GetCultureInfoName(new CultureInfo(mtal.locale));                menuItem.Tag = mtal.locale;                menuItem.Click += new EventHandler(LanguageMenuItem_Click);                if (0 == string.Compare(mtal.locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase))                {                    menuItem.Checked = true;                }                //this.menuHelpLanguage.DropDownItems.Add(menuItem);            }        }        /// <summary>        /// 原来切换语言的功能        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void LanguageMenuItem_Click(object sender, EventArgs e)        {            /**            // Save off the old locale name in case they decide to cancel            string oldLocaleName = PdnResources.Culture.Name;            // Now, apply the chosen language so that the confirmation buttons show up in the right language            ToolStripMenuItem miwt = (ToolStripMenuItem)sender;            string newLocaleName = (string)miwt.Tag;            PdnResources.SetNewCulture(newLocaleName);            // Load the text and buttons in the new language            Icon formIcon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuHelpLanguageIcon.png").Reference);            string title = PdnResources.GetString("ConfirmLanguageDialog.Title");            Image taskImage = null;            string introText = PdnResources.GetString("ConfirmLanguageDialog.IntroText");            Image restartImage = PdnResources.GetImageResource("Icons.RightArrowBlue.png").Reference;            string explanationTextFormat = PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ExplanationText.Format");            CultureInfo newCI = new CultureInfo(newLocaleName);            // We prefer to show "English (United States)" as just "English"            CultureInfo en_US = new CultureInfo("en-US");            if (newCI.Equals(en_US))            {                newCI = newCI.Parent;            }            string languageName = newCI.NativeName;            string explanationText = string.Format(explanationTextFormat, languageName);            TaskButton restartTB = new TaskButton(                restartImage,                PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ActionText"),                explanationText);            Image cancelImage = PdnResources.GetImageResource("Icons.CancelIcon.png").Reference;            TaskButton cancelTB = new TaskButton(                cancelImage,                PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ActionText"),                PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ExplanationText"));            int width96dpi = (TaskDialog.DefaultPixelWidth96Dpi * 5) / 4;            TaskButton clickedTB = TaskDialog.Show(                AppWorkspace,                formIcon,                title,                taskImage,                true,                introText,                new TaskButton[] { restartTB, cancelTB },                restartTB,                cancelTB,                width96dpi,                false,                0,                out bool unuse);            if (clickedTB == restartTB)            {                // Next, apply restart logic                CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction();                cawa.PerformAction(AppWorkspace);                if (!cawa.Cancelled)                {                    SystemLayer.Shell.RestartApplication();                    Startup.CloseApplication();                }            }            else            {                // Revert to the old language                PdnResources.SetNewCulture(oldLocaleName);            }            **/        }    }}
 |