Esempio n. 1
0
		public virtual bool GetIsValid (ColorScheme 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 void InvalidMimeTypeInScriptTypeAttribute ()
		{
			var doc = new TextDocument ();
			var syntaxMode = new WebFormsSyntaxMode ();
			syntaxMode.Document = doc;
			doc.Text = 
@"<%@ Page Language=""C#"" Inherits=""AspnetTest.Default"" %>
<!DOCTYPE html>
<html>
<head runat=""server"">
	<title>Default</title>
</head>
<body>
	<form id=""form1"" runat=""server"">
		<asp:Button id=""button1"" runat=""server"" Text=""Click me!"" OnClick=""button1Clicked"" />
	</form>
	<script type=""></script>
</body>
</html>
";
			var style = new ColorScheme ();
			foreach (DocumentLine line in doc.Lines) {
				Assert.DoesNotThrow (() => syntaxMode.GetChunks (style, line, line.Offset, line.Length).ToList ());
			}
		}
		public static string GetFileNameForStyle (ColorScheme style)
		{
			string result;
			if (!isLoadedFromFile.TryGetValue (style.Name, out result))
				return null;
			return result;
		}
Esempio n. 4
0
		public virtual bool GetIsValid (ColorScheme style)
		{
			if (style.GetChunkStyle (Color) == null) {
				System.Console.WriteLine("color:" + Color + " not found.");
				return false;
			}
			return true;
		}
Esempio n. 5
0
            void CopyData(TextEditorData data, Selection selection)
            {
                if (!selection.IsEmpty && data != null && data.Document != null)
                {
                    this.docStyle = data.ColorStyle;
                    this.options  = data.Options;
                    copyData      = null;


                    switch (selection.SelectionMode)
                    {
                    case SelectionMode.Normal:
                        isBlockMode = false;
                        var segment = selection.GetSelectionRange(data);
                        copiedColoredChunks = ColoredSegment.GetChunks(data, segment);
                        var pasteHandler = data.TextPasteHandler;
                        if (pasteHandler != null)
                        {
                            try {
                                copyData = pasteHandler.GetCopyData(segment);
                            } catch (Exception e) {
                                Console.WriteLine("Exception while getting copy data:" + e);
                            }
                        }
                        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);
                        copiedColoredChunks = new List <List <ColoredSegment> > ();
                        for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++)
                        {
                            DocumentLine curLine = data.Document.GetLine(lineNr);
                            int          col1    = curLine.GetLogicalColumn(data, startCol) - 1;
                            int          col2    = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.Length);
                            if (col1 < col2)
                            {
                                copiedColoredChunks.Add(ColoredSegment.GetChunks(data, new TextSegment(curLine.Offset + col1, col2 - col1)).First());
                            }
                            else
                            {
                                copiedColoredChunks.Add(new List <ColoredSegment> ());
                            }
                        }
                        break;
                    }
                }
                else
                {
                    copiedColoredChunks = null;
                }
            }
		public SignatureMarkupCreator (CSharpResolver resolver, CSharpFormattingOptions formattingOptions)
		{
			this.colorStyle = SyntaxModeService.GetColorStyle (MonoDevelop.Ide.IdeApp.Preferences.ColorScheme);

			this.resolver = resolver;
			this.astBuilder = new TypeSystemAstBuilder (resolver) {
				ConvertUnboundTypeArguments = true,
				UseAliases = false
			};
			this.formattingOptions = formattingOptions;
		}
