예제 #1
0
파일: InfoToolTip.cs 프로젝트: massreuy/3P
        /// <summary>
        /// Method called when the tooltip is opened from the mouse being inactive on scintilla
        /// </summary>
        public static void ShowToolTipFromDwell(bool openTemporary = true)
        {
            if (Config.Instance.ToolTipDeactivate)
            {
                return;
            }
            InitIfneeded();

            var position = Sci.GetPositionFromMouseLocation();

            if (position < 0)
            {
                return;
            }

            // check caret context, dont display a tooltip for comments
            var curContext = (UdlStyles)Sci.GetStyleAt(position);

            if (curContext == UdlStyles.Comment || curContext == UdlStyles.Delimiter8)
            {
                return;
            }

            // sets the tooltip content
            var data = AutoCompletion.FindInCompletionData(Sci.GetWordAtPosition(position, AutoCompletion.CurrentLangAllChars, AutoCompletion.CurrentLangAdditionalChars), Sci.LineFromPosition(position));

            if (data != null && data.Count > 0)
            {
                _currentCompletionList = data;
            }
            else
            {
                return;
            }

            // in strings, only functions trigger the tooltip
            if ((curContext == UdlStyles.Delimiter1 || curContext == UdlStyles.Delimiter2 || curContext == UdlStyles.Delimiter4 || curContext == UdlStyles.Delimiter5) && _currentCompletionList.First().Type != CompletionType.Function)
            {
                return;
            }

            SetToolTip();

            // update position
            var point = Sci.GetPointXyFromPosition(position);

            point.Offset(Sci.GetScintillaRectangle().Location);
            var lineHeight = Sci.TextHeight(Sci.Line.CurrentLine);

            point.Y       += lineHeight + 5;
            _form.Location = _form.GetBestAutocompPosition(point, lineHeight + 5);

            _openedFromDwell = openTemporary;
            if (!_form.Visible)
            {
                _form.UnCloak();
            }
        }
예제 #2
0
        public override string ToString()
        {
            var toDisplay = new StringBuilder();

            toDisplay.Append(HtmlHelper.FormatRow("Type of keyword", HtmlHelper.FormatSubString(SubText)));

            // for abbreviations, find the complete keyword first
            string keyword = DisplayText;

            if (!string.IsNullOrEmpty(_fullWord))
            {
                toDisplay.Append(HtmlHelper.FormatRow("Abbreviation of", HtmlHelper.FormatSubString(FullWord)));
            }

            string keyToFind = string.Join(" ", DisplayText, KeywordType);

            // for the keywords define and create, we try to match the second keyword that goes with it
            if (KeywordType == KeywordType.Statement && (keyword.EqualsCi("define") || keyword.EqualsCi("create")))
            {
                var lineStr        = Sci.GetLine(Sci.LineFromPosition(Sci.GetPositionFromMouseLocation())).LineText;
                var listOfSecWords = new List <string> {
                    "ALIAS", "BROWSE", "BUFFER", "BUTTON", "CALL", "CLIENT-PRINCIPAL", "DATA-SOURCE", "DATABASE", "DATASET", "EVENT", "FRAME", "IMAGE", "MENU", "PARAMETER", "PROPERTY", "QUERY", "RECTANGLE", "SAX-ATTRIBUTES", "SAX-READER", "SAX-WRITER", "SERVER", "SERVER-SOCKET", "SOAP-HEADER", "SOAP-HEADER-ENTRYREF", "SOCKET", "STREAM", "SUB-MENU", "TEMP-TABLE", "VARIABLE", "WIDGET-POOL", "WORK-TABLE", "WORKFILE", "X-DOCUMENT", "X-NODEREF"
                };
                foreach (var word in listOfSecWords)
                {
                    if (lineStr.ContainsFast(word))
                    {
                        keyToFind = string.Join(" ", keyword, word, KeywordType);
                        break;
                    }
                }
            }

            var dataHelp = Keywords.Instance.GetKeywordHelp(keyToFind);

            if (dataHelp != null)
            {
                toDisplay.Append(HtmlHelper.FormatSubtitle("DESCRIPTION"));
                toDisplay.Append(dataHelp.Description);

                // synthax
                if (dataHelp.Synthax.Count >= 1 && !string.IsNullOrEmpty(dataHelp.Synthax[0]))
                {
                    toDisplay.Append(HtmlHelper.FormatSubtitle("SYNTAX"));
                    toDisplay.Append(@"<div class='ToolTipcodeSnippet'>");
                    var i = 0;
                    foreach (var synthax in dataHelp.Synthax)
                    {
                        if (i > 0)
                        {
                            toDisplay.Append(@"<br>");
                        }
                        toDisplay.Append(synthax);
                        i++;
                    }
                    toDisplay.Append(@"</div>");
                }
            }
            else
            {
                toDisplay.Append(HtmlHelper.FormatSubtitle("404 NOT FOUND"));
                if (KeywordType == KeywordType.Option)
                {
                    toDisplay.Append("<i><b>Sorry, this keyword doesn't have any help associated</b><br>Since this keyword is an option, try to hover the first keyword of the statement or refer to the 4GL help</i>");
                }
                else
                {
                    toDisplay.Append("<i><b>Sorry, this keyword doesn't have any help associated</b><br>Please refer to the 4GL help</i>");
                }
            }

            return(toDisplay.ToString());
        }
