Beispiel #1
0
        private void setUIState(WorkbookState wbs)
        {
            var       isAChart       = false;
            var       sheetProtected = false;
            Worksheet w = null;

            try
            {
                w = (Worksheet)Globals.ThisAddIn.Application.ActiveSheet;
                sheetProtected = wbs.WorksheetProtected(w);
            } catch
            {
                isAChart = true;
            }

            if (wbs == null || Globals.ThisAddIn.Application.ActiveProtectedViewWindow != null || sheetProtected || isAChart)
            {
                // disable all controls
                var disabled_text = "ExceLint is disabled in protected mode.  Please enable editing to continue.";

                // tell the user ExceLint doesn't work
                SetTooltips(disabled_text);
            }
            else
            {
                // clear button text
                SetTooltips("");

                // button should never be locked here
                // (gets locked when there is no workbook open)
                this.RegularityMap.Enabled = true;

                // only enable reveal structure button if at least
                // one checkbox is checked
                if (this.enableDataHighlight.Checked || this.analyzeFormulas.Checked)
                {
                    this.RegularityMap.Enabled = true;
                }
                else
                {
                    this.RegularityMap.Enabled = false;
                }

                // only enable viewing heatmaps if we are not in the middle of an analysis
                if (wbs.Analyze_Enabled)
                {
                    this.RegularityMap.Label         = "Reveal Structure";
                    this.enableDataHighlight.Enabled = true;
                    this.analyzeFormulas.Enabled     = true;
                }
                else
                {
                    this.RegularityMap.Label         = "Hide Structure";
                    this.enableDataHighlight.Enabled = false;
                    this.analyzeFormulas.Enabled     = false;
                }
            }
        }
Beispiel #2
0
 // This event is called when Excel brings an opened workbook
 // to the foreground
 private void WorkbookActivated(Excel.Workbook workbook)
 {
     // when opening a blank sheet, Excel does not emit
     // a WorkbookOpen event, so we need to call it manually
     if (!wbstates.ContainsKey(workbook))
     {
         WorkbookOpen(workbook);
     }
     currentWorkbook = wbstates[workbook];
     setUIState(currentWorkbook);
 }
Beispiel #3
0
        private WorkbookState WorkbookOpenHelper(Excel.Workbook workbook)
        {
            WorkbookState wbs;

            if (!wbstates.ContainsKey(workbook))
            {
                wbs = new WorkbookState(Globals.ThisAddIn.Application, workbook);
                wbstates.Add(workbook, wbs);
                wbShutdown.AddOrUpdate(workbook, false, (k, v) => v);
            }
            else
            {
                wbs = wbstates[workbook];
            }

            return(wbs);
        }
Beispiel #4
0
        // This event is called when Excel sends an opened workbook
        // to the background
        private void WorkbookDeactivated(Excel.Workbook workbook)
        {
            if (annotations != null)
            {
                annotations.Write();
            }

            // if we recorded a workbook close for this workbook,
            // remove all workbook state
            if (wbShutdown[workbook])
            {
                wbstates.Remove(workbook);
                if (wbstates.Count == 0)
                {
                    SetUIStateNoWorkbooks();
                }
                Boolean outcome;
                wbShutdown.TryRemove(workbook, out outcome);
            }

            currentWorkbook = null;

            // WorkbookBeforeClose event does not fire for default workbooks
            // containing no data
            var wbs = new List <Excel.Workbook>();

            foreach (var wb in Globals.ThisAddIn.Application.Workbooks)
            {
                if (wb != workbook)
                {
                    wbs.Add((Excel.Workbook)wb);
                }
            }

            if (wbs.Count == 0)
            {
                wbstates.Clear();
                SetUIStateNoWorkbooks();
            }
        }