Esempio n. 7
0
        internal static string GenerateHtml(List <List <ColoredSegment> > chunks, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options)
        {
            var htmlText = new StringBuilder();

            htmlText.AppendLine(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
            htmlText.AppendLine("<HTML>");
            htmlText.AppendLine("<HEAD>");
            htmlText.AppendLine("<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=utf-8\">");
            htmlText.AppendLine("<META NAME=\"GENERATOR\" CONTENT=\"Mono Text Editor\">");
            htmlText.AppendLine("</HEAD>");
            htmlText.AppendLine("<BODY>");

            htmlText.AppendLine("<FONT face = '" + options.Font.Family + "'>");
            bool first = true;

            foreach (var line in chunks)
            {
                if (!first)
                {
                    htmlText.AppendLine("<BR>");
                }
                else
                {
                    first = false;
                }

                foreach (var chunk in line)
                {
                    var chunkStyle = style.GetChunkStyle(chunk.Style);
                    htmlText.Append("<SPAN style='");
                    if (chunkStyle.FontWeight != Xwt.Drawing.FontWeight.Normal)
                    {
                        htmlText.Append("font-weight:" + ((int)chunkStyle.FontWeight) + ";");
                    }
                    if (chunkStyle.FontStyle != Xwt.Drawing.FontStyle.Normal)
                    {
                        htmlText.Append("font-style:" + chunkStyle.FontStyle.ToString().ToLower() + ";");
                    }
                    htmlText.Append("color:" + ((HslColor)chunkStyle.Foreground).ToPangoString() + ";");
                    htmlText.Append("'>");
                    AppendHtmlText(htmlText, chunk.Text, options);
                    htmlText.Append("</SPAN>");
                }
            }
            htmlText.AppendLine("</FONT>");
            htmlText.AppendLine("</BODY></HTML>");

            if (Platform.IsWindows)
            {
                return(GenerateCFHtml(htmlText.ToString()));
            }

            return(htmlText.ToString());
        }
Esempio n. 8
0
		public static TooltipInformation Create(DNode dn, ColorScheme st, bool templateParamCompletion = false, int currentMethodParam = -1)
		{
			var markupGen = new TooltipMarkupGen (st);

			var tti = new TooltipInformation { 
				SignatureMarkup = markupGen.GenTooltipSignature(dn, templateParamCompletion, currentMethodParam)
			};

			CreateTooltipBody (markupGen, dn, tti);

			return tti;
		}
Esempio n. 9
0
		void ApplyStyle (ColorScheme sheme)
		{
			sheme.Name = entryName.Text;
			sheme.Description = entryDescription.Text;
			
			Gtk.TreeIter iter;
			if (colorStore.GetIterFirst (out iter)) {
				do {
					var data = (ColorScheme.PropertyDecsription)colorStore.GetValue (iter, 1);
					var style = colorStore.GetValue (iter, 2);
					data.Info.SetValue (sheme, style, null);
				} while (colorStore.IterNext (ref iter));
			}
		}
Esempio n. 10
0
		//TODO: Für semantisches Highlighting den TypeRefFinder benutzen und einfach pauschal alle Ids entsprechend highlighten
		public static TooltipInformation Create(AbstractType t, ColorScheme st, bool templateParamCompletion = false, int currentMethodParam = -1)
		{
			var markupGen = new TooltipMarkupGen (st);

			var tti = new TooltipInformation { 
				SignatureMarkup = markupGen.GenTooltipSignature (t, templateParamCompletion, currentMethodParam)
			};

			var ds = t as DSymbol;
			DNode n;
			if (ds != null && (n = ds.Definition) != null)
				CreateTooltipBody (markupGen, n, tti);

			return tti;
		}
Esempio n. 11
0
        List <Chunk> GetCachedChunks(ISyntaxMode mode, TextDocument doc, Mono.TextEditor.Highlighting.ColorScheme style, DocumentLine line, int offset, int length)
        {
            ChunkDescriptor descriptor;

            if (chunkDict.TryGetValue(line, out descriptor))
            {
                bool isInvalid;
                if (descriptor.Equals(line, offset, length, out isInvalid))
                {
                    return(descriptor.Chunk);
                }
                chunkDict.Remove(line);
            }
            ;

            var chunks = mode.GetChunks(style, line, offset, length).ToList();

            descriptor       = new ChunkDescriptor(line, offset, length, chunks);
            chunkDict [line] = descriptor;
            return(chunks);
        }
		public override IEnumerable<Chunk> GetChunks (ColorScheme style, DocumentLine line, int offset, int length)
		{
			// Multiline comment
			if (line.StartSpan.Count != 0 && line.StartSpan.Peek ().Begin.Pattern == "@*")
				return base.GetChunks (style, line, offset, length);

			var tokenizer = new CSharpTokenizer (new SeekableTextReader (doc.GetTextAt (offset, length)));
			chunks = new List<Chunk> ();
			CSharpSymbol symbol;
			CSharpSymbol prevSymbol = null;
			int off = line.Offset;
			currentState = State.None;

			while ((symbol = tokenizer.NextSymbol ()) != null) {
				// Apostrophes in text
				bool inApostrophes = false;
				if (symbol.Type == CSharpSymbolType.CharacterLiteral && prevSymbol != null && Char.IsLetterOrDigit (prevSymbol.Content.Last ())) {
					if (symbol.Content.Last () == '\'')
						inApostrophes = true;
					else {
						chunks.Add (new Chunk (off, 1, "Plain Text"));
						off++;
						tokenizer = new CSharpTokenizer (new SeekableTextReader (symbol.Content.Substring (1)));
						symbol = tokenizer.NextSymbol ();
						prevSymbol = null;
					}
				}

				string chunkStyle = inApostrophes ? "Plain Text" : GetStyleForChunk (symbol, prevSymbol, off);
				chunks.Add (new Chunk (off, symbol.Content.Length, chunkStyle));
				prevSymbol = symbol;
				off += symbol.Content.Length;
			}

			return chunks;
		}
		public static void AddStyle (ColorScheme style)
		{
			styles [style.Name] = style;
		}
Esempio n. 14
0
 protected override void OnRealized()
 {
     base.OnRealized();
     highlightStyle = SyntaxModeService.GetColorStyle(IdeApp.Preferences.ColorScheme);
 }
Esempio n. 15
0
			public ChunkParser (SyntaxMode mode, SpanParser spanParser, ColorScheme style, DocumentLine line)
			{
				this.mode = mode;
				this.doc = mode.Document;
				this.line = line;
				this.lineOffset = line.Offset;
				this.spanParser = spanParser;
				spanParser.FoundSpanBegin = FoundSpanBegin;
				spanParser.FoundSpanEnd = FoundSpanEnd;
				spanParser.FoundSpanExit = FoundSpanExit;
				spanParser.ParseChar += ParseChar;
				spanParser.IsAtWordStart = () => wordbuilder.Length == 0;
				if (line == null)
					throw new ArgumentNullException ("line");
			}
Esempio n. 16
0
		public virtual IEnumerable<Chunk> GetChunks (ColorScheme style, DocumentLine line, int offset, int length)
		{
			SpanParser spanParser = CreateSpanParser (line, null);
			ChunkParser chunkParser = CreateChunkParser (spanParser, style, line);
			Chunk result = chunkParser.GetChunks (chunkParser.lineOffset, line.Length);
			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;
					}
				}
			}
			while (result != null) {
				// crop to end
				if (result.EndOffset >= offset + length) {
					result.Length = offset + length - result.Offset;
					result.Next = null;
					if (result.Length < 0) {
						result.Length = 0;
						yield break;
					}
				}
				yield return result;
				result = result.Next;
			}
		}
