Exemplo n.º 1
0
        FormattedText GetFunctionIntelliSense(FunctionInfo functionInfo, int currentArgIndex)
        {
            var nameLine = new TextLine {
                new TextRun {
                    Text = functionInfo.Name, LinkAddress = FixHelpTopic(functionInfo.HelpTopic)
                }
            };

            nameLine.Add(new TextRun {
                Text = "("
            });
            if (functionInfo.ArgumentList.Count > 0)
            {
                var argNames = functionInfo.ArgumentList.Take(currentArgIndex).Select(arg => arg.Name).ToArray();
                if (argNames.Length >= 1)
                {
                    nameLine.Add(new TextRun {
                        Text = string.Join(_argumentSeparator, argNames)
                    });
                }

                if (functionInfo.ArgumentList.Count > currentArgIndex)
                {
                    if (argNames.Length >= 1)
                    {
                        nameLine.Add(new TextRun
                        {
                            Text = _argumentSeparator
                        });
                    }

                    nameLine.Add(new TextRun
                    {
                        Text  = functionInfo.ArgumentList[currentArgIndex].Name,
                        Style = System.Drawing.FontStyle.Bold
                    });

                    argNames = functionInfo.ArgumentList.Skip(currentArgIndex + 1).Select(arg => arg.Name).ToArray();
                    if (argNames.Length >= 1)
                    {
                        nameLine.Add(new TextRun {
                            Text = _argumentSeparator + string.Join(_argumentSeparator, argNames)
                        });
                    }
                }
            }
            nameLine.Add(new TextRun {
                Text = ")"
            });

            var descriptionLines = GetFunctionDescriptionOrNull(functionInfo);

            var formattedText = new FormattedText {
                nameLine, descriptionLines
            };

            if (functionInfo.ArgumentList.Count > currentArgIndex)
            {
                var description = GetArgumentDescriptionOrNull(functionInfo.ArgumentList[currentArgIndex]);
                if (description != null)
                {
                    formattedText.Add(description);
                }
            }

            return(formattedText);
        }
        FormattedText GetFunctionIntelliSense(FunctionInfo functionInfo, int currentArgIndex)
        {
            // In case of the special params pattern (x, y, arg1, ...) we base the argument display on an expanded argument list, matching Excel's behaviour,
            // and the magic expansion in the function wizard.
            var argumentList = GetExpandedArgumentList(functionInfo, currentArgIndex);

            var nameLine = new TextLine {
                new TextRun {
                    Text = functionInfo.Name, LinkAddress = FixHelpTopic(functionInfo.HelpTopic)
                }
            };

            nameLine.Add(new TextRun {
                Text = "("
            });
            if (argumentList.Count > 0)
            {
                var argNames = argumentList.Take(currentArgIndex).Select(arg => arg.Name).ToArray();
                if (argNames.Length >= 1)
                {
                    nameLine.Add(new TextRun {
                        Text = string.Join(_argumentSeparator, argNames)
                    });
                }

                if (argumentList.Count > currentArgIndex)
                {
                    if (argNames.Length >= 1)
                    {
                        nameLine.Add(new TextRun
                        {
                            Text = _argumentSeparator
                        });
                    }

                    nameLine.Add(new TextRun
                    {
                        Text  = argumentList[currentArgIndex].Name,
                        Style = System.Drawing.FontStyle.Bold
                    });

                    argNames = argumentList.Skip(currentArgIndex + 1).Select(arg => arg.Name).ToArray();
                    if (argNames.Length >= 1)
                    {
                        nameLine.Add(new TextRun {
                            Text = _argumentSeparator + string.Join(_argumentSeparator, argNames)
                        });
                    }
                }
            }
            nameLine.Add(new TextRun {
                Text = ")"
            });

            var descriptionLines = GetFunctionDescriptionOrNull(functionInfo);

            var formattedText = new FormattedText {
                nameLine, descriptionLines
            };

            if (argumentList.Count > currentArgIndex)
            {
                var description = GetArgumentDescription(argumentList[currentArgIndex]);
                formattedText.Add(description);
            }

            return(formattedText);
        }