Ejemplo n.º 1
0
        public static void Add(string info, string file, int pos)
        {
            if (!System.IO.File.Exists(file))
            {
                return;
            }

            Jump oldPos = new Jump(NPP.GetCurrentWord2(), NPP.GetCurrentFile(), NPP.GetCurrentLine(), NPP.GetCurrentPosition());

            if (oldPos.Info == "")
            {
                oldPos.Info = string.Format("line-{0}", oldPos.LineNo + 1);
            }

            Jump newPos = new Jump(info, file, 0, pos);

            while (_JumpList.Count > _Cursor + 1 ||
                   _JumpList.Count > 0 && _JumpList[_JumpList.Count - 1].File == file && _JumpList[_JumpList.Count - 1].Pos == pos)
            {
                _JumpList.RemoveAt(_JumpList.Count - 1);
            }

            if (_JumpList.Count == 0 || _JumpList.Count > 0 && (_JumpList[_JumpList.Count - 1].LineNo != oldPos.LineNo || _JumpList[_JumpList.Count - 1].File != oldPos.File))
            {
                _JumpList.Add(oldPos);
            }
            _JumpList.Add(newPos);

            while (_JumpList.Count > 20)    // Keep up to 20 items
            {
                _JumpList.RemoveAt(0);
            }
            _Cursor = _JumpList.Count - 1;
        }
Ejemplo n.º 2
0
        internal static void GotoDefinition()
        {
            if (FrmMain == null)
            {
                ShowNppPIALexer2View();
            }

            string      tagName = NPP.GetCurrentWord2();
            List <ITag> lst     = TagCache.SearchTag(tagName, TagParser.GetDefaultLang(NPP.GetCurrentFile()));

            if (lst.Count == 0)
            {
                return;
            }

            if (lst.Count == 1)
            {
                Jump.Add(tagName, lst[0].SourceFile, lst[0].LineNo - 1);
                //NPP.GoToDefinition(lst[0].SourceFile, lst[0].LineNo - 1, lst[0].TagName);
                Jump.Cursor.Go();
            }
            else
            {
                if (_ctntGoToDefinition == null)
                {
                    _ctntGoToDefinition = new ContextMenuStrip();
                }

                Point pos = NPP.GetCurrentPoint();
                _ctntGoToDefinition.Items.Clear();
                foreach (ITag tag in lst)
                {
                    string            txt  = string.Format("{0}    [{1}] {2}", tag.FullName, tag.LineNo, tag.SourceFile);
                    ToolStripMenuItem item = new ToolStripMenuItem(txt);
                    item.Tag         = tag;
                    item.ToolTipText = tag.Signature;
                    _ctntGoToDefinition.Items.Add(item);
                    item.Click += new EventHandler(delegate(object src, EventArgs ex)
                    {
                        ToolStripMenuItem i = src as ToolStripMenuItem;
                        if (i != null)
                        {
                            var t = item.Tag as ITag;
                            Jump.Add(t.TagName, t.SourceFile, t.LineNo - 1);
                            Jump.Cursor.Go();
                            //NPP.GoToDefinition(t.SourceFile, t.LineNo - 1, t.TagName);
                        }
                    });
                }
                _ctntGoToDefinition.Show(pos);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Go to function definition
        /// </summary>
        /// <param name="file"></param>
        /// <param name="lineNo">行号,从0开始</param>
        /// <param name="tagName"></param>
        public static void GoToDefinition(string file, int lineNo, string tagName)
        {
            GoToLine(file, lineNo);
            int startPos = (int)Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_POSITIONFROMLINE, lineNo, 0);
            int endPos   = (int)Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_POSITIONFROMLINE, lineNo + 1, 0);

            if (endPos <= startPos)
            {
                return;
            }
            Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_SETTARGETSTART, startPos, 0);
            Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_SETTARGETEND, endPos, 0);
            int pos = (int)Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_SEARCHINTARGET, tagName.Length, tagName);

            if (pos != -1)
            {
                Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GOTOPOS, pos, 0);
                //Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GRABFOCUS, 0, 0);
                NPP.GetCurrentWord2();
            }
        }