Exemple #1
0
        // TODO: Need better formula parsing story here
        // Here are some ideas: http://fastexcel.wordpress.com/2013/10/27/parsing-functions-from-excel-formulas-using-vba-is-mid-or-a-byte-array-the-best-method/
        void FormulaEditStateChanged(StateChangeTypeEnum stateChangeType)
        {
            // Check for watcher already disposed
            // CONSIDER: How to manage threading with disposal...?
            if (_formulaEditWatcher == null)
            {
                return;
            }

            if (stateChangeType == StateChangeTypeEnum.Move && _argumentsToolTip != null)
            {
                _argumentsToolTip.MoveToolTip(
                    (int)_formulaEditWatcher.EditWindowBounds.Left, (int)_formulaEditWatcher.EditWindowBounds.Bottom + 5);
                return;
            }

            Debug.Print("^^^ FormulaEditStateChanged. CurrentPrefix: " + _formulaEditWatcher.CurrentPrefix);
            if (_formulaEditWatcher.IsEditingFormula && _formulaEditWatcher.CurrentPrefix != null)
            {
                string prefix = _formulaEditWatcher.CurrentPrefix;
                var    match  = Regex.Match(prefix, @"^=(?<functionName>\w*)\(");
                if (match.Success)
                {
                    string functionName = match.Groups["functionName"].Value;

                    IntelliSenseFunctionInfo functionInfo;
                    if (_functionInfoMap.TryGetValue(functionName, out functionInfo))
                    {
                        // It's ours!
                        if (_argumentsToolTip == null)
                        {
                            _argumentsToolTip = new ToolTipForm(_windowWatcher.MainWindow);
                        }

                        // TODO: Fix this: Need to consider subformulae
                        int currentArgIndex = _formulaEditWatcher.CurrentPrefix.Count(c => c == ',');
                        _argumentsToolTip.ShowToolTip(
                            GetFunctionIntelliSense(functionInfo, currentArgIndex),
                            (int)_formulaEditWatcher.EditWindowBounds.Left, (int)_formulaEditWatcher.EditWindowBounds.Bottom + 5);
                        return;
                    }
                }
            }

            // All other paths, we just clear the box
            if (_argumentsToolTip != null)
            {
                _argumentsToolTip.Hide();
            }
        }
Exemple #2
0
 public StateChangeEventArgs(StateChangeTypeEnum? stateChangeType = null)
 {
     StateChangeType = stateChangeType ?? StateChangeTypeEnum.Undefined;
 }
Exemple #3
0
 public StateChangeEventArgs(StateChangeTypeEnum?stateChangeType = null)
 {
     StateChangeType = stateChangeType ?? StateChangeTypeEnum.Undefined;
 }
        // TODO: Need better formula parsing story here
        // Here are some ideas: http://fastexcel.wordpress.com/2013/10/27/parsing-functions-from-excel-formulas-using-vba-is-mid-or-a-byte-array-the-best-method/
        void FormulaEditStateChanged(StateChangeTypeEnum stateChangeType)
        {
            // Check for watcher already disposed
            // CONSIDER: How to manage threading with disposal...?
            if (_formulaEditWatcher == null) return;

            if (stateChangeType == StateChangeTypeEnum.Move && _argumentsToolTip != null)
            {
                _argumentsToolTip.MoveToolTip(
                    (int)_formulaEditWatcher.EditWindowBounds.Left, (int)_formulaEditWatcher.EditWindowBounds.Bottom + 5);
                return;
            }

            Debug.Print("^^^ FormulaEditStateChanged. CurrentPrefix: " + _formulaEditWatcher.CurrentPrefix);
            if (_formulaEditWatcher.IsEditingFormula && _formulaEditWatcher.CurrentPrefix != null)
            {
                string prefix = _formulaEditWatcher.CurrentPrefix;
                var match = Regex.Match(prefix, @"^=(?<functionName>\w*)\(");
                if (match.Success)
                {
                    string functionName = match.Groups["functionName"].Value;

                    IntelliSenseFunctionInfo functionInfo;
                    if (_functionInfoMap.TryGetValue(functionName, out functionInfo))
                    {
                        // It's ours!
                        if (_argumentsToolTip == null)
                        {
                            _argumentsToolTip = new ToolTipForm(_windowWatcher.MainWindow);
                        }

                        // TODO: Fix this: Need to consider subformulae
                        int currentArgIndex = _formulaEditWatcher.CurrentPrefix.Count(c => c == ',');
                        _argumentsToolTip.ShowToolTip(
                            GetFunctionIntelliSense(functionInfo, currentArgIndex),
                            (int)_formulaEditWatcher.EditWindowBounds.Left, (int)_formulaEditWatcher.EditWindowBounds.Bottom + 5);
                        return;
                    }
                }
            }

            // All other paths, we just clear the box
            if (_argumentsToolTip != null)
                _argumentsToolTip.Hide();
        }