internal static void JumpForward() { if (FrmMain == null) { ShowNppPIALexer2View(); } Jump cur = Jump.Cursor; if (cur != null) { string file = NPP.GetCurrentFile(); int line = NPP.GetCurrentLine(); if (file != cur.File || line != cur.LineNo) { cur.Go(); } else { Jump fard = Jump.Forward; if (fard != null) { fard.Go(); } } } }
internal static void JumpBack() { if (FrmMain == null) { ShowNppPIALexer2View(); } Jump cur = Jump.Cursor; if (cur != null) { string file = NPP.GetCurrentFile(); // After entering the function, the cursor changes and goes back to the function int line = NPP.GetCurrentPosition(); //?? .GetCurrentLine(); if (file != cur.File || line != cur.Pos) //??.LineNo) Todo LineNo is not properly set when jumping { cur.Go(); } else // After entering the function, the cursor does not leave the current line and returns to the previous position { Jump back = Jump.Back; if (back != null) { back.Go(); } } } }
public void Execute() { Project project = (Resource.ProjectTreeView.SelectedNode.Tag as ProjectItem).Project; string activeFile = NPP.GetCurrentFile(); string initDir = InitDir; initDir = initDir.Replace("$(ProjectDir)", project.BaseDir); initDir = initDir.Replace("$(ActiveFileDir)", Path.GetDirectoryName(activeFile)); string args = Args; args = args.Replace("$(ProjectDir)", project.BaseDir); args = args.Replace("$(ProjectFile)", project.ProjectFile); args = args.Replace("$(ProjectName)", project.Root.Name); args = args.Replace("$(ActiveFile)", activeFile); args = args.Replace("$(ActiveFileDir)", Path.GetDirectoryName(activeFile)); args = args.Replace("$(ActiveFileName)", Path.GetFileName(activeFile)); Process p = new Process(); p.StartInfo.WorkingDirectory = initDir; p.StartInfo.FileName = Cmd; p.StartInfo.Arguments = args; p.StartInfo.WindowStyle = ProcessWindowStyle.Normal; p.StartInfo.CreateNoWindow = false; p.StartInfo.UseShellExecute = false; p.Start(); }
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; }
/// <summary> /// 智能提示 /// </summary> /// <param name="enfocus"></param> internal static void ShowAutoCompletion(bool enfocus) { if (FrmMain == null) { ShowNppPIALexer2View(); } string curFile = NPP.GetCurrentFile(); string ext = Path.GetExtension(curFile); //TagParser.Ext2Lang.TryGetValue(ext, out lang); //??if (Utility.IsAllowedAutoCompletion(lang)) if (ext.Equals(ModelDocument.FileExtension, StringComparison.OrdinalIgnoreCase)) { Project proj = ProjectManager.GetProjectByItsFile(curFile); if (proj != null) { string word = NPP.GetCurrentWord(); string line = NPP.GetLine(NPP.GetCurrentLine()); if (word.Length >= 2) { List <NppPIALexer2.ObjDecl> lst = proj.Model.lookupAll(word, line, proj.Model.GetRelativePath(curFile)); //proj.Model.GetObjects(word, curFile, "", out lst); if (enfocus || lst.Count > 0) //&& !_IsEqual(lst)) { NPP.ShowAutoCompletion(word.Length, lst); } //_Last = lst; //if (lst.Count > 0) //{ // if (focus) // NPP.ShowAutoCompletion(word.Length, lst); // else // { // if (!_IsEqual(lst)) // { // NPP.ShowAutoCompletion(word.Length, lst); // } // } //} //_Last = lst; //if (lst.Count > 0) //{ // if (_LastWord != lst[0] || _Count != lst.Count) // { // _LastWord = lst[0]; // _Count = lst.Count; // NPP.ShowAutoCompletion(word.Length, lst); // } //} //else //{ // _LastWord = ""; // _Count = 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); } }
static void beNotified(IntPtr notifyCode) { SCNotification nc = (SCNotification)Marshal.PtrToStructure(notifyCode, typeof(SCNotification)); if (nc.nmhdr.code == (uint)NppMsg.NPPN_TBMODIFICATION) { PluginBase._funcItems.RefreshItems(); Main.SetToolBarIcon(); Main.InitNppPIALexer2(); } else if (nc.nmhdr.code == (uint)NppMsg.NPPN_SHUTDOWN) { Main.PluginCleanUp(); Marshal.FreeHGlobal(_ptrPluginName); } else { // open NppPIALexer2 file if ((NppMsg)nc.nmhdr.code == NppMsg.NPPN_FILEOPENED) { StringBuilder sb = new StringBuilder(Win32.MAX_PATH); if ((int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETFULLPATHFROMBUFFERID, (int)nc.nmhdr.idFrom, sb) != -1) { string path = sb.ToString(); if (Path.GetExtension(path).ToLower() == ".nppproj") { if (Main.FrmMain == null) { Main.ShowNppPIALexer2View(); } Main.FrmMain.OpenProject(path); NPP.CloseFile(path); return; } } } if (Main.FrmMain == null) { return; } try { switch ((NppMsg)nc.nmhdr.code) { case NppMsg.NPPN_FILEOPENED: // 项目中已打开的文件名加下划线 { if (Main.FrmMain.Visible) { StringBuilder sb = new StringBuilder(Win32.MAX_PATH); if ((int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETFULLPATHFROMBUFFERID, (int)nc.nmhdr.idFrom, sb) != -1) { string path = sb.ToString(); Utility.UnderlineTreeNode(path); } } break; } case NppMsg.NPPN_FILEBEFORECLOSE: // 项目文件关闭时,取消下划线 { string file = NPP.GetCurrentFile(); if (Main.FrmMain.Visible) { Utility.UnUnderlineTreeNode(file); } } break; case NppMsg.NPPN_BUFFERACTIVATED: // Highlight current Active file { StringBuilder sb = new StringBuilder(Win32.MAX_PATH); if ((int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETFULLPATHFROMBUFFERID, (int)nc.nmhdr.idFrom, sb) != -1) { string file = sb.ToString(); Utility.HighlightActiveTreeNode(file); //ProjectItem item = ProjectManager.GetProjectItemByFile(file); //if (item != null && item.Bookmarks.Count > 0) // 设置书签 //{ // foreach (Bookmark book in item.Bookmarks) // NPP.SetBookmark(book.LineNo); //} } } break; case NppMsg.NPPN_FILESAVED: // 有文件更新保存时,更新ctag标签 { StringBuilder sb = new StringBuilder(Win32.MAX_PATH); if ((int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETFULLPATHFROMBUFFERID, (int)nc.nmhdr.idFrom, sb) != -1) { string path = sb.ToString(); int index = ProjectManager.GetProjectIndex(path); if (index != -1) { //AutoCompletionHelper.SetUpdateFlag(proj.ProjectFile); TagUpdater.Update(index, path); TaskUpdater.Update(path); } } } break; } switch ((SciMsg)nc.nmhdr.code) { case SciMsg.SCN_CHARADDED: // 智能提示 case SciMsg.SCN_AUTOCCHARDELETED: //case SciMsg.SCN_AUTOCCANCELLED: { if (Config.Instance.AutoCompletion) { Main.ShowAutoCompletion(SciMsg.SCN_AUTOCCHARDELETED == (SciMsg)nc.nmhdr.code); } } break; case SciMsg.SCN_MARGINCLICK: int line = NPP.GetLineFromPosition(nc.position); NPP.ToggleFold(line); break; } } catch (Exception ex) { Utility.Debug("{0}: {1}", ex.Message, ex.StackTrace); } } }