Exemplo n.º 1
0
        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();
                    }
                }
            }
        }
Exemplo n.º 2
0
        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();
                    }
                }
            }
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
        public static void GoToDefinition(string file, int pos)
        {
            NPP.OpenFile(file);
            int _line = GetLineFromPosition(pos);

            GoToLine(_line);
            //Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GOTOPOS, pos, 0);
            //NPP.GetCurrentWord2();
        }
Exemplo n.º 6
0
        public int AnalyseFile(String filePath)
        {
            m_Comment          = "";
            m_SlashStarComment = false;
            int _Ret = 0;

            if (!File.Exists(filePath))
            {
                return(-1);
            }

            string ext = Path.GetExtension(filePath).ToLower();

            if (string.IsNullOrEmpty(ext) || !ext.Equals(".seq"))    //only .seq files are parsed
            {
                return(-1);
            }
            m_Scope      = m_Model.GetRelativePath(filePath); // the sequence relative to project-dir
            m_IsClassDef = false;

            /* TODO
             * if (resource.getProjectRelativePath().segment(0).equalsIgnoreCase("SOURCE")) {
             *  m_IsClassDef = true;  //Version 1   its in //SOURCE//...
             * }
             * if (resource.getProjectRelativePath().segment(0).equalsIgnoreCase("APP")) {
             *  m_IsClassDef = true;   //Version 2    its in //APP//PLUGINS//...
             * }*/
            if (!m_IsClassDef)  //each SEQ includes itself
            {
                m_Model.UpdateObjList(new Obj(m_Scope, "", m_Scope, ""));
            }
            int levelCurrent = 0;
            int levelPrev    = -1;
            int lineNo       = 0;

            foreach (string _line in File.ReadAllLines(filePath))
            {
                evaluate(_line, lineNo);

                if (_line.Contains("{"))
                {
                    levelCurrent++;
                }
                if (_line.Contains("}"))
                {
                    levelCurrent--;
                }
                uint lev = (uint)levelPrev;
                NPP.SetFoldLevel(lineNo, lev, levelCurrent > levelPrev);  //Todo !!
                levelPrev = levelCurrent;
                lineNo++;
            }
            return(_Ret);
        }
Exemplo n.º 7
0
 public void Go()
 {
     if (Pos != -1)
     {
         NPP.GoToDefinition(File, Pos);
     }
     else
     {
         NPP.GoToDefinition(File, LineNo, Info);
     }
 }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 在项目管理树中 下划线显示所有打开的文件
        /// </summary>
        public static void UnderLineTreeView()
        {
            TreeView tv = Resource.ProjectTreeView;

            foreach (TreeNode node in tv.Nodes)
            {
                _ClearUnderLine(node);
            }

            foreach (string file in NPP.GetOpenedFiles())
            {
                UnderlineTreeNode(file);
            }
        }
Exemplo n.º 10
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();
            }
        }
Exemplo n.º 11
0
        /// <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;
                        //}
                    }
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 显示/隐藏 项目树
        /// </summary>
        internal static void ShowNppPIALexer2View()
        {
            if (FrmMain == null)
            {
                string path = Path.Combine(Config.Instance.NppPIALexer2Dir, "ctags.exe");
                if (!File.Exists(path))
                {
                    //??Utility.Error(@"Can't find '${Config}\NppPIALexer2\ctags.exe'.");
                    //??   return;
                }

                _RegisterTagParser();
                //??   TagParser.LoadExt2LangMapping();

                CommandManager.Load();

                FrmMain = new frmMain();

                // 设置状态栏图标
                using (Bitmap newBmp = new Bitmap(16, 16))
                {
                    Graphics   g        = Graphics.FromImage(newBmp);
                    ColorMap[] colorMap = new ColorMap[1];
                    colorMap[0]          = new ColorMap();
                    colorMap[0].OldColor = Color.White;
                    colorMap[0].NewColor = Color.FromKnownColor(KnownColor.ButtonFace);
                    ImageAttributes attr = new ImageAttributes();
                    attr.SetRemapTable(colorMap);
                    g.DrawImage(tbBmp_tbTab, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
                    tbIcon = Icon.FromHandle(newBmp.GetHicon());
                }

                NppTbData _nppTbData = new NppTbData();
                _nppTbData.hClient       = FrmMain.Handle;
                _nppTbData.pszName       = "NppPIALexer2";
                _nppTbData.dlgID         = IdFrmMain;
                _nppTbData.uMask         = NppTbMsg.DWS_DF_CONT_LEFT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR;
                _nppTbData.hIconTab      = (uint)tbIcon.Handle;
                _nppTbData.pszModuleName = PluginName;
                IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
                Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);

                Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);
                Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_SETMENUITEMCHECK, PluginBase._funcItems.Items[Main.IdFrmMain]._cmdID, 1);

                Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_AUTOCSETMAXHEIGHT, 15, 0);
                Win32.SendMessage(PluginBase.nppData._scintillaSecondHandle, SciMsg.SCI_AUTOCSETMAXHEIGHT, 15, 0);
                NPP.SetupFolding();
                // load Project
                foreach (Project proj in ProjectManager.Projects)
                {
                    FrmMain.BindProject(proj);
                }

                // Themen erstellen, Etiketten und Lesezeichen Überwachung von Änderungen
                TagUpdater.Work();
                TaskUpdater.Work();
                //BookmarkUpdater.Work();

                Utility.UnderLineTreeView();
            }
            else
            {
                if (FrmMain.Visible)
                {
                    Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMHIDE, 0, FrmMain.Handle);
                }
                else
                {
                    Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMSHOW, 0, FrmMain.Handle);
                    Utility.UnderLineTreeView();
                }
            }
        }
