当前位置: 首页>>代码示例>>C#>>正文


C# TextEditorData.GetMarkup方法代码示例

本文整理汇总了C#中Mono.TextEditor.TextEditorData.GetMarkup方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditorData.GetMarkup方法的具体用法?C# TextEditorData.GetMarkup怎么用?C# TextEditorData.GetMarkup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.TextEditor.TextEditorData的用法示例。


在下文中一共展示了TextEditorData.GetMarkup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResultTextDataFunc

//		void ResultLineDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
//		{
//			if (TreeIter.Zero.Equals (iter))
//				return;
//			var lineRenderer = (CellRendererText)cell;
//			var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
//			if (searchResult == null)
//				return;
//			
//			Document doc = GetDocument (searchResult);
//			int lineNr = doc.OffsetToLineNumber (searchResult.Offset) + 1;
//			bool didRead = (bool)store.GetValue (iter, DidReadColumn);
//			lineRenderer.Markup = MarkupText (lineNr.ToString (), didRead);
//		}
//		
		void ResultTextDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
		{
			if (TreeIter.Zero.Equals (iter))
				return;
			var textRenderer = (CellRendererText)cell;
			var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
			if (searchResult == null || searchResult.Offset < 0) {
				textRenderer.Markup = "Invalid search result";
				return;
			}
			
			var doc = GetDocument (searchResult);
			if (doc == null) {
				textRenderer.Markup = "Can't create document for:" + searchResult.FileName;
				return;
			}
			bool isSelected = treeviewSearchResults.Selection.IterIsSelected (iter);

			if (searchResult.Markup == null) {
				if (searchResult.LineNumber <= 0)
					searchResult.LineNumber = doc.OffsetToLineNumber (searchResult.Offset); 
				DocumentLine line = doc.GetLine (searchResult.LineNumber );
				if (line == null) {
					textRenderer.Markup = "Invalid line number " + searchResult.LineNumber + " from offset: " + searchResult.Offset;
					return;
				}
				int indent = line.GetIndentation (doc).Length;
				var data = new Mono.TextEditor.TextEditorData (doc);
				data.ColorStyle = highlightStyle;
				var lineText = doc.GetTextAt (line.Offset + indent, line.Length - indent);
				int col = searchResult.Offset - line.Offset - indent;
				// search result contained part of the indent.
				if (col + searchResult.Length < lineText.Length)
					lineText = doc.GetTextAt (line.Offset, line.Length);

				var markup = doc.SyntaxMode != null ?
				data.GetMarkup (line.Offset + indent, line.Length - indent, true, !isSelected, false) :
				GLib.Markup.EscapeText (lineText);
				searchResult.Markup = AdjustColors (markup.Replace ("\t", new string (' ', TextEditorOptions.DefaultOptions.TabSize)));

				uint start;
				uint end;
				try {
					start = (uint)TextViewMargin.TranslateIndexToUTF8 (lineText, col);
					end = (uint)TextViewMargin.TranslateIndexToUTF8 (lineText, Math.Min (lineText.Length, col + searchResult.Length));
				} catch (Exception e) {
					LoggingService.LogError ("Exception while translating index to utf8 (column was:" +col + " search result length:" + searchResult.Length + " line text:" + lineText + ")", e);
					return;
				}
				searchResult.StartIndex = start;
				searchResult.EndIndex = end;
			}


			try {
				textRenderer.Markup = searchResult.Markup;

				if (!isSelected) {
					var searchColor = searchResult.GetBackgroundMarkerColor (highlightStyle).Color;
					double b1 = Mono.TextEditor.HslColor.Brightness (searchColor);
					double b2 = Mono.TextEditor.HslColor.Brightness (AdjustColor (Style.Base (StateType.Normal), (Mono.TextEditor.HslColor)highlightStyle.PlainText.Foreground));
					double delta = Math.Abs (b1 - b2);
					if (delta < 0.1) {
						Mono.TextEditor.HslColor color1 = highlightStyle.SearchResult.Color;
						if (color1.L + 0.5 > 1.0) {
							color1.L -= 0.5;
						} else {
							color1.L += 0.5;
						}
						searchColor = color1;
					}
					var attr = new Pango.AttrBackground ((ushort)(searchColor.R * ushort.MaxValue), (ushort)(searchColor.G * ushort.MaxValue), (ushort)(searchColor.B * ushort.MaxValue));
					attr.StartIndex = searchResult.StartIndex;
					attr.EndIndex = searchResult.EndIndex;

					using (var list = textRenderer.Attributes.Copy ()) {
						list.Insert (attr);
						textRenderer.Attributes = list;
					}
				}
			} catch (Exception e) {
				LoggingService.LogError ("Error whil setting the text renderer markup to: " + searchResult.Markup, e);
			}
		}
