public static ColorSheme LoadFrom(XmlReader reader) { var result = new ColorSheme(); XmlReadHelper.ReadList(reader, "EditorStyle", delegate() { switch (reader.LocalName) { case "EditorStyle": result.Name = reader.GetAttribute(NameAttribute); result.Description = reader.GetAttribute("_description"); return(true); case "Color": result.customPalette [reader.GetAttribute("name")] = reader.GetAttribute("value"); return(true); case "Style": ReadStyleTree(reader, result, null, null, null, null); return(true); } return(false); }); result.GetChunkStyle(DefaultString).ChunkProperties |= ChunkProperties.TransparentBackground; return(result); }
public virtual bool GetIsValid (ColorSheme style) { foreach (Keywords keyword in keywords) { if (!keyword.GetIsValid (style)) { System.Console.WriteLine (keyword + " failed."); return false; } } foreach (Span span in spans) { if (!span.GetIsValid (style)) { System.Console.WriteLine (span + " failed."); return false; } } foreach (Match match in matches) { if (!match.GetIsValid (style)) { System.Console.WriteLine (match + " failed."); return false; } } foreach (Marker marker in prevMarker) { if (!marker.GetIsValid (style)) { System.Console.WriteLine (marker + " failed."); return false; } } return true; }
void CopyData(TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (selection != null && data != null && data.Document != null) { copiedDocument = new Document(); monoDocument = new Document(); this.docStyle = data.ColorStyle; this.options = data.Options; this.mode = data.Document.SyntaxMode != null && data.Options.EnableSyntaxHighlighting ? data.Document.SyntaxMode : Mono.TextEditor.Highlighting.SyntaxMode.Default; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; ISegment segment = selection.GetSelectionRange(data); copiedDocument.Text = this.mode.GetTextWithoutMarkup(data.Document, data.ColorStyle, segment.Offset, segment.Length); monoDocument.Text = this.mode.GetTextWithoutMarkup(data.Document, data.ColorStyle, segment.Offset, segment.Length); LineSegment line = data.Document.GetLineByOffset(segment.Offset); var spanStack = line.StartSpan.Clone(); SyntaxModeService.ScanSpans(data.Document, this.mode, this.mode, spanStack, line.Offset, segment.Offset); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation(selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation(selection.Lead); int startCol = System.Math.Min(visStart.Column, visEnd.Column); int endCol = System.Math.Max(visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { LineSegment curLine = data.Document.GetLine(lineNr); int col1 = curLine.GetLogicalColumn(data, startCol) - 1; int col2 = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.EditableLength); if (col1 < col2) { ((IBuffer)copiedDocument).Insert(copiedDocument.Length, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); ((IBuffer)monoDocument).Insert(monoDocument.Length, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. ((IBuffer)copiedDocument).Insert(copiedDocument.Length, Environment.NewLine); // \r in mono document stands for block selection line end. ((IBuffer)monoDocument).Insert(monoDocument.Length, "\r"); } } line = data.Document.GetLine(selection.MinLine); spanStack = line.StartSpan.Clone(); SyntaxModeService.ScanSpans(data.Document, this.mode, this.mode, spanStack, line.Offset, line.Offset + startCol); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
public static string GetFileNameForStyle (ColorSheme style) { string result; if (!isLoadedFromFile.TryGetValue (style.Name, out result)) return null; return result; }
static void ReadStyleTree(XmlReader reader, ColorSheme result, string curName, string curWeight, string curColor, string curBgColor) { string name = reader.GetAttribute("name"); string weight = reader.GetAttribute("weight") ?? curWeight; string color = reader.GetAttribute("color"); string bgColor = reader.GetAttribute("bgColor"); string fullName; if (String.IsNullOrEmpty(curName)) { fullName = name; } else { fullName = curName + "." + name; } if (!String.IsNullOrEmpty(color)) { result.SetChunkStyle(fullName, weight, color, bgColor); } XmlReadHelper.ReadList(reader, "Style", delegate() { switch (reader.LocalName) { case "Style": ReadStyleTree(reader, result, fullName, weight, color, bgColor); return(true); } return(false); }); }
static ChunkStyle GetChunkStyle(ColorSheme style, IEnumerable <Tag> tagStack) { ChunkStyle result = new ChunkStyle(); if (style == null) { style = new DefaultStyle(null); } result.CairoColor = style.Default.CairoColor; foreach (Tag tag in tagStack) { //System.Console.WriteLine("'" + tag.Command + "'"); switch (tag.Command) { case "B": result.ChunkProperties |= ChunkProperties.Bold; break; case "SPAN": string val; if (tag.Arguments.TryGetValue("style", out val)) { ChunkStyle chunkStyle = style.GetChunkStyle(val); if (chunkStyle != null) { result.CairoColor = chunkStyle.CairoColor; result.ChunkProperties |= chunkStyle.ChunkProperties; } else { throw new Exception("Style " + val + " not found."); } } if (tag.Arguments.TryGetValue("foreground", out val)) { result.CairoColor = style.GetColorFromString(val); } if (tag.Arguments.TryGetValue("background", out val)) { result.CairoBackgroundColor = style.GetColorFromString(val); } break; case "A": result.Link = tag.Arguments["ref"]; break; case "I": result.ChunkProperties |= ChunkProperties.Italic; break; case "U": result.ChunkProperties |= ChunkProperties.Underline; break; } } return(result); }
public virtual bool GetIsValid (ColorSheme style) { if (style.GetChunkStyle (Color) == null) { System.Console.WriteLine("color:" + Color + " not found."); return false; } return true; }
public static IXmlProvider GetProvider(ColorSheme style) { if (styleLookup.ContainsKey(style.Name)) { return(styleLookup[style.Name]); } return(null); }
public virtual bool GetIsValid(ColorSheme style) { if (style.GetChunkStyle(Color) == null) { System.Console.WriteLine("color:" + Color + " not found."); return(false); } return(true); }
public static string GetFileNameForStyle(ColorSheme style) { string result; if (!isLoadedFromFile.TryGetValue(style.Name, out result)) { return(null); } return(result); }
public static void Remove(ColorSheme style) { if (styles.ContainsKey(style.Name)) { styles.Remove(style.Name); } if (styleLookup.ContainsKey(style.Name)) { styleLookup.Remove(style.Name); } }
public bool Validate (ColorSheme style) { if (!GetIsValid (style)) { return false; } foreach (Rule rule in Rules) { if (!rule.GetIsValid (style)) { return false; } } return true; }
public bool Validate(ColorSheme style) { if (!GetIsValid(style)) { return(false); } foreach (Rule rule in Rules) { if (!rule.GetIsValid(style)) { return(false); } } return(true); }
public virtual Chunk GetChunks(Document doc, ColorSheme style, LineSegment line, int offset, int length) { SpanParser spanParser = CreateSpanParser(doc, this, line, null); ChunkParser chunkParser = CreateChunkParser(spanParser, doc, style, this, line); Chunk result = chunkParser.GetChunks(chunkParser.lineOffset, line.EditableLength); if (SemanticRules != null) { foreach (SemanticRule sematicRule in SemanticRules) { sematicRule.Analyze(doc, line, result, offset, offset + length); } } if (result != null) { // crop to begin if (result.Offset != offset) { while (result != null && result.EndOffset < offset) { result = result.Next; } if (result != null) { int endOffset = result.EndOffset; result.Offset = offset; result.Length = endOffset - offset; } } if (result != null && offset + length != chunkParser.lineOffset + line.EditableLength) { // crop to end Chunk cur = result; while (cur != null && cur.EndOffset < offset + length) { cur = cur.Next; } if (cur != null) { cur.Length = offset + length - cur.Offset; cur.Next = null; } } } return(result); }
static void LoadStyle(string name) { if (!styleLookup.ContainsKey(name)) { throw new System.ArgumentException("Style " + name + " not found", "name"); } XmlReader reader = styleLookup [name].Open(); try { styles [name] = ColorSheme.LoadFrom(reader); } catch (Exception e) { throw new IOException("Error while loading style :" + name, e); } finally { reader.Close(); } }
public ChunkParser(SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) { this.mode = mode; this.doc = doc; this.line = line; this.lineOffset = line.Offset; this.spanParser = spanParser; spanParser.FoundSpanBegin = FoundSpanBegin; spanParser.FoundSpanEnd = FoundSpanEnd; spanParser.FoundSpanExit = FoundSpanExit; spanParser.ParseChar += ParseChar; if (line == null) { throw new ArgumentNullException("line"); } }
public override string GetTextWithoutMarkup(Document doc, ColorSheme style, int offset, int length) { StringBuilder result = new StringBuilder(); int curOffset = offset; int endOffset = offset + length; while (curOffset < endOffset) { LineSegment curLine = doc.GetLineByOffset(curOffset); for (Chunk chunk = GetChunks(doc, style, curLine, curOffset, System.Math.Min(endOffset - curOffset, curLine.EndOffset - curOffset)); chunk != null; chunk = chunk.Next) { result.Append(chunk.GetText(doc)); } curOffset = curLine.EndOffset; } return(result.ToString()); }
public virtual Chunk GetChunks (Document doc, ColorSheme style, LineSegment line, int offset, int length) { SpanParser spanParser = CreateSpanParser (doc, this, line, null); ChunkParser chunkParser = CreateChunkParser (spanParser, doc, style, this, line); Chunk result = chunkParser.GetChunks (chunkParser.lineOffset, line.EditableLength); if (SemanticRules != null) { foreach (SemanticRule sematicRule in SemanticRules) { sematicRule.Analyze (doc, line, result, offset, offset + length); } } if (result != null) { // crop to begin if (result.Offset != offset) { while (result != null && result.EndOffset < offset) result = result.Next; if (result != null) { int endOffset = result.EndOffset; result.Offset = offset; result.Length = endOffset - offset; } } if (result != null && offset + length != chunkParser.lineOffset + line.EditableLength) { // crop to end Chunk cur = result; while (cur != null && cur.EndOffset < offset + length) { cur = cur.Next; } if (cur != null) { cur.Length = offset + length - cur.Offset; cur.Next = null; } } } return result; }
public virtual bool GetIsValid(ColorSheme style) { foreach (Keywords keyword in keywords) { if (!keyword.GetIsValid(style)) { System.Console.WriteLine(keyword + " failed."); return(false); } } foreach (Span span in spans) { if (!span.GetIsValid(style)) { System.Console.WriteLine(span + " failed."); return(false); } } foreach (Match match in matches) { if (!match.GetIsValid(style)) { System.Console.WriteLine(match + " failed."); return(false); } } foreach (Marker marker in prevMarker) { if (!marker.GetIsValid(style)) { System.Console.WriteLine(marker + " failed."); return(false); } } return(true); }
public virtual bool GetIsValid(ColorSheme style) { return(style.GetChunkStyle(Color) != null); }
public static IXmlProvider GetProvider (ColorSheme style) { if (styleLookup.ContainsKey (style.Name)) return styleLookup[style.Name]; return null; }
public override bool GetIsValid (ColorSheme style) { return true; }
public string GetMarkup(Document doc, ITextEditorOptions options, ColorSheme style, int offset, int length, bool removeIndent, bool useColors, bool replaceTabs) { int indentLength = GetIndentLength(doc, offset, length, false); int curOffset = offset; StringBuilder result = new StringBuilder(); while (curOffset < offset + length && curOffset < doc.Length) { LineSegment line = doc.GetLineByOffset(curOffset); int toOffset = System.Math.Min(line.Offset + line.EditableLength, offset + length); Stack <ChunkStyle> styleStack = new Stack <ChunkStyle> (); for (Chunk chunk = GetChunks(doc, style, line, curOffset, toOffset - curOffset); chunk != null; chunk = chunk.Next) { ChunkStyle chunkStyle = chunk.GetChunkStyle(style); bool setBold = chunkStyle.Bold && (styleStack.Count == 0 || !styleStack.Peek().Bold) || !chunkStyle.Bold && (styleStack.Count == 0 || styleStack.Peek().Bold); bool setItalic = chunkStyle.Italic && (styleStack.Count == 0 || !styleStack.Peek().Italic) || !chunkStyle.Italic && (styleStack.Count == 0 || styleStack.Peek().Italic); bool setUnderline = chunkStyle.Underline && (styleStack.Count == 0 || !styleStack.Peek().Underline) || !chunkStyle.Underline && (styleStack.Count == 0 || styleStack.Peek().Underline); bool setColor = styleStack.Count == 0 || TextViewMargin.GetPixel(styleStack.Peek().Color) != TextViewMargin.GetPixel(chunkStyle.Color); if (setColor || setBold || setItalic || setUnderline) { if (styleStack.Count > 0) { result.Append("</span>"); styleStack.Pop(); } result.Append("<span"); if (useColors) { result.Append(" foreground=\""); result.Append(ColorToPangoMarkup(chunkStyle.Color)); result.Append("\""); } if (chunkStyle.Bold) { result.Append(" weight=\"bold\""); } if (chunkStyle.Italic) { result.Append(" style=\"italic\""); } if (chunkStyle.Underline) { result.Append(" underline=\"single\""); } result.Append(">"); styleStack.Push(chunkStyle); } for (int i = 0; i < chunk.Length && chunk.Offset + i < doc.Length; i++) { char ch = chunk.GetCharAt(doc, chunk.Offset + i); switch (ch) { case '&': result.Append("&"); break; case '<': result.Append("<"); break; case '>': result.Append(">"); break; case '\t': if (replaceTabs) { result.Append(new string (' ', options.TabSize)); } else { result.Append('\t'); } break; default: result.Append(ch); break; } } } while (styleStack.Count > 0) { result.Append("</span>"); styleStack.Pop(); } curOffset = line.EndOffset; if (removeIndent) { curOffset += indentLength; } if (result.Length > 0 && curOffset < offset + length) { result.AppendLine(); } } return(result.ToString()); }
public virtual string GetTextWithoutMarkup(Document doc, ColorSheme style, int offset, int length) { return(doc.GetTextAt(offset, length)); }
public override Chunk GetChunks(Document doc, ColorSheme style, LineSegment line, int offset, int length) { int endOffset = System.Math.Min(offset + length, doc.Length); Stack <Tag> tagStack = new Stack <Tag> (); TextChunk curChunk = new TextChunk(new ChunkStyle(), offset); Chunk startChunk = curChunk; Chunk endChunk = curChunk; bool inTag = true, inSpecial = false; int specialBegin = -1; StringBuilder tagBuilder = new StringBuilder(); StringBuilder specialBuilder = new StringBuilder(); for (int i = offset; i < endOffset; i++) { char ch = doc.GetCharAt(i); switch (ch) { case '<': curChunk.Length = i - curChunk.Offset; if (curChunk.Length > 0) { curChunk.ChunkStyle = GetChunkStyle(style, tagStack); endChunk = endChunk.Next = curChunk; curChunk = new TextChunk(new ChunkStyle(), offset); } tagBuilder.Length = 0; specialBuilder.Length = 0; inTag = true; break; case '&': curChunk.Length = i - curChunk.Offset; if (curChunk.Length > 0) { curChunk.ChunkStyle = GetChunkStyle(style, tagStack); endChunk = endChunk.Next = curChunk; curChunk = new TextChunk(new ChunkStyle(), offset); } inSpecial = true; specialBuilder.Length = 0; tagBuilder.Length = 0; specialBegin = i; break; case ';': if (inSpecial) { string specialText = specialBuilder.ToString(); switch (specialText) { case "lt": endChunk = endChunk.Next = new TextChunk(GetChunkStyle(style, tagStack), specialBegin, "<"); break; case "gt": endChunk = endChunk.Next = new TextChunk(GetChunkStyle(style, tagStack), specialBegin, ">"); break; case "amp": endChunk = endChunk.Next = new TextChunk(GetChunkStyle(style, tagStack), specialBegin, "&"); break; } curChunk.Offset = i + 1; inSpecial = false; specialBuilder.Length = 0; tagBuilder.Length = 0; } break; case '>': if (!inTag) { break; } string tagText = tagBuilder.ToString(); tagBuilder.Length = 0; if (tagText.StartsWith("/")) { if (tagStack.Count > 0) { tagStack.Pop(); } } else { tagStack.Push(Tag.Parse(tagText)); } curChunk.Offset = i + 1; inTag = false; specialBuilder.Length = 0; tagBuilder.Length = 0; break; default: if (inSpecial) { specialBuilder.Append(ch); } else { tagBuilder.Append(ch); } break; } } curChunk.Length = endOffset - curChunk.Offset; if (curChunk.Length > 0) { curChunk.ChunkStyle = GetChunkStyle(style, tagStack); endChunk = endChunk.Next = curChunk; } endChunk.Next = null; return(startChunk); }
public virtual ChunkParser CreateChunkParser (SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) { return new ChunkParser (spanParser, doc, style, mode, line); }
public override string GetTextWithoutMarkup (Document doc, ColorSheme style, int offset, int length) { StringBuilder result = new StringBuilder (); int curOffset = offset; int endOffset = offset + length; while (curOffset < endOffset) { LineSegment curLine = doc.GetLineByOffset (curOffset); for (Chunk chunk = GetChunks (doc, style, curLine, curOffset, System.Math.Min (endOffset - curOffset, curLine.EndOffset - curOffset)); chunk != null; chunk = chunk.Next) { result.Append (chunk.GetText (doc)); } curOffset = curLine.EndOffset; } return result.ToString (); }
public ReferencedChunkStyle (ColorSheme style, string referencedStyle) { this.style = style; this.referencedStyle = referencedStyle; }
public virtual bool GetIsValid (ColorSheme style) { return (string.IsNullOrEmpty (Color) || style.GetChunkStyle (Color) != null) && (string.IsNullOrEmpty (TagColor) || style.GetChunkStyle (TagColor) != null) && (string.IsNullOrEmpty (NextColor) || style.GetChunkStyle (NextColor) != null); }
public override Chunk GetChunks (Document doc, ColorSheme style, LineSegment line, int offset, int length) { int endOffset = System.Math.Min (offset + length, doc.Length); Stack<Tag> tagStack = new Stack<Tag> (); TextChunk curChunk = new TextChunk (new ChunkStyle (), offset); Chunk startChunk = curChunk; Chunk endChunk = curChunk; bool inTag = true, inSpecial = false; int specialBegin = -1; StringBuilder tagBuilder = new StringBuilder (); StringBuilder specialBuilder = new StringBuilder (); for (int i = offset; i < endOffset; i++) { char ch = doc.GetCharAt (i); switch (ch) { case '<': curChunk.Length = i - curChunk.Offset; if (curChunk.Length > 0) { curChunk.ChunkStyle = GetChunkStyle (style, tagStack); endChunk = endChunk.Next = curChunk; curChunk = new TextChunk (new ChunkStyle (), offset); } tagBuilder.Length = 0; specialBuilder.Length = 0; inTag = true; break; case '&': curChunk.Length = i - curChunk.Offset; if (curChunk.Length > 0) { curChunk.ChunkStyle = GetChunkStyle (style, tagStack); endChunk = endChunk.Next = curChunk; curChunk = new TextChunk (new ChunkStyle (), offset); } inSpecial = true; specialBuilder.Length = 0; tagBuilder.Length = 0; specialBegin = i; break; case ';': if (inSpecial) { string specialText = specialBuilder.ToString (); switch (specialText) { case "lt": endChunk = endChunk.Next = new TextChunk (GetChunkStyle (style, tagStack), specialBegin, "<"); break; case "gt": endChunk = endChunk.Next = new TextChunk (GetChunkStyle (style, tagStack), specialBegin, ">"); break; case "amp": endChunk = endChunk.Next = new TextChunk (GetChunkStyle (style, tagStack), specialBegin, "&"); break; } curChunk.Offset = i + 1; inSpecial = false; specialBuilder.Length = 0; tagBuilder.Length = 0; } break; case '>': if (!inTag) break; string tagText = tagBuilder.ToString (); tagBuilder.Length = 0; if (tagText.StartsWith ("/")) { if (tagStack.Count > 0) tagStack.Pop (); } else { tagStack.Push (Tag.Parse (tagText)); } curChunk.Offset = i + 1; inTag = false; specialBuilder.Length = 0; tagBuilder.Length = 0; break; default: if (inSpecial) { specialBuilder.Append (ch); } else { tagBuilder.Append (ch); } break; } } curChunk.Length = endOffset - curChunk.Offset; if (curChunk.Length > 0) { curChunk.ChunkStyle = GetChunkStyle (style, tagStack); endChunk = endChunk.Next = curChunk; } endChunk.Next = null; return startChunk; }
public static void AddStyle(string fileName, ColorSheme style) { isLoadedFromFile [style.Name] = fileName; styles [style.Name] = style; }
public override ChunkStyle GetChunkStyle (ColorSheme style) { return ChunkStyle; }
public CSharpChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) : base (spanParser, doc, style, mode, line) { document = IdeApp.Workbench.GetDocument (doc.FileName); foreach (var tag in ProjectDomService.SpecialCommentTags) { tags.Add (tag.Tag); } ICSharpCode.OldNRefactory.Ast.CompilationUnit unit = null; if (document != null && document.ParsedDocument != null && MonoDevelop.Core.PropertyService.Get ("EnableSemanticHighlighting", false)) { resolver = document.GetResolver (); if (!document.ParsedDocument.TryGetTag (out unit)) { try { using (ICSharpCode.OldNRefactory.IParser parser = ICSharpCode.OldNRefactory.ParserFactory.CreateParser (ICSharpCode.OldNRefactory.SupportedLanguage.CSharp, document.Editor.Document.OpenTextReader ())) { parser.Parse (); unit = parser.CompilationUnit; document.ParsedDocument.SetTag (unit); } } catch (Exception) { resolver = null; return; } } resolver.SetupParsedCompilationUnit (unit); } }
public string GetMarkup (Document doc, ITextEditorOptions options, ColorSheme style, int offset, int length, bool removeIndent) { return GetMarkup (doc, options, style, offset, length, removeIndent, true, true); }
protected override void OnRealized() { base.OnRealized(); highlightStyle = SyntaxModeService.GetColorStyle(Style, PropertyService.Get("ColorScheme", "Default")); }
public static void AddStyle (string fileName, ColorSheme style) { isLoadedFromFile [style.Name] = fileName; styles [style.Name] = style; }
static void ReadStyleTree (XmlReader reader, ColorSheme result, string curName, string curWeight, string curColor, string curBgColor) { string name = reader.GetAttribute ("name"); string weight = reader.GetAttribute ("weight") ?? curWeight; string color = reader.GetAttribute ("color"); string bgColor = reader.GetAttribute ("bgColor"); string fullName; if (String.IsNullOrEmpty (curName)) { fullName = name; } else { fullName = curName + "." + name; } if (!String.IsNullOrEmpty (color)) { result.SetChunkStyle (fullName, weight, color, bgColor); } XmlReadHelper.ReadList (reader, "Style", delegate () { switch (reader.LocalName) { case "Style": ReadStyleTree (reader, result, fullName, weight, color, bgColor); return true; } return false; }); }
public virtual bool GetIsValid (ColorSheme style) { return style.GetChunkStyle (Color) != null; }
static ChunkStyle GetChunkStyle (ColorSheme style, IEnumerable<Tag> tagStack) { ChunkStyle result = new ChunkStyle (); if (style == null) style = new DefaultStyle (null); result.CairoColor = style.Default.CairoColor; foreach (Tag tag in tagStack) { //System.Console.WriteLine("'" + tag.Command + "'"); switch (tag.Command) { case "B": result.ChunkProperties |= ChunkProperties.Bold; break; case "SPAN": string val; if (tag.Arguments.TryGetValue ("style", out val)) { ChunkStyle chunkStyle = style.GetChunkStyle (val); if (chunkStyle != null) { result.CairoColor = chunkStyle.CairoColor; result.ChunkProperties |= chunkStyle.ChunkProperties; } else { throw new Exception ("Style " + val + " not found."); } } if (tag.Arguments.TryGetValue ("foreground", out val)) result.CairoColor = style.GetColorFromString (val); if (tag.Arguments.TryGetValue ("background", out val)) result.CairoBackgroundColor = style.GetColorFromString (val); break; case "A": result.Link = tag.Arguments["ref"]; break; case "I": result.ChunkProperties |= ChunkProperties.Italic; break; case "U": result.ChunkProperties |= ChunkProperties.Underline; break; } } return result; }
public string GetMarkup(Document doc, ITextEditorOptions options, ColorSheme style, int offset, int length, bool removeIndent) { return(GetMarkup(doc, options, style, offset, length, removeIndent, true, true)); }
public ReferencedChunkStyle(ColorSheme style, string referencedStyle) { this.style = style; this.referencedStyle = referencedStyle; }
public virtual ChunkParser CreateChunkParser(SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) { return(new ChunkParser(spanParser, doc, style, mode, line)); }
static string GenerateRtf(Document doc, Mono.TextEditor.Highlighting.SyntaxMode mode, Mono.TextEditor.Highlighting.ColorSheme style, ITextEditorOptions options) { StringBuilder rtfText = new StringBuilder(); List <Gdk.Color> colorList = new List <Gdk.Color> (); ISegment selection = new Segment(0, doc.Length); int startLineNumber = doc.OffsetToLineNumber(selection.Offset); int endLineNumber = doc.OffsetToLineNumber(selection.EndOffset); bool isItalic = false; bool isBold = false; int curColor = -1; foreach (var line in doc.GetLinesBetween(startLineNumber, endLineNumber)) { bool appendSpace = false; for (Chunk chunk = mode.GetChunks(doc, style, line, line.Offset, line.EditableLength); chunk != null; chunk = chunk.Next) { int start = System.Math.Max(selection.Offset, chunk.Offset); int end = System.Math.Min(chunk.EndOffset, selection.EndOffset); ChunkStyle chunkStyle = chunk.GetChunkStyle(style); if (start < end) { if (isBold != chunkStyle.Bold) { rtfText.Append(chunkStyle.Bold ? @"\b" : @"\b0"); isBold = chunkStyle.Bold; appendSpace = true; } if (isItalic != chunkStyle.Italic) { rtfText.Append(chunkStyle.Italic ? @"\i" : @"\i0"); isItalic = chunkStyle.Italic; appendSpace = true; } if (!colorList.Contains(chunkStyle.Color)) { colorList.Add(chunkStyle.Color); } int color = colorList.IndexOf(chunkStyle.Color); if (curColor != color) { curColor = color; rtfText.Append(@"\cf" + (curColor + 1)); appendSpace = true; } for (int i = start; i < end; i++) { char ch = chunk.GetCharAt(doc, i); switch (ch) { case '\\': rtfText.Append(@"\\"); break; case '{': rtfText.Append(@"\{"); break; case '}': rtfText.Append(@"\}"); break; case '\t': rtfText.Append(@"\tab"); appendSpace = true; break; default: if (appendSpace) { rtfText.Append(' '); appendSpace = false; } rtfText.Append(ch); break; } } } } rtfText.Append(@"\par"); rtfText.AppendLine(); } // color table StringBuilder colorTable = new StringBuilder(); colorTable.Append(@"{\colortbl ;"); for (int i = 0; i < colorList.Count; i++) { Gdk.Color color = colorList[i]; colorTable.Append(@"\red"); colorTable.Append(color.Red / 256); colorTable.Append(@"\green"); colorTable.Append(color.Green / 256); colorTable.Append(@"\blue"); colorTable.Append(color.Blue / 256); colorTable.Append(";"); } colorTable.Append("}"); StringBuilder rtf = new StringBuilder(); rtf.Append(@"{\rtf1\ansi\deff0\adeflang1025"); // font table rtf.Append(@"{\fonttbl"); rtf.Append(@"{\f0\fnil\fprq1\fcharset128 " + options.Font.Family + ";}"); rtf.Append("}"); rtf.Append(colorTable.ToString()); rtf.Append(@"\viewkind4\uc1\pard"); rtf.Append(@"\f0"); try { string fontName = options.Font.ToString(); double fontSize = Double.Parse(fontName.Substring(fontName.LastIndexOf(' ') + 1), System.Globalization.CultureInfo.InvariantCulture) * 2; rtf.Append(@"\fs"); rtf.Append(fontSize); } catch (Exception) {}; rtf.Append(@"\cf1"); rtf.Append(rtfText.ToString()); rtf.Append("}"); // System.Console.WriteLine(rtf); return(rtf.ToString()); }
public void Import (MonoDevelop.Core.FilePath source, ColorSheme target) { }
protected override void OnRealized () { base.OnRealized (); highlightStyle = SyntaxModeService.GetColorStyle (Style, PropertyService.Get ("ColorScheme", "Default")); }
public override bool GetIsValid(ColorSheme style) { return(true); }
void CopyData (TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (selection != null && data != null && data.Document != null) { copiedDocument = new Document (); monoDocument = new Document (); this.docStyle = data.ColorStyle; this.options = data.Options; this.mode = data.Document.SyntaxMode != null && data.Options.EnableSyntaxHighlighting ? data.Document.SyntaxMode : Mono.TextEditor.Highlighting.SyntaxMode.Default; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; ISegment segment = selection.GetSelectionRange (data); copiedDocument.Text = this.mode.GetTextWithoutMarkup (data.Document, data.ColorStyle, segment.Offset, segment.Length); monoDocument.Text = this.mode.GetTextWithoutMarkup (data.Document, data.ColorStyle, segment.Offset, segment.Length); LineSegment line = data.Document.GetLineByOffset (segment.Offset); var spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode, this.mode, spanStack, line.Offset, segment.Offset); this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { LineSegment curLine = data.Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (data, startCol) - 1; int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol) - 1, curLine.EditableLength); if (col1 < col2) { ((IBuffer)copiedDocument).Insert (copiedDocument.Length, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); ((IBuffer)monoDocument).Insert (monoDocument.Length, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. ((IBuffer)copiedDocument).Insert (copiedDocument.Length, Environment.NewLine); // \r in mono document stands for block selection line end. ((IBuffer)monoDocument).Insert (monoDocument.Length, "\r"); } } line = data.Document.GetLine (selection.MinLine); spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode, this.mode, spanStack, line.Offset, line.Offset + startCol); this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
public override ChunkParser CreateChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) { return new CSharpChunkParser (spanParser, doc, style, mode, line); }
public virtual ChunkStyle GetChunkStyle (ColorSheme style) { if (style == null) return null; return style.GetChunkStyle (Style); }
public virtual string GetTextWithoutMarkup (Document doc, ColorSheme style, int offset, int length) { return doc.GetTextAt (offset, length); }
public virtual bool GetIsValid(ColorSheme style) { return((string.IsNullOrEmpty(Color) || style.GetChunkStyle(Color) != null) && (string.IsNullOrEmpty(TagColor) || style.GetChunkStyle(TagColor) != null) && (string.IsNullOrEmpty(NextColor) || style.GetChunkStyle(NextColor) != null)); }
public string GetMarkup (Document doc, ITextEditorOptions options, ColorSheme style, int offset, int length, bool removeIndent, bool useColors, bool replaceTabs) { int indentLength = GetIndentLength (doc, offset, length, false); int curOffset = offset; StringBuilder result = new StringBuilder (); while (curOffset < offset + length && curOffset < doc.Length) { LineSegment line = doc.GetLineByOffset (curOffset); int toOffset = System.Math.Min (line.Offset + line.EditableLength, offset + length); Stack<ChunkStyle> styleStack = new Stack<ChunkStyle> (); for (Chunk chunk = GetChunks (doc, style, line, curOffset, toOffset - curOffset); chunk != null; chunk = chunk.Next) { ChunkStyle chunkStyle = chunk.GetChunkStyle (style); bool setBold = chunkStyle.Bold && (styleStack.Count == 0 || !styleStack.Peek ().Bold) || !chunkStyle.Bold && (styleStack.Count == 0 || styleStack.Peek ().Bold); bool setItalic = chunkStyle.Italic && (styleStack.Count == 0 || !styleStack.Peek ().Italic) || !chunkStyle.Italic && (styleStack.Count == 0 || styleStack.Peek ().Italic); bool setUnderline = chunkStyle.Underline && (styleStack.Count == 0 || !styleStack.Peek ().Underline) || !chunkStyle.Underline && (styleStack.Count == 0 || styleStack.Peek ().Underline); bool setColor = styleStack.Count == 0 || TextViewMargin.GetPixel (styleStack.Peek ().Color) != TextViewMargin.GetPixel (chunkStyle.Color); if (setColor || setBold || setItalic || setUnderline) { if (styleStack.Count > 0) { result.Append("</span>"); styleStack.Pop (); } result.Append("<span"); if (useColors) { result.Append(" foreground=\""); result.Append(ColorToPangoMarkup (chunkStyle.Color)); result.Append("\""); } if (chunkStyle.Bold) result.Append(" weight=\"bold\""); if (chunkStyle.Italic) result.Append(" style=\"italic\""); if (chunkStyle.Underline) result.Append(" underline=\"single\""); result.Append(">"); styleStack.Push (chunkStyle); } for (int i = 0; i < chunk.Length && chunk.Offset + i < doc.Length; i++) { char ch = chunk.GetCharAt (doc, chunk.Offset + i); switch (ch) { case '&': result.Append ("&"); break; case '<': result.Append ("<"); break; case '>': result.Append (">"); break; case '\t': if (replaceTabs) { result.Append (new string (' ', options.TabSize)); } else { result.Append ('\t'); } break; default: result.Append (ch); break; } } } while (styleStack.Count > 0) { result.Append("</span>"); styleStack.Pop (); } curOffset = line.EndOffset; if (removeIndent) curOffset += indentLength; if (result.Length > 0 && curOffset < offset + length) result.AppendLine (); } return result.ToString (); }
void ApplyStyle (ColorSheme sheme) { sheme.Name = entryName.Text; sheme.Description = entryDescription.Text; Gtk.TreeIter iter; if (colorStore.GetIterFirst (out iter)) { do { var data = (ColorMetaData)colorStore.GetValue (iter, 2); var style = (ChunkStyle)colorStore.GetValue (iter, 1); sheme.SetChunkStyle (data.Name, style); } while (colorStore.IterNext (ref iter)); } }
public ChunkParser (SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) { this.mode = mode; this.doc = doc; this.line = line; this.lineOffset = line.Offset; this.spanParser = spanParser; spanParser.FoundSpanBegin = FoundSpanBegin; spanParser.FoundSpanEnd = FoundSpanEnd; spanParser.FoundSpanExit = FoundSpanExit; spanParser.ParseChar += ParseChar; if (line == null) throw new ArgumentNullException ("line"); }
public void SetSheme (ColorSheme style) { if (style == null) throw new ArgumentNullException ("style"); this.fileName = Mono.TextEditor.Highlighting.SyntaxModeService.GetFileNameForStyle (style); this.colorSheme = style; this.entryName.Text = style.Name; this.entryDescription.Text = style.Description; this.textEditor.Document.MimeType = "text/x-csharp"; this.textEditor.GetTextEditorData ().ColorStyle = style; this.textEditor.Text = @"using System; // This is an example class Example { public static void Main (string[] args) { Console.WriteLine (""Hello World""); } }"; foreach (var data in metaData) { colorStore.AppendValues (data.Description, style.GetChunkStyle (data.Name), data); } Stylechanged (null, null); }
public static ColorSheme LoadFrom (XmlReader reader) { var result = new ColorSheme (); XmlReadHelper.ReadList (reader, "EditorStyle", delegate () { switch (reader.LocalName) { case "EditorStyle": result.Name = reader.GetAttribute (NameAttribute); result.Description = reader.GetAttribute ("_description"); return true; case "Color": result.customPalette [reader.GetAttribute ("name")] = reader.GetAttribute ("value"); return true; case "Style": ReadStyleTree (reader, result, null, null, null, null); return true; } return false; }); result.GetChunkStyle (DefaultString).ChunkProperties |= ChunkProperties.TransparentBackground; return result; }
public override ChunkStyle GetChunkStyle(ColorSheme style) { return(ChunkStyle); }