Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
0
        static void _Work()
        {
            List <string> addedFile = new List <string>();

            foreach (Project project in ProjectManager.Projects)
            {
                List <string> t = new List <string>();
                foreach (string file in project.Root.SubFiles2)
                {
                    var tasks = _GetTask(file);
                    if (tasks != null && tasks.Count > 0)
                    {
                        t.Add(file);
                        _Cache[file] = tasks;
                    }

                    // Unload items during loading
                    if (ProjectManager.GetProjectIndex(project) == -1)
                    {
                        foreach (string f in t)
                        {
                            if (_Cache.ContainsKey(file))
                            {
                                _Cache.Remove(file);
                            }
                        }
                        t.Clear();
                        break;
                    }
                }
                if (t.Count > 0)
                {
                    addedFile.AddRange(t);
                }
            }
            if (addedFile.Count > 0 && TaskChanged != null)
            {
                foreach (string file in addedFile)
                {
                    TaskChanged(file, _Cache[file]);
                }
            }


            while (true)
            {
                DateTime current = DateTime.Now;

                try
                {
                    Dictionary <string, int> r = null;
                    Dictionary <string, int> u = null;
                    lock (typeof(TaskUpdater))
                    {
                        r             = _RemovedFiles;
                        _RemovedFiles = new Dictionary <string, int>();
                        u             = _UpdatedFiles;
                        _UpdatedFiles = new Dictionary <string, int>();
                    }
                    foreach (string file in r.Keys)
                    {
                        if (_Cache.ContainsKey(file))
                        {
                            _Cache.Remove(file);
                        }
                    }

                    List <string> updatedFiles = new List <string>();
                    foreach (string file in u.Keys)
                    {
                        var tasks = _GetTask(file);
                        if (_Cache.ContainsKey(file))
                        {
                            var oldTasks = _Cache[file];
                            if (!_IsEqual(tasks, oldTasks))
                            {
                                _Cache[file] = tasks;
                                updatedFiles.Add(file);
                            }
                        }
                        else
                        {
                            _Cache[file] = _GetTask(file);
                            updatedFiles.Add(file);
                        }
                    }

                    if (TaskChanged != null)
                    {
                        foreach (string file in r.Keys)
                        {
                            TaskChanged(file, null);
                        }
                        foreach (string file in updatedFiles)
                        {
                            TaskChanged(file, _Cache[file]);
                        }
                    }
                }
                catch
                {
                }

                var d = DateTime.Now - current;
                if (d.TotalSeconds < 1)
                {
                    Thread.Sleep((int)(1 - d.TotalSeconds) * 1000);
                }
            }
        }