[gnote] Make default note creation not create template note



commit ebc7cbb99f646acea2489dc07132c1fba045d2ff
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Mon Apr 13 15:12:06 2020 +0300

    Make default note creation not create template note

 src/notemanager.cpp                 | 13 ++++++++++++-
 src/notemanager.hpp                 |  3 ++-
 src/notemanagerbase.cpp             | 20 ++++++++++++++++++--
 src/notemanagerbase.hpp             |  3 ++-
 src/test/unit/notemanagerutests.cpp | 10 ++++++++++
 5 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index 55838a35..d72c7de6 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2014,2017,2019 Aurimas Cernius
+ * Copyright (C) 2010-2014,2017,2019-2020 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -273,6 +273,17 @@ namespace gnote {
   }
 
 
+  NoteBase::Ptr NoteManager::create_note(Glib::ustring title, Glib::ustring body)
+  {
+    bool select_body = body.empty();
+    auto new_note = NoteManagerBase::create_note(std::move(title), std::move(body));
+    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();
+    }
+    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)
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index 63a0108e..ad8912e5 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2014,2017,2019 Aurimas Cernius
+ * Copyright (C) 2010-2014,2017,2019-2020 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -79,6 +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_new_note(const Glib::ustring & title, const Glib::ustring & xml_content,
                                           const Glib::ustring & guid) override;
diff --git a/src/notemanagerbase.cpp b/src/notemanagerbase.cpp
index f564bd41..12258d0d 100644
--- a/src/notemanagerbase.cpp
+++ b/src/notemanagerbase.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2014,2016-2017,2019 Aurimas Cernius
+ * Copyright (C) 2010-2014,2016-2017,2019-2020 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -237,7 +237,7 @@ NoteBase::Ptr NoteManagerBase::create_note_from_template(const Glib::ustring & t
 
 NoteBase::Ptr NoteManagerBase::create()
 {
-  return create("");
+  return create_note("", "");
 }
 
 NoteBase::Ptr NoteManagerBase::create(const Glib::ustring & title)
@@ -295,6 +295,22 @@ Glib::ustring NoteManagerBase::get_unique_name(const Glib::ustring & basename) c
   return title;
 }
 
+NoteBase::Ptr NoteManagerBase::create_note(Glib::ustring title, Glib::ustring body)
+{
+  if(title.empty()) {
+    title = get_unique_name(_("New Note"));
+  }
+
+  Glib::ustring content;
+  if(body.empty()) {
+    // Use a simple "Describe..." body and highlight
+    // it so it can be easily overwritten
+    content = get_note_template_content(title);
+  }
+
+  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)
diff --git a/src/notemanagerbase.hpp b/src/notemanagerbase.hpp
index ff5941fd..7feb2cfe 100644
--- a/src/notemanagerbase.hpp
+++ b/src/notemanagerbase.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2014,2017,2019 Aurimas Cernius
+ * Copyright (C) 2010-2014,2017,2019-2020 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -112,6 +112,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_new_note(const Glib::ustring & title, const Glib::ustring & xml_content, 
                                         const Glib::ustring & guid);
diff --git a/src/test/unit/notemanagerutests.cpp b/src/test/unit/notemanagerutests.cpp
index c092358a..1e9d364d 100644
--- a/src/test/unit/notemanagerutests.cpp
+++ b/src/test/unit/notemanagerutests.cpp
@@ -46,6 +46,16 @@ SUITE(NoteManager)
   };
 
 
+  TEST_FIXTURE(Fixture, create_no_args)
+  {
+    auto note1 = manager.create();
+    auto note2 = manager.create();
+
+    CHECK_EQUAL("New Note 1", note1->get_title());
+    CHECK_EQUAL("New Note 2", note2->get_title());
+    CHECK_EQUAL(2, manager.get_notes().size());
+  }
+
   TEST_FIXTURE(Fixture, create_and_find)
   {
     manager.create();


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