Ejemplo n.º 1
0
		public virtual bool GetIsValid (Style 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;
		}
Ejemplo n.º 2
0
            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 virtual bool GetIsValid (Style style)
		{
			if (style.GetChunkStyle (Color) == null) {
				System.Console.WriteLine("color:" + Color + " not found.");
				return false;
			}
			return true;
		}
Ejemplo n.º 4
0
		public bool Validate (Style style)
		{
			if (!GetIsValid (style)) {
				return false;
			}
			foreach (Rule rule in Rules) {
				if (!rule.GetIsValid (style)) {
					return false;
				}
			}
			return true;
		}
Ejemplo n.º 5
0
        void ShowStyles()
        {
            styleStore.Clear();
            TreeIter selectedIter = styleStore.AppendValues(GetMarkup(GettextCatalog.GetString("Default"), GettextCatalog.GetString("The default color scheme.")), "Default");

            foreach (string styleName in Mono.TextEditor.Highlighting.SyntaxModeService.Styles)
            {
                Mono.TextEditor.Highlighting.Style style = Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle(null, styleName);
                TreeIter iter = styleStore.AppendValues(GetMarkup(GettextCatalog.GetString(style.Name), GettextCatalog.GetString(style.Description)), style.Name);
                if (style.Name == DefaultSourceEditorOptions.Instance.ColorScheme)
                {
                    selectedIter = iter;
                }
            }
            styleTreeview.Selection.SelectIter(selectedIter);
        }
Ejemplo n.º 6
0
        private void LoadSetting()
        {
            TextEditorOptions options = new TextEditorOptions();

            options.ColorScheme          = "Moscrif";
            options.ShowInvalidLines     = true;
            options.ShowLineNumberMargin = true;
            options.AutoIndent           = true;
            options.TabSize      = MainClass.Settings.SourceEditorSettings.TabSpace;       //8;
            options.TabsToSpaces = MainClass.Settings.SourceEditorSettings.TabsToSpaces;

            options.ShowEolMarkers = MainClass.Settings.SourceEditorSettings.ShowEolMarker;
            options.ShowRuler      = MainClass.Settings.SourceEditorSettings.ShowRuler;
            options.RulerColumn    = MainClass.Settings.SourceEditorSettings.RulerColumn;
            options.ShowTabs       = MainClass.Settings.SourceEditorSettings.ShowTab;
            options.ShowSpaces     = MainClass.Settings.SourceEditorSettings.ShowSpaces;

            options.EnableAnimations     = MainClass.Settings.SourceEditorSettings.EnableAnimations;
            options.ShowLineNumberMargin = MainClass.Settings.SourceEditorSettings.ShowLineNumber;

            options.HighlightCaretLine = true;

            options.DefaultEolMarker          = "\n";
            options.OverrideDocumentEolMarker = true;

            if (!String.IsNullOrEmpty(MainClass.Settings.SourceEditorSettings.EditorFont))
            {
                options.FontName = MainClass.Settings.SourceEditorSettings.EditorFont;
            }

            try{            //check parse style
                Mono.TextEditor.Highlighting.Style style = SyntaxModeService.GetColorStyle(null, "Moscrif");
            }catch (Exception ex) {
                options.ColorScheme = "";

                //MessageDialogs msd = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("error_load_styles"),ex.Message, Gtk.MessageType.Error,null);
                //msd.ShowDialog();
                Tool.Logger.Error(MainClass.Languages.Translate("error_load_styles"));
                Tool.Logger.Error(ex.Message);
            }
            editor.Options = options;
            //
            editor.Options.ShowFoldMargin = true;
        }
Ejemplo n.º 7
0
		public virtual Chunk GetChunks (Document doc, Style 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;
		}
Ejemplo n.º 8
0
			public ChunkParser (SpanParser spanParser, Document doc, Style 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");
			}
Ejemplo n.º 9
0
 protected override void OnRealized()
 {
     base.OnRealized();
     highlightStyle = SyntaxModeService.GetColorStyle(this.Style, PropertyService.Get("ColorScheme", "Default"));
 }
Ejemplo n.º 10
0
		public string GetMarkup (Document doc, ITextEditorOptions options, Style 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 ("&amp;");
							break;
						case '<':
							result.Append ("&lt;");
							break;
						case '>':
							result.Append ("&gt;");
							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 ();
		}
Ejemplo n.º 11
0
		public virtual ChunkParser CreateChunkParser (SpanParser spanParser, Document doc, Style style, SyntaxMode mode, LineSegment line)
		{
			return new ChunkParser (spanParser, doc, style, mode, line);
		}
