[gnote] Add find_template_note method to Notebook



commit c80edb08bcf2c15a0e85100788ce231cc8d5ace5
Author: Aurimas Ä?ernius <aurisc4 gmail com>
Date:   Sun Feb 27 19:10:45 2011 +0200

    Add find_template_note method to Notebook
    
    Refactor get_template_note method accordingly.

 src/notebooks/notebook.cpp |   20 ++++++++++++++++----
 src/notebooks/notebook.hpp |    1 +
 2 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index 494406e..6088d25 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -102,12 +102,14 @@ namespace notebooks {
   }
 
 
-  Note::Ptr Notebook::get_template_note() const
+  Note::Ptr Notebook::find_template_note() const
   {
-    NoteManager & noteManager = Gnote::obj().default_note_manager();
     Note::Ptr note;
-    Tag::Ptr template_tag = TagManager::obj().get_or_create_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
-    Tag::Ptr notebook_tag = TagManager::obj().get_or_create_system_tag (NOTEBOOK_TAG_PREFIX + get_name());
+    Tag::Ptr template_tag = TagManager::obj().get_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+    Tag::Ptr notebook_tag = TagManager::obj().get_system_tag (NOTEBOOK_TAG_PREFIX + get_name());
+    if(!template_tag || !notebook_tag) {
+      return note;
+    }
     std::list<Note*> notes;
     template_tag->get_notes(notes);
     for (std::list<Note*>::iterator iter = notes.begin(); iter != notes.end(); ++iter) {
@@ -117,6 +119,14 @@ namespace notebooks {
       }
     }
 
+    return note;
+  }
+
+  Note::Ptr Notebook::get_template_note() const
+  {
+    NoteManager & noteManager = Gnote::obj().default_note_manager();
+    Note::Ptr note = find_template_note();
+
     if (!note) {
       std::string title = m_default_template_note_title;
       if (noteManager.find(title)) {
@@ -135,11 +145,13 @@ namespace notebooks {
       buffer->move_mark (buffer->get_insert(), buffer->end());
 
       // Flag this as a template note
+      Tag::Ptr template_tag = TagManager::obj().get_or_create_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
       note->add_tag (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.
+      Tag::Ptr notebook_tag = TagManager::obj().get_or_create_system_tag (NOTEBOOK_TAG_PREFIX + get_name());
       note->add_tag (notebook_tag);
         
       note->queue_save (Note::CONTENT_CHANGED);
diff --git a/src/notebooks/notebook.hpp b/src/notebooks/notebook.hpp
index 620695e..9ab7f86 100644
--- a/src/notebooks/notebook.hpp
+++ b/src/notebooks/notebook.hpp
@@ -48,6 +48,7 @@ public:
   void set_name(const std::string &);
   virtual std::string get_normalized_name() const;
   virtual Tag::Ptr    get_tag() const;
+  Note::Ptr find_template_note() const;
   virtual Note::Ptr   get_template_note() const;
   Note::Ptr create_notebook_note();
   bool contains_note(const Note::Ptr &);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]