/// <summary> /// Updates recent file menu items</summary> protected virtual void UpdateRecentFilesMenuItems() { if (CommandService != null) { var newCommandInfos = new List <CommandInfo>(); foreach (RecentDocumentInfo info in m_recentDocuments) { if (m_registeredRecentDocs.Contains(info)) { CommandService.UnregisterCommand(info, this); m_registeredRecentDocs.Remove(info); } } if (m_recentDocuments.Count > 0) { // Remove the "empty" entry from the MRU, since we have at least one document now. if (m_emptyMruCommandInfo != null) { CommandService.UnregisterCommand(m_emptyMruCommandInfo.CommandTag, this); m_emptyMruCommandInfo = null; } } foreach (RecentDocumentInfo info in m_recentDocuments.MostRecentOrder) { if (!m_registeredRecentDocs.Contains(info)) { string pathName = info.Uri.LocalPath; // replace slashes, so command service doesn't create hierarchical menu; actual path // is set in our UpdateCommand method. pathName = pathName.Replace("/", "-"); pathName = pathName.Replace("\\", "-"); var commandInfo = new CommandInfo( info, StandardMenu.File, StandardCommandGroup.FileRecentlyUsed, "Recent Files".Localize() + "/" + pathName, "Open a recently used file".Localize(), Keys.None); commandInfo.ImageName = info.Pinned ? Resources.PinGreenImage : Resources.PinGreyImage; commandInfo.ShortcutsEditable = false; CommandService.RegisterCommand( commandInfo, this); newCommandInfos.Add(commandInfo); m_registeredRecentDocs.Add(info); } } CommandInfos = newCommandInfos; } }
private void documentInfo_ItemRemoved(object sender, ItemRemovedEventArgs <RecentDocumentInfo> e) { if (CommandService != null) { if (m_registeredRecentDocs.Contains(e.Item)) { CommandService.UnregisterCommand(e.Item, this); m_registeredRecentDocs.Remove(e.Item); } } }