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); }
/// <summary> /// Find and capitalize all Markdown Titles in the document. /// </summary> internal static void CapitalizeMDTitles() { // Get scintilla gateway. IntPtr currentScint = PluginBase.GetCurrentScintilla(); ScintillaGateway scintillaGateway = new ScintillaGateway(currentScint); string line; // Get the number of lines in the document. int numLines = scintillaGateway.GetLineCount(); // Traverse through each line. for (int i = 0; i < numLines; i++) { // Set line to the current line. line = scintillaGateway.GetLine(i); // Check each character in the line to see if it begins // with a '#'. for (int j = 0; j < line.Length; j++) { if (line[j] == '#') { // If it begins with '#', select the line and call // the CapitalizeTitle method with these parameters. scintillaGateway.GotoLine(i); scintillaGateway.SetSel(scintillaGateway.PositionFromLine(i), scintillaGateway.GetLineEndPosition(i)); CapitalizeTitle(); break; } // Support for Setext headers. else if ((line[j] == '-' || line[j] == '=') && !IsAlphaNumeric(line)) { // If it begins with '-' or '=', select the previous line and call // the CapitalizeTitle method with these parameters. scintillaGateway.GotoLine(i - 1); scintillaGateway.SetSel(scintillaGateway.PositionFromLine(i - 1), scintillaGateway.GetLineEndPosition(i - 1)); CapitalizeTitle(); break; } } } }
static public int[] LinesWithMarker(this ScintillaGateway document, int marker) { Application.DoEvents(); int mask = 1 << marker; var result = new List <int>(); // int line = -1; // while (-1 != (line = document.MarkerNext(++line, mask))) // result.Add(line); for (int line = 0; line < document.GetLineCount(); line++) { var markers = document.HasMarker(line); if ((markers & mask) != 0) { result.Add(line); } } return(result.ToArray()); }
static public int[] LinesWithMarker(this ScintillaGateway document, int marker) { Application.DoEvents(); int mask = 1 << marker; var result = new List <int>(); // ideal solution but for unknown reason MarkerNext does not work reliably. // So resorting to line by line inefficient iterations. // int line = -1; // while (-1 != (line = document.MarkerNext(++line, mask))) // result.Add(line); for (int line = 0; line < document.GetLineCount(); line++) { var markers = document.HasMarker(line); if ((markers & mask) != 0) { result.Add(line); } } return(result.ToArray()); }
internal static void Process(bool isScript, string script = null, Action <object> setResult = null, bool forceErrorInOutput = false) { Init(); if (!Config.Instance.KeepVariablesBetweenEvaluations) { LastVariables = new Dictionary <string, object>(); } else if (LastVariables != null) { LastVariables .ToList() .FindAll(kvp => kvp.Value is StronglyTypedVariable) .ForEach(kvp => LastVariables.Remove(kvp.Key)); } evaluator.Variables = LastVariables; evaluator.OptionForceIntegerNumbersEvaluationsAsDoubleByDefault = Config.Instance.OptionForceIntegerNumbersEvaluationsAsDoubleByDefault; evaluator.OptionCaseSensitiveEvaluationActive = Config.Instance.CaseSensitive; evaluator.OptionsSyntaxRules.MandatoryLastStatementTerminalPunctuator = false; evaluator.OptionsSyntaxRules.IsNewKeywordForAnonymousExpandoObjectOptional = true; evaluator.OptionsSyntaxRules.AllowSimplifiedCollectionSyntax = true; evaluator.OptionsSyntaxRules.SimplifiedCollectionMode = SimplifiedCollectionMode.List; evaluator.OptionsSyntaxRules.InitializerPropertyValueSeparators = new[] { "=", ":" }; evaluator.OptionsSyntaxRules.InitializerAllowStringForProperties = true; try { if (BNpp.SelectionLength <= 0) { IScintillaGateway scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla()); int line = scintilla.GetCurrentLineNumber(); int end = scintilla.GetLineEndPosition(line); int start = 0; if (isScript) { // TODO special start script tag } else { int i; for (i = line; i > 0 && scintilla.GetLine(line).TrimStart().StartsWith("."); i--) { ; } start = scintilla.PositionFromLine(i); for (i = line; i < scintilla.GetLineCount() && scintilla.GetLine(line).TrimStart().StartsWith("."); i++) { ; } end = scintilla.GetLineEndPosition(i); } if (setResult == null) { scintilla.SetSel(new Position(start), new Position(end)); } } setResult ??= Config.Instance.CurrentResultOut.SetResult; script ??= BNpp.SelectedText; Config.Instance.LastScripts.Insert(0, script); while (Config.Instance.LastScripts.Count > Config.Instance.NbrOfLastScriptToKeep) { Config.Instance.LastScripts.RemoveAt(Config.Instance.LastScripts.Count - 1); } Config.Instance.LastScripts = Config.Instance.LastScripts.Distinct().ToList(); object result = isScript ? evaluator.ScriptEvaluate(evaluator.RemoveComments(script)) : evaluator.Evaluate(evaluator.RemoveComments(script.TrimEnd(';'))); setResult(result); } catch (Exception exception) { if (Config.Instance.ShowExceptionInMessageBox && !forceErrorInOutput) { MessageBox.Show(exception.Message); } if (Config.Instance.ShowExceptionInOutput || forceErrorInOutput) { setResult(exception); } if (!string.IsNullOrEmpty(CustomEvaluations.Print)) { setResult(CustomEvaluations.Print); } } finally { LastVariables = evaluator.Variables; Config.Instance.Save(); } }
/// <summary>Trennt die Punkte aus dem Aktuellem Text</summary> /// <param name="settings"></param> public void getMeasuresFromCurrentCADdy(Settings settings) { IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); standpunkte.Clear(); if (editor != null) { Int32 countLines = editor.GetLineCount(); ClassCADdyStandpunkt cuStandpunkt = null; 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 ((4 >= split.Length) && (split.Length >= 3)) // Standpunkt { if (split[0].StartsWith("-")) { if (cuStandpunkt != null) { standpunkte.Add(cuStandpunkt); } cuStandpunkt = new ClassCADdyStandpunkt(); cuStandpunkt.LineNumber = lc; cuStandpunkt.Punktnummer = ClassStringTools.trimToEmpty(split[settings.PointName_Column - 1]); if (settings.PointName_ToUpper) { cuStandpunkt.Punktnummer = cuStandpunkt.Punktnummer.ToUpper(); } Double temp = Double.NaN; if (ClassConverters.StringToDouble(split[settings.Messd_I_Column - 1], out temp)) { cuStandpunkt.I = temp; // code cuStandpunkt.Code = ClassStringTools.trimToEmpty(split[settings.Messd_STPKCode_Column - 1]); if (split.Length == 4) { // code cuStandpunkt.Bemerkung = ClassStringTools.trimToEmpty(split[settings.Messd_STPKDescript_Column - 1]); } } } } if (split.Length >= 5) // = Zielpunkt { if (cuStandpunkt != null) { ClassCADdyZielung zielung = new ClassCADdyZielung(); { zielung.Zielpunkt = ClassStringTools.trimToEmpty(split[settings.PointName_Column - 1]); if (settings.PointName_ToUpper) { zielung.Zielpunkt = zielung.Zielpunkt.ToUpper(); } if (!ClassStringTools.IsNullOrWhiteSpace(zielung.Zielpunkt)) { Double temp = Double.NaN; if (ClassConverters.StringToDouble(split[settings.Messd_Hz_Column - 1], out temp)) { zielung.Hz = temp; if (ClassConverters.StringToDouble(split[settings.Messd_S_Column - 1], out temp)) { zielung.S = temp; if (ClassConverters.StringToDouble(split[settings.Messd_V_Column - 1], out temp)) { zielung.V = temp; if (ClassConverters.StringToDouble(split[settings.Messd_D_Column - 1], out temp)) { zielung.D = temp; if (split.Length >= 6) { // code zielung.Code = ClassStringTools.trimToEmpty(split[settings.Messd_Code_Column - 1]); if (split.Length >= 7) { // Beschreibung zielung.Bemerkung = ClassStringTools.trimToEmpty(split[settings.Messd_Descript_Column - 1]); } } } zielung.LineNumber = lc; cuStandpunkt.Zielungen.Add(zielung); } } } } } } } } } // den letzten nicht vergessen if (cuStandpunkt != null) { standpunkte.Add(cuStandpunkt); } } hasMessdaten = standpunkte.Count > 0; }
/// <summary>Testet, um welche Datenstruktut es sich handeln könnte</summary> /// <param name="settings"></param> /// <returns></returns> public static enWhatIAm check(Settings settings) { enWhatIAm result = enWhatIAm.iDontKnown; IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); if (editor.GetLineCount() > 0) { String cuLine = editor.GetLine(0); 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) { switch (split.Length) { case 3: if (split[settings.PointName_Column - 1].StartsWith("-")) { result = enWhatIAm.CADdyMeasure; } break; case 4: if (split[settings.PointName_Column - 1].StartsWith("-")) { result = enWhatIAm.CADdyMeasure; } else if (split[settings.Koord_RW_E_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Koord_RW_E_Column - 1])) { if (split[settings.Koord_HW_N_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Koord_HW_N_Column - 1])) { if (split[settings.Koord_Elev_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Koord_Elev_Column - 1])) { // Koordinaten ohne Code result = enWhatIAm.CADdyCoord; } } } break; case 5: if (split[settings.Koord_RW_E_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Koord_RW_E_Column - 1])) { if (split[settings.Koord_HW_N_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Koord_HW_N_Column - 1])) { if (split[settings.Koord_Elev_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Koord_Elev_Column - 1])) { if (!split[settings.Koord_Code_Column - 1].Contains(settings.Decimalseperator)) { result = enWhatIAm.CADdyCoord; } } } } if (result == enWhatIAm.iDontKnown) { if (split[settings.Messd_Hz_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_Hz_Column - 1])) { if (split[settings.Messd_V_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_V_Column - 1])) { if (split[settings.Messd_S_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_S_Column - 1])) { if (split[settings.Messd_D_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_D_Column])) { result = enWhatIAm.CADdyMeasure; } } } } } break; case 6: if (split[settings.Koord_RW_E_Column - 1].Contains(settings.Decimalseperator)) { if (split[settings.Koord_HW_N_Column - 1].Contains(settings.Decimalseperator)) { if (split[settings.Koord_Elev_Column - 1].Contains(settings.Decimalseperator)) { if (!split[settings.Koord_Code_Column - 1].Contains(settings.Decimalseperator)) { result = enWhatIAm.CADdyCoord; } } } } if (result == enWhatIAm.iDontKnown) { if (split[settings.Messd_Hz_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_Hz_Column - 1])) { if (split[settings.Messd_V_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_V_Column - 1])) { if (split[settings.Messd_S_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_S_Column - 1])) { if (split[settings.Messd_D_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_D_Column - 1])) { if (!split[settings.Messd_Code_Column - 1].Contains(settings.Decimalseperator)) { result = enWhatIAm.CADdyMeasure; } } } } } } break; case 7: if (split[settings.Messd_Hz_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_Hz_Column - 1])) { if (split[settings.Messd_V_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_V_Column - 1])) { if (split[settings.Messd_S_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_S_Column - 1])) { if (split[settings.Messd_D_Column - 1].Contains(settings.Decimalseperator) || ClassStringTools.IsNumeric(split[settings.Messd_D_Column - 1])) { if (!split[settings.Messd_Code_Column - 1].Contains(settings.Decimalseperator)) { result = enWhatIAm.CADdyMeasure; } } } } } break; default: break; } } } return(result); }