/// <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); }
// Create a new note with the specified title from the default // template note. Optionally the body can be overridden by appending // it to title. private Note CreateNewNote(string title, string guid) { string body = null; title = SplitTitleFromContent(title, out body); if (title == null) { return(null); } Note template_note = GetOrCreateTemplateNote(); if (String.IsNullOrEmpty(body)) { return(CreateNoteFromTemplate(title, template_note, 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 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 ApplyWikiwordToBlock(Gtk.TextIter start, Gtk.TextIter end) { NoteBuffer.GetBlockExtents(ref start, ref end, 80 /* max wiki name */, broken_link_tag); Buffer.RemoveTag(broken_link_tag, start, end); for (Match match = regex.Match(start.GetText(end)); match.Success; match = match.NextMatch()) { System.Text.RegularExpressions.Group group = match.Groups [1]; Gtk.TextIter start_cpy = start; start_cpy.ForwardChars(group.Index); end = start_cpy; end.ForwardChars(group.Length); if (Note.TagTable.HasLinkTag(start_cpy)) { break; } Logger.Debug("Highlighting wikiword: '{0}' at offset {1}", group, group.Index); if (Manager.Find(group.ToString()) == null) { Buffer.ApplyTag(broken_link_tag, start_cpy, end); } } }
public void ResetNoteCount() { NoteOccurences = new int[12]; NoteBuffer.Clear(); NoteError.Clear(); }