Exemplo n.º 13
0
        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);
                }
            }
        }
Exemplo n.º 14
0
        void RebuildObjList()
        {
            // add the basic types to Intelisense
            ObjDecl _A;

            for (int i = 0; i < BASIC_TYPES.Count; i++)
            {
                _A = new ObjDecl(BASIC_TYPES[i], ObjDecl.TClassType.tCTType, "", "", "", "", 0, 0);
                UpdateObjDecl(_A);
            }
            DateTime _start = DateTime.Now;
            //Log.getInstance().Add("collecting files ", Log.EnuSeverity.Info, "");
            Tokenizer _tokenizer = new Tokenizer();
            LinkedList <Tokenizer.Token> _Tokens = new LinkedList <Tokenizer.Token>();
            List <String> Dirs = new List <String>(); //stack of directories relative to _path
            int           k    = 0;

            try {
                String[] _SubProj = getSubProj();
                for (int i = 0; i < _SubProj.Length; i++)
                {
                    Dirs.Add(Path.Combine(m_ProjectDir, getSeqDir(_SubProj[i])));
                }

                while (k < Dirs.Count)
                {
                    FileInfo[] _files = new DirectoryInfo(Dirs[k]).GetFiles();
                    for (int i = 0; i < _files.Length; i++)
                    {
                        if (_files[i].Extension.Equals(".seq", StringComparison.OrdinalIgnoreCase))
                        {
                            _Tokens.AddLast(_tokenizer.TokenizeFile(_files[i].FullName));
                            NPP.SetFoldLevel(1, 1, true); //Todo !!
                            NPP.SetFoldLevel(2, 2, false);
                            NPP.SetFoldLevel(3, 2, false);
                            NPP.SetFoldLevel(4, 1, false);
                        }
                    }
                    DirectoryInfo[] _Dirs = new DirectoryInfo(Dirs[k]).GetDirectories();
                    for (int i = 0; i < _Dirs.Length; i++)
                    {
                        // If the file is a directory (or is in some way invalid) we'll skip it
                        Dirs.Insert(k + 1, _Dirs[i].FullName);
                    }
                    k++;
                }
                //Log.getInstance().Add("Tokenized all" , Log.EnuSeverity.Info, "");
                Parser2 _parser2 = new Parser2(this, m_ProjectDir);
                _parser2.ParseTokens(_Tokens);
                LinkedList <Parser2.Context.Log> .Enumerator _l = _parser2.GetLogs().GetEnumerator();
                while (_l.MoveNext())
                {
                    Log.getInstance().Add(_l.Current.m_Text, Log.EnuSeverity.Warn, _l.Current.m_Cmd.AsText());
                }
                //update database with parserresult
                LinkedList <Parser2.CmdBase> .Enumerator _Cmds;
                List <String> .Enumerator _Scopes = _parser2.GetScopes().GetEnumerator();
                while (_Scopes.MoveNext())
                {
                    //Log.getInstance().Add("write DB " + _Scopes.Current, Log.EnuSeverity.Info, "");
                    // if(!m_IsClassDef) {
                    { //each SEQ includes itself
                        this.UpdateObjList(new Obj(_Scopes.Current, "", _Scopes.Current, "", 0, 0));
                    }
                    _Cmds = _parser2.GetCmds(_Scopes.Current).GetEnumerator();
                    while (_Cmds.MoveNext())
                    {
                        PublishCmdToDB(_Scopes.Current, _Cmds.Current);
                    }
                }
                Log.getInstance().Add("Parsing done ", Log.EnuSeverity.Info, "");
            } catch (Exception ex) {
                Log.getInstance().Add(ex.Message, Log.EnuSeverity.Error, "");
            }
            finally {
            }
        }