Exemple #1
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();
                }
            }
        }
Exemple #2
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);
                }
            }
        }