Beispiel #1
0
        /// <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();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Opens the lgrfeng.chm file if it can find it in the config
        /// </summary>
        public static void Open4GlHelp()
        {
            var helpPath = Config.Instance.GlobalHelpFilePath;

            // Try to find the help file from the prowin32.exe location
            if (File.Exists(ProEnvironment.Current.ProwinExePath))
            {
                var versionHelpPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(ProEnvironment.Current.ProwinExePath) ?? "", "..", "prohelp", "lgrfeng.chm"));
                if (File.Exists(versionHelpPath))
                {
                    helpPath = versionHelpPath;
                }
            }

            // set path in config
            if (string.IsNullOrEmpty(Config.Instance.GlobalHelpFilePath))
            {
                if (!string.IsNullOrEmpty(helpPath))
                {
                    Config.Instance.GlobalHelpFilePath = helpPath;
                    UserCommunication.Notify("I've found an help file here :<br>" + helpPath.ToHtmlLink() + "<br>If you think this is incorrect, you can change the help file path in the settings", MessageImg.MsgInfo, "Opening 4GL help", "Found help file", 10);
                }
            }

            if (string.IsNullOrEmpty(helpPath) || !File.Exists(helpPath) || !Path.GetExtension(helpPath).EqualsCi(".chm"))
            {
                UserCommunication.Notify("Could not access the help file, please be sure to provide a valid path the the file <b>lgrfeng.chm</b> in the settings window", MessageImg.MsgInfo, "Opening help file", "File not found", 10);
                return;
            }

            if (!helpPath.Equals(Config.Instance.GlobalHelpFilePath) && !string.IsNullOrEmpty(Config.Instance.GlobalHelpFilePath))
            {
                UserCommunication.Notify("Found a different help file for you version of prowin.exe, the following file will be used :<br>" + helpPath.ToHtmlLink(), MessageImg.MsgInfo, "Help file", "New file used", 5);
            }

            // if a tooltip is opened, we search for the displayed word, otherwise take the word at caret
            string searchWord = null;

            if (InfoToolTip.InfoToolTip.IsVisible && !string.IsNullOrEmpty(InfoToolTip.InfoToolTip.CurrentWord))
            {
                searchWord = InfoToolTip.InfoToolTip.CurrentWord;
            }

            HtmlHelpInterop.DisplayIndex(0, helpPath, searchWord ?? Sci.GetWordAtPosition(Sci.CurrentPosition, AutoCompletion.CurrentLangAdditionalChars));
        }
Beispiel #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);
        }
Beispiel #4
0
        static public bool NavigateToNextParam()
        {
            var indic = Sci.GetIndicator(SnippetContext.IndicatorId);

            indic.IndicatorStyle = IndicatorStyle.Box;
            indic.ForeColor      = Color.Blue;

            var indicators = indic.FindRanges().ToArray();

            if (!indicators.Any())
            {
                return(false);
            }

            if (LocSnippetContext.CurrentParameter != null)
            {
                Point  currentParam             = LocSnippetContext.CurrentParameter.Value;
                string currentParamOriginalText = LocSnippetContext.CurrentParameterValue;

                Sci.SetSelection(currentParam.X, currentParam.X);
                string currentParamDetectedText = Sci.GetWordAtPosition(Sci.CurrentPosition, AutoCompletion.CurrentLangAdditionalChars);

                if (currentParamOriginalText != currentParamDetectedText)
                {
                    //current parameter is modified, indicator is destroyed so restore the indicator first
                    indic.Add(currentParam.X, currentParam.X + currentParamDetectedText.Length);

                    indicators = indic.FindRanges().ToArray(); //needs refreshing as the document is modified

                    var paramsInfo = indicators.Select(p => new {
                        Index = indicators.IndexOf(p),
                        Text  = Sci.GetTextBetween(p),
                        Range = p,
                        Pos   = p.X
                    })
                                     .OrderBy(x => x.Pos)
                                     .ToArray();

                    var paramsToUpdate = paramsInfo.Where(item => item.Text == currentParamOriginalText).ToArray();

                    foreach (var param in paramsToUpdate)
                    {
                        ReplaceTextAtIndicator(currentParamDetectedText, indicators[param.Index]);
                        indicators = indic.FindRanges().ToArray(); //needs refreshing as the document is modified
                    }
                }

                Point?nextParameter = null;

                int currentParamIndex = indicators.FindIndex(x => x.X >= currentParam.X); //can also be logical 'next'
                var prevParamsValues  = indicators.Take(currentParamIndex).Select(p => Sci.GetTextBetween(p)).ToList();
                prevParamsValues.Add(currentParamOriginalText);
                prevParamsValues.Add(currentParamDetectedText);
                prevParamsValues.Add(" ");
                prevParamsValues.Add("|");

                foreach (var range in indicators.ToArray())
                {
                    if (currentParam.X < range.X && !prevParamsValues.Contains(Sci.GetTextBetween(range)))
                    {
                        nextParameter = range;
                        break;
                    }
                }

                if (!nextParameter.HasValue)
                {
                    nextParameter = indicators.FirstOrDefault();
                }

                LocSnippetContext.CurrentParameter = nextParameter;
            }
            if (LocSnippetContext.CurrentParameter.HasValue)
            {
                Sci.SetSelection(LocSnippetContext.CurrentParameter.Value.X, LocSnippetContext.CurrentParameter.Value.Y);
                LocSnippetContext.CurrentParameterValue = Sci.GetTextBetween(LocSnippetContext.CurrentParameter.Value);
            }

            return(true);
        }