예제 #3
0
        /// <summary>
        /// This method allows the user to GOTO a word definition, if a tooltip is opened then it tries to
        /// go to the definition of the displayed word, otherwise it tries to find the declaration of the parsed word under the
        /// caret. At last, it tries to find a file in the propath
        /// </summary>
        public static void GoToDefinition(bool fromMouseClick)
        {
            // if a tooltip is opened, try to execute the "go to definition" of the tooltip first
            if (InfoToolTip.InfoToolTip.IsVisible)
            {
                if (!string.IsNullOrEmpty(InfoToolTip.InfoToolTip.GoToDefinitionFile))
                {
                    Npp.Goto(InfoToolTip.InfoToolTip.GoToDefinitionFile, InfoToolTip.InfoToolTip.GoToDefinitionPoint.X, InfoToolTip.InfoToolTip.GoToDefinitionPoint.Y);
                    InfoToolTip.InfoToolTip.Cloak();
                    return;
                }
                InfoToolTip.InfoToolTip.Cloak();
            }

            // try to go to the definition of the selected word
            var position = fromMouseClick ? Sci.GetPositionFromMouseLocation() : Sci.CurrentPosition;

            if (fromMouseClick && position <= 0)
            {
                return;
            }
            var curWord = Sci.GetWordAtPosition(position, AutoCompletion.CurrentLangAdditionalChars);

            if (string.IsNullOrEmpty(curWord))
            {
                return;
            }

            // match a word in the autocompletion? go to definition
            var listKeywords = AutoCompletion.FindInCompletionData(curWord, Sci.LineFromPosition(position));

            if (listKeywords != null)
            {
                var listItems = listKeywords.Where(item => item.FromParser && item.ParsedBaseItem is ParsedItem).ToList();
                if (listItems.Count > 0)
                {
                    // only one match, then go to the definition
                    if (listItems.Count == 1)
                    {
                        var pItem = listItems.First().ParsedBaseItem as ParsedItem;
                        if (pItem != null)
                        {
                            Npp.Goto(pItem.FilePath, pItem.Line, pItem.Column);
                            return;
                        }
                    }
                    if (listItems.Count > 1)
                    {
                        // otherwise, list the items and notify the user
                        var output = new StringBuilder(@"Found several matching items, please choose the correct one :<br>");
                        foreach (var cData in listItems)
                        {
                            var pItem = listItems.First().ParsedBaseItem as ParsedItem;
                            if (pItem != null)
                            {
                                output.Append("<div>" + (pItem.FilePath + "|" + pItem.Line + "|" + pItem.Column).ToHtmlLink("In " + Path.GetFileName(pItem.FilePath) + " (line " + pItem.Line + ")"));
                                cData.DoForEachFlag((s, flag) => { output.Append("<img style='padding-right: 0px; padding-left: 5px;' src='" + s + "' height='15px'>"); });
                                output.Append("</div>");
                            }
                        }
                        UserCommunication.NotifyUnique("GoToDefinition", output.ToString(), MessageImg.MsgQuestion, "Question", "Go to the definition", args => {
                            Utils.OpenPathClickHandler(null, args);
                            UserCommunication.CloseUniqueNotif("GoToDefinition");
                        }, 0, 500);
                        return;
                    }
                }
            }

            // last resort, try to find a matching file in the propath

            // if in a string, read the whole string

            // try to read all the . and \

            // first look in the propath
            var fullPaths = ProEnvironment.Current.FindFiles(curWord, Config.Instance.FilesPatternProgress.Replace("*", ""));

            if (fullPaths.Count > 0)
            {
                if (fullPaths.Count > 1)
                {
                    var output = new StringBuilder(@"Found several files matching this name, please choose the correct one :<br>");
                    foreach (var fullPath in fullPaths)
                    {
                        output.Append("<div>" + fullPath.ToHtmlLink() + "</div>");
                    }
                    UserCommunication.NotifyUnique("GoToDefinition", output.ToString(), MessageImg.MsgQuestion, "Question", "Open a file", args => {
                        Npp.Goto(args.Link);
                        UserCommunication.CloseUniqueNotif("GoToDefinition");
                        args.Handled = true;
                    }, 0, 500);
                }
                else
                {
                    Npp.Goto(fullPaths[0]);
                }
                return;
            }

            UserCommunication.Notify("Sorry, couldn't go to the definition of <b>" + curWord + "</b>", MessageImg.MsgInfo, "Information", "Failed to find an origin", 5);
        }