Esempio n. 1
0
        void PrependTimestampedText(Note note, DateTime timestamp, string text)
        {
            NoteBuffer    buffer      = note.Buffer;
            StringBuilder insert_text = new StringBuilder();

            insert_text.Append("\n");              // initial newline
            string date_format = Catalog.GetString("dddd, MMMM d, h:mm tt");

            insert_text.Append(timestamp.ToString(date_format));
            insert_text.Append("\n");              // begin content
            insert_text.Append(text);
            insert_text.Append("\n");              // trailing newline

            buffer.Undoer.FreezeUndo();

            // Insert the date and list of links...
            Gtk.TextIter cursor = buffer.StartIter;
            cursor.ForwardLines(1);              // skip title

            buffer.Insert(ref cursor, insert_text.ToString());

            // Make the date string a small font...
            cursor = buffer.StartIter;
            cursor.ForwardLines(2);              // skip title & leading newline

            Gtk.TextIter end = cursor;
            end.ForwardToLineEnd();              // end of date

            buffer.ApplyTag("datetime", cursor, end);

            // Select the text we've inserted (avoid trailing newline)...
            end = cursor;
            end.ForwardChars(insert_text.Length - 1);

            buffer.MoveMark(buffer.SelectionBound, cursor);
            buffer.MoveMark(buffer.InsertMark, end);

            buffer.Undoer.ThawUndo();
        }