/// <summary> /// Applies the shortcut display string to items with keyid or same id /// </summary> public static void ApplySecondaryShortcut(ToolStripItem item) { Boolean view = Globals.Settings.ViewShortcuts; if (item != null && item.Tag != null) { String id = String.Empty; String[] ids = ((ItemData)item.Tag).Id.Split(';'); if (ids.Length == 2 && String.IsNullOrEmpty(ids[1])) { id = StripBarManager.GetMenuItemId(item); } else if (ids.Length == 2) { id = ids[1]; } else { return; // No work for us here... } Keys keys = Globals.MainForm.GetShortcutItemKeys(id); if (keys != Keys.None) { if (item is ToolStripMenuItem) { var casted = item as ToolStripMenuItem; if (casted.ShortcutKeys == Keys.None) { String keytext = DataConverter.KeysToString(keys); casted.ShortcutKeyDisplayString = view ? keytext : ""; } } else { Int32 end = item.ToolTipText.IndexOf(" ("); String keytext = view ? " (" + DataConverter.KeysToString(keys) + ")" : ""; if (end != -1) { item.ToolTipText = item.ToolTipText.Substring(0, end) + keytext; } else { item.ToolTipText = item.ToolTipText + keytext; } } } } }
/// <summary> /// Gets the specified registered shortcut item /// </summary> public static ToolStripItem GetSecondaryItem(String id) { foreach (ToolStripItem item in SecondaryItems) { String[] ids = ((ItemData)item.Tag).Id.Split(';'); if (ids.Length == 2) { String temp = String.IsNullOrEmpty(ids[1]) ? StripBarManager.GetMenuItemId(item) : ids[1]; if (temp == id) { return(item); } } } return(null); }
/// <summary> /// Adds a new menu item to the reopen menu /// </summary> public static void AddNewReopenMenuItem(String file) { try { ToolStripMenuItem reopenMenu = (ToolStripMenuItem)StripBarManager.FindMenuItem("ReopenMenu"); if (Globals.PreviousDocuments.Contains(file)) { Globals.PreviousDocuments.Remove(file); } Globals.PreviousDocuments.Insert(0, file); PopulateReopenMenu(); } catch (Exception ex) { ErrorManager.ShowError(ex); } }
/// <summary> /// Populates the reopen menu from the documents class /// </summary> public static void PopulateReopenMenu() { try { ToolStripMenuItem reopenMenu = (ToolStripMenuItem)StripBarManager.FindMenuItem("ReopenMenu"); reopenMenu.DropDownItems.Clear(); for (Int32 i = 0; i < Globals.PreviousDocuments.Count; i++) { String file = Globals.PreviousDocuments[i]; ToolStripMenuItem item = new ToolStripMenuItem(); item.Click += new EventHandler(Globals.MainForm.Reopen); item.Tag = file; item.Text = PathHelper.GetCompactPath(file); if (i < Globals.Settings.MaxRecentFiles) { reopenMenu.DropDownItems.Add(item); } else { Globals.PreviousDocuments.Remove(file); } } if (Globals.PreviousDocuments.Count > 0) { String cleanLabel = TextHelper.GetString("Label.CleanReopenList"); String clearLabel = TextHelper.GetString("Label.ClearReopenList"); reopenMenu.DropDownItems.Add(new ToolStripSeparator()); reopenMenu.DropDownItems.Add(new ToolStripMenuItem(cleanLabel, null, new EventHandler(Globals.MainForm.CleanReopenList))); reopenMenu.DropDownItems.Add(new ToolStripMenuItem(clearLabel, null, new EventHandler(Globals.MainForm.ClearReopenList))); reopenMenu.Enabled = true; } else { reopenMenu.Enabled = false; } } catch (Exception ex) { ErrorManager.ShowError(ex); } }