Beispiel #1
0
        public static bool ReplaceSelection(this Gtk.TextBuffer buffer, string newText, bool keepSelection = true)
        {
            bool     retval = false;
            TextIter start;
            TextIter end;

            if (buffer.GetSelectionBounds(out start, out end))
            {
                TextMark startMark = buffer.CreateMark("start", start, false);
                TextMark endMark   = buffer.CreateMark("end", end, true);

                buffer.DeleteSelection(true, true);

                TextIter start2 = buffer.GetIterAtMark(startMark);
                buffer.Insert(ref start2, newText);

                if (keepSelection)
                {
                    TextIter start3 = buffer.GetIterAtMark(startMark);
                    TextIter end3   = buffer.GetIterAtMark(endMark);

                    buffer.SelectRange(start3, end3);
                }
                retval = true;
            }
            return(retval);
        }
Beispiel #2
0
 private void FormatTextBuffer(TextBuffer textBuffer, XmlNode linkTextNode)
 {
     XmlNodeList childNodes = linkTextNode.ChildNodes;
        foreach(XmlNode childNode in childNodes)
        {
     if (childNode.Name.Equals("a"))
     {
      XmlAttribute href = childNode.Attributes["href"];
      if (href != null)
      {
       string textTagName = href.Value;
       TextTag textTag = textBuffer.TagTable.Lookup(textTagName);
       if (textTag != null)
       {
        TextMark startTagMark = textBuffer.CreateMark(textTagName, textBuffer.EndIter, true);
        textBuffer.InsertAtCursor(childNode.InnerText);
        TextIter startTagIter = textBuffer.GetIterAtMark(startTagMark);
        TextIter endTagIter = textBuffer.EndIter;
        textBuffer.ApplyTag(textTag, startTagIter, endTagIter);
       }
      }
      else
       textBuffer.InsertAtCursor(childNode.InnerText);
     }
     else
     {
      textBuffer.InsertAtCursor(childNode.InnerText);
     }
        }
        textBuffer.ApplyTag("small-font", textBuffer.StartIter, textBuffer.EndIter);
 }
Beispiel #3
0
    protected void UpdCursorLocation(TextBuffer tb)
    {
        TextIter ti = tb.GetIterAtMark(tb.InsertMark);

          cursorLineNo = ti.Line + 1;
          cursorColumnNo = ti.LineOffset + 1;

          // Update cursor position on status bar:

          StatusBarCursorPosLabel.Text = "(" + cursorLineNo.ToString() + ", " +
          cursorColumnNo.ToString() + ")";
    }
        // Execute first SQL statement at cursor
        public string GetSqlStatementAtCursor(TextBuffer sqlTextBuffer, out TextIter iter)
        {
            TextIter start_iter, end_iter, insert_iter;
            TextIter match_start1, match_end1, match_start2, match_end2;
            TextIter begin_iter, finish_iter;
            string text = String.Empty;
            int char_count = 0;
            TextMark insert_mark;

            insert_mark = sqlTextBuffer.InsertMark;
            insert_iter = sqlTextBuffer.GetIterAtMark (insert_mark);
            start_iter = sqlTextBuffer.GetIterAtOffset (0);

            char_count = sqlTextBuffer.CharCount;
            end_iter = sqlTextBuffer.GetIterAtOffset (char_count);
            iter = end_iter;

            match_start1 = sqlTextBuffer.GetIterAtOffset (0);
            match_end1 = sqlTextBuffer.GetIterAtOffset (char_count);
            match_start2 = sqlTextBuffer.GetIterAtOffset (0);
            match_end2 = sqlTextBuffer.GetIterAtOffset (char_count);

            begin_iter = sqlTextBuffer.GetIterAtOffset (0);
            finish_iter = sqlTextBuffer.GetIterAtOffset (char_count);

            if (start_iter.IsEnd == false)
            {
                if (insert_iter.BackwardSearch (";", TextSearchFlags.TextOnly,
                        out match_start1, out match_end1, start_iter) == true) {
                    begin_iter = match_start1;
                    begin_iter.ForwardChars (1);
                }

                if (insert_iter.ForwardSearch (";",	TextSearchFlags.TextOnly,
                        out match_start2, out match_end2, end_iter) == true) {
                    finish_iter = match_end2;
                    finish_iter.BackwardChars (1);
                }
                iter = finish_iter;
                text = sqlTextBuffer.GetText (begin_iter, finish_iter, false);

                // FIXME: for this to work.  GetSqlStatement has to rewritten to be line-based
                if (text.Length > 0) {
                    // search does not work if what you are searching for is
                    // at the end of the buffer,
                    // this compensates for this
                    int j = text.Length;
                    int cont = 1;
                    for(int i = text.Length - 1; cont == 1 && i >= 0; i--) {
                        char ch = text[i];
                        switch(ch) {
                        case ' ':
                        case ';':
                            j--;
                            break;
                        default:
                            cont = 0;
                            break;
                        }
                    }

                    if (j != text.Length) {
                        string t = text.Substring(0, j);
                        text = t;
                    }
                }
            }

            return text;
        }