private static void ScrollToLine(int sectionImplementationLine) { var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); int linesOnScreen = editor.LinesOnScreen(); editor.SetFirstVisibleLine(sectionImplementationLine - linesOnScreen / 2 + 1 < 0 ? 0 : sectionImplementationLine - linesOnScreen / 2 + 1); }
/// <summary> /// Selects the wor at caret. /// </summary> /// <param name="document">The document.</param> static public void SelectWorAtCaret(this ScintillaGateway document) { Point p; document.GetWordAtCursor(out p); document.SendMessage(SciMsg.SCI_SETSELECTION, p.X, p.Y); }
public Position SelectFirstWordOfLine(ScintillaGateway scintilla) { int lineNumber = scintilla.GetCurrentLineNumber(); var lineContent = scintilla.GetLine(lineNumber); if (lineContent.StartsWith("#")) { return(null); } int endOfFirstWordOnLine = lineContent.IndexOf(' '); if (endOfFirstWordOnLine == -1) { return(null); } var positionOfLine = scintilla.PositionFromLine(lineNumber); var cursorpos = scintilla.GetCurrentPos() - positionOfLine; var cursorIsWithinFirstWord = cursorpos.Value <= endOfFirstWordOnLine; if (!cursorIsWithinFirstWord) { return(null); } var newPosition = new Position(positionOfLine.Value + endOfFirstWordOnLine); scintilla.SetAnchor(newPosition); scintilla.SetCurrentPos(positionOfLine); return(newPosition); }
static public void PlaceIndicator(this ScintillaGateway document, int indicator, int startPos, int endPos) { // !!! // The implementation is identical to "ClearIndicator". Looks like intentional. document.SetIndicatorCurrent(indicator); document.IndicatorClearRange(startPos, endPos - startPos); }
public static void OnNotification(ScNotification notification) { if (notification.Header.Code == (ulong)NppMsg.NPPN_BUFFERACTIVATED) { isPluginActive = IsGitRebaseFile(); return; } if (notification.Header.Code == (ulong)NppMsg.NPPN_FILEOPENED) { if (IsGitRebaseFile()) { var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla()); AddTextToRebaseFile(scintillaGateway); DisableAutoCompletePopup(scintillaGateway); SetSyntaxHighlighting(); } return; } EnsureFirstWordIsSelected(notification); }
public static void ClearSelection(this ScintillaGateway document) { int currentPos = document.GetCurrentPos(); document.SetSelectionStart(currentPos); document.SetSelectionEnd(currentPos); }
static public void ReplaceWordAtCaret(this ScintillaGateway document, string text) { string word = document.GetWordAtCursor(out Point p, SimpleCodeCompletion.Delimiters); document.SetSel(p.X, p.Y); document.ReplaceSelection(text); }
/// <summary>Gibt eine CADdy-Formatierte Liste zurück</summary> /// <param name="settings"></param> public void formatCurrentToCADdy(Settings settings) { IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); if (standpunkte.Count > 0) { Position selStart = editor.GetSelectionStart(); Position selEnd = editor.GetSelectionEnd(); editor.BeginUndoAction(); Position oldPos = editor.GetCurrentPos(); editor.ClearAll(); foreach (ClassCADdyStandpunkt item in standpunkte) { String temp = item.getCADdyFormatString(settings); editor.AppendText(temp.Length + 1, temp + Environment.NewLine); foreach (ClassCADdyZielung ziel in item.Zielungen) { temp = ziel.getCADdyFormatString(settings); editor.AppendText(temp.Length + 1, temp + Environment.NewLine); } } editor.ConvertEOLs(0); editor.SetSelection(selStart.Value, selEnd.Value); editor.SetCurrentPos(oldPos); editor.EndUndoAction(); } }
static public Point[] FindIndicatorRanges(this ScintillaGateway document, int indicator) { var ranges = new List <Point>(); int testPosition = 0; while (true) { //finding the indicator ranges //For example indicator 4..6 in the doc 0..10 will have three logical regions: //0..4, 4..6, 6..10 //Probing will produce following when outcome: //probe for 0 : 0..4 //probe for 4 : 4..6 //probe for 6 : 4..10 int rangeStart = document.IndicatorStart(indicator, testPosition); int rangeEnd = document.IndicatorEnd(indicator, testPosition); int value = document.IndicatorValueAt(indicator, testPosition); if (value == 1) //indicator is present { ranges.Add(new Point(rangeStart, rangeEnd)); } if (testPosition == rangeEnd) { break; } testPosition = rangeEnd; } return(ranges.ToArray()); }
private static void copyAsImage() { try { IntPtr currentScint = PluginBase.GetCurrentScintilla(); ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint); // Get selected text. string selectedText = scintillaGateway.GetSelText(); var lines = selectedText.Split('\n'); DrawIOBuilder builder = new DrawIOBuilder(); for (var i = 0; i < lines.Length; i++) { var line = lines[i]; lines[i] = line.Trim(new char[] { ' ', '\r' }); } DrawIOComponent[] drawIOComponent = builder.FlowchartBuilder(lines); builder.DrawToClipBoard(drawIOComponent); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Gets the word at cursor. /// </summary> /// <param name="document">The scintilla object.</param> /// <param name="point">The point - start and end position of the word.</param> /// <returns></returns> static public string GetWordAtCursor(this ScintillaGateway document, out Point point) { int currentPos = document.SendMessage(SciMsg.SCI_GETCURRENTPOS, 0, 0); int fullLength = document.SendMessage(SciMsg.SCI_GETLENGTH, 0, 0); string leftText = document.TextBeforeCaret(512); string rightText = document.TextAfterCaret(512); var delimiters = "\t\n\r .,:;'\"[]{}()".ToCharArray(); string wordLeftPart = ""; int startPos = currentPos; if (leftText != null) { startPos = leftText.LastIndexOfAny(delimiters); wordLeftPart = (startPos != -1) ? leftText.Substring(startPos + 1) : ""; int relativeStartPos = leftText.Length - startPos; startPos = (startPos != -1) ? (currentPos - relativeStartPos) + 1 : 0; } string wordRightPart = ""; int endPos = currentPos; if (rightText != null) { endPos = rightText.IndexOfAny(delimiters); wordRightPart = (endPos != -1) ? rightText.Substring(0, endPos) : ""; endPos = (endPos != -1) ? currentPos + endPos : fullLength; } point = new Point(startPos, endPos); return(wordLeftPart + wordRightPart); }
private static void EnsureFirstWordIsSelected(ScNotification notification) { if (isPluginActive) { nppResource.ClearIndicator(); if (notification.Header.Code == (ulong)SciMsg.SCN_UPDATEUI) { var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla()); var currentPosition = scintillaGateway.GetCurrentPos(); if (currentPosition != lastPositionWhenUiUpdate) { if (scintillaGateway.GetSelectionEmpty()) { lastPositionWhenUiUpdate = firstWordSelector.SelectFirstWordOfLine(scintillaGateway); } } return; } if (notification.Header.Code == (ulong)SciMsg.SCN_MODIFIED) { var isTextInsertedOrDeleted = (notification.ModificationType & ((int)SciMsg.SC_MOD_INSERTTEXT | (int)SciMsg.SC_MOD_DELETETEXT)) > 0; if (isTextInsertedOrDeleted) { lastPositionWhenUiUpdate = null; } } } }
public static string GetSelectedText(this ScintillaGateway document) { int start = document.GetSelectionStart(); int end = document.GetSelectionEnd(); return(document.GetTextBetween(start, end)); }
static public int ClosestNonEmptyLineTo(this ScintillaGateway document, int line) { if (document.GetLine(line).HasText()) { return(line); } int lineCount = document.GetLineCount(); for (int i = 1; i < lineCount; i++) { if (line - i >= 0) { if (document.GetLine(line - i).HasText()) { return(line - i); } } if (line + i < lineCount) { if (document.GetLine(line + i).HasText()) { return(line + i); } } } return(-1); }
private static void MoveLineDown() { var scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla()); scintillaGateway.SelectCurrentLine(); scintillaGateway.MoveSelectedLinesDown(); scintillaGateway.ClearSelectionToCursor(); }
static public void SetMarkerStyle(this ScintillaGateway document, int marker, SciMsg style, Color foreColor, Color backColor) { int mask = document.GetMarginMaskN(1); document.MarkerDefine(marker, (int)style); document.MarkerSetFore(marker, foreColor.ToColour()); document.MarkerSetBack(marker, backColor.ToColour()); document.SetMarginMaskN(1, (1 << marker) | mask); }
static public void SetMarkerStyle(this ScintillaGateway document, int marker, Bitmap bitmap) { int mask = document.GetMarginMaskN(1); string bookmark_xpm = ConvertToXPM(bitmap, "#FF00FF"); document.MarkerDefinePixmap(marker, bookmark_xpm); document.SetMarginMaskN(1, (1 << marker) | mask); }
static public string GetStatementAtPosition(this ScintillaGateway document, int position = -1) { if (position == -1) { position = document.GetCurrentPos(); } return(document.GetWordAtPosition(position, out Point point, statementDelimiters)); }
static public string GetTextBetween(this ScintillaGateway document, int start, int end = -1) { if (end == -1) { end = document.GetLength(); } return(document.get_text_range(start, end, end - start + 1)); //+1 for null termination }
public static void CheckAndSwitchOnCobolWords() { var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); if (!editor.GetWordChars().Contains("-")) { SetCobolLikeWords(true); } }
/// <summary> /// Find and capitalize the first letter of the beginning of all /// sentences in a document. /// </summary> internal static void CapSentence() { // Get current scintilla instance. IntPtr currentScint = PluginBase.GetCurrentScintilla(); ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint); try { // Get the length of the document. int length = scintillaGateway.GetLength(); // Get the text in the document. string allText = scintillaGateway.GetText(length + 1); // Convert the text to char array for easy manipulation. char[] charArrayAllText = allText.ToCharArray(); char firstLetter = new char(); bool capAfterPunct = true; // For the length of the selected text... for (int i = 0; i < allText.Length; i++) { // If there is punctuation that ends a sentence // the next word should be capitalized. if (allText[i] == '.' || allText[i] == '?' || allText[i] == '!' || allText[i] == '\r') { capAfterPunct = true; } // Don't capitalize Markdown titles in this method. else if (allText[i] == '#') { capAfterPunct = false; } if (capAfterPunct && !ignoreChars.Contains(allText[i])) { // If the current character is not a whitespace character // convert the first letter of the word to uppercase. firstLetter = Convert.ToChar(allText[i].ToString().ToUpperInvariant()); // Replace the correct char in the selected text with its uppercase letter. charArrayAllText.SetValue(firstLetter, i); // Revert to false until beginning of next sentence. capAfterPunct = false; } } // Convert char array back to string. allText = new string(charArrayAllText); // Replace the document text with the new text. scintillaGateway.SelectAll(); scintillaGateway.ReplaceSel(allText); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
static public void ClearIndicator(this ScintillaGateway document, int indicator, int startPos, int endPos = -1) { if (endPos == -1) { endPos = document.GetLength(); } document.SetIndicatorCurrent(indicator); document.IndicatorClearRange(startPos, endPos - startPos); }
private static void AddTextToRebaseFile(ScintillaGateway scintillaGateway) { string additionalText = @"# # Use Ctrl+Down to move lines down # Use Ctrl+Up to move lines up # Convenience brought by RebaseAssister plugin " + Version + @" "; scintillaGateway.AppendText(additionalText.Length, additionalText); }
static public int GetPositionFromMouseLocation(this ScintillaGateway document) { Point point = Cursor.Position; ScreenToClient(document.Handle, ref point); int pos = document.CharPositionFromPointClose(point.X, point.Y); return(pos); }
static public Point GetCaretScreenLocation(this ScintillaGateway document) { int pos = document.GetCurrentPos(); int x = document.PointXFromPosition(pos); int y = document.PointYFromPosition(pos); var point = new Point(x, y); ClientToScreen(document.Handle, ref point); return(point); }
/// <summary>Setzt die Punktnummern auf den angegebenen Code</summary> /// <param name="pointnumber"></param> /// <param name="newCode"></param> /// <returns>true = es wurde mind. ein Code geändert</returns> public Boolean setPointNumberToCode(String pointnumber, String newCode) { Boolean allPoints = false; Boolean hasAnyChanged = false; if (ClassStringTools.IsNullOrWhiteSpace(pointnumber)) { pointnumber = "*"; } if (!ClassStringTools.IsNullOrWhiteSpace(newCode)) { IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); int sLnrStart = -1; int sLnrEnd = -1; if (editor != null) { sLnrStart = editor.LineFromPosition(editor.GetSelectionStart()); sLnrEnd = editor.LineFromPosition(editor.GetSelectionEnd()); if (editor.GetColumn(editor.GetSelectionEnd()) < 2) { sLnrEnd--; } } ClassRegexTools regexT = null; if (pointnumber == "*") { allPoints = true; } else { regexT = new ClassRegexTools(pointnumber); } foreach (ClassCADdyPunkt item in Punkte) { if (allPoints || regexT.isMatch(item.Punktnummer)) { if ((sLnrStart >= 0) && (sLnrEnd >= 0)) { if ((item.LineNumber >= sLnrStart) && (item.LineNumber <= sLnrEnd)) { item.Code = newCode; hasAnyChanged = true; } } else { item.Code = newCode; hasAnyChanged = true; } } } } return(hasAnyChanged); }
/// <summary>Koordinaten verschieben</summary> /// <param name="tRW"></param> /// <param name="tHW"></param> /// <param name="tHO"></param> /// <param name="settings"></param> public Boolean translateCoords(Double tRW, Double tHW, Double tHO) { Boolean hasAnyChanged = false; IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); int sLnrStart = -1; int sLnrEnd = -1; if (editor != null) { sLnrStart = editor.LineFromPosition(editor.GetSelectionStart()); sLnrEnd = editor.LineFromPosition(editor.GetSelectionEnd()); if (editor.GetColumn(editor.GetSelectionEnd()) < 2) { sLnrEnd--; } if ((sLnrEnd - sLnrStart) <= 0) { sLnrStart = sLnrEnd = -1; } } if (Double.IsNaN(tRW)) { tRW = 0.0; } if (Double.IsNaN(tHW)) { tHW = 0.0; } if (Double.IsNaN(tHO)) { tHO = 0.0; } foreach (ClassCADdyPunkt item in Punkte) { if ((sLnrStart >= 0) && (sLnrEnd >= 0)) { if ((item.LineNumber >= sLnrStart) && (item.LineNumber <= sLnrEnd)) { item.Rechtswert += tRW; item.Hochwert += tHW; item.Hoehe += tHO; hasAnyChanged = true; } } else { item.Rechtswert += tRW; item.Hochwert += tHW; item.Hoehe += tHO; hasAnyChanged = true; } } return(hasAnyChanged); }
/// <summary> /// Replaces the word at cursor. /// </summary> /// <param name="document">The document.</param> /// <param name="replacement">The replacement.</param> static public void ReplaceWordAtCursor(this ScintillaGateway document, string replacement) { Point p; string word = Npp.Document.GetWordAtCursor(out p); if (!string.IsNullOrWhiteSpace(word)) { document.SendMessage(SciMsg.SCI_SETSELECTION, p.X, p.Y); } document.SendMessage(SciMsg.SCI_REPLACESEL, 0, replacement); }
public void InsertSnippet() { var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); editor.AddText(SnippetBody.Length, SnippetBody); using (TextToFind textToFind = new TextToFind(editor.GetCurrentPos().Value - SnippetBody.Length, editor.GetCurrentPos().Value, Placeholder)) { Position placeholderPosition = editor.FindText(0, textToFind); editor.SetSelection(placeholderPosition.Value + Placeholder.Length, placeholderPosition.Value); } }
/// <summary> /// Gets the text between two text positions. /// </summary> /// <param name="sci">The scintilla object.</param> /// <param name="start">The start position.</param> /// <param name="end">The end position.</param> /// <returns></returns> static public string GetTextBetween(this ScintillaGateway sci, int start, int end = -1) { if (end == -1) { end = sci.SendMessage(SciMsg.SCI_GETLENGTH, 0, 0); } using (var tr = new TextRange(start, end, end - start + 1)) //+1 for null termination { sci.SendMessage(SciMsg.SCI_GETTEXTRANGE, 0, tr.NativePointer); return(tr.lpstrText); } }