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


C# TextEditorData.OffsetToLocation方法代码示例

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


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

示例1: GetInsertionPoints

		public static List<InsertionPoint> GetInsertionPoints (TextEditorData data, ParsedDocument parsedDocument, IUnresolvedTypeDefinition type)
		{
			if (data == null)
				throw new ArgumentNullException ("data");
			if (parsedDocument == null)
				throw new ArgumentNullException ("parsedDocument");
			if (type == null)
				throw new ArgumentNullException ("type");
			
			// update type from parsed document, since this is always newer.
			//type = parsedDocument.GetInnermostTypeDefinition (type.GetLocation ()) ?? type;
			List<InsertionPoint> result = new List<InsertionPoint> ();
			int offset = data.LocationToOffset (type.Region.Begin);
			if (offset < 0 || type.BodyRegion.IsEmpty)
				return result;
			while (offset < data.Length && data.GetCharAt (offset) != '{') {
				offset++;
			}
			var realStartLocation = data.OffsetToLocation (offset);
			result.Add (GetInsertionPosition (data.Document, realStartLocation.Line, realStartLocation.Column));
			result [0].LineBefore = NewLineInsertion.None;
			
			foreach (var member in type.Members) {
				TextLocation domLocation = member.BodyRegion.End;
				if (domLocation.Line <= 0) {
					DocumentLine lineSegment = data.GetLine (member.Region.BeginLine);
					if (lineSegment == null)
						continue;
					domLocation = new TextLocation (member.Region.BeginLine, lineSegment.Length + 1);
				}
				result.Add (GetInsertionPosition (data.Document, domLocation.Line, domLocation.Column));
			}

			foreach (var nestedType in type.NestedTypes) {
				TextLocation domLocation = nestedType.BodyRegion.End;
				if (domLocation.Line <= 0) {
					DocumentLine lineSegment = data.GetLine (nestedType.Region.BeginLine);
					if (lineSegment == null)
						continue;
					domLocation = new TextLocation (nestedType.Region.BeginLine, lineSegment.Length + 1);
				}
				result.Add (GetInsertionPosition (data.Document, domLocation.Line, domLocation.Column));
			}

			result [result.Count - 1].LineAfter = NewLineInsertion.None;
			CheckStartPoint (data.Document, result [0], result.Count == 1);
			if (result.Count > 1) {
				result.RemoveAt (result.Count - 1); 
				NewLineInsertion insertLine;
				var lineBefore = data.GetLine (type.BodyRegion.EndLine - 1);
				if (lineBefore != null && lineBefore.Length == lineBefore.GetIndentation (data.Document).Length) {
					insertLine = NewLineInsertion.None;
				} else {
					insertLine = NewLineInsertion.Eol;
				}
				// search for line start
				int col = type.BodyRegion.EndColumn - 1;
				var line = data.GetLine (type.BodyRegion.EndLine);
				if (line != null) {
					while (col > 1 && char.IsWhiteSpace (data.GetCharAt (line.Offset + col - 2)))
						col--;
				}
				result.Add (new InsertionPoint (new DocumentLocation (type.BodyRegion.EndLine, col), insertLine, NewLineInsertion.Eol));
				CheckEndPoint (data.Document, result [result.Count - 1], result.Count == 1);
			}
			
			foreach (var region in parsedDocument.UserRegions.Where (r => type.BodyRegion.IsInside (r.Region.Begin))) {
				result.Add (new InsertionPoint (new DocumentLocation (region.Region.BeginLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
				result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
				result.Add (new InsertionPoint (new DocumentLocation (region.Region.EndLine + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
			}
			result.Sort ((left, right) => left.Location.CompareTo (right.Location));
			return result;
		}
开发者ID:dodev,项目名称:monodevelop,代码行数:74,代码来源:CodeGenerationService.cs

示例2: GetInsertionPoint

        private InsertionPoint GetInsertionPoint(MonoDevelop.Ide.Gui.Document document, IType type)
        {
            data = document.Editor;
            if (data == null) {
                throw new System.ArgumentNullException ("data");
            }
            var parsedDocument = document.ParsedDocument;
            if (parsedDocument == null) {
                throw new System.ArgumentNullException ("parsedDocument");
            }
            if (type == null) {
                throw new System.ArgumentNullException ("type");
            }
            type = (parsedDocument.CompilationUnit.GetTypeAt (type.Location) ?? type);
            DomRegion domRegion = type.BodyRegion;
            var start = type.BodyRegion.Start.Line;
            indent = data.GetLine(start).GetIndentation(data.Document);
            DomLocation domLocation = domRegion.End;
            int num = data.LocationToOffset (domLocation.Line, 1);
            while (num < data.Length && data.GetCharAt(num) != '}') {
                num++;
            }
            num++;
            DocumentLocation documentLocation = data.OffsetToLocation (num);

            LineSegment lineAfterClassEnd = data.GetLine (domLocation.Line + 1);
            NewLineInsertion lineAfter;
            if (lineAfterClassEnd != null && lineAfterClassEnd.EditableLength == lineAfterClassEnd.GetIndentation (data.Document).Length)
                lineAfter = NewLineInsertion.BlankLine;
            else
                lineAfter = NewLineInsertion.None;

            return new InsertionPoint (documentLocation, NewLineInsertion.None, lineAfter);
        }
开发者ID:nieve,项目名称:Stereo,代码行数:34,代码来源:GenerateNewTypeRefactoring.cs

示例3: CopyData

			public void CopyData (TextEditorData data)
			{
				Selection selection;
				isLineSelectionMode = !data.IsSomethingSelected;
				if (data.IsSomethingSelected) {
					selection = data.MainSelection;
				} else {
					var start = DeleteActions.GetStartOfLineOffset (data, data.Caret.Location);
					var end = DeleteActions.GetEndOfLineOffset (data, data.Caret.Location, false);
					selection = new Selection (data.OffsetToLocation (start), data.OffsetToLocation (end));
				}
				CopyData (data, selection);
				
				if (Copy != null)
					Copy (copiedDocument != null ? copiedDocument.Text : null);
			}
开发者ID:kekekeks,项目名称:monodevelop,代码行数:16,代码来源:ClipboardActions.cs

示例4: RemoveCharBeforeCaret

		static void RemoveCharBeforeCaret (TextEditorData data)
		{
			int offset = data.Caret.Offset;
			if (offset <= 0)
				return;
			var version = data.Version;
			data.Remove (offset - 1, 1);
			data.Caret.Location = data.OffsetToLocation (version.MoveOffsetTo (data.Version, offset));
		}
开发者ID:brantwedel,项目名称:monodevelop,代码行数:9,代码来源:DeleteActions.cs

示例5: SelectAll

		public static void SelectAll (TextEditorData data)
		{
			data.Caret.PreserveSelection = true;
			data.MainSelection = new Selection (new DocumentLocation (DocumentLocation.MinLine, DocumentLocation.MinColumn), data.OffsetToLocation (data.Length));
			data.Caret.PreserveSelection = false;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:6,代码来源:SelectionActions.cs

示例6: GetInsertionPoints

		public static List<InsertionPoint> GetInsertionPoints (TextEditorData data, ParsedDocument parsedDocument, IType type)
		{
			if (data == null)
				throw new ArgumentNullException ("data");
			if (parsedDocument == null)
				throw new ArgumentNullException ("parsedDocument");
			if (type == null)
				throw new ArgumentNullException ("type");
			List<InsertionPoint> result = new List<InsertionPoint> ();
			int offset = data.LocationToOffset (type.BodyRegion.Start.Line, type.BodyRegion.Start.Column);
			if (offset < 0)
				return result;
			
			while (offset < data.Length && data.GetCharAt (offset) != '{') {
				offset++;
			}
			
			var realStartLocation = data.OffsetToLocation (offset);
			result.Add (GetInsertionPosition (data.Document, realStartLocation.Line, realStartLocation.Column));
			result[0].LineBefore = NewLineInsertion.None;
			foreach (IMember member in type.Members) {
				DomLocation domLocation = member.BodyRegion.End;
				if (domLocation.Line <= 0) {
					LineSegment lineSegment = data.GetLine (member.Location.Line);
					if (lineSegment == null)
						continue;
					domLocation = new DomLocation (member.Location.Line, lineSegment.EditableLength + 1);
				}
				result.Add (GetInsertionPosition (data.Document, domLocation.Line, domLocation.Column));
			}
			result[result.Count - 1].LineAfter = NewLineInsertion.None;
			CheckStartPoint (data.Document, result[0], result.Count == 1);
			if (result.Count > 1) {
				result.RemoveAt (result.Count - 1); 
				NewLineInsertion insertLine;
				var lineBefore = data.GetLine (type.BodyRegion.End.Line - 1);
				if (lineBefore != null && lineBefore.EditableLength == lineBefore.GetIndentation (data.Document).Length) {
					insertLine = NewLineInsertion.None;
				} else {
					insertLine = NewLineInsertion.Eol;
				}
				// search for line start
				var line = data.GetLine (type.BodyRegion.End.Line);
				int col = type.BodyRegion.End.Column - 1;
				while (col > 1 && char.IsWhiteSpace (data.GetCharAt (line.Offset + col - 2)))
					col--;
				result.Add (new InsertionPoint (new DocumentLocation (type.BodyRegion.End.Line, col), insertLine, NewLineInsertion.Eol));
				CheckEndPoint (data.Document, result[result.Count - 1], result.Count == 1);
			}
			
			foreach (var region in parsedDocument.UserRegions.Where (r => type.BodyRegion.Contains (r.Region))) {
				result.Add (new InsertionPoint (new DocumentLocation (region.Region.Start.Line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
				result.Add (new InsertionPoint (new DocumentLocation (region.Region.End.Line, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
				result.Add (new InsertionPoint (new DocumentLocation (region.Region.End.Line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol));
			}
			result.Sort ((left, right) => left.Location.CompareTo (right.Location));
			return result;
		}
开发者ID:okrmartin,项目名称:monodevelop,代码行数:58,代码来源:CodeGenerationService.cs

示例7: ResolveExpression

		public string ResolveExpression (TextEditorData ed, Document doc, int offset, out int startOffset)
		{
			startOffset = offset;
			var editorData = DResolverWrapper.CreateEditorData(doc);
			if (editorData == null)
				return null;
			editorData.CaretOffset = offset;
			var edLoc = ed.OffsetToLocation(offset);
			editorData.CaretLocation = new CodeLocation(edLoc.Column,edLoc.Line);

			var o = DResolver.GetScopedCodeObject(editorData);
			if (o != null) {
				startOffset = ed.LocationToOffset (o.Location.Line, o.Location.Column);
				if (o is INode)
					return (o as INode).Name;
				return o.ToString ();
			}

			return null;
		}
开发者ID:DinrusGroup,项目名称:Mono-D,代码行数:20,代码来源:EditorCompletionExtension.cs


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