Esempio n. 17
0
 public ReferencedChunkStyle(ColorScheme style, string referencedStyle)
 {
     this.style           = style;
     this.referencedStyle = referencedStyle;
 }
Esempio n. 18
0
 public override bool GetIsValid(ColorScheme style)
 {
     return(true);
 }
Esempio n. 19
0
		public static ColorScheme LoadFrom (Stream stream)
		{
			var result = new ColorScheme ();
			var reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader (stream, new System.Xml.XmlDictionaryReaderQuotas ());

			var root = XElement.Load(reader);
			
			// The fields we'd like to extract
			result.Name = root.XPathSelectElement("name").Value;

			if (result.Name != TextEditorOptions.DefaultColorStyle)
				result.CopyValues (SyntaxModeService.DefaultColorStyle);

			var version = Version.Parse (root.XPathSelectElement("version").Value);
			if (version.Major != 1)
				return null;
			var el = root.XPathSelectElement ("description");
			if (el != null)
				result.Description = el.Value;
			el = root.XPathSelectElement ("originator");
			if (el != null)
				result.Originator = el.Value;
			el = root.XPathSelectElement ("baseScheme");
			if (el != null)
				result.BaseScheme = el.Value;

			if (result.BaseScheme != null) {
				var baseScheme = SyntaxModeService.GetColorStyle (result.BaseScheme);
				if (baseScheme != null)
					result.CopyValues (baseScheme);
			}

			var palette = new Dictionary<string, Cairo.Color> ();
			foreach (var color in root.XPathSelectElements("palette/*")) {
				var name = color.XPathSelectElement ("name").Value;
				if (palette.ContainsKey (name))
					throw new InvalidDataException ("Duplicate palette color definition for: " + name);
				palette.Add (
					name,
					ParseColor (color.XPathSelectElement ("value").Value)
				);
			}

			foreach (var colorElement in root.XPathSelectElements("//colors/*")) {
				var color = AmbientColor.Create (colorElement, palette);
				PropertyDecsription info;
				if (!ambientColors.TryGetValue (color.Name, out info)) {
					Console.WriteLine ("Ambient color:" + color.Name + " not found.");
					continue;
				}
				info.Info.SetValue (result, color, null);
			}

			foreach (var textColorElement in root.XPathSelectElements("//text/*")) {
				var color = ChunkStyle.Create (textColorElement, palette);
				PropertyDecsription info;
				if (!textColors.TryGetValue (color.Name, out info)) {
					Console.WriteLine ("Text color:" + color.Name + " not found.");
					continue;
				}
				info.Info.SetValue (result, color, null);
			}

			// Check scheme
			bool valid = true;
			foreach (var color in textColors.Values) {
				if (color.Info.GetValue (result, null) == null) {
					Console.WriteLine (color.Attribute.Name + " == null");
					valid = false;
				}
			}
			foreach (var color in ambientColors.Values) {
				if (color.Info.GetValue (result, null) == null) {
					Console.WriteLine (color.Attribute.Name + " == null");
					valid = false;
				}
			}
			if (!valid)
				throw new InvalidDataException ("Scheme " + result.Name + " is not valid.");
			return result;
		}
		void SetStyle ()
		{
			colorStyle = SyntaxModeService.GetColorStyle (hexEditor.Style, PropertyService.Get ("ColorScheme", "Default"));
		}
