예제 #1
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);
        }
예제 #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        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);
        }
예제 #3
0
        public static Note Create(NoteManager manager, DateTime day)
        {
            string title = GetTitle(day);
            string xml   = GetContent(day, manager);

            Note notd = null;

            try {
                notd = manager.Create(title, xml);
            } catch (Exception e) {
                // Prevent blowup if note creation fails
                Logger.Error(
                    "NoteOfTheDay could not create \"{0}\": {1}",
                    title,
                    e.Message);
                notd = null;
            }

            if (notd != null)
            {
                // Automatically tag all new Note of the Day notes
                Tag notd_tag = TagManager.GetOrCreateSystemTag("NoteOfTheDay");
                notd.AddTag(notd_tag);

                // notd.AddTag queues a save so the following is no longer necessary
                //notd.Save ();
            }

            return(notd);
        }
예제 #4
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);
        }
예제 #5
0
        public static Notebook GetOrCreateNotebook(string notebookName)
        {
            if (notebookName == null)
            {
                throw new ArgumentNullException("NotebookManager.GetNotebook () called with a null name.");
            }

            Notebook notebook = GetNotebook(notebookName);

            if (notebook != null)
            {
                return(notebook);
            }

            Gtk.TreeIter iter = Gtk.TreeIter.Zero;
            lock (locker) {
                notebook = GetNotebook(notebookName);
                if (notebook != null)
                {
                    return(notebook);
                }

                try {
                    AddingNotebook = true;
                    notebook       = new Notebook(notebookName);
                } finally {
                    AddingNotebook = false;
                }
                iter = notebooks.Append();
                notebooks.SetValue(iter, 0, notebook);
                notebookMap [notebook.NormalizedName] = iter;

                // Create the template note so the system tag
                // that represents the notebook actually gets
                // saved to a note (and persisted after Tomboy
                // is shut down).
                Note templateNote = notebook.GetTemplateNote();

                // Make sure the template note has the notebook tag.
                // Since it's possible for the template note to already
                // exist, we need to make sure it gets tagged.
                templateNote.AddTag(notebook.Tag);
                if (NoteAddedToNotebook != null)
                {
                    NoteAddedToNotebook(templateNote, notebook);
                }
            }

            return(notebook);
        }
예제 #6
0
        public Note CreateNotebookNote()
        {
            string      temp_title;
            Note        template     = GetTemplateNote();
            NoteManager note_manager = Tomboy.DefaultNoteManager;

            temp_title = note_manager.GetUniqueName(Catalog.GetString("New Note"), note_manager.Notes.Count);
            Note note = note_manager.CreateNoteFromTemplate(temp_title, template);

            // Add the notebook tag
            note.AddTag(tag);

            return(note);
        }
예제 #7
0
        public void Test_Database_TryGetNoteReturnsFullNote()
        {
            using (Database context = new Database())
            {
                Note note = new Note {
                    Name = $"Test_Database_TryGetNoteReturnsFullNote", Content = "testNote"
                };
                Tag tag = new Tag {
                    Name = $"Test_Database_TryGetNoteReturnsFullNote_tag", Description = ""
                };
                note.Save(context);
                note.AddTag(tag, context);

                context.TryGetNote($"Test_Database_TryGetNoteReturnsFullNote", out Note extractedNote);
                Assert.AreEqual(1, extractedNote.NoteTags.Count, $"Could not get full note");
            }
        }
예제 #8
0
        public bool AddTagToNote(string uri, string tag_name)
        {
            if (note_manager.ReadOnly)
            {
                return(false);
            }
            Note note = note_manager.FindByUri(uri);

            if (note == null)
            {
                return(false);
            }
            Tag tag = TagManager.GetOrCreateTag(tag_name);

            note.AddTag(tag);
            note.QueueSave(ChangeType.OtherDataChanged);
            return(true);
        }
예제 #9
0
        public void Test_Database_CanInsertNoteWithTag()
        {
            using (Database context = new Database())
            {
                Note note = new Note();
                note.Save("TestContent", "Test_Database_CanInsertNoteWithTag_NOTE", context);
                Tag tag = new Tag {
                    Name = " Test_Database_CanInsertNoteWithTag_TAG", Description = "TestDesc"
                };
                note.AddTag(tag, context);


                Note assertableNote = context.Notes.AsEnumerable().FirstOrDefault(note => note.Name == "Test_Database_CanInsertNoteWithTag_NOTE");
                assertableNote.TryGetFullNote(context, out Note fullNote);

                Assert.IsNotEmpty(fullNote.NoteTags, "Note did not have 1 tag");
                Assert.AreEqual(1, fullNote.NoteTags.Count, "Note did not have 1 tag");
            }
        }
예제 #10
0
        /// <summary>
        /// Place the specified note into the specified notebook.  If the
        /// note already belongs to a notebook, it will be removed from that
        /// notebook first.
        /// </summary>
        /// <param name="note">
        /// A <see cref="Note"/>
        /// </param>
        /// <param name="notebook">
        /// A <see cref="Notebook"/>.  If Notebook is null, the note will
        /// be removed from its current notebook.
        /// </param>
        /// <returns>True if the note was successfully moved.</returns>
        public static bool MoveNoteToNotebook(Note note, Notebook notebook)
        {
            if (note == null)
            {
                return(false);
            }

            // NOTE: In the future we may want to allow notes
            // to exist in multiple notebooks.  For now, to
            // alleviate the confusion, only allow a note to
            // exist in one notebook at a time.

            Notebook currentNotebook = GetNotebookFromNote(note);

            if (currentNotebook == notebook)
            {
                return(true);                // It's already there.
            }
            if (currentNotebook != null)
            {
                note.RemoveTag(currentNotebook.Tag);
                if (NoteRemovedFromNotebook != null)
                {
                    NoteRemovedFromNotebook(note, currentNotebook);
                }
            }

            // Only attempt to add the notebook tag when this
            // menu item is not the "No notebook" menu item.
            if (notebook != null && (notebook is SpecialNotebook) == false)
            {
                note.AddTag(notebook.Tag);
                if (NoteAddedToNotebook != null)
                {
                    NoteAddedToNotebook(note, notebook);
                }
            }

            return(true);
        }
        /// <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);
        }