Ejemplo n.º 12
0
		public virtual bool GetIsValid (Style style)
		{
			return (string.IsNullOrEmpty (Color) || style.GetChunkStyle (Color) != null) && 
			        (string.IsNullOrEmpty (TagColor) || style.GetChunkStyle (TagColor) != null) && 
			        (string.IsNullOrEmpty (NextColor) || style.GetChunkStyle (NextColor) != null);
		}
Ejemplo n.º 13
0
            static string GenerateRtf(Document doc, Mono.TextEditor.Highlighting.SyntaxMode mode, Mono.TextEditor.Highlighting.Style 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());
            }
Ejemplo n.º 14
0
		public override ChunkParser CreateChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, Style style, SyntaxMode mode, LineSegment line)
		{
			return new CSharpChunkParser (spanParser, doc, style, mode, line);
		}
Ejemplo n.º 15
0
			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);
							int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol), 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;
				}
			}
Ejemplo n.º 16
0
		static ChunkStyle GetChunkStyle (Style style, IEnumerable<Tag> tagStack)
		{
			ChunkStyle result = new ChunkStyle ();
			if (style == null)
				style = new DefaultStyle (null);
			result.Color = style.Default.Color;
			
			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.Color = chunkStyle.Color;
							result.ChunkProperties |= chunkStyle.ChunkProperties;
						} else {
							throw new Exception ("Style " + val + " not found.");
						}
					}
					if (tag.Arguments.TryGetValue ("foreground", out val))
						result.Color = style.GetColorFromString (val);
					if (tag.Arguments.TryGetValue ("background", out val))
						result.BackgroundColor = 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;
		}
Ejemplo n.º 17
0
		public override string GetTextWithoutMarkup (Document doc, Style 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 ();
		}
		void SetStyle ()
		{
			colorStyle = SyntaxModeService.GetColorStyle (hexEditor.Style, PropertyService.Get ("ColorScheme", "Default"));
		}
Ejemplo n.º 19
0
		protected override void OnRealized ()
		{
			base.OnRealized ();
			highlightStyle = SyntaxModeService.GetColorStyle (Style, PropertyService.Get ("ColorScheme", "Default"));
		}
Ejemplo n.º 20
0
		public static void Remove (Style style)
		{
			if (styles.ContainsKey (style.Name))
				styles.Remove (style.Name);
			if (styleLookup.ContainsKey (style.Name))
				styleLookup.Remove (style.Name);
		}
Ejemplo n.º 21
0
		public override bool GetIsValid (Style style)
		{
			return true;
		}
Ejemplo n.º 22
0
		public static Style LoadFrom (XmlReader reader)
		{
			Style result = new Style ();
			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;
		}
Ejemplo n.º 23
0
		public virtual bool GetIsValid (Style style)
		{
			return style.GetChunkStyle (Color) != null;
		}
Ejemplo n.º 24
0
		public virtual ChunkStyle GetChunkStyle (Style style)
		{
			if (style == null)
				return null;
			return style.GetChunkStyle (Style);
		}
Ejemplo n.º 25
0
		public override Chunk GetChunks (Document doc, Style 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;
		}
Ejemplo n.º 26
0
		public static IXmlProvider GetProvider (Style style)
		{
			if (styleLookup.ContainsKey (style.Name)) 
				return styleLookup[style.Name];
			return null;
		}
Ejemplo n.º 27
0
			public CSharpChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, Style style, SyntaxMode mode, LineSegment line) : base (spanParser, doc, style, mode, line)
			{
				foreach (var tag in ProjectDomService.SpecialCommentTags) {
					tags.Add (tag.Tag);
				}
			}
Ejemplo n.º 28
0
			public override ChunkStyle GetChunkStyle (Style style)
			{
				return ChunkStyle;
			}
Ejemplo n.º 29
0
		static void ReadStyleTree (XmlReader reader, Style 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") ?? curColor;
			string bgColor = reader.GetAttribute ("bgColor") ?? curBgColor;
			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;
			});
		}
Ejemplo n.º 30
0
		public virtual string GetTextWithoutMarkup (Document doc, Style style, int offset, int length)
		{
			return doc.GetTextAt (offset, length);
		}
		public ReferencedChunkStyle (Style style, string referencedStyle)
		{
			this.style           = style;
			this.referencedStyle = referencedStyle;
		}
Ejemplo n.º 32
0
		public string GetMarkup (Document doc, ITextEditorOptions options, Style style, int offset, int length, bool removeIndent)
		{
			return GetMarkup (doc, options, style, offset, length, removeIndent, true, true);
		}