开发者ID:LogosBible,项目名称:monodevelop,代码行数:99,代码来源:SearchResultWidget.cs

示例2: ResultTextDataFunc

//		void ResultLineDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
//		{
//			if (TreeIter.Zero.Equals (iter))
//				return;
//			var lineRenderer = (CellRendererText)cell;
//			var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
//			if (searchResult == null)
//				return;
//			
//			Document doc = GetDocument (searchResult);
//			int lineNr = doc.OffsetToLineNumber (searchResult.Offset) + 1;
//			bool didRead = (bool)store.GetValue (iter, DidReadColumn);
//			lineRenderer.Markup = MarkupText (lineNr.ToString (), didRead);
//		}
//		
		void ResultTextDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
		{
			if (TreeIter.Zero.Equals (iter))
				return;
			var textRenderer = (CellRendererText)cell;
			var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
			if (searchResult == null || searchResult.Offset < 0) {
				textRenderer.Markup = "Invalid search result";
				return;
			}
			
			var doc = GetDocument (searchResult);
			if (doc == null) {
				textRenderer.Markup = "Can't create document for:" + searchResult.FileName;
				return;
			}
			int lineNr = doc.OffsetToLineNumber (searchResult.Offset);
			DocumentLine line = doc.GetLine (lineNr);
			if (line == null) {
				textRenderer.Markup = "Invalid line number " + lineNr + " from offset: " + searchResult.Offset;
				return;
			}
			bool isSelected = treeviewSearchResults.Selection.IterIsSelected (iter);
			int indent = line.GetIndentation (doc).Length;
			var data = new Mono.TextEditor.TextEditorData (doc);
			data.ColorStyle = highlightStyle;
			string markup = doc.SyntaxMode != null ?
				data.GetMarkup (line.Offset + indent, line.Length - indent, true, !isSelected, false) :
				GLib.Markup.EscapeText (doc.GetTextAt (line.Offset, line.Length));
			
			if (!isSelected) {
				int col = searchResult.Offset - line.Offset - indent;
				string tag;
				int pos1 = FindPosition (markup, col, out tag);
				int pos2 = FindPosition (markup, col + searchResult.Length, out tag);
				if (pos1 >= 0 && pos2 >= 0) {
					markup = tag.StartsWith ("span") ? markup.Insert (pos2, "</span></span><" + tag + ">") : markup.Insert (pos2, "</span>");
					Color searchColor = Mono.TextEditor.Highlighting.ColorScheme.ToGdkColor (highlightStyle.SearchTextBg);
					double b1 = Mono.TextEditor.HslColor.Brightness (searchColor);
					double b2 = Mono.TextEditor.HslColor.Brightness (AdjustColor (Style.Base (StateType.Normal), highlightStyle.Default.Color));
					double delta = Math.Abs (b1 - b2);
					if (delta < 0.1) {
						Mono.TextEditor.HslColor color1 = highlightStyle.SearchTextBg;
						if (color1.L + 0.5 > 1.0) {
							color1.L -= 0.5;
						} else {
							color1.L += 0.5;
						}
						searchColor = color1;
					}
					markup = markup.Insert (pos1, "<span background=\"" + SyntaxMode.ColorToPangoMarkup (searchColor) + "\">");
				}
			}
			string markupText = AdjustColors (markup.Replace ("\t", new string (' ', TextEditorOptions.DefaultOptions.TabSize)));
			try {
				textRenderer.Markup = markupText;
			} catch (Exception e) {
				LoggingService.LogError ("Error whil setting the text renderer markup to: " + markup, e);
			}
		}
开发者ID:nocache,项目名称:monodevelop,代码行数:75,代码来源:SearchResultWidget.cs


注:本文中的Mono.TextEditor.TextEditorData.GetMarkup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。