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


C# TextSegment类代码示例

本文整理汇总了C#中TextSegment的典型用法代码示例。如果您正苦于以下问题:C# TextSegment类的具体用法?C# TextSegment怎么用?C# TextSegment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GenerateHtml

		public static string GenerateHtml (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, 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>"); 

			var selection = new TextSegment (0, doc.TextLength);
			int startLineNumber = doc.OffsetToLineNumber (selection.Offset);
			int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset);
			htmlText.AppendLine ("<FONT face = '" + options.Font.Family + "'>");
			bool first = true;
			if (mode is SyntaxMode) {
				SyntaxModeService.StartUpdate (doc, (SyntaxMode)mode, selection.Offset, selection.EndOffset);
				SyntaxModeService.WaitUpdate (doc);
			}

			foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) {
				if (!first) {
					htmlText.AppendLine ("<BR>");
				} else {
					first = false;
				}

				if (mode == null) {
					AppendHtmlText (htmlText, doc, options, System.Math.Max (selection.Offset, line.Offset), System.Math.Min (line.EndOffset, selection.EndOffset));
					continue;
				}
				int curSpaces = 0;

				foreach (var chunk in mode.GetChunks (style, line, line.Offset, line.Length)) {
					int start = System.Math.Max (selection.Offset, chunk.Offset);
					int end = System.Math.Min (chunk.EndOffset, selection.EndOffset);
					var chunkStyle = style.GetChunkStyle (chunk);
					if (start < end) {
						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, doc, options, start, end);
						htmlText.Append ("</SPAN>");
					}
				}
			}
			htmlText.AppendLine ("</FONT>");
            htmlText.AppendLine ("</BODY></HTML>");

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

			return htmlText.ToString ();
		}
开发者ID:handless,项目名称:monodevelop,代码行数:60,代码来源:HtmlWriter.cs

示例2: RefreshMarkers

		void RefreshMarkers()
		{
			TypeReferencesResult res=null;
			try
			{
				var ParseCache = DResolverWrapper.CreateCacheList(Document);

				res = TypeReferenceFinder.Scan(SyntaxTree, ParseCache);

				RemoveMarkers(false);

				var txtDoc = Document.Editor.Document;

				DocumentLine curLine=null;
				int ln=-1;
				int len = 0;
				foreach (var id in res.TypeMatches)
				{
					var loc = DeepASTVisitor.ExtractIdLocation(id, out len);
					if(ln!=loc.Line)
						curLine = Document.Editor.GetLine(ln = loc.Line);

					var segment = new TextSegment(curLine.Offset,len);
					var m = new UnderlineTextSegmentMarker("keyword.semantic.type", loc.Column, TypeReferenceFinder.ExtractId(id));

					txtDoc.AddMarker(m);
					markers.Add(m);
				}
			}
			catch
			{
				
			}
		}
开发者ID:Geod24,项目名称:Mono-D,代码行数:34,代码来源:TypeHighlightingExtension.cs

示例3: GetSegmentsToRenameTest2

        public void GetSegmentsToRenameTest2()
        {
            string text = "";
            RenameProvider target;
            TextSegment segment = new TextSegment ();

            text        = "<expr>!*some comments*!     {myset}\r\n" +
                        "keyword = 'keyword' <expr>!another comment\r\n"+
                        "myterm = '<'{myset}'>'keyword";
            //in <expr>
            target = new RenameProvider (text, 1);
            segment = target.SelectedTextSegment;
            Assert.AreEqual ("expr".Length, segment.Length);
            Assert.AreEqual (1, segment.Offset);

            //in keyword - cursor is at 40, and item starts at 37
            target = new RenameProvider (text, 40);
            segment = target.SelectedTextSegment;
            Assert.AreEqual ("keyword".Length, segment.Length);
            Assert.AreEqual (37, segment.Offset);

            //in {myset}
            target = new RenameProvider (text, 29);
            segment = target.SelectedTextSegment;
            Assert.AreEqual ("myset".Length, segment.Length);
            Assert.AreEqual (29, segment.Offset);

            //in <expr> (2nd occurence)
            target = new RenameProvider (text, 60);
            segment = target.SelectedTextSegment;
            Assert.AreEqual ("expr".Length, segment.Length);
            Assert.AreEqual (58, segment.Offset);
        }
