Mono.TextEditor.TextDocument.OffsetToLocation C# (CSharp) Method

OffsetToLocation() public method

public OffsetToLocation ( int offset ) : DocumentLocation
offset int
return DocumentLocation
		public DocumentLocation OffsetToLocation (int offset)
		{
			int lineNr = splitter.OffsetToLineNumber (offset);
			if (lineNr < DocumentLocation.MinLine)
				return DocumentLocation.Empty;
			DocumentLine line = GetLine (lineNr);
			var col = System.Math.Max (1, System.Math.Min (line.LengthIncludingDelimiter, offset - line.Offset) + 1);
			return new DocumentLocation (lineNr, col);
		}

Usage Example

    void SetLocationTextData (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
    {
        CellRendererText cellRendererText = (CellRendererText)cell;
        Change change = store.GetValue (iter, objColumn) as Change;
        cellRendererText.Visible = (bool)store.GetValue (iter, statusVisibleColumn);
        TextReplaceChange replaceChange = change as TextReplaceChange;
        if (replaceChange == null)
        {
            cellRendererText.Text = "";
            return;
        }

        Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument ();
        doc.Text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText (replaceChange.FileName);
        DocumentLocation loc = doc.OffsetToLocation (replaceChange.Offset);

        string text = string.Format (GettextCatalog.GetString ("(Line:{0}, Column:{1})"), loc.Line, loc.Column);
        if (treeviewPreview.Selection.IterIsSelected (iter))
        {
            cellRendererText.Text = text;
        }
        else
        {
            cellRendererText.Markup = "<span foreground=\"" + MonoDevelop.Components.PangoCairoHelper.GetColorString (Style.Text (StateType.Insensitive)) + "\">" + text + "</span>";
        }
    }
All Usage Examples Of Mono.TextEditor.TextDocument::OffsetToLocation
TextDocument