private static string FindLineWithMarker(IScintillaGateway scintillaGateway, string selection, string marker, int lineNumber, int direction) { string result = null; for (int i = 1; i < 20; i++) { int checkLine = lineNumber + direction * i; if (checkLine < 0) { break; } string line = scintillaGateway.GetLine(checkLine); if (!string.IsNullOrEmpty(line) && line.Contains(selection) && line.Contains(marker)) { result = line; break; } } if (string.IsNullOrEmpty(result)) { throw new Exception(string.Format("cannot find marker '{0}' in the vicinity of current line", marker)); } else { return(SubstringAfterText(result, marker)); } }
internal static void hexToBase64() { IScintillaGateway scintillaGateway = PluginBase.GetGatewayFactory()(); string selection = scintillaGateway.GetSelText(); if (string.IsNullOrEmpty(selection)) { Tuple <string, Position, Position> hex = extractHexFromCurrentPosition(scintillaGateway); if (hex != null) { string base64 = convertToBase64(hex.Item1); if (base64 != null) { scintillaGateway.SetSel(hex.Item2, hex.Item3); scintillaGateway.ReplaceSel(base64); } } } else { if (selection.Length % 2 != 0) { MessageBox.Show("selection length not divisible by 2"); return; } string base64 = convertToBase64(selection); if (base64 != null) { scintillaGateway.ReplaceSel(base64); } } }
internal static void mergeParamsInNewTab() { IScintillaGateway scintillaGateway = PluginBase.GetGatewayFactory()(); string selection = scintillaGateway.GetSelText(); if (string.IsNullOrEmpty(selection)) { MessageBox.Show("no selection"); return; } try { string sql; int lineNumber = 0; if (IsOneLineSelection(scintillaGateway, ref lineNumber)) { sql = FindSql(scintillaGateway, selection, lineNumber); } else { sql = FindInSelection(selection); } Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_FILE_NEW); scintillaGateway.SetText(sql); } catch (Exception e) { MessageBox.Show(e.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static string get_text_range(this IScintillaGateway document, int startPos, int endPos, int bufCapacity) { bool newNppVersion = IsNewNppApiVersion; if (Environment.GetEnvironmentVariable("CSSCRIPT_NPP_NEW_NPP_API") != null) { newNppVersion = Environment.GetEnvironmentVariable("CSSCRIPT_NPP_NEW_NPP_API").ToLower() == "true"; } if (newNppVersion) { using (var tr = new TextRange((IntPtr)startPos, (IntPtr)endPos, bufCapacity)) { document.GetTextRange(tr); return(tr.lpstrText); } } else { using (var tr = new TextRangeLegacy(startPos, endPos, bufCapacity)) { document.GetTextRangeLegacy(tr); return(tr.lpstrText); } } }
internal static void removeWhitespaces() { IScintillaGateway scintillaGateway = PluginBase.GetGatewayFactory()(); string selection = scintillaGateway.GetSelText(); string result = ""; bool addedSpace = false; foreach (char ch in selection) { if (Char.IsWhiteSpace(ch)) { if (!addedSpace) { addedSpace = true; result += " "; } } else { addedSpace = false; result += ch; } } scintillaGateway.ReplaceSel(result); }
internal static void base64toHex() { IScintillaGateway scintillaGateway = PluginBase.GetGatewayFactory()(); string selection = scintillaGateway.GetSelText(); try { if (string.IsNullOrEmpty(selection)) { Tuple <string, Position, Position> base64AndRange = extractBase64FromCurrentPosition(scintillaGateway); if (base64AndRange != null) { string hex = convertBase64ToHex(base64AndRange.Item1); scintillaGateway.SetSel(base64AndRange.Item2, base64AndRange.Item3); scintillaGateway.ReplaceSel(hex); } } else { scintillaGateway.ReplaceSel(convertBase64ToHex(selection)); } } catch (FormatException e) { MessageBox.Show("FormatException " + e.Message); } }
public JsonSearchContext(string selectedWord, IScintillaGateway gateway, int initialLineIndex, int indexOfSelectedWord) { _gateway = gateway; _selectedWord = selectedWord; _totalLinesCount = _gateway.GetLineCount(); _selectedProperty = TryInitSelectedProperty(initialLineIndex, indexOfSelectedWord); }
private void UpdateSNList() { Editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); List <SourceNavigationItem> SNList = new List <SourceNavigationItem>(); SNList.Clear(); SNList.Add(new SourceNavigationItem { Name = "<TOP>", LineNumber = 0 }); if (Editor.GetTextLength() <= 999999) { string text = Editor.GetText(Editor.GetTextLength()); string search = @"^[\s]*([\w|-]+)[\s]+(SECTION|DIVISION)[\s]*\.[\s]*$"; MatchCollection matches = Regex.Matches(text, search, RegexOptions.Multiline | RegexOptions.IgnoreCase); if (matches.Count > 0) { foreach (Match match in matches) { SNList.Add(new SourceNavigationItem { Name = ((match.Groups[2].Value.StartsWith("SECTION", StringComparison.OrdinalIgnoreCase) ? " " : "") + match.Groups[1].Value + " " + match.Groups[2].Value).ToUpper(), LineNumber = Editor.LineFromPosition(new Position(match.Index)) }); } } } PostDataToSNListBox(SNList); }
private void LastPartOfGuidPossiblySelected(int relativeLineOfset, string lineContent, Position absolutePosStart, bool isLeftToRigthSelection, IScintillaGateway scintillaGateway) { var canLineFitGuid = relativeLineOfset >= LengthGuidExceptLastPart && lineContent.Length >= GuidHelperConstants.Regexlength; var isMatch = canLineFitGuid && GuidHelperConstants.GuidRex.IsMatch(lineContent.Substring(relativeLineOfset - LengthGuidExceptLastPart)); if (!isMatch) { return; } var finalStartSelection = new Position(absolutePosStart.Value - LengthGuidExceptLastPart); var end = new Position(finalStartSelection.Value + GuidHelperConstants.Regexlength); if (isLeftToRigthSelection) { scintillaGateway.SetAnchor(finalStartSelection); scintillaGateway.SetCurrentPos(end); } else // "reverse" selection from right-to-left { scintillaGateway.SetAnchor(end); scintillaGateway.SetCurrentPos(finalStartSelection); } }
public frmMain(IScintillaGateway editor) { _editor = editor; InitializeComponent(); InitControls(); WireEvents(); }
/// <summary>Trennt die Punkte aus dem angegebenen Text</summary> /// <param name="settings"></param> /// <param name="editor"></param> public void getPointsFromEditor(Settings settings, IScintillaGateway editor) { punkte.Clear(); if (editor != null) { Int32 countLines = editor.GetLineCount(); for (Int32 lc = 0; lc < countLines; lc++) { String cuLine = editor.GetLine(lc); // Auch Excel Splitbar machen ;-) cuLine = cuLine.Replace('\t', ' '); // Tab durch Leerzeichen ersetzten cuLine = cuLine.Replace(',', settings.Decimalseperator[0]); // , durch . ersetzten String[] split = ClassStringTools.GetFieldsManyDelimiters(cuLine, ' ', true); if (split != null) { if (split.Length >= 4) // mind PNR R H E { ClassCADdyPunkt newPoint = new ClassCADdyPunkt(); { newPoint.Punktnummer = ClassStringTools.trimToEmpty(split[settings.PointName_Column - 1]); if (settings.PointName_ToUpper) { newPoint.Punktnummer = newPoint.Punktnummer.ToUpper(); } if (!ClassStringTools.IsNullOrWhiteSpace(newPoint.Punktnummer)) { Double temp = Double.NaN; if (ClassConverters.StringToDouble(split[settings.Koord_RW_E_Column - 1], out temp)) { newPoint.Rechtswert = temp; if (ClassConverters.StringToDouble(split[settings.Koord_HW_N_Column - 1], out temp)) { newPoint.Hochwert = temp; if (ClassConverters.StringToDouble(split[settings.Koord_Elev_Column - 1], out temp)) { newPoint.Hoehe = temp; newPoint.LineNumber = lc; if (split.Length >= 5) { // code newPoint.Code = ClassStringTools.trimToEmpty(split[settings.Koord_Code_Column - 1]); if (split.Length >= 6) { // code newPoint.Bemerkung = ClassStringTools.trimToEmpty(split[settings.Koord_Descript_Column - 1]); } } punkte.Add(newPoint); } } } } } } } } } hasPunkte = punkte.Count > 0; }
public MarkdownPanelController() { scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla()); notepadPPGateway = new NotepadPPGateway(); markdownPreviewForm = new MarkdownPreviewForm(ToolWindowCloseAction); renderTimer = new Timer(); renderTimer.Interval = renderRefreshRateMilliSeconds; renderTimer.Tick += OnRenderTimerElapsed; }
private static bool IsOneLineSelection(IScintillaGateway scintillaGateway, ref int lineNumber) { Position posStart = scintillaGateway.GetSelectionStart(); Position posEnd = scintillaGateway.GetSelectionEnd(); int lineA = scintillaGateway.LineFromPosition(posStart); int lineB = scintillaGateway.LineFromPosition(posEnd); lineNumber = lineA; return(lineA == lineB); }
private string IndentSelectedStrings(IScintillaGateway editor, Position start, Position end) { int firstLine = editor.LineFromPosition(start); int lastLine = editor.LineFromPosition(end); string output = ""; for (int i = firstLine; i <= lastLine; i++) { string lineText = editor.GetLine(i); output += lineText.StartsWith("*") ? lineText : new string(' ', IndentSelection) + lineText; } return(output); }
private void GotoSelectedSection() { Editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); SourceNavigationItem selectedItem = (SourceNavigationItem)SNListBox.SelectedItem; int line = selectedItem.LineNumber; int linesOnScreen = Editor.LinesOnScreen(); string sectionName = selectedItem.Name.Trim().Split(' ')[0]; string lineText = Editor.GetLine(line).ToUpper(); Editor.GotoLine(line); Editor.SetFirstVisibleLine(line - linesOnScreen / 2 + 1 < 0 ? 0 : line - linesOnScreen / 2 + 1); Editor.SetSelection(Editor.PositionFromLine(line).Value + lineText.IndexOf(sectionName) + sectionName.Length, Editor.PositionFromLine(line).Value + lineText.IndexOf(sectionName)); Editor.GrabFocus(); }
private void FrmSNDlg_SNListBox_Context_Click(object sender, EventArgs e) { Editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); int line = int.Parse(((ToolStripItem)sender).Text.Split(':')[0]) - 1; int linesOnScreen = Editor.LinesOnScreen(); string lineText = Editor.GetLine(line); Editor.GotoLine(line); Editor.SetFirstVisibleLine(line - linesOnScreen / 2 + 1 < 0 ? 0 : line - linesOnScreen / 2 + 1); string sectionName = lineText.Trim().Split(' ')[1]; Editor.SetSelection(Editor.WordEndPosition(new Position(Editor.PositionFromLine(line).Value + lineText.IndexOf(sectionName)), true), Editor.PositionFromLine(line).Value + lineText.IndexOf(sectionName)); Editor.GrabFocus(); ((ToolStripItem)sender).Owner.Dispose(); }
// init public frmMyDlg(IScintillaGateway editor) { this.editor = editor; InitializeComponent(); // get the connected board list GetConnectedBoardsList(); // set the board list in cimbo box SetConnecteBoardsComboBox(); // get the installed list GetInstalledBoardsList(); //set the list in the drop down SetInstalledBoardsComboBox(); }
public LinksHighlighter(IScintillaGateway gateway, Settings settings) { if (!settings.Config.HighlightingEnabled) { _settingsMapping = null; gateway.SetIndicatorStyle(HIGHLIGHT_INDICATOR_ID, STYLE_NONE); Logger.Warn("Highlighting is disabled by settings"); return; } _settingsMapping = settings.Mapping; _gateway = gateway; _searchContextProvider = (word, initialLineIndex, indexOfSelectedWord) => new JsonSearchContext(word, gateway, initialLineIndex, indexOfSelectedWord); gateway.SetIndicatorStyle(HIGHLIGHT_INDICATOR_ID, STYLE_UNDERLINE); _updateUiTimer = CreateTimer(Defaults.HIGHLIGHTING_TIMER_INTERVAL); }
static public string TextBeforePosition(this IScintillaGateway document, int position, int maxLength) { int bufCapacity = maxLength + 1; IntPtr hCurrentEditView = PluginBase.GetCurrentScintilla(); int currentPos = position; int beginPos = currentPos - maxLength; int startPos = (beginPos > 0) ? beginPos : 0; int size = currentPos - startPos; if (size > 0) { return(document.get_text_range(startPos, currentPos, bufCapacity)); } else { return(null); } }
private void SNListBox_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { Editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); ContextMenuStrip menuStrip = new ContextMenuStrip(); int index = SNListBox.IndexFromPoint(e.X, e.Y); SNListBox.SetSelected(index, true); string text = Editor.GetText(Editor.GetTextLength()); string search = @"^[ ]*PERFORM[\s]*" + ((SourceNavigationItem)SNListBox.Items[index]).Name.Trim().Split(' ')[0] + @"[\s]*[\.]{0,1}[\s]*$"; MatchCollection matches = Regex.Matches(text, search, RegexOptions.Multiline | RegexOptions.IgnoreCase); if (matches.Count > 0) { foreach (Match match in matches) { string itemName = ""; foreach (SourceNavigationItem item in GetStoredSectionsList()) { int line = Editor.LineFromPosition(new Position(match.Index)); string currentText = ""; if (item.LineNumber > line) { break; } else { currentText = item.Name.Trim().Split(' ')[0]; } if (currentText != "") { itemName = (line + 1) + ": " + currentText; } Editor.LineFromPosition(new Position(match.Index)); } menuStrip.Items.Add(itemName).Click += FrmSNDlg_SNListBox_Context_Click; } } if (menuStrip.Items.Count > 0) { menuStrip.Show(SNListBox, e.X, e.Y); } } }
private static string FindSql(IScintillaGateway scintillaGateway, string selection, int lineNumber) { string line = scintillaGateway.GetLine(lineNumber); if (line.Contains(PREPARING_MARKER)) { string parametersLine = FindLineWithMarker(scintillaGateway, selection, PARAMETERS_MARKER, lineNumber, 1); return(FillParameters(SubstringAfterText(line, PREPARING_MARKER), parametersLine)); } else if (line.Contains(PARAMETERS_MARKER)) { string preparingLine = FindLineWithMarker(scintillaGateway, selection, PREPARING_MARKER, lineNumber, -1); return(FillParameters(preparingLine, SubstringAfterText(line, PARAMETERS_MARKER))); } else { throw new Exception(string.Format("current line contains neither '{0}' nor '{1}'", PREPARING_MARKER, PARAMETERS_MARKER)); } }
internal static Position findBeginningOfFragment(IScintillaGateway scintillaGateway, Position start, Predicate <char> predicate) { for (int pos = start.Value; ; pos--) { if (pos == 0) { if (predicate((char)scintillaGateway.GetCharAt(new Position(0)))) { return(new Position(0)); } else { return(new Position(1)); } } if (!predicate((char)scintillaGateway.GetCharAt(new Position(pos)))) { return(new Position(pos + 1)); } } }
internal static Tuple <string, Position, Position> getFragmentStartingFrom(IScintillaGateway scintillaGateway, int start, Predicate <char> predicate) { int length = scintillaGateway.GetLength(); int lastValid = start; List <char> chars = new List <char>(); for (int pos = start; pos < length; pos++) { int ch = scintillaGateway.GetCharAt(new Position(pos)); if (predicate((char)ch)) { chars.Add((char)ch); lastValid = pos; } else { break; } } return(new Tuple <string, Position, Position>(new string(chars.ToArray()), new Position(start), new Position(lastValid + 1))); }
private void FirstPartOfGuidPossiblySelected(int relativeLineOfset, string lineContent, Position absolutePosOfLine, bool isLeftToRigthSelection, IScintillaGateway scintillaGateway, Position absolutePosStart) { var isMatch = lineContent.Length >= GuidHelperConstants.Regexlength + relativeLineOfset && GuidHelperConstants.GuidRex.IsMatch(lineContent.Substring(relativeLineOfset)); if (!isMatch) { return; } var end = new Position(absolutePosOfLine.Value + relativeLineOfset + GuidHelperConstants.Regexlength); if (isLeftToRigthSelection) { scintillaGateway.SetAnchor(absolutePosStart); scintillaGateway.SetCurrentPos(end); } else // "reverse" selection from right-to-left { scintillaGateway.SetAnchor(end); scintillaGateway.SetCurrentPos(absolutePosStart); } }
public NppRenderer(INotepadPPGateway npp, IScintillaGateway editor, Logger logger) { Editor = editor; Logger = logger; Npp = npp; }
static public string TextBeforeCursor(this IScintillaGateway document, int maxLength) { int currentPos = document.GetCurrentPos(); return(document.TextBeforePosition(currentPos, maxLength)); }
public InsertGuid(IScintillaGateway scintilla) { this.scintilla = scintilla; }
public InsertGuid(IScintillaGateway scintilla) { this.scintilla = scintilla; }
public frmGoToLine(IScintillaGateway editor) { this.editor = editor; InitializeComponent(); }
public Scintilla(IScintillaGateway scintilla) { this.scintilla = scintilla; }
public frmLexerSettings(IScintillaGateway editor) { this.editor = editor; InitializeComponent(); }