Esempio n. 21
0
		protected override void OnRealized ()
		{
			base.OnRealized ();
			highlightStyle = SyntaxModeService.GetColorStyle (Style, PropertyService.Get ("ColorScheme", "Default"));
		}
Esempio n. 22
0
        public static ColorScheme LoadFrom(Stream stream)
        {
            var result = new ColorScheme();
            var reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader(stream, new System.Xml.XmlDictionaryReaderQuotas());

            var root = XElement.Load(reader);

            // The fields we'd like to extract
            result.Name = root.XPathSelectElement("name").Value;

            if (result.Name != "Default")
            {
                result.CopyValues(SyntaxModeService.DefaultColorStyle);
            }

            var version = Version.Parse(root.XPathSelectElement("version").Value);

            if (version.Major != 1)
            {
                return(null);
            }
            var el = root.XPathSelectElement("description");

            if (el != null)
            {
                result.Description = el.Value;
            }
            el = root.XPathSelectElement("originator");
            if (el != null)
            {
                result.Originator = el.Value;
            }
            el = root.XPathSelectElement("baseScheme");
            if (el != null)
            {
                result.BaseScheme = el.Value;
            }

            if (result.BaseScheme != null)
            {
                var baseScheme = SyntaxModeService.GetColorStyle(result.BaseScheme);
                if (baseScheme != null)
                {
                    result.CopyValues(baseScheme);
                }
            }

            var palette = new Dictionary <string, Cairo.Color> ();

            foreach (var color in root.XPathSelectElements("palette/*"))
            {
                var name = color.XPathSelectElement("name").Value;
                if (palette.ContainsKey(name))
                {
                    throw new InvalidDataException("Duplicate palette color definition for: " + name);
                }
                palette.Add(
                    name,
                    ParseColor(color.XPathSelectElement("value").Value)
                    );
            }

            foreach (var colorElement in root.XPathSelectElements("//colors/*"))
            {
                var color = AmbientColor.Create(colorElement, palette);
                PropertyDecsription info;
                if (!ambientColors.TryGetValue(color.Name, out info))
                {
                    Console.WriteLine("Ambient color:" + color.Name + " not found.");
                    continue;
                }
                info.Info.SetValue(result, color, null);
            }

            foreach (var textColorElement in root.XPathSelectElements("//text/*"))
            {
                var color = ChunkStyle.Create(textColorElement, palette);
                PropertyDecsription info;
                if (!textColors.TryGetValue(color.Name, out info))
                {
                    Console.WriteLine("Text color:" + color.Name + " not found.");
                    continue;
                }
                info.Info.SetValue(result, color, null);
            }

            // Check scheme
            bool valid = true;

            foreach (var color in textColors.Values)
            {
                if (color.Info.GetValue(result, null) == null)
                {
                    Console.WriteLine(color.Attribute.Name + " == null");
                    valid = false;
                }
            }
            foreach (var color in ambientColors.Values)
            {
                if (color.Info.GetValue(result, null) == null)
                {
                    Console.WriteLine(color.Attribute.Name + " == null");
                    valid = false;
                }
            }
            if (!valid)
            {
                throw new InvalidDataException("Scheme " + result.Name + " is not valid.");
            }
            return(result);
        }
Esempio n. 23
0
 protected override void OnRealized()
 {
     base.OnRealized();
     highlightStyle = SyntaxModeService.GetColorStyle(Style, PropertyService.Get("ColorScheme", "Default"));
 }
Esempio n. 24
0
 public virtual bool GetIsValid(ColorScheme style)
 {
     return((string.IsNullOrEmpty(Color) || style.GetChunkStyle(Color) != null) &&
            (string.IsNullOrEmpty(TagColor) || style.GetChunkStyle(TagColor) != null) &&
            (string.IsNullOrEmpty(NextColor) || style.GetChunkStyle(NextColor) != null));
 }
 public virtual bool GetIsValid(ColorScheme style)
 {
     return(style.GetChunkStyle(Color) != null);
 }
Esempio n. 26
0
		public virtual AmbientColor GetBackgroundMarkerColor (ColorScheme style)
		{
			return style.SearchResult;
		}
Esempio n. 27
0
		public ColorScheme Clone ()
		{
			var result = new ColorScheme () {
				Name = this.Name,
				BaseScheme = this.BaseScheme,
				Originator = this.Originator,
				Description = this.Description
			};
			result.CopyValues (this);
			return result;
		}
