[gnote] Do not create template note when creating with guid



commit 3420ebba2b881ffe8fb3ec165be2a9b79a02fc39
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Mon Apr 13 17:04:35 2020 +0300

    Do not create template note when creating with guid

 src/notemanager.cpp                 | 16 ++--------------
 src/notemanager.hpp                 |  3 +--
 src/notemanagerbase.cpp             | 37 +++++--------------------------------
 src/notemanagerbase.hpp             |  3 +--
 src/test/unit/notemanagerutests.cpp | 31 +++++++++++++++++++++++++++++++
 5 files changed, 40 insertions(+), 50 deletions(-)
---
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index d72c7de6..5c58ee25 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -273,10 +273,10 @@ namespace gnote {
   }
 
 
-  NoteBase::Ptr NoteManager::create_note(Glib::ustring title, Glib::ustring body)
+  NoteBase::Ptr NoteManager::create_note(Glib::ustring title, Glib::ustring body, const Glib::ustring & guid)
   {
     bool select_body = body.empty();
-    auto new_note = NoteManagerBase::create_note(std::move(title), std::move(body));
+    auto new_note = NoteManagerBase::create_note(std::move(title), std::move(body), guid);
     if(select_body) {
       // Select the inital text so typing will overwrite the body text
       std::static_pointer_cast<Note>(new_note)->get_buffer()->select_note_body();
@@ -284,18 +284,6 @@ namespace gnote {
     return new_note;
   }
 
-  // Create a new note with the specified title from the default
-  // template note. Optionally the body can be overridden.
-  NoteBase::Ptr NoteManager::create_new_note(Glib::ustring title, const Glib::ustring & guid)
-  {
-    NoteBase::Ptr new_note = NoteManagerBase::create_new_note(title, guid);
-
-    // Select the inital text so typing will overwrite the body text
-    std::static_pointer_cast<Note>(new_note)->get_buffer()->select_note_body();
-
-    return new_note;
-  }
-
   // Create a new note with the specified Xml content
   NoteBase::Ptr NoteManager::create_new_note(const Glib::ustring & title, const Glib::ustring & xml_content, 
                                         const Glib::ustring & guid)
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index ad8912e5..f05ee0a4 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -79,8 +79,7 @@ namespace gnote {
     virtual NoteBase::Ptr create_note_from_template(const Glib::ustring & title,
                                                     const NoteBase::Ptr & template_note,
                                                     const Glib::ustring & guid) override;
-    virtual NoteBase::Ptr create_note(Glib::ustring title, Glib::ustring body) override;
-    virtual NoteBase::Ptr create_new_note(Glib::ustring title, const Glib::ustring & guid) override;
+    virtual NoteBase::Ptr create_note(Glib::ustring title, Glib::ustring body, const Glib::ustring & guid = 
Glib::ustring()) override;
     virtual NoteBase::Ptr create_new_note(const Glib::ustring & title, const Glib::ustring & xml_content,
                                           const Glib::ustring & guid) override;
     virtual NoteBase::Ptr note_create_new(const Glib::ustring & title, const Glib::ustring & file_name) 
override;
diff --git a/src/notemanagerbase.cpp b/src/notemanagerbase.cpp
index eed30b46..82f08d11 100644
--- a/src/notemanagerbase.cpp
+++ b/src/notemanagerbase.cpp
@@ -297,7 +297,7 @@ Glib::ustring NoteManagerBase::get_unique_name(const Glib::ustring & basename) c
   return title;
 }
 
-NoteBase::Ptr NoteManagerBase::create_note(Glib::ustring title, Glib::ustring body)
+NoteBase::Ptr NoteManagerBase::create_note(Glib::ustring title, Glib::ustring body, const Glib::ustring & 
guid)
 {
   if(title.empty()) {
     title = get_unique_name(_("New Note"));
@@ -313,36 +313,7 @@ NoteBase::Ptr NoteManagerBase::create_note(Glib::ustring title, Glib::ustring bo
     content = get_note_content(title, body);
   }
 
-  return create_new_note(title, content, "");
-}
-
-// Create a new note with the specified title from the default
-// template note. Optionally the body can be overridden.
-NoteBase::Ptr NoteManagerBase::create_new_note(Glib::ustring title, const Glib::ustring & guid)
-{
-  Glib::ustring body;
-
-  title = split_title_from_content(title, body);
-
-  if(title.empty()) {
-    title = get_unique_name(_("New Note"));
-  }
-
-  NoteBase::Ptr template_note = get_or_create_template_note();
-
-  if(body.empty()) {
-    return create_note_from_template(title, template_note, guid);
-  }
-
-  // Use a simple "Describe..." body and highlight
-  // it so it can be easily overwritten
-  Glib::ustring content = get_note_template_content(title);
-  NoteBase::Ptr new_note = create_new_note(title, content, guid);
-
-  // Select the inital text so typing will overwrite the body text
-  std::static_pointer_cast<Note>(new_note)->get_buffer()->select_note_body();
-
-  return new_note;
+  return create_new_note(title, content, guid);
 }
 
 // Create a new note with the specified Xml content
@@ -529,7 +500,9 @@ NoteBase::Ptr NoteManagerBase::import_note(const Glib::ustring & file_path)
 
 NoteBase::Ptr NoteManagerBase::create_with_guid(const Glib::ustring & title, const Glib::ustring & guid)
 {
-  return create_new_note(title, guid);
+  Glib::ustring body;
+  auto note_title = split_title_from_content(title, body);
+  return create_note(note_title, body, guid);
 }
 
 
diff --git a/src/notemanagerbase.hpp b/src/notemanagerbase.hpp
index f0a258a0..66dbf881 100644
--- a/src/notemanagerbase.hpp
+++ b/src/notemanagerbase.hpp
@@ -113,8 +113,7 @@ protected:
   virtual NoteBase::Ptr create_note_from_template(const Glib::ustring & title,
                                                   const NoteBase::Ptr & template_note,
                                                   const Glib::ustring & guid);
-  virtual NoteBase::Ptr create_note(Glib::ustring title, Glib::ustring body);
-  virtual NoteBase::Ptr create_new_note(Glib::ustring title, const Glib::ustring & guid);
+  virtual NoteBase::Ptr create_note(Glib::ustring title, Glib::ustring body, const Glib::ustring & guid = 
Glib::ustring());
   virtual NoteBase::Ptr create_new_note(const Glib::ustring & title, const Glib::ustring & xml_content, 
                                         const Glib::ustring & guid);
   virtual NoteBase::Ptr note_create_new(const Glib::ustring & title, const Glib::ustring & file_name) = 0;
diff --git a/src/test/unit/notemanagerutests.cpp b/src/test/unit/notemanagerutests.cpp
index fcec61be..5e759b0c 100644
--- a/src/test/unit/notemanagerutests.cpp
+++ b/src/test/unit/notemanagerutests.cpp
@@ -110,5 +110,36 @@ SUITE(NoteManager)
     CHECK(manager.find("test note") == test_note);
     CHECK(manager.find_by_uri(test_note->uri()) == test_note);
   }
+
+  TEST_FIXTURE(Fixture, create_with_xml)
+  {
+    auto note = manager.create("test", "<note-content><note-title>test</note-title>\n\ntest content");
+    CHECK_EQUAL("test", note->get_title());
+    CHECK(note->data().text().find("test content") != Glib::ustring::npos);
+    CHECK_EQUAL(1, manager.get_notes().size());
+  }
+
+  TEST_FIXTURE(Fixture, create_with_guid)
+  {
+    auto note = manager.create_with_guid("test", "93b3f3ef-9eea-4cdc-9f78-76af1629987a");
+    CHECK_EQUAL("test", note->get_title());
+    CHECK(note->data().text().find("Describe your new note here.") != Glib::ustring::npos);
+    CHECK_EQUAL("93b3f3ef-9eea-4cdc-9f78-76af1629987a", note->id());
+    CHECK_EQUAL("note://gnote/93b3f3ef-9eea-4cdc-9f78-76af1629987a", note->uri());
+    CHECK_EQUAL(1, manager.get_notes().size());
+    auto other = manager.find_by_uri("note://gnote/93b3f3ef-9eea-4cdc-9f78-76af1629987a");
+    CHECK_EQUAL(note, other);
+  }
+
+
+  TEST_FIXTURE(Fixture, create_with_guid_multiline_title)
+  {
+    auto note = manager.create_with_guid("test\ntest content", "93b3f3ef-9eea-4cdc-9f78-76af1629987a");
+    CHECK_EQUAL("test", note->get_title());
+    CHECK(note->data().text().find("test content") != Glib::ustring::npos);
+    CHECK_EQUAL("93b3f3ef-9eea-4cdc-9f78-76af1629987a", note->id());
+    CHECK_EQUAL("note://gnote/93b3f3ef-9eea-4cdc-9f78-76af1629987a", note->uri());
+    CHECK_EQUAL(1, manager.get_notes().size());
+  }
 }
 


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