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)); } }
static void hello() { notepad.FileNew(); editor.SetText("Hello, Notepad++...from.NET!"); var rest = editor.GetLine(0); editor.SetText(rest + rest + rest); }
/// <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; }
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(); }
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)); } }