예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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);
        }
        /// <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);
        }