Exemplo n.º 1
0
 internal TextMonitor(PluginBase pluginBase)
 {
     this.pluginBase = pluginBase;
     GetEOL();
     GetTabs();
     endsRegex = new Regex(@"^(\s*)(if[ \(]|unless[ \(]|class |begin|def )");
 }
Exemplo n.º 2
0
        internal static string GetCurrentFileText(int length = -1)
        {
            if (length == -1)
            {
                length = Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GETLENGTH, 0, 0).ToInt32();
            }

            var text = new StringBuilder(length + 1);

            Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GETTEXT, length + 1, text);

            return(text.ToString());
        }
Exemplo n.º 3
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();
            }
            else if (nc.nmhdr.code == (uint)NppMsg.NPPN_SHUTDOWN)
            {
                PluginBase.PluginCleanUp();
                Marshal.FreeHGlobal(_ptrPluginName);
            }
        }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            int line;

            if (!int.TryParse(textBox1.Text, out line))
            {
                return;
            }
            IntPtr curScintilla = PluginBase.GetCurrentScintilla();

            Win32.SendMessage(curScintilla, SciMsg.SCI_ENSUREVISIBLE, line - 1, 0);
            Win32.SendMessage(curScintilla, SciMsg.SCI_GOTOLINE, line - 1, 0);
            Win32.SendMessage(curScintilla, SciMsg.SCI_GRABFOCUS, 0, 0);
        }
        public void bufferChanged()
        {
            IntPtr curScintilla = IntPtr.Zero;

            try
            {
                // Get current filename
                StringBuilder path = new StringBuilder(Win32.MAX_PATH);
                Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETFULLCURRENTPATH, 0, path);

                // initialize CommentFile
                file.FileName = String.Format("{0}.ano", path.ToString());

                file.LoadComments();

                bindComments();

                // highlight all comments
                curScintilla = PluginBase.GetCurrentScintilla();

                foreach (Comment comment in file.Comments)
                {
                    // get selection start and end from comment
                    int selectionStartLine = comment.StartLine;
                    int selectionStartCol  = comment.StartColumn;
                    int selectionEndLine   = comment.EndLine;
                    int selectionEndCol    = comment.EndColumn;

                    // convert to position
                    int selectionStartPos = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_POSITIONFROMLINE, selectionStartLine, 0) + selectionStartCol;
                    int selectionEndPos   = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_POSITIONFROMLINE, selectionEndLine, 0) + selectionEndCol;

                    // Highlight
                    Win32.SendMessage(curScintilla, SciMsg.SCI_INDICSETSTYLE, 20, 7);
                    Win32.SendMessage(curScintilla, SciMsg.SCI_INDICSETFORE, 20, 0x00FFFF);
                    Win32.SendMessage(curScintilla, SciMsg.SCI_INDICSETALPHA, 20, 32);
                    Win32.SendMessage(curScintilla, SciMsg.SCI_SETINDICATORCURRENT, 20, 0);
                    Win32.SendMessage(curScintilla, SciMsg.SCI_INDICATORFILLRANGE, selectionStartPos, selectionEndPos - selectionStartPos);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Marshal.Release(curScintilla);
            }
        }
Exemplo n.º 6
0
        internal static void CommandMenuInit()
        {
            StringBuilder sbIniFilePath = new StringBuilder(Win32.MAX_PATH);

            Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, sbIniFilePath);
            iniFilePath = sbIniFilePath.ToString();
            if (!Directory.Exists(iniFilePath))
            {
                Directory.CreateDirectory(iniFilePath);
            }
            iniFilePath = Path.Combine(iniFilePath, PluginName + ".ini");
            someSetting = (Win32.GetPrivateProfileInt("SomeSection", "SomeKey", 0, iniFilePath) != 0);

            PluginBase.SetCommand(0, "Code Annotation Dock", myDockableDialog); idMyDlg = 1;
            PluginBase.SetCommand(1, "About this plugin", myMenuFunction, new ShortcutKey(false, false, false, Keys.None));
        }
        private void btnAddComment_Click(object sender, EventArgs e)
        {
            IntPtr curScintilla = IntPtr.Zero;

            try
            {
                curScintilla = PluginBase.GetCurrentScintilla();

                int selectionStartPos = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_GETSELECTIONSTART, 0, 0);
                int selectionEndPos   = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_GETSELECTIONEND, 0, 0);

                int selectionStartLine = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_LINEFROMPOSITION, selectionStartPos, 0);
                int selectionEndLine   = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_LINEFROMPOSITION, selectionEndPos, 0);

                int selectionStartCol = selectionStartPos - (int)Win32.SendMessage(curScintilla, SciMsg.SCI_POSITIONFROMLINE, selectionStartLine, 0);
                int selectionEndCol   = selectionEndPos - (int)Win32.SendMessage(curScintilla, SciMsg.SCI_POSITIONFROMLINE, selectionEndLine, 0);

                using (frmAddComment frm = new frmAddComment())
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        file.AddComment(selectionStartLine, selectionEndLine, selectionStartCol, selectionEndCol, frm.Comment.CommentText);

                        bindComments();

                        // Highlight
                        Win32.SendMessage(curScintilla, SciMsg.SCI_INDICSETSTYLE, 20, 7);
                        Win32.SendMessage(curScintilla, SciMsg.SCI_INDICSETFORE, 20, 0x00FFFF);
                        Win32.SendMessage(curScintilla, SciMsg.SCI_INDICSETALPHA, 20, 50);
                        Win32.SendMessage(curScintilla, SciMsg.SCI_SETINDICATORCURRENT, 20, 0);
                        Win32.SendMessage(curScintilla, SciMsg.SCI_INDICATORFILLRANGE, selectionStartPos, selectionEndPos - selectionStartPos);

                        // select the latest item
                        lstComments.SelectedIndex = lstComments.Items.Count - 1;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Marshal.Release(curScintilla);
            }
        }