开发者ID:rwbloc,项目名称:gold-addin,代码行数:33,代码来源:RenameProviderTest.cs

示例4: CreateTrackedSegment

		protected override ISegment CreateTrackedSegment(int offset, int length)
		{
			var segment = new TextSegment();
			segment.StartOffset = offset;
			segment.Length = length;
			textSegmentCollection.Add(segment);
			return segment;
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:8,代码来源:EditorScript.cs

示例5: Equals

		public bool Equals (TextSegment other)
		{
			if (other == null)
				return false;
			
			return Equals (Text, other.Text) &&
				StartLocation == other.StartLocation &&
				EndLocation == other.EndLocation;
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:9,代码来源:TextSegment.cs

示例6: CreateMarker

 private UnderlineTextSegmentMarker CreateMarker(TextSegment segment, 
                                                 Color color)
 {
     return new UnderlineTextSegmentMarker(color, segment)
     {
         IsVisible = true,
         Wave = false
     };
 }
开发者ID:nomit007,项目名称:MonoDevelop.MouseJumper,代码行数:9,代码来源:JumperDecorator.cs

示例7: SpellSuggestMenuItem

 private static MenuItem SpellSuggestMenuItem(string header, TextSegment segment)
 {
     return new MenuItem
     {
         Header = header,
         FontWeight = FontWeights.Bold,
         Command = EditingCommands.CorrectSpellingError,
         CommandParameter = new Tuple<string, TextSegment>(header, segment)
     };
 }
开发者ID:foukation,项目名称:Markdown-Edit,代码行数:10,代码来源:EditorSpellCheck.cs

示例8: RenameProvider

 /// <summary>
 /// Initializes a new instance of the <see cref="GoldAddin.RenameProvider"/> class.
 /// </summary>
 /// <param name="text">The document text</param>
 /// <param name="documentPosition">Position within the text</param>
 public RenameProvider(string text, int documentPosition)
 {
     textSegmentList = new List<TextSegment> ();
     primarySegment = new TextSegment ();
     symbolType = DefinitionType.None;
     if (!string.IsNullOrEmpty (text))
     {
         findSegmentsForRenaming (text, documentPosition);
     }
 }
开发者ID:rwbloc,项目名称:gold-addin,代码行数:15,代码来源:RenameProvider.cs

示例9: Run

        public static void Run()
        {
            // ExStart:AddTOC
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Load an existing PDF files
            Document doc = new Document(dataDir + "AddTOC.pdf");

            // Get access to first page of PDF file
            Page tocPage = doc.Pages.Insert(1);

            // Create object to represent TOC information
            TocInfo tocInfo = new TocInfo();
            TextFragment title = new TextFragment("Table Of Contents");
            title.TextState.FontSize = 20;
            title.TextState.FontStyle = FontStyles.Bold;

            // Set the title for TOC
            tocInfo.Title = title;
            tocPage.TocInfo = tocInfo;

            // Create string objects which will be used as TOC elements
            string[] titles = new string[4];
            titles[0] = "First page";
            titles[1] = "Second page";
            titles[2] = "Third page";
            titles[3] = "Fourth page";
            for (int i = 0; i < 2; i++)
            {
                // Create Heading object
                Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(1);
                TextSegment segment2 = new TextSegment();
                heading2.TocPage = tocPage;
                heading2.Segments.Add(segment2);

                // Specify the destination page for heading object
                heading2.DestinationPage = doc.Pages[i + 2];

                // Destination page
                heading2.Top = doc.Pages[i + 2].Rect.Height;

                // Destination coordinate
                segment2.Text = titles[i];

                // Add heading to page containing TOC
                tocPage.Paragraphs.Add(heading2);
            }
            dataDir = dataDir + "TOC_out.pdf";
            // Save the updated document
            doc.Save(dataDir);
            // ExEnd:AddTOC
            Console.WriteLine("\nTOC added successfully to an existing PDF.\nFile saved at " + dataDir);
        }
开发者ID:aspose-pdf,项目名称:Aspose.Pdf-for-.NET,代码行数:54,代码来源:AddTOC.cs

示例10: MoveToSegment

        public static void MoveToSegment(MonoDevelop.Ide.Gui.Document doc, TextSegment segment)
        {
            if(segment.IsInvalid || segment.IsEmpty)
                return;

            TextEditorData data = doc.Editor;
            data.Caret.Offset = segment.Offset;
            data.Parent.ScrollTo(segment.EndOffset);

            var loc = data.Document.OffsetToLocation(segment.EndOffset);
            if(data.Parent.TextViewMargin.ColumnToX(data.Document.GetLine (loc.Line), loc.Column) < data.HAdjustment.PageSize)
                data.HAdjustment.Value = 0;
        }
开发者ID:hazama-yuinyan,项目名称:monodevelop-bvebinding,代码行数:13,代码来源:MoveToUsagesHandler.cs

示例11: Main

        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Load an existing PDF files
            Document doc = new Document(dataDir + "input.pdf");

            // Get access to first page of PDF file
            Page tocPage = doc.Pages.Insert(1);

            // Create object to represent TOC information
            TocInfo tocInfo = new TocInfo();
            TextFragment title = new TextFragment("Table Of Contents");
            title.TextState.FontSize = 20;
            title.TextState.FontStyle = FontStyles.Bold;

            // Set the title for TOC
            tocInfo.Title = title;
            tocPage.TocInfo = tocInfo;

            // Create string objects which will be used as TOC elements
            string[] titles = new string[4];
            titles[0] = "First page";
            titles[1] = "Second page";
            titles[2] = "Third page";
            titles[3] = "Fourth page";
            for (int i = 0; i < 2; i++)
            {
                // Create Heading object
                Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(1);
                TextSegment segment2 = new TextSegment();
                heading2.TocPage = tocPage;
                heading2.Segments.Add(segment2);

                // Specify the destination page for heading object
                heading2.DestinationPage = doc.Pages[i + 2];

                // Destination page
                heading2.Top = doc.Pages[i + 2].Rect.Height;

                // Destination coordinate
                segment2.Text = titles[i];

                // Add heading to page containing TOC
                tocPage.Paragraphs.Add(heading2);
            }
            // Save the updated document
            doc.Save(dataDir + "TOC_Output.pdf");
        }
开发者ID:Ravivishnubhotla,项目名称:Aspose_Pdf_NET,代码行数:50,代码来源:Program.cs

示例12: GetChunks

		public static List<List<ColoredSegment>> GetChunks (TextEditorData data, TextSegment selectedSegment)
		{
			int startLineNumber = data.OffsetToLineNumber (selectedSegment.Offset);
			int endLineNumber = data.OffsetToLineNumber (selectedSegment.EndOffset);
			var copiedColoredChunks = new List<List<ColoredSegment>> ();
			foreach (var line in data.Document.GetLinesBetween (startLineNumber, endLineNumber)) {
				copiedColoredChunks.Add (
					data.GetChunks (
					line, 
					System.Math.Max (selectedSegment.Offset, line.Offset),
					System.Math.Max (selectedSegment.EndOffset, line.EndOffset) - line.Offset
					)
					.Select (chunk => new ColoredSegment (chunk, data.Document))
					.ToList ()
				);
			}
			return copiedColoredChunks;
		}
开发者ID:sturmrutsturm,项目名称:monodevelop,代码行数:18,代码来源:HtmlWriter.cs

示例13: GenerateHtml

		public static string GenerateHtml (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options)
		{
			var htmlText = new StringBuilder ();

			htmlText.Append (@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN""><HTML><BODY>");

			var selection = new TextSegment (0, doc.TextLength);
			int startLineNumber = doc.OffsetToLineNumber (selection.Offset);
			int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset);
			htmlText.Append ("<FONT face = '" + options.Font.Family + "'>");
			bool first = true;
			foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) {
				if (!first) {
					htmlText.Append ("<BR/>");
				} else {
					first = false;
				}

				if (mode == null) {
					AppendHtmlText (htmlText, doc, options, System.Math.Max (selection.Offset, line.Offset), System.Math.Min (line.EndOffset, selection.EndOffset));
					continue;
				}

				foreach (var chunk in mode.GetChunks (style, line, line.Offset, line.Length)) {
					int start = System.Math.Max (selection.Offset, chunk.Offset);
					int end = System.Math.Min (chunk.EndOffset, selection.EndOffset);
					var chunkStyle = style.GetChunkStyle (chunk);
					if (start < end) {
						htmlText.Append ("<SPAN style = '");
						if (chunkStyle.Bold)
							htmlText.Append ("font-weight:bold;");
						if (chunkStyle.Italic)
							htmlText.Append ("font-style:italic;");
						htmlText.Append ("color:" + ((HslColor)chunkStyle.Foreground).ToPangoString () + ";");
						htmlText.Append ("' >");
						AppendHtmlText (htmlText, doc, options, start, end);
						htmlText.Append ("</SPAN>");
					}
				}
			}
			htmlText.Append ("</FONT>");
			htmlText.Append ("</BODY></HTML>");
			return htmlText.ToString ();
		}
