static private GetCurrentScintilla ( ) : |
||
return |
private void lstComments_SelectedIndexChanged(object sender, EventArgs e) { IntPtr curScintilla = IntPtr.Zero; try { // highlight the commented segment curScintilla = PluginBase.GetCurrentScintilla(); // get selected comment int intSelection = (int)lstComments.SelectedIndex; if (intSelection >= 0) { 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 int selectionStartPos = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_POSITIONFROMLINE, selectionStartLine, 0) + selectionStartCol; int selectionEndPos = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_POSITIONFROMLINE, selectionEndLine, 0) + selectionEndCol; // goto the starting line Win32.SendMessage(curScintilla, SciMsg.SCI_GOTOLINE, selectionEndLine + 100, 0); Win32.SendMessage(curScintilla, SciMsg.SCI_GOTOLINE, selectionStartLine - 1, 0); Win32.SendMessage(curScintilla, SciMsg.SCI_GRABFOCUS, 0, 0); // select the segment Win32.SendMessage(curScintilla, SciMsg.SCI_SETSELECTIONSTART, selectionStartPos, 0); Win32.SendMessage(curScintilla, SciMsg.SCI_SETSELECTIONEND, selectionEndPos, 0); } else { // goto the starting line Win32.SendMessage(curScintilla, SciMsg.SCI_GOTOLINE, 100, 0); Win32.SendMessage(curScintilla, SciMsg.SCI_GOTOLINE, -1, 0); Win32.SendMessage(curScintilla, SciMsg.SCI_GRABFOCUS, 0, 0); Win32.SendMessage(curScintilla, SciMsg.SCI_SETSELECTIONSTART, 0, 0); Win32.SendMessage(curScintilla, SciMsg.SCI_SETSELECTIONEND, 0, 0); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Marshal.Release(curScintilla); } }
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()); }
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); } }
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); } }
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); } }
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); } }
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; } }
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(); }
internal void CharAdded(char c) { try { // Add 'end' after certain statements if (((eolMode == SciMsg.SC_EOL_CR || eolMode == SciMsg.SC_EOL_CRLF) && c == '\n') || (eolMode == SciMsg.SC_EOL_LF && c == '\r')) { var curLineBuilder = new StringBuilder(512); //TODO: get line length from Scintilla var lineNum = (int)Win32.SendMessage(pluginBase.nppData._nppHandle, NppMsg.NPPM_GETCURRENTLINE, 0, 0); Win32.SendMessage(pluginBase.GetCurrentScintilla(), SciMsg.SCI_GETLINE, lineNum - 1, curLineBuilder); var curLine = curLineBuilder.ToString(); var match = endsRegex.Match(curLine); if (match.Success) { lastAutoInsertLine = -1; Win32.SendMessage(pluginBase.GetCurrentScintilla(), SciMsg.SCI_INSERTTEXT, -1, string.Format("{0}{1}end", eol, match.Groups[1].Value)); pluginBase.SendScintillaMessage(SciMsg.SCI_TAB); } } // add closing array bracket else if (c == '[') { var curLineBuilder = new StringBuilder(512); //TODO: get line length from Scintilla var lineNum = (int)Win32.SendMessage(pluginBase.nppData._nppHandle, NppMsg.NPPM_GETCURRENTLINE, 0, 0); var linePos = pluginBase.SendScintillaMessage(SciMsg.SCI_POSITIONFROMLINE, lineNum); Win32.SendMessage(pluginBase.GetCurrentScintilla(), SciMsg.SCI_GETLINE, lineNum, curLineBuilder); var curLine = curLineBuilder.ToString(); var curPos = pluginBase.SendScintillaMessage(SciMsg.SCI_GETCURRENTPOS); if (AreMoreOf('[', ']', curLine)) // if there are more opening brackets than closing ones { var posInLine = curPos - linePos; if (posInLine == curLine.Length - eol.Length || (posInLine < curLine.Length && curLine[posInLine] == ' ')) // only add if caret is left of whitespace, or at EOL { lastAutoInsertLine = lineNum; Win32.SendMessage(pluginBase.GetCurrentScintilla(), SciMsg.SCI_INSERTTEXT, -1, "]"); } } } // ignore closing array bracket if we already auto-inserted it else if (c == ']') { var curLineBuilder = new StringBuilder(512); //TODO: get line length from Scintilla var lineNum = (int)Win32.SendMessage(pluginBase.nppData._nppHandle, NppMsg.NPPM_GETCURRENTLINE, 0, 0); if (lastAutoInsertLine != lineNum) { return; } var linePos = pluginBase.SendScintillaMessage(SciMsg.SCI_POSITIONFROMLINE, lineNum); Win32.SendMessage(pluginBase.GetCurrentScintilla(), SciMsg.SCI_GETLINE, lineNum, curLineBuilder); var curLine = curLineBuilder.ToString(); var curPos = pluginBase.SendScintillaMessage(SciMsg.SCI_GETCURRENTPOS); if (AreMoreOf(']', '[', curLine)) // if there are more closing brackets than opening ones { var posInLine = curPos - linePos; if (posInLine < curLine.Length && curLine[posInLine] == ']') // only add if caret is left of whitespace, or at EOL { pluginBase.SendScintillaMessage(SciMsg.SCI_CHARRIGHT); pluginBase.SendScintillaMessage(SciMsg.SCI_DELETEBACK); } } } } catch (Exception e) { MessageBox.Show("Error while handling character key press: " + e.Message + "\r\n" + e.StackTrace, "Ruby. Boo!"); } }