Exemplo n.º 8
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();
                //PluginBase.SetToolBarIcon();
            }
            else if (nc.nmhdr.code == (uint)SciMsg.SCN_CHARADDED)
            {
                // PluginBase.doInsertHtmlCloseTag((char)nc.ch);
            }
            else if (nc.nmhdr.code == (uint)NppMsg.NPPN_SHUTDOWN)
            {
                PluginBase.PluginCleanUp();
                Marshal.FreeHGlobal(_ptrPluginName);
            }
        }
        private void btnReport_Click(object sender, EventArgs e)
        {
            IntPtr curScintilla = IntPtr.Zero;

            try
            {
                // Get the report
                String report = file.Report();

                // Open a new document
                Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_FILE_NEW);

                // Get the current scintilla
                curScintilla = PluginBase.GetCurrentScintilla();

                Win32.SendMessage(curScintilla, SciMsg.SCI_APPENDTEXT, report.Length, report);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 10
0
        private void btnDeleteComment_Click(object sender, EventArgs e)
        {
            IntPtr curScintilla = IntPtr.Zero;

            try
            {
                int intSelection = (int)lstComments.SelectedIndex;

                Comment comment = new Comment();

                comment = file.Comments[intSelection];

                // get selection start and end from comment
                int selectionStartLine = comment.StartLine;
                int selectionStartCol  = comment.StartColumn;
                int selectionEndLine   = comment.EndLine;
                int selectionEndCol    = comment.EndColumn;

                // convert to position
                curScintilla = PluginBase.GetCurrentScintilla();
                int selectionStartPos = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_POSITIONFROMLINE, selectionStartLine, 0) + selectionStartCol;
                int selectionEndPos   = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_POSITIONFROMLINE, selectionEndLine, 0) + selectionEndCol;

                // Remove highlight
                Win32.SendMessage(curScintilla, SciMsg.SCI_INDICATORCLEARRANGE, selectionStartPos, selectionEndPos - selectionStartPos);

                file.DeleteComment(comment);

                bindComments();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Marshal.Release(curScintilla);
            }
        }
Exemplo n.º 11
0
 private void frmGoToLine_KeyDown(object sender, KeyEventArgs e)
 {
     if ((e.KeyData == Keys.Return) || (e.Alt && (e.KeyCode == Keys.G)))
     {
         button1.PerformClick();
         e.Handled = true;
     }
     else if (e.KeyData == Keys.Escape)
     {
         Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GRABFOCUS, 0, 0);
     }
     else if (e.KeyCode == Keys.Tab)
     {
         Control next = GetNextControl((Control)sender, !e.Shift);
         while ((next == null) || (!next.TabStop))
         {
             next = GetNextControl(next, !e.Shift);
         }
         next.Focus();
         e.Handled = true;
     }
 }
Exemplo n.º 12
0
        public static string GetDocumentText(IntPtr curScintilla)
        {
            IntPtr hCurrScintilla = PluginBase.GetCurrentScintilla();
            int    textLen        = (int)Win32.SendMessage(hCurrScintilla, SciMsg.SCI_GETSELTEXT, 0, 0);
            IntPtr ptrText        = Marshal.AllocHGlobal(textLen);

            Win32.SendMessage(hCurrScintilla, SciMsg.SCI_GETSELTEXT, 0, ptrText);
            // get it as string but truncated..
            string s = Marshal.PtrToStringAnsi(ptrText);

            // or everything.. well as byte array
            byte[] b = new byte[textLen];
            Marshal.Copy(ptrText, b, 0, textLen);

            Marshal.FreeHGlobal(ptrText);
            return(s);

            //int start = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_GETSELECTIONNEND, 0, 0);
            //int end = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_GETSELECTIONNEND, 0, 0);
            //int textLen2 = end - start;
            //StringBuilder sb = new StringBuilder();
            //Win32.SendMessage(curScintilla, SciMsg.SCI_GETSELTEXT, 0, sb);
            //return sb.ToString();
        }
Exemplo n.º 13
0
 static void setInfo(NppData notepadPlusData)
 {
     PluginBase.nppData = notepadPlusData;
     PluginBase.CommandMenuInit();
 }
Exemplo n.º 14
0
 internal ScriptRunner(PluginBase plgBase)
 {
     pluginBase = plgBase;
 }
 public FrmPlsqlObjects(PluginBase plgBase)
 {
     pluginBase = plgBase;
     InitializeComponent();
 }
Exemplo n.º 16
0
 internal ScriptRunner(PluginBase plgBase)
 {
     pluginBase = plgBase;
 }