开发者ID:kekekeks,项目名称:monodevelop,代码行数:44,代码来源:HtmlWriter.cs

示例14: Create

		public static TextEditorData Create (string input, bool reverse)
		{
			TextEditorData data = new Mono.TextEditor.TextEditorData ();
			
			int offset1 = input.IndexOf ('[');
			int offset2 = input.IndexOf (']');
			var selection = new TextSegment (offset1, offset2 - offset1 - 1);

			data.Text = input.Substring (0, offset1) + input.Substring (offset1 + 1, (offset2 - offset1) - 1) + input.Substring (offset2 + 1);
			if (reverse) {
				data.Caret.Offset = selection.Offset;
				data.SelectionAnchor = selection.EndOffset;
				data.ExtendSelectionTo (selection.Offset);
			} else {
				data.Caret.Offset = selection.EndOffset;
				data.SelectionAnchor = selection.Offset;
				data.ExtendSelectionTo (selection.EndOffset);
			}
			return data;
		}
开发者ID:ischyrus,项目名称:monodevelop,代码行数:20,代码来源:InsertTabTests.cs

示例15: CodeSegmentPreviewWindow

		public CodeSegmentPreviewWindow (TextEditor editor, bool hideCodeSegmentPreviewInformString, TextSegment segment, int width, int height, bool removeIndent = true) : base (Gtk.WindowType.Popup)
		{
			this.HideCodeSegmentPreviewInformString = hideCodeSegmentPreviewInformString;
			this.Segment = segment;
			this.editor = editor;
			this.AppPaintable = true;
			this.SkipPagerHint = this.SkipTaskbarHint = true;
			this.TypeHint = WindowTypeHint.Menu;
			layout = PangoUtil.CreateLayout (this);
			informLayout = PangoUtil.CreateLayout (this);
			informLayout.SetText (CodeSegmentPreviewInformString);
			
			fontDescription = Pango.FontDescription.FromString (editor.Options.FontName);
			fontDescription.Size = (int)(fontDescription.Size * 0.8f);
			layout.FontDescription = fontDescription;
			layout.Ellipsize = Pango.EllipsizeMode.End;
			// setting a max size for the segment (40 lines should be enough), 
			// no need to markup thousands of lines for a preview window
			SetSegment (segment, removeIndent);
			CalculateSize (width);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:21,代码来源:CodeSegmentPreviewWindow.cs


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