Beispiel #1
0
        //*************************************************************************
        //  Method: mnuGroups_ItemsLoading()
        //
        /// <summary>
        /// Handles the ItemsLoading event on the mnuGroups RibbonMenu.
        /// </summary>
        ///
        /// <param name="sender">
        /// Standard event argument.
        /// </param>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        //*************************************************************************
        private void mnuGroups_ItemsLoading(
            object sender,
            RibbonControlEventArgs e
            )
        {
            AssertValid();

            GroupCommands [] aeGroupCommands = {
            GroupCommands.CollapseSelectedGroups,
            GroupCommands.ExpandSelectedGroups,
            GroupCommands.CollapseAllGroups,
            GroupCommands.ExpandAllGroups,
            GroupCommands.SelectGroupsWithSelectedVertices,
            GroupCommands.SelectAllGroups,
            GroupCommands.AddSelectedVerticesToGroup,
            GroupCommands.RemoveSelectedVerticesFromGroups,
            GroupCommands.RemoveSelectedGroups,
            GroupCommands.RemoveAllGroups,
            };

            RibbonButton [] aoCorrespondingRibbonButtons = {
            btnCollapseSelectedGroups,
            btnExpandSelectedGroups,
            btnCollapseAllGroups,
            btnExpandAllGroups,
            btnSelectGroupsWithSelectedVertices,
            btnSelectAllGroups,
            btnAddSelectedVerticesToGroup,
            btnRemoveSelectedVerticesFromGroups,
            btnRemoveSelectedGroups,
            btnRemoveAllGroups,
            };

            Debug.Assert(aeGroupCommands.Length ==
            aoCorrespondingRibbonButtons.Length);

            // Various worksheets must be activated to read their selection.  Save
            // the active worksheet state.

            Microsoft.Office.Interop.Excel.Workbook oWorkbook =
            this.ThisWorkbook.InnerObject;

            ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
            new ExcelActiveWorksheetRestorer(oWorkbook);

            ExcelActiveWorksheetState oExcelActiveWorksheetState =
            oExcelActiveWorksheetRestorer.GetActiveWorksheetState();

            GroupCommands eGroupCommandsToEnable;

            try
            {
            eGroupCommandsToEnable =
                GroupManager.GetGroupCommandsToEnable(oWorkbook);
            }
            finally
            {
            oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }

            for (Int32 i = 0; i < aeGroupCommands.Length; i++)
            {
            aoCorrespondingRibbonButtons[i].Enabled =
                ( (eGroupCommandsToEnable & aeGroupCommands[i] ) != 0);
            }

            // This is required to force the ItemsLoading event to fire the next
            // time the mnuGroups menu is opened.

            this.RibbonUI.InvalidateControl(this.mnuGroups.Name);
        }
Beispiel #2
0
        //*************************************************************************
        //  Method: RunGroupCommand()
        //
        /// <summary>
        /// Runs a group command.
        /// </summary>
        ///
        /// <param name="groupCommand">
        /// One of the flags in the <see cref="GroupCommands" /> enumeration.
        /// </param>
        //*************************************************************************
        public void RunGroupCommand(
            GroupCommands groupCommand
            )
        {
            AssertValid();

            if ( !this.ExcelApplicationIsReady(true) )
            {
            return;
            }

            // Various worksheets must be activated for reading and writing.  Save
            // the active worksheet state.

            ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
            new ExcelActiveWorksheetRestorer(this.InnerObject);

            ExcelActiveWorksheetState oExcelActiveWorksheetState =
            oExcelActiveWorksheetRestorer.GetActiveWorksheetState();

            try
            {
            if ( !GroupManager.TryRunGroupCommand(groupCommand,
                this.InnerObject, Globals.Sheet2, Globals.Sheet5) )
            {
                return;
            }

            switch (groupCommand)
            {
                case GroupCommands.CollapseSelectedGroups:
                case GroupCommands.ExpandSelectedGroups:

                    // Let the TaskPane know about the collapsed or expanded
                    // groups.

                    FireCollapseOrExpandGroups(
                        groupCommand == GroupCommands.CollapseSelectedGroups,
                        Globals.Sheet5.GetSelectedGroupNames() );

                    break;

                case GroupCommands.CollapseAllGroups:
                case GroupCommands.ExpandAllGroups:

                    ICollection<String> oUniqueGroupNames;

                    if ( ExcelUtil.TryGetUniqueTableColumnStringValues(
                            this.InnerObject, WorksheetNames.Groups,
                            TableNames.Groups, GroupTableColumnNames.Name,
                            out oUniqueGroupNames) )
                    {
                        FireCollapseOrExpandGroups(
                            groupCommand == GroupCommands.CollapseAllGroups,
                            oUniqueGroupNames);
                    }

                    break;

                default:

                    break;
            }
            }
            catch (Exception oException)
            {
            ErrorUtil.OnException(oException);
            }
            finally
            {
            oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }
        }