HelpMenu.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. using PaintDotNet.Actions;
  2. using PaintDotNet.Base.Functionodel;
  3. using PaintDotNet.Base.CommTool;
  4. using PaintDotNet.Data.Param;
  5. using PaintDotNet.Hardware;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Drawing;
  9. using System.Globalization;
  10. using System.IO;
  11. using System.Windows.Forms;
  12. using PaintDotNet.Base;
  13. namespace PaintDotNet.Menus
  14. {
  15. /// <summary>
  16. /// 帮助菜单
  17. /// </summary>
  18. internal sealed class HelpMenu : PdnMenuItem
  19. {
  20. private PdnMenuItem menuHelpHelpTopics;
  21. private PdnMenuItem menuHelpHelpIndex;
  22. private ToolStripSeparator menuHelpSeparator1;
  23. //private PdnMenuItem menuHelpLanguage;
  24. //private PdnMenuItem menuHelpLanguageSentinel;
  25. //private ToolStripSeparator menuHelpSeparator2;
  26. private PdnMenuItem menuHelpAbout;
  27. private PdnMenuItem menuHelpSoftWareComposition;
  28. public HelpMenu(int menuId)
  29. {
  30. InitializeComponent();
  31. this.MenuId = menuId;
  32. //在脚本中不显示
  33. this.CanUseInScript = false;
  34. this.AutomaticScript = false;
  35. }
  36. protected override void OnAppWorkspaceChanged()
  37. {
  38. base.OnAppWorkspaceChanged();
  39. }
  40. private void InitializeComponent()
  41. {
  42. this.menuHelpHelpTopics = new PdnMenuItem(ActionType.HelpTopics);
  43. this.menuHelpHelpIndex = new PdnMenuItem(ActionType.HelpIndex);
  44. this.menuHelpSeparator1 = new ToolStripSeparator();
  45. //this.menuHelpLanguage = new PdnMenuItem();
  46. //this.menuHelpLanguageSentinel = new PdnMenuItem();
  47. //this.menuHelpSeparator2 = new ToolStripSeparator();
  48. this.menuHelpAbout = new PdnMenuItem(ActionType.About);
  49. this.menuHelpSoftWareComposition = new PdnMenuItem(ActionType.SoftWareComposition);
  50. //
  51. // HelpMenu
  52. //
  53. this.DropDownItems.AddRange(
  54. new ToolStripItem[]
  55. {
  56. this.menuHelpHelpTopics,
  57. this.menuHelpHelpIndex,
  58. this.menuHelpSeparator1,
  59. //this.menuHelpLanguage,
  60. //this.menuHelpSeparator2,
  61. this.menuHelpAbout,
  62. this.menuHelpSoftWareComposition
  63. });
  64. this.Name = "Menu.Help";
  65. this.Text = PdnResources.GetString("Menu.Help.Text");
  66. //
  67. // 目录
  68. //
  69. this.menuHelpHelpTopics.Click += new EventHandler(this.MenuHelpHelpTopics_Click);
  70. //
  71. // 索引
  72. //
  73. this.menuHelpHelpIndex.Click += new EventHandler(this.MenuHelpHelpIndex_Click);
  74. /*//
  75. // menuHelpLanguage
  76. //
  77. this.menuHelpLanguage.Name = "Language";
  78. this.menuHelpLanguage.DropDownItems.AddRange(
  79. new ToolStripItem[]
  80. {
  81. this.menuHelpLanguageSentinel
  82. });
  83. this.menuHelpLanguage.DropDownOpening += new EventHandler(MenuHelpLanguage_DropDownOpening);
  84. //
  85. // menuHelpLanguageSentinel
  86. //
  87. this.menuHelpLanguageSentinel.Text = "(sentinel)";*/
  88. //
  89. // 关于
  90. //
  91. this.menuHelpAbout.Click += new System.EventHandler(this.MenuHelpAbout_Click);
  92. //
  93. // 软件构成
  94. //
  95. this.menuHelpSoftWareComposition.Click += new EventHandler(this.MenuHelpSoftWareComposition_Click);
  96. //
  97. // 加载菜单的文字和icon
  98. //
  99. this.LoadNames(this.Name);
  100. this.LoadIcons();
  101. }
  102. /// <summary>
  103. /// 关于我们
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void MenuHelpAbout_Click(object sender, System.EventArgs e)
  108. {
  109. if (AppWorkspace.startScriptRecording)
  110. {
  111. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  112. }
  113. using (AboutDialog af = new AboutDialog(AppWorkspace,1))
  114. {
  115. af.ShowDialog(AppWorkspace);
  116. }
  117. }
  118. /// <summary>
  119. /// 软件构成
  120. /// </summary>
  121. /// <param name="sender"></param>
  122. /// <param name="e"></param>
  123. private void MenuHelpSoftWareComposition_Click(object sender, System.EventArgs e)
  124. {
  125. if (AppWorkspace.startScriptRecording)
  126. {
  127. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  128. }
  129. using (AboutDialog af = new AboutDialog(AppWorkspace, 2))
  130. {
  131. af.ShowDialog(AppWorkspace);
  132. }
  133. }
  134. /// <summary>
  135. /// 目录
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. private void MenuHelpHelpTopics_Click(object sender, System.EventArgs e)
  140. {
  141. if (AppWorkspace.startScriptRecording)
  142. {
  143. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  144. }
  145. Utility.ShowHelp(AppWorkspace,1);
  146. }
  147. /// <summary>
  148. /// 索引
  149. /// </summary>
  150. /// <param name="sender"></param>
  151. /// <param name="e"></param>
  152. private void MenuHelpHelpIndex_Click(object sender, System.EventArgs e)
  153. {
  154. if (AppWorkspace.startScriptRecording)
  155. {
  156. AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List<Args>());
  157. }
  158. Utility.ShowHelp(AppWorkspace,2);
  159. }
  160. private class MenuTitleAndLocale
  161. {
  162. public string title;
  163. public string locale;
  164. public MenuTitleAndLocale(string title, string locale)
  165. {
  166. this.title = title;
  167. this.locale = locale;
  168. }
  169. }
  170. private string GetCultureInfoName(CultureInfo ci)
  171. {
  172. CultureInfo en_US = new CultureInfo("en-US");
  173. // For "English (United States)" we'd rather just display "English"
  174. if (ci.Equals(en_US))
  175. {
  176. return GetCultureInfoName(ci.Parent);
  177. }
  178. else
  179. {
  180. return ci.NativeName;
  181. }
  182. }
  183. private void MenuHelpLanguage_DropDownOpening(object sender, EventArgs e)
  184. {
  185. //this.menuHelpLanguage.DropDownItems.Clear();
  186. string[] locales = PdnResources.GetInstalledLocales();
  187. MenuTitleAndLocale[] mtals = new MenuTitleAndLocale[locales.Length];
  188. for (int i = 0; i < locales.Length; ++i)
  189. {
  190. string locale = locales[i];
  191. CultureInfo ci = new CultureInfo(locale);
  192. mtals[i] = new MenuTitleAndLocale(ci.DisplayName, locale);
  193. }
  194. Array.Sort(
  195. mtals,
  196. delegate (MenuTitleAndLocale x, MenuTitleAndLocale y)
  197. {
  198. return string.Compare(x.title, y.title, StringComparison.InvariantCultureIgnoreCase);
  199. });
  200. foreach (MenuTitleAndLocale mtal in mtals)
  201. {
  202. ToolStripMenuItem menuItem = new ToolStripMenuItem();
  203. menuItem.Text = GetCultureInfoName(new CultureInfo(mtal.locale));
  204. menuItem.Tag = mtal.locale;
  205. menuItem.Click += new EventHandler(LanguageMenuItem_Click);
  206. if (0 == string.Compare(mtal.locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase))
  207. {
  208. menuItem.Checked = true;
  209. }
  210. //this.menuHelpLanguage.DropDownItems.Add(menuItem);
  211. }
  212. }
  213. /// <summary>
  214. /// 原来切换语言的功能
  215. /// </summary>
  216. /// <param name="sender"></param>
  217. /// <param name="e"></param>
  218. private void LanguageMenuItem_Click(object sender, EventArgs e)
  219. {
  220. /**
  221. // Save off the old locale name in case they decide to cancel
  222. string oldLocaleName = PdnResources.Culture.Name;
  223. // Now, apply the chosen language so that the confirmation buttons show up in the right language
  224. ToolStripMenuItem miwt = (ToolStripMenuItem)sender;
  225. string newLocaleName = (string)miwt.Tag;
  226. PdnResources.SetNewCulture(newLocaleName);
  227. // Load the text and buttons in the new language
  228. Icon formIcon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuHelpLanguageIcon.png").Reference);
  229. string title = PdnResources.GetString("ConfirmLanguageDialog.Title");
  230. Image taskImage = null;
  231. string introText = PdnResources.GetString("ConfirmLanguageDialog.IntroText");
  232. Image restartImage = PdnResources.GetImageResource("Icons.RightArrowBlue.png").Reference;
  233. string explanationTextFormat = PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ExplanationText.Format");
  234. CultureInfo newCI = new CultureInfo(newLocaleName);
  235. // We prefer to show "English (United States)" as just "English"
  236. CultureInfo en_US = new CultureInfo("en-US");
  237. if (newCI.Equals(en_US))
  238. {
  239. newCI = newCI.Parent;
  240. }
  241. string languageName = newCI.NativeName;
  242. string explanationText = string.Format(explanationTextFormat, languageName);
  243. TaskButton restartTB = new TaskButton(
  244. restartImage,
  245. PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ActionText"),
  246. explanationText);
  247. Image cancelImage = PdnResources.GetImageResource("Icons.CancelIcon.png").Reference;
  248. TaskButton cancelTB = new TaskButton(
  249. cancelImage,
  250. PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ActionText"),
  251. PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ExplanationText"));
  252. int width96dpi = (TaskDialog.DefaultPixelWidth96Dpi * 5) / 4;
  253. TaskButton clickedTB = TaskDialog.Show(
  254. AppWorkspace,
  255. formIcon,
  256. title,
  257. taskImage,
  258. true,
  259. introText,
  260. new TaskButton[] { restartTB, cancelTB },
  261. restartTB,
  262. cancelTB,
  263. width96dpi,
  264. false,
  265. 0,
  266. out bool unuse);
  267. if (clickedTB == restartTB)
  268. {
  269. // Next, apply restart logic
  270. CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction();
  271. cawa.PerformAction(AppWorkspace);
  272. if (!cawa.Cancelled)
  273. {
  274. SystemLayer.Shell.RestartApplication();
  275. Startup.CloseApplication();
  276. }
  277. }
  278. else
  279. {
  280. // Revert to the old language
  281. PdnResources.SetNewCulture(oldLocaleName);
  282. }
  283. **/
  284. }
  285. }
  286. }