Bloom.CollectionTab.LibraryListView._bookContextMenu_Opening C# (CSharp) Method

_bookContextMenu_Opening() private method

private _bookContextMenu_Opening ( object sender, CancelEventArgs e ) : void
sender object
e CancelEventArgs
return void
        private void _bookContextMenu_Opening(object sender, CancelEventArgs e)
        {
            var btn = (sender as ContextMenuStrip).SourceControl as Button;
            if (btn == null)
            {
                // At least in Mono, the button selection doesn't always survive from the click to this point.
                // See https://silbloom.myjetbrains.com/youtrack/issue/BL-3424 and various internet posts like
                // http://stackoverflow.com/questions/3026380/getting-the-highest-owner-of-a-toolstripdropdownitem.
                // This might be needed only on Linux/Mono, but is safe for windows.
                btn = _clickedButton;
                _clickedButton = null;
                if (btn == null)
                {
                    e.Cancel = true; // don't show the menu at all
                    return;
                }
            }
            var btnInfo = btn.Tag as BookButtonInfo;
            if (btnInfo.IsEditable)
                return; // leave them all on
            if (btnInfo.HasNoContextMenu)
            {
                e.Cancel = true; // don't show the menu at all (but leave them visible for next time)
                return;
            }
            foreach (ToolStripItem menuItem in (sender as ContextMenuStrip).Items)
            {
                if (menuItem == deleteMenuItem && btnInfo.IsBLibraryBook)
                    continue; // leave this one on for BloomLibrary books
                if (menuItem == _openFolderOnDisk)
                    continue; // leave this one on (for both BloomLibrary and BloomPack books)
                menuItem.Visible = false;
            }
        }