[gnote] Add find_template_note method to NoteManager
- From: Aurimas ÄŒernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Add find_template_note method to NoteManager
- Date: Sun, 27 Feb 2011 17:20:29 +0000 (UTC)
commit 3b784616d9a1a3f076f837732007ff2d139f9237
Author: Aurimas Ä?ernius <aurisc4 gmail com>
Date: Sun Feb 27 19:03:52 2011 +0200
Add find_template_note method to NoteManager
Refactor get_or_create_template_note method accordingly.
src/notemanager.cpp | 28 +++++++++++++++++++---------
src/notemanager.hpp | 1 +
2 files changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index 0173d87..d396bf0 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -614,17 +614,13 @@ namespace gnote {
return new_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>
- Note::Ptr NoteManager::get_or_create_template_note()
+ Note::Ptr NoteManager::find_template_note() const
{
Note::Ptr template_note;
- Tag::Ptr template_tag = TagManager::obj().get_or_create_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+ Tag::Ptr template_tag = TagManager::obj().get_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+ if(!template_tag) {
+ return template_note;
+ }
std::list<Note*> notes;
template_tag->get_notes(notes);
for (std::list<Note*>::iterator iter = notes.begin(); iter != notes.end(); ++iter) {
@@ -635,6 +631,19 @@ namespace gnote {
}
}
+ 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>
+ Note::Ptr NoteManager::get_or_create_template_note()
+ {
+ Note::Ptr template_note = find_template_note();
if (!template_note) {
std::string title = m_default_note_template_title;
if (find(title)) {
@@ -651,6 +660,7 @@ namespace gnote {
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);
template_note->add_tag(template_tag);
template_note->queue_save(Note::CONTENT_CHANGED);
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index b62fac1..110c323 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -87,6 +87,7 @@ namespace gnote {
// Will ensure the sanity including the unique title.
Note::Ptr import_note(const std::string & file_path);
Note::Ptr create_with_guid(const std::string & title, std::string & guid);
+ Note::Ptr find_template_note() const;
Note::Ptr get_or_create_template_note();
static std::string get_note_template_content(const std::string & title);
static std::string split_title_from_content (std::string title, std::string & body);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]