Esempio n. 28
0
		public virtual bool GetIsValid (ColorScheme style)
		{
			return (string.IsNullOrEmpty (Color) || style.GetChunkStyle (Color) != null) &&
			        (string.IsNullOrEmpty (TagColor) || style.GetChunkStyle (TagColor) != null) &&
			        (string.IsNullOrEmpty (NextColor) || style.GetChunkStyle (NextColor) != null);
		}
Esempio n. 29
0
 public virtual ChunkParser CreateChunkParser(SpanParser spanParser, ColorScheme style, DocumentLine line)
 {
     return(new ChunkParser(this, spanParser, style, line));
 }
Esempio n. 30
0
        public static ColorScheme Import(string fileName, Stream stream)
        {
            var result = new ColorScheme();

            result.Name        = Path.GetFileNameWithoutExtension(fileName);
            result.Description = "Imported color scheme";
            result.Originator  = "Imported from " + fileName;

            var colors = new Dictionary <string, VSSettingColor> ();

            using (var reader = XmlReader.Create(stream)) {
                while (reader.Read())
                {
                    if (reader.LocalName == "Item")
                    {
                        var color = VSSettingColor.Create(reader);
                        if (colors.ContainsKey(color.Name))
                        {
                            Console.WriteLine("Warning: {0} is defined twice in vssettings.", color.Name);
                            continue;
                        }
                        colors[color.Name] = color;
                    }
                }
            }


            HashSet <string> importedAmbientColors = new HashSet <string> ();

            // convert ambient colors
            foreach (var ambient in ambientColors.Values)
            {
                if (!string.IsNullOrEmpty(ambient.Attribute.VSSetting))
                {
                    var import = AmbientColor.Import(colors, ambient.Attribute.VSSetting);
                    if (import != null)
                    {
                        importedAmbientColors.Add(import.Name);
                        ambient.Info.SetValue(result, import, null);
                        continue;
                    }
                }
            }

            // convert text colors
            foreach (var vsc in colors.Values)
            {
                bool found = false;
                foreach (var color in textColors)
                {
                    if (color.Value.Attribute.VSSetting == null)
                    {
                        continue;
                    }
                    var split = color.Value.Attribute.VSSetting.Split('?');
                    foreach (var s in split)
                    {
                        if (s == vsc.Name)
                        {
                            /*	if (vsc.Foreground == "0x02000000" && vsc.Background == "0x02000000") {
                             *              color.Value.Info.SetValue (result, result.PlainText, null);
                             *              found = true;
                             *              continue;
                             *      }*/
                            var textColor = ChunkStyle.Import(color.Value.Attribute.Name, vsc);
                            if (textColor != null)
                            {
                                color.Value.Info.SetValue(result, textColor, null);
                                found = true;
                            }
                        }
                    }
                }
                if (!found && !importedAmbientColors.Contains(vsc.Name))
                {
                    Console.WriteLine(vsc.Name + " not imported!");
                }
            }

            result.IndentationGuide = new AmbientColor();
            result.IndentationGuide.Colors.Add(Tuple.Create("color", AlphaBlend(result.PlainText.Foreground, result.PlainText.Background, 0.3)));

            result.TooltipText = result.PlainText.Clone();
            var h = (HslColor)result.TooltipText.Background;

            h.L += 0.01;
            result.TooltipText.Background = h;

            result.TooltipPagerTop = new AmbientColor();
            result.TooltipPagerTop.Colors.Add(Tuple.Create("color", result.TooltipText.Background));

            result.TooltipPagerBottom = new AmbientColor();
            result.TooltipPagerBottom.Colors.Add(Tuple.Create("color", result.TooltipText.Background));

            result.TooltipPagerTriangle = new AmbientColor();
            result.TooltipPagerTriangle.Colors.Add(Tuple.Create("color", AlphaBlend(result.PlainText.Foreground, result.PlainText.Background, 0.8)));

            result.TooltipBorder = new AmbientColor();
            result.TooltipBorder.Colors.Add(Tuple.Create("color", AlphaBlend(result.PlainText.Foreground, result.PlainText.Background, 0.5)));

            var defaultStyle = SyntaxModeService.GetColorStyle(HslColor.Brightness(result.PlainText.Background) < 0.5 ? "Monokai" : "Default");

            foreach (var color in textColors.Values)
            {
                if (color.Info.GetValue(result, null) == null)
                {
                    color.Info.SetValue(result, color.Info.GetValue(defaultStyle, null), null);
                }
            }
            foreach (var color in ambientColors.Values)
            {
                if (color.Info.GetValue(result, null) == null)
                {
                    color.Info.SetValue(result, color.Info.GetValue(defaultStyle, null), null);
                }
            }
            if (result.PlainText.TransparentForeground)
            {
                result.PlainText.Foreground = new Cairo.Color(0, 0, 0);
            }
            return(result);
        }
