コード例 #1
0
        public void AttachPlaylistItemMenu(PlaylistItem plItem, MenuWrapper <T> menu, MenuType menuType, EventHandler clickHandler)
        {
            if (menuType != MenuType.Playlist)
            {
                AttachCommonPlaylistToolsMenu(menu, menuType, clickHandler, plItem);
            }

            MenuWrapper <T> menuToAlter = menu;

            if (menuType == MenuType.Playlist)
            {
                OPMToolStripMenuItem item = new OPMToolStripMenuItem(plItem.DisplayName);
                item.Tag     = plItem;
                item.Click  += clickHandler;
                item.Checked = _pnlPlaylist.IsActiveItem(plItem);
                menu.AddSingleEntry(item);

                menuToAlter = new MenuWrapper <OPMToolStripMenuItem>(item) as MenuWrapper <T>;
            }

            if (plItem != null && menuType != MenuType.MultipleItems)
            {
                // It may have subitems:
                // * a DVD item will have titles, chapters, etc ...
                // * other media files may have bookmarks ...
                Dictionary <PlaylistSubItem, List <PlaylistSubItem> > submenu = plItem.GetSubmenu();

                if (submenu != null && submenu.Count >= 1)
                {
                    if (menuType == MenuType.SingleItem)
                    {
                        menuToAlter.AddSingleEntry(new OPMMenuStripSeparator());
                    }

                    foreach (KeyValuePair <PlaylistSubItem, List <PlaylistSubItem> > subitems in submenu)
                    {
                        OPMToolStripMenuItem subItem = new OPMToolStripMenuItem(subitems.Key.Name);
                        subItem.Click += clickHandler;
                        subItem.Tag    = subitems.Key;

                        if (subitems.Value != null)
                        {
                            foreach (PlaylistSubItem ssitem in subitems.Value)
                            {
                                OPMToolStripMenuItem subSubItem = null;

                                if (ssitem is DvdSubItem)
                                {
                                    subSubItem        = new OPMToolStripMenuItem(ssitem.Name);
                                    subSubItem.Click += clickHandler;
                                    subSubItem.Tag    = ssitem;

                                    DvdSubItem            si   = ssitem as DvdSubItem;
                                    DvdRenderingStartHint hint = (si != null) ?
                                                                 si.StartHint as DvdRenderingStartHint : null;

                                    if (hint != null && hint.IsSubtitleHint)
                                    {
                                        subSubItem.Checked = (hint.SID == MediaRenderer.DefaultInstance.SubtitleStream);
                                    }
                                }
                                else if (ssitem is BookmarkSubItem)
                                {
                                    BookmarkSubItem   bsi  = (ssitem as BookmarkSubItem);
                                    BookmarkStartHint hint = (bsi != null) ?
                                                             bsi.StartHint as BookmarkStartHint : new BookmarkStartHint(Bookmark.Empty);

                                    string name = string.Format("{0} - '{1}'", hint.Bookmark.PlaybackTime, bsi.Name);
                                    subSubItem        = new OPMToolStripMenuItem(name);
                                    subSubItem.Click += clickHandler;
                                    subSubItem.Tag    = ssitem;
                                }

                                if (subSubItem != null)
                                {
                                    subItem.DropDownItems.Add(subSubItem);
                                }
                            }
                        }

                        menuToAlter.AddSingleEntry(subItem);
                    }
                }

                if (menuType == MenuType.SingleItem)
                {
                    if (plItem is DvdPlaylistItem)
                    {
                        AttachDvdMenuItems(plItem as DvdPlaylistItem, menuToAlter, clickHandler);
                    }
                    else
                    {
                        AttachFileMenuItems(plItem as PlaylistItem, menuToAlter, clickHandler);
                    }
                }
            }
        }