예제 #1
0
        //*************************************************************************
        //  Method: WorksheetContextMenuManager_RequestEdgeCommandEnable()
        //
        /// <summary>
        /// Handles the RequestEdgeCommandEnable event on the
        /// WorksheetContextMenuManager object.
        /// </summary>
        ///
        /// <param name="sender">
        /// Standard event argument.
        /// </param>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        //*************************************************************************
        protected void WorksheetContextMenuManager_RequestEdgeCommandEnable(
            Object sender,
            RequestEdgeCommandEnableEventArgs e
            )
        {
            AssertValid();

            // Get the edge corresponding to the row the user right-clicked in the
            // edge worksheet.  This can be null.

            IEdge oClickedEdge =
            WorksheetContextMenuManagerRowIDToEdge(e.EdgeRowID);

            Boolean bEnableSelectAllEdges, bEnableDeselectAllEdges,
            bEnableSelectAdjacentVertices, bEnableDeselectAdjacentVertices;

            GetEdgeCommandEnableFlags(oClickedEdge,
            out bEnableSelectAllEdges,
            out bEnableDeselectAllEdges,
            out bEnableSelectAdjacentVertices,
            out bEnableDeselectAdjacentVertices
            );

            e.EnableSelectAllEdges = bEnableSelectAllEdges;
            e.EnableDeselectAllEdges = bEnableDeselectAllEdges;
            e.EnableSelectAdjacentVertices = bEnableSelectAdjacentVertices;
            e.EnableDeselectAdjacentVertices = bEnableDeselectAdjacentVertices;
        }
        //*************************************************************************
        //  Method: AddEdgeContextMenuItems()
        //
        /// <summary>
        /// Adds custom menu items to the context menu that appears when a cell is
        /// right-clicked in the edge table.
        /// </summary>
        ///
        /// <param name="oClickedRange">
        /// Range that was right-clicked.
        /// </param>
        //*************************************************************************
        protected void AddEdgeContextMenuItems(
            Microsoft.Office.Interop.Excel.Range oClickedRange
            )
        {
            Debug.Assert(oClickedRange != null);
            AssertValid();

            Int32 iClickedEdgeID;
            CommandBarPopup oTopLevelPopup;

            // Add a top-level NodeXL popup menu item.

            PrepareToAddChildMenuItems(oClickedRange, m_oEdgeTable,
            CommonTableColumnNames.ID, out iClickedEdgeID,
            out oTopLevelPopup);

            // Add child menu items.

            CommandBarButton oSelectAllEdgesButton = AddContextMenuItem(
            oTopLevelPopup, "Select &All Edges", iClickedEdgeID,
            new _CommandBarButtonEvents_ClickEventHandler(
                oSelectAllEdgesButton_Click) );

            CommandBarButton oDeselectAllEdgesButton = AddContextMenuItem(
            oTopLevelPopup, "&Deselect All Edges", iClickedEdgeID,
            new _CommandBarButtonEvents_ClickEventHandler(
                oDeselectAllEdgesButton_Click) );

            CommandBarButton oSelectAdjacentVerticesOfEdgeButton =
            AddContextMenuItem(oTopLevelPopup, "Select Ad&jacent Vertices",
            iClickedEdgeID,
            new _CommandBarButtonEvents_ClickEventHandler(
                oSelectAdjacentVerticesOfEdgeButton_Click) );

            CommandBarButton oDeselectAdjacentVerticesOfEdgeButton =
            AddContextMenuItem(oTopLevelPopup, "Deselect Adjace&nt Vertices",
            iClickedEdgeID,
            new _CommandBarButtonEvents_ClickEventHandler(
                oDeselectAdjacentVerticesOfEdgeButton_Click) );

            // The custom menu items are disabled by default.  To enable them, the
            // RequestEdgeCommandEnable event must be handled.

            RequestEdgeCommandEnableEventHandler oRequestEdgeCommandEnable =
            this.RequestEdgeCommandEnable;

            if (oRequestEdgeCommandEnable == null)
            {
            return;
            }

            RequestEdgeCommandEnableEventArgs oEventArgs =
            new RequestEdgeCommandEnableEventArgs(iClickedEdgeID);

            oRequestEdgeCommandEnable(this, oEventArgs);

            oSelectAllEdgesButton.Enabled = oEventArgs.EnableSelectAllEdges;

            oDeselectAllEdgesButton.Enabled = oEventArgs.EnableDeselectAllEdges;

            oSelectAdjacentVerticesOfEdgeButton.Enabled =
            oEventArgs.EnableSelectAdjacentVertices;

            oDeselectAdjacentVerticesOfEdgeButton.Enabled =
            oEventArgs.EnableDeselectAdjacentVertices;

            // Add a "set color" menu item if the clicked range is a color cell.

            AddSetColorContextMenuItem(m_oEdgeTable, oClickedRange,
            EdgeTableColumnNames.Color);
        }