Esempio n. 31
0
			void CopyData (TextEditorData data, Selection selection)
			{
				if (!selection.IsEmpty && data != null && data.Document != null) {
					this.docStyle = data.ColorStyle;
					this.options = data.Options;
					copyData = null;


					switch (selection.SelectionMode) {
					case SelectionMode.Normal:
						isBlockMode = false;
						var segment = selection.GetSelectionRange (data);
						copiedColoredChunks = ColoredSegment.GetChunks (data, segment);
						var pasteHandler = data.TextPasteHandler;
						if (pasteHandler != null)
							copyData = pasteHandler.GetCopyData (segment);
						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);
						copiedColoredChunks = new List<List<ColoredSegment>> ();
						for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) {
							DocumentLine curLine = data.Document.GetLine (lineNr);
							int col1 = curLine.GetLogicalColumn (data, startCol) - 1;
							int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol) - 1, curLine.Length);
							if (col1 < col2) {
								copiedColoredChunks.Add (ColoredSegment.GetChunks (data, new TextSegment (curLine.Offset + col1, col2 - col1)).First ());
							} else {
								copiedColoredChunks.Add (new List<ColoredSegment> ());
							}
						}
						break;
					}
				} else {
					copiedColoredChunks = null;
				}
			}
		public static void Remove (ColorScheme style)
		{
			if (styles.ContainsKey (style.Name))
				styles.Remove (style.Name);
			if (styleLookup.ContainsKey (style.Name))
				styleLookup.Remove (style.Name);
		}
Esempio n. 33
0
		public bool Validate (ColorScheme style)
		{
			if (!GetIsValid (style)) {
				return false;
			}
			foreach (Rule rule in Rules) {
				if (!rule.GetIsValid (style)) {
					return false;
				}
			}
			return true;
		}
		public static void AddStyle (string fileName, ColorScheme style)
		{
			isLoadedFromFile [style.Name] = fileName;
			styles [style.Name] = style;
		}
Esempio n. 35
0
		public virtual ChunkParser CreateChunkParser (SpanParser spanParser, ColorScheme style, DocumentLine line)
		{
			return new ChunkParser (this, spanParser, style, line);
		}
Esempio n. 36
0
        internal static string GenerateRtf(List <List <ColoredSegment> > chunks, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options)
        {
            var rtfText   = new StringBuilder();
            var colorList = new List <Color>();

            bool isItalic = false;
            bool isBold   = false;
            int  curColor = -1;

            foreach (var line in chunks)
            {
                bool appendSpace = false;
                foreach (var chunk in line)
                {
                    var chunkStyle = style.GetChunkStyle(chunk.Style);
                    if (isBold != (chunkStyle.FontWeight == Xwt.Drawing.FontWeight.Bold))
                    {
                        isBold = chunkStyle.FontWeight == Xwt.Drawing.FontWeight.Bold;
                        rtfText.Append(isBold ? @"\b" : @"\b0");
                        appendSpace = true;
                    }
                    if (isItalic != (chunkStyle.FontStyle == Xwt.Drawing.FontStyle.Italic))
                    {
                        isItalic = chunkStyle.FontStyle == Xwt.Drawing.FontStyle.Italic;
                        rtfText.Append(isItalic ? @"\i" : @"\i0");
                        appendSpace = true;
                    }
                    var foreground = style.GetForeground(chunkStyle);
                    if (!colorList.Contains(foreground))
                    {
                        colorList.Add(foreground);
                    }
                    int color = colorList.IndexOf(foreground);
                    if (curColor != color)
                    {
                        curColor = color;
                        rtfText.Append(@"\cf" + (curColor + 1));
                        appendSpace = true;
                    }
                    AppendRtfText(rtfText, chunk.Text, ref appendSpace);
                }
                rtfText.AppendLine(@"\line");
            }

            var rtf = new StringBuilder();

            rtf.AppendLine(@"{\rtf1\ansi\deff0\adeflang1025");
            rtf.AppendLine(@"{\fonttbl");
            rtf.AppendLine(@"{\f0\fnil\fprq1\fcharset128 " + options.Font.Family + ";}");
            rtf.AppendLine("}");
            rtf.Append(CreateColorTable(colorList));
            rtf.AppendLine(@"\viewkind4\uc1\pard");
            rtf.AppendLine(@"\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 e) { System.Diagnostics.Debug.WriteLine(e); }
            rtf.AppendLine(@"\cf1");
            rtf.Append(rtfText.ToString());
            rtf.Append("}");
            return(rtf.ToString());
        }
Esempio n. 37
0
            void CopyData(TextEditorData data, Selection selection)
            {
                copiedDocument = null;
                monoDocument   = null;
                if (selection != null && data != null && data.Document != null)
                {
                    copiedDocument = new TextDocument();
                    monoDocument   = new TextDocument();
                    this.docStyle  = data.ColorStyle;
                    this.options   = data.Options;
                    this.mode      = SyntaxModeService.GetSyntaxMode(monoDocument, data.MimeType);
                    switch (selection.SelectionMode)
                    {
                    case SelectionMode.Normal:
                        isBlockMode = false;
                        var segment = selection.GetSelectionRange(data);
                        var text    = data.GetTextAt(segment);
                        copiedDocument.Text = text;
                        monoDocument.Text   = text;
                        var line      = data.Document.GetLineByOffset(segment.Offset);
                        var spanStack = line.StartSpan.Clone();
                        SyntaxModeService.ScanSpans(data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, 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++)
                        {
                            DocumentLine curLine = data.Document.GetLine(lineNr);
                            int          col1    = curLine.GetLogicalColumn(data, startCol) - 1;
                            int          col2    = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.Length);
                            if (col1 < col2)
                            {
                                copiedDocument.Insert(copiedDocument.TextLength, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1));
                                monoDocument.Insert(monoDocument.TextLength, 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.
                                copiedDocument.Insert(copiedDocument.TextLength, Environment.NewLine);
                                // \r in mono document stands for block selection line end.
                                monoDocument.Insert(monoDocument.TextLength, "\r");
                            }
                        }
                        line      = data.Document.GetLine(selection.MinLine);
                        spanStack = line.StartSpan.Clone();
                        SyntaxModeService.ScanSpans(data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, spanStack, line.Offset, line.Offset + startCol);
                        this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack;
                        break;
                    }
                }
                else
                {
                    copiedDocument = null;
                }
            }
