Пример #1
0
        // Runs on the UIMonitor's automation thread - return true if we might want to process
        bool ShouldProcessFormulaEditTextChange(string formulaPrefix)
        {
            // CAREFUL: Because of threading, this might run before FormulaEditStart!

            if (_argumentsToolTip?.Visible == true)
            {
                return(true);
            }

            // TODO: Why do this twice....?
            string functionName;
            int    currentArgIndex;

            if (FormulaParser.TryGetFormulaInfo(formulaPrefix, out functionName, out currentArgIndex))
            {
                if (_functionInfoMap.ContainsKey(functionName))
                {
                    return(true);
                }
            }
            // Not interested...
            Debug.Print($"Not processing formula {formulaPrefix}");
            return(false);
        }
Пример #2
0
        // Runs on the main thread
        void FormulaEditTextChange(string formulaPrefix, Rect editWindowBounds, IntPtr excelToolTipWindow)
        {
            Debug.Print($"^^^ FormulaEditStateChanged. CurrentPrefix: {formulaPrefix}, Thread {Thread.CurrentThread.ManagedThreadId}");
            string functionName;
            int    currentArgIndex;
            int    toolTipBottom = (int)editWindowBounds.Location.Y + 5;

            if (FormulaParser.TryGetFormulaInfo(formulaPrefix, out functionName, out currentArgIndex))
            {
                FunctionInfo functionInfo;
                if (_functionInfoMap.TryGetValue(functionName, out functionInfo))
                {
                    var lineBeforeFunctionName = FormulaParser.GetLineBeforeFunctionName(formulaPrefix, functionName);
                    // We have a function name and we want to show info
                    if (_argumentsToolTip != null)
                    {
                        // NOTE: Hiding or moving just once doesn't help - the tooltip pops up in its original place again
                        // TODO: Try to move it off-screen, behind or make invisible
                        //if (!_argumentsToolTip.Visible)
                        //{
                        //    // Fiddle a bit with the ExcelToolTip if it is already visible when we first show our FunctionEdit ToolTip
                        //    // At other times, the explicit UI update should catch and hide as appropriate
                        //    if (excelToolTipWindow != IntPtr.Zero)
                        //    {
                        //        Win32Helper.HideWindow(excelToolTipWindow);
                        //    }
                        //}
                        int           topOffset = GetTopOffset(excelToolTipWindow);
                        FormattedText infoText  = GetFunctionIntelliSense(functionInfo, currentArgIndex);
                        try
                        {
                            _argumentsToolTip.ShowToolTip(infoText, lineBeforeFunctionName, (int)editWindowBounds.Location.X, (int)editWindowBounds.Location.Y + (int)editWindowBounds.Height + 5, topOffset);
                            toolTipBottom = (int)editWindowBounds.Location.Y + (int)editWindowBounds.Height + 5 + _argumentsToolTip.Height;
                        }
                        catch (Exception ex)
                        {
                            Logger.Display.Warn($"IntelliSenseDisplay - FormulaEditTextChange Error - {ex}");
                            _argumentsToolTip.Dispose();
                            _argumentsToolTip = null;
                        }
                    }
                    else
                    {
                        Logger.Display.Warn("FormulaEditTextChange with no arguments tooltip !?");
                    }

                    if (_selectBox != null)
                    {
                        try
                        {
                            var argDescription = functionInfo.ArgumentList[currentArgIndex].Description;
                            int topOffset      = GetTopOffset(excelToolTipWindow);
                            if (hasArgList(argDescription))
                            {
                                _selectBox.ShowToolTip(argDescription, lineBeforeFunctionName, (int)editWindowBounds.Location.X, toolTipBottom + 10, topOffset);
                            }
                            //else
                            //{
                            //    _selectBox.Dispose();
                            //    _selectBox = null;
                            //}
                        }
                        catch (Exception ex)
                        {
                            Logger.Display.Warn($"IntelliSenseDisplay - FormulaEditTextChange Error - {ex}");
                            _selectBox.Dispose();
                            _selectBox = null;
                        }
                    }

                    return;
                }
            }

            // All other paths, we hide the box
            _argumentsToolTip?.Hide();
        }