/// <summary> /// Call this method to set the back/fore color and font type of each type used in 3P according to the /// styles defined in the SyntaxHighlighting file /// </summary> public static void SetSyntaxStyles() { var curTheme = Current; if (Config.Instance.UseSyntaxHighlightTheme) { // Default SetFontStyle((byte)SciMsg.STYLE_DEFAULT, curTheme.Default); // Npp.StyleClearAll(); // to apply the default style to all styles SetFontStyle((byte)SciMsg.STYLE_CONTROLCHAR, curTheme.Default); SetFontStyle((byte)UdlStyles.Idk, curTheme.Default); SetFontStyle((byte)UdlStyles.Default, curTheme.Default); // categories SetFontStyle((byte)UdlStyles.Comment, curTheme.Comment); SetFontStyle((byte)UdlStyles.CommentLine, curTheme.PreProcessed); SetFontStyle((byte)UdlStyles.Number, curTheme.Numbers); SetFontStyle((byte)UdlStyles.KeyWordsList1, curTheme.JumpStatement); SetFontStyle((byte)UdlStyles.KeyWordsList2, curTheme.Statement); SetFontStyle((byte)UdlStyles.KeyWordsList3, curTheme.VarType); SetFontStyle((byte)UdlStyles.KeyWordsList4, curTheme.OtherKeywords); SetFontStyle((byte)UdlStyles.KeyWordsList5, curTheme.PreProcessed); SetFontStyle((byte)UdlStyles.KeyWordsList6, curTheme.NormedVariables); SetFontStyle((byte)UdlStyles.KeyWordsList7, curTheme.Abbreviations); SetFontStyle((byte)UdlStyles.KeyWordsList8, curTheme.SpecialWord); SetFontStyle((byte)UdlStyles.Operators, curTheme.Operators); SetFontStyle((byte)UdlStyles.FolderInCode2, curTheme.Statement); SetFontStyle((byte)UdlStyles.Delimiter1, curTheme.DoubleQuote); SetFontStyle((byte)UdlStyles.Delimiter2, curTheme.SimpleQuote); SetFontStyle((byte)UdlStyles.Delimiter3, curTheme.Includes); SetFontStyle((byte)UdlStyles.Delimiter4, curTheme.DoubleQuote); SetFontStyle((byte)UdlStyles.Delimiter5, curTheme.SimpleQuote); SetFontStyle((byte)UdlStyles.Delimiter7, curTheme.SingleLineComment); SetFontStyle((byte)UdlStyles.Delimiter8, curTheme.NestedComment); // line numbers SetFontStyle((byte)SciMsg.STYLE_LINENUMBER, curTheme.LineNumberMargin); // set url as strings SetFontStyle(80, curTheme.SimpleQuote); // brace highlighting SetFontStyle((byte)SciMsg.STYLE_BRACELIGHT, curTheme.BraceHighLight); SetFontStyle((byte)SciMsg.STYLE_BRACEBAD, curTheme.BadBraceHighLight); // smart highlighting in npp Sci.GetIndicator(29).ForeColor = curTheme.SmartHighLighting.ForeColor; } // Setting styles for errors SetErrorStyles((byte)ErrorLevel.Information, curTheme.Error0.BackColor, curTheme.Error0.ForeColor); SetErrorStyles((byte)ErrorLevel.Warning, curTheme.Error1.BackColor, curTheme.Error1.ForeColor); SetErrorStyles((byte)ErrorLevel.StrongWarning, curTheme.Error2.BackColor, curTheme.Error2.ForeColor); SetErrorStyles((byte)ErrorLevel.Error, curTheme.Error3.BackColor, curTheme.Error3.ForeColor); SetErrorStyles((byte)ErrorLevel.Critical, curTheme.Error4.BackColor, curTheme.Error4.ForeColor); }
static public void ReplaceTextAtIndicator(string text, Point indicatorRange) { Sci.SetTextByRange(indicatorRange.X, indicatorRange.Y, text); //restore the indicator var indic = Sci.GetIndicator(SnippetContext.IndicatorId); indic.IndicatorStyle = IndicatorStyle.Box; indic.ForeColor = Color.Blue; indic.Add(indicatorRange.X, indicatorRange.X + text.Length); }
public static bool TriggerCodeSnippetInsertion() { if (InsertionActive) { return(false); // do no insert a snippet within a snippet! } string token = Sci.GetWord(null, Sci.CurrentPosition); var curPos = Sci.CurrentPosition; Point tokenPoints = new Point(curPos - token.Length, curPos); if (Contains(token)) { string replacement = GetTemplate(token); if (replacement != null) { int line = Sci.Line.CurrentLine; int lineStartPos = Sci.GetLine(line).Position; int horizontalOffset = tokenPoints.X - lineStartPos; //relative selection in the replacement text PrepareForIncertion(replacement, horizontalOffset, tokenPoints.X); var indic = Sci.GetIndicator(SnippetContext.IndicatorId); indic.IndicatorStyle = IndicatorStyle.Box; indic.ForeColor = Color.Blue; foreach (var point in LocSnippetContext.Parameters) { indic.Add(point.X, point.Y); } if (LocSnippetContext.CurrentParameter.HasValue) { Sci.SetSelection(LocSnippetContext.CurrentParameter.Value.X, LocSnippetContext.CurrentParameter.Value.Y); LocSnippetContext.CurrentParameterValue = Sci.GetTextBetween(LocSnippetContext.CurrentParameter.Value); } AutoCompletion.Cloak(); if (LocSnippetContext.Parameters.Count <= 1) { FinalizeCurrent(); } } return(true); } return(false); }
/// <summary> /// Call this method to set the back/fore color and font type of each type used in 3P according to the /// styles defined in the SyntaxHighlighting file /// </summary> public void SetScintillaStyles() { // Default SetFontStyle((byte)SciMsg.STYLE_DEFAULT, GetStyle(SciStyleId.Default)); SetFontStyle((byte)SciMsg.STYLE_CONTROLCHAR, GetStyle(SciStyleId.Default)); foreach (var kpv in Items) { SetFontStyle((byte)kpv.Key, kpv.Value); } // line numbers SetFontStyle((byte)SciMsg.STYLE_LINENUMBER, GetStyle(SciStyleId.LineNumberMargin)); // set url as strings SetFontStyle(80, GetStyle(SciStyleId.SimpleQuote)); // brace highlighting SetFontStyle((byte)SciMsg.STYLE_BRACELIGHT, GetStyle(SciStyleId.BraceHighLight)); SetFontStyle((byte)SciMsg.STYLE_BRACEBAD, GetStyle(SciStyleId.BadBraceHighLight)); // smart highlighting in npp Sci.GetIndicator(29).ForeColor = GetStyle(SciStyleId.SmartHighLighting).ForeColor; // Setting styles for errors SetErrorStyles((byte)ErrorLevel.Information, GetStyle(SciStyleId.Error0)); SetErrorStyles((byte)ErrorLevel.Warning, GetStyle(SciStyleId.Error1)); SetErrorStyles((byte)ErrorLevel.StrongWarning, GetStyle(SciStyleId.Error2)); SetErrorStyles((byte)ErrorLevel.Error, GetStyle(SciStyleId.Error3)); SetErrorStyles((byte)ErrorLevel.Critical, GetStyle(SciStyleId.Error4)); Sci.SetIndentGuideColor(GetStyle(SciStyleId.WhiteSpace).BackColor, GetStyle(SciStyleId.WhiteSpace).ForeColor); Sci.SetWhiteSpaceColor(true, Color.Transparent, GetStyle(SciStyleId.WhiteSpace).ForeColor); Sci.SetSelectionColor(true, GetStyle(SciStyleId.Selection).BackColor, Color.Transparent); Sci.CaretLineBackColor = GetStyle(SciStyleId.CaretLine).BackColor; Sci.CaretColor = GetStyle(SciStyleId.CaretColor).ForeColor; // Set colors for all folding markers and margin Sci.SetFoldMarginColors(true, GetStyle(SciStyleId.FoldMargin).BackColor, GetStyle(SciStyleId.FoldMargin).BackColor); Sci.SetFoldMarginMarkersColor(GetStyle(SciStyleId.FoldMargin).ForeColor, GetStyle(SciStyleId.FoldMargin).BackColor, GetStyle(SciStyleId.FoldActiveMarker).ForeColor); // Configure folding markers with respective symbols Sci.GetMarker(Sci.Marker.FolderEnd).Symbol = MarkerSymbol.BoxPlusConnected; Sci.GetMarker(Sci.Marker.Folder).Symbol = MarkerSymbol.BoxPlus; Sci.GetMarker(Sci.Marker.FolderMidTail).Symbol = MarkerSymbol.TCorner; Sci.GetMarker(Sci.Marker.FolderOpenMid).Symbol = MarkerSymbol.BoxMinusConnected; Sci.GetMarker(Sci.Marker.FolderSub).Symbol = MarkerSymbol.VLine; Sci.GetMarker(Sci.Marker.FolderTail).Symbol = MarkerSymbol.LCorner; Sci.GetMarker(Sci.Marker.FolderOpen).Symbol = MarkerSymbol.BoxMinus; }
static public void FinalizeCurrent() { var indic = Sci.GetIndicator(SnippetContext.IndicatorId); var indicators = indic.FindRanges().ToArray(); foreach (var range in indicators) { indic.Clear(range.X, range.Y); } var caretPoint = indicators.Where(point => { string text = Sci.GetTextBetween(point); return(text == " " || text == "|"); }) .FirstOrDefault(); if (caretPoint.X != caretPoint.Y) { Sci.SetTextByRange(caretPoint.X, caretPoint.Y, ""); Sci.SetSelection(caretPoint.X, caretPoint.X); } LocSnippetContext = null; }
static public bool NavigateToNextParam() { var indic = Sci.GetIndicator(SnippetContext.IndicatorId); indic.IndicatorStyle = IndicatorStyle.Box; indic.ForeColor = Color.Blue; var indicators = indic.FindRanges().ToArray(); if (!indicators.Any()) { return(false); } if (LocSnippetContext.CurrentParameter != null) { Point currentParam = LocSnippetContext.CurrentParameter.Value; string currentParamOriginalText = LocSnippetContext.CurrentParameterValue; Sci.SetSelection(currentParam.X, currentParam.X); string currentParamDetectedText = Sci.GetWordAtPosition(Sci.CurrentPosition, AutoCompletion.CurrentLangAdditionalChars); if (currentParamOriginalText != currentParamDetectedText) { //current parameter is modified, indicator is destroyed so restore the indicator first indic.Add(currentParam.X, currentParam.X + currentParamDetectedText.Length); indicators = indic.FindRanges().ToArray(); //needs refreshing as the document is modified var paramsInfo = indicators.Select(p => new { Index = indicators.IndexOf(p), Text = Sci.GetTextBetween(p), Range = p, Pos = p.X }) .OrderBy(x => x.Pos) .ToArray(); var paramsToUpdate = paramsInfo.Where(item => item.Text == currentParamOriginalText).ToArray(); foreach (var param in paramsToUpdate) { ReplaceTextAtIndicator(currentParamDetectedText, indicators[param.Index]); indicators = indic.FindRanges().ToArray(); //needs refreshing as the document is modified } } Point?nextParameter = null; int currentParamIndex = indicators.FindIndex(x => x.X >= currentParam.X); //can also be logical 'next' var prevParamsValues = indicators.Take(currentParamIndex).Select(p => Sci.GetTextBetween(p)).ToList(); prevParamsValues.Add(currentParamOriginalText); prevParamsValues.Add(currentParamDetectedText); prevParamsValues.Add(" "); prevParamsValues.Add("|"); foreach (var range in indicators.ToArray()) { if (currentParam.X < range.X && !prevParamsValues.Contains(Sci.GetTextBetween(range))) { nextParameter = range; break; } } if (!nextParameter.HasValue) { nextParameter = indicators.FirstOrDefault(); } LocSnippetContext.CurrentParameter = nextParameter; } if (LocSnippetContext.CurrentParameter.HasValue) { Sci.SetSelection(LocSnippetContext.CurrentParameter.Value.X, LocSnippetContext.CurrentParameter.Value.Y); LocSnippetContext.CurrentParameterValue = Sci.GetTextBetween(LocSnippetContext.CurrentParameter.Value); } return(true); }