Esempio n. 38
0
		protected override void OnRealized ()
		{
			base.OnRealized ();
			highlightStyle = SyntaxModeService.GetColorStyle (IdeApp.Preferences.ColorScheme);
		}
		public static void Remove (ColorScheme style)
		{
			if (styleLookup.ContainsKey (style.Name))
				styleLookup.Remove (style.Name);

			foreach (var kv in styles) {
				if (kv.Value == style) {
					styles.Remove (kv.Key); 
					return;
				}
			}
		}
Esempio n. 40
0
 public static void AddStyle(ColorScheme style)
 {
     styles[style.Name] = style;
 }
		public static IStreamProvider GetProvider (ColorScheme style)
		{
			if (styleLookup.ContainsKey (style.Name)) 
				return styleLookup[style.Name];
			return null;
		}
		void SetStyle ()
		{
			colorStyle = SyntaxModeService.GetColorStyle (IdeApp.Preferences.ColorScheme);
		}
Esempio n. 43
0
			void CopyData (TextEditorData data, Selection selection)
			{
				copiedDocument = null;
				monoDocument = null;
				if (selection != null && data != null && data.Document != null) {
					copiedDocument = new TextDocument ();
					monoDocument = new TextDocument ();
					this.docStyle = data.ColorStyle;
					this.options = data.Options;
					this.mode = SyntaxModeService.GetSyntaxMode (monoDocument, data.MimeType);
					switch (selection.SelectionMode) {
					case SelectionMode.Normal:
						isBlockMode = false;
						var segment = selection.GetSelectionRange (data);
						var text = data.GetTextAt (segment);
						copiedDocument.Text = text;
						monoDocument.Text = text;
						var line = data.Document.GetLineByOffset (segment.Offset);
						var spanStack = line.StartSpan.Clone ();
						SyntaxModeService.ScanSpans (data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, 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++) {
							DocumentLine curLine = data.Document.GetLine (lineNr);
							int col1 = curLine.GetLogicalColumn (data, startCol) - 1;
							int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol) - 1, curLine.Length);
							if (col1 < col2) {
								copiedDocument.Insert (copiedDocument.TextLength, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1));
								monoDocument.Insert (monoDocument.TextLength, 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.
								copiedDocument.Insert (copiedDocument.TextLength, Environment.NewLine);
								// \r in mono document stands for block selection line end.
								monoDocument.Insert (monoDocument.TextLength, "\r");
							}
						}
						line = data.Document.GetLine (selection.MinLine);
						spanStack = line.StartSpan.Clone ();
						SyntaxModeService.ScanSpans (data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, 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.Highlighting.ColorScheme style, DocumentLine line)
 {
     return(new CSharpChunkParser(this, spanParser, style, line));
 }
Esempio n. 45
0
		void CopyValues (ColorScheme baseScheme)
		{
			foreach (var color in textColors.Values)
				color.Info.SetValue (this, color.Info.GetValue (baseScheme, null), null);
			foreach (var color in ambientColors.Values)
				color.Info.SetValue (this, color.Info.GetValue (baseScheme, null), null);
		}
 public CSharpChunkParser(SemanticHighlightingSyntaxMode semanticMode, SpanParser spanParser, Mono.TextEditor.Highlighting.ColorScheme style, DocumentLine line) : base(semanticMode, spanParser, style, line)
 {
     this.semanticMode = semanticMode;
 }
Esempio n. 47
0
		public static ColorScheme Import (string fileName, Stream stream)
		{
			var result = new ColorScheme ();
			result.Name = Path.GetFileNameWithoutExtension (fileName);
			result.Description = "Imported color scheme";
			result.Originator = "Imported from " + fileName;

			var colors = new Dictionary<string, VSSettingColor> ();
			using (var reader = XmlReader.Create (stream)) {
				while (reader.Read ()) {
					if (reader.LocalName == "Item") {
						var color = VSSettingColor.Create (reader);
						if (colors.ContainsKey (color.Name)) {
							Console.WriteLine ("Warning: {0} is defined twice in vssettings.", color.Name);
							continue;
						}
						colors[color.Name] = color;
					}
				}
			}


			HashSet<string> importedAmbientColors = new HashSet<string> ();
			// convert ambient colors
			foreach (var ambient in ambientColors.Values) {
				if (!string.IsNullOrEmpty (ambient.Attribute.VSSetting)) {
					var import = AmbientColor.Import (colors, ambient.Attribute.VSSetting);
					if (import != null) {
						importedAmbientColors.Add (import.Name);
						ambient.Info.SetValue (result, import, null);
						continue;
					}
				}
			}

			// convert text colors
			foreach (var vsc in colors.Values) {
				bool found = false;
				foreach (var color in textColors) {
					if (color.Value.Attribute.VSSetting == null)
						continue;
					var split = color.Value.Attribute.VSSetting.Split ('?');
					foreach (var s in split) {
						if (s == vsc.Name) {
						/*	if (vsc.Foreground == "0x02000000" && vsc.Background == "0x02000000") {
								color.Value.Info.SetValue (result, result.PlainText, null);
								found = true;
								continue;
							}*/
							var textColor = ChunkStyle.Import (color.Value.Attribute.Name, vsc);
							if (textColor != null) {
								color.Value.Info.SetValue (result, textColor, null);
								found = true;
							}
						}
					}
				}
				if (!found && !importedAmbientColors.Contains (vsc.Name))
					Console.WriteLine (vsc.Name + " not imported!");
			}

			result.IndentationGuide = new AmbientColor ();
			result.IndentationGuide.Colors.Add (Tuple.Create ("color", AlphaBlend (result.PlainText.Foreground, result.PlainText.Background, 0.3)));

			result.TooltipText = result.PlainText.Clone ();
			var h = (HslColor)result.TooltipText.Background;
			h.L += 0.01;
			result.TooltipText.Background = h;

			result.TooltipPagerTop = new AmbientColor ();
			result.TooltipPagerTop.Colors.Add (Tuple.Create ("color", result.TooltipText.Background));

			result.TooltipPagerBottom = new AmbientColor ();
			result.TooltipPagerBottom.Colors.Add (Tuple.Create ("color", result.TooltipText.Background));
			
			result.TooltipPagerTriangle = new AmbientColor ();
			result.TooltipPagerTriangle.Colors.Add (Tuple.Create ("color", AlphaBlend (result.PlainText.Foreground, result.PlainText.Background, 0.8)));

			result.TooltipBorder = new AmbientColor ();
			result.TooltipBorder.Colors.Add (Tuple.Create ("color", AlphaBlend (result.PlainText.Foreground, result.PlainText.Background, 0.5)));

			var defaultStyle = SyntaxModeService.GetColorStyle (HslColor.Brightness (result.PlainText.Background) < 0.5 ? "Monokai" : TextEditorOptions.DefaultColorStyle);

			foreach (var color in textColors.Values) {
				if (color.Info.GetValue (result, null) == null)
					color.Info.SetValue (result, color.Info.GetValue (defaultStyle, null), null);
			}
			foreach (var color in ambientColors.Values) {
				if (color.Info.GetValue (result, null) == null) 
					color.Info.SetValue (result, color.Info.GetValue (defaultStyle, null), null);
			}
			if (result.PlainText.TransparentForeground)
				result.PlainText.Foreground = new Cairo.Color (0, 0, 0);
			return result;
		}
 public static void AddStyle(string fileName, ColorScheme style)
 {
     isLoadedFromFile [style.Name] = fileName;
     styles [style.Name]           = style;
 }