/// <summary> /// Return the template Tomboy Note that corresponds with /// this Notebook. /// </summary> /// <returns> /// A <see cref="Note"/> /// </returns> public virtual Note GetTemplateNote() { NoteManager noteManager = Tomboy.DefaultNoteManager; Note note = noteManager.Find(templateNoteTitle); if (note == null) { note = noteManager.Create(templateNoteTitle, NoteManager.GetNoteTemplateContent(templateNoteTitle)); // Select the initial text NoteBuffer buffer = note.Buffer; Gtk.TextIter iter = buffer.GetIterAtLineOffset(2, 0); buffer.MoveMark(buffer.SelectionBound, iter); buffer.MoveMark(buffer.InsertMark, buffer.EndIter); // Flag this as a template note Tag tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag); note.AddTag(tag); // Add on the notebook system tag so Tomboy // will persist the tag/notebook across sessions // if no other notes are added to the notebook. tag = TagManager.GetOrCreateSystemTag(NotebookTagPrefix + Name); note.AddTag(tag); note.QueueSave(ChangeType.ContentChanged); } return(note); }
/// <summary> /// Get the existing template note or create a new one /// if it doesn't already exist. /// </summary> /// <returns> /// A <see cref="Note"/> /// </returns> public Note GetOrCreateTemplateNote() { Note template_note = Find(NoteTemplateTitle); if (template_note == null) { template_note = Create(NoteTemplateTitle, GetNoteTemplateContent(NoteTemplateTitle)); // Select the initial text NoteBuffer buffer = template_note.Buffer; Gtk.TextIter iter = buffer.GetIterAtLineOffset(2, 0); buffer.MoveMark(buffer.SelectionBound, iter); buffer.MoveMark(buffer.InsertMark, buffer.EndIter); // Flag this as a template note Tag tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag); template_note.AddTag(tag); template_note.QueueSave(ChangeType.ContentChanged); } return(template_note); }
/// <summary> /// Return the template Tomboy Note that corresponds with /// this Notebook. /// </summary> /// <returns> /// A <see cref="Note"/> /// </returns> public virtual Note GetTemplateNote() { NoteManager noteManager = Tomboy.DefaultNoteManager; Note template_note = null; Tag template_tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag); Tag notebook_tag = TagManager.GetOrCreateSystemTag(NotebookTagPrefix + Name); foreach (Note note in template_tag.Notes) { if (note.ContainsTag(notebook_tag)) { template_note = note; break; } } if (template_note == null) { // Check name does not exist String template_name = templateNoteTitle; if (noteManager.Find(template_name) != null) { template_name = noteManager.GetUniqueName(template_name, 1); } template_note = noteManager.Create(template_name, NoteManager.GetNoteTemplateContent(template_name)); // Select the initial text NoteBuffer buffer = template_note.Buffer; Gtk.TextIter iter = buffer.GetIterAtLineOffset(2, 0); buffer.MoveMark(buffer.SelectionBound, iter); buffer.MoveMark(buffer.InsertMark, buffer.EndIter); // Flag this as a template note template_note.AddTag(template_tag); // Add on the notebook system tag so Tomboy // will persist the tag/notebook across sessions // if no other notes are added to the notebook. template_note.AddTag(notebook_tag); template_note.QueueSave(ChangeType.ContentChanged); } return(template_note); }
// Create a new note with the specified title, and a simple // "Describe..." body or the body from the "New Note Template" // note if it exists. If the "New Note Template" body is found // the text will not automatically be highlighted. private Note CreateNewNote(string title, string guid) { string body = null; title = SplitTitleFromContent(title, out body); if (title == null) { return(null); } Note note_template = Find(NoteTemplateTitle); if (note_template != null) { // Use the body from the "New Note Template" note string xml_content = note_template.XmlContent.Replace(NoteTemplateTitle, XmlEncoder.Encode(title)); return(CreateNewNote(title, xml_content, guid)); } // Use a simple "Describe..." body and highlight // it so it can be easily overwritten body = Catalog.GetString("Describe your new note here."); string header = title + "\n\n"; string content = String.Format("<note-content>{0}{1}</note-content>", XmlEncoder.Encode(header), XmlEncoder.Encode(body)); Note new_note = CreateNewNote(title, content, guid); // Select the inital // "Describe..." text so typing will overwrite the body text, NoteBuffer buffer = new_note.Buffer; Gtk.TextIter iter = buffer.GetIterAtOffset(header.Length); buffer.MoveMark(buffer.SelectionBound, iter); buffer.MoveMark(buffer.InsertMark, buffer.EndIter); return(new_note); }
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(); }
/// <summary> /// Get the existing template note or create a new one /// if it doesn't already exist. /// </summary> /// <returns> /// A <see cref="Note"/> /// </returns> public Note GetOrCreateTemplateNote() { // The default template note will have the system template tag and // will belong to zero notebooks. We find this by searching all // notes with the TemplateNoteSystemTag and check that it's // notebook == null Note template_note = null; Tag template_tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag); foreach (Note note in template_tag.Notes) { if (Notebooks.NotebookManager.GetNotebookFromNote(note) == null) { template_note = note; break; } } if (template_note == null) { template_note = Create(NoteTemplateTitle, GetNoteTemplateContent(NoteTemplateTitle)); // Select the initial text NoteBuffer buffer = template_note.Buffer; Gtk.TextIter iter = buffer.GetIterAtLineOffset(2, 0); buffer.MoveMark(buffer.SelectionBound, iter); buffer.MoveMark(buffer.InsertMark, buffer.EndIter); // Flag this as a template note template_note.AddTag(template_tag); template_note.QueueSave(ChangeType.ContentChanged); } return(template_note); }