[gnote] New method add_note for Notebook



commit 09f3f1960a192c4de29bdf1ef125c5c000e8f6f0
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sat Nov 10 20:55:50 2012 +0200

    New method add_note for Notebook
    
    Used to add note into notebook.
    Overrided in special notebooks to work properly.
    Used for D&D to notebook.

 src/notebooks/notebook.cpp          |   25 +++++++++++++++++++++++++
 src/notebooks/notebook.hpp          |    5 +++++
 src/notebooks/notebookmanager.cpp   |    9 ++-------
 src/notebooks/notebookstreeview.cpp |   12 ++++--------
 4 files changed, 36 insertions(+), 15 deletions(-)
---
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index f020573..8a57818 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -188,6 +188,12 @@ namespace notebooks {
     return note->contains_tag (m_tag);
   }
 
+  bool Notebook::add_note(const Note::Ptr & note)
+  {
+    NotebookManager::instance().move_note_to_notebook(note, shared_from_this());
+    return true;
+  }
+
   std::string Notebook::normalize(const std::string & s)
   {
     return sharp::string_to_lower(sharp::string_trim(s));
@@ -222,6 +228,12 @@ namespace notebooks {
   }
 
 
+  bool AllNotesNotebook::add_note(const Note::Ptr &)
+  {
+    return false;
+  }
+
+
   UnfiledNotesNotebook::UnfiledNotesNotebook()
     : SpecialNotebook(_("Unfiled Notes"))
   {
@@ -239,6 +251,13 @@ namespace notebooks {
   }
 
 
+  bool UnfiledNotesNotebook::add_note(const Note::Ptr & note)
+  {
+    NotebookManager::instance().move_note_to_notebook(note, Notebook::Ptr());
+    return true;
+  }
+
+
   PinnedNotesNotebook::PinnedNotesNotebook()
     : SpecialNotebook(_("Pinned Notes"))
   {
@@ -255,5 +274,11 @@ namespace notebooks {
     return note->is_pinned();
   }
 
+  bool PinnedNotesNotebook::add_note(const Note::Ptr & note)
+  {
+    note->set_pinned(true);
+    return true;
+  }
+
 }
 }
diff --git a/src/notebooks/notebook.hpp b/src/notebooks/notebook.hpp
index ad311b5..9a0737d 100644
--- a/src/notebooks/notebook.hpp
+++ b/src/notebooks/notebook.hpp
@@ -37,6 +37,7 @@ namespace notebooks {
 /// An object that represents a notebook in Tomboy
 /// </summary>
 class Notebook 
+  : public std::tr1::enable_shared_from_this<Notebook>
 {
 public:
   typedef std::tr1::shared_ptr<Notebook> Ptr;
@@ -52,6 +53,7 @@ public:
   virtual Note::Ptr   get_template_note() const;
   Note::Ptr create_notebook_note();
   virtual bool contains_note(const Note::Ptr &);
+  virtual bool add_note(const Note::Ptr &);
   static std::string normalize(const std::string & s);
 ////
   virtual ~Notebook()
@@ -101,6 +103,7 @@ public:
   AllNotesNotebook();
   virtual std::string get_normalized_name() const;
   virtual bool        contains_note(const Note::Ptr &);
+  virtual bool        add_note(const Note::Ptr &);
 };
 
 
@@ -117,6 +120,7 @@ public:
   UnfiledNotesNotebook();
   virtual std::string get_normalized_name() const;
   virtual bool        contains_note(const Note::Ptr &);
+  virtual bool        add_note(const Note::Ptr &);
 };
 
 
@@ -128,6 +132,7 @@ public:
   PinnedNotesNotebook();
   virtual std::string get_notmalized_name() const;
   virtual bool        contains_note(const Note::Ptr &);
+  virtual bool        add_note(const Note::Ptr &);
 };
 
 
diff --git a/src/notebooks/notebookmanager.cpp b/src/notebooks/notebookmanager.cpp
index a36b4cb..5d6f508 100644
--- a/src/notebooks/notebookmanager.cpp
+++ b/src/notebooks/notebookmanager.cpp
@@ -390,19 +390,14 @@ namespace gnote {
       if (currentNotebook == notebook)
         return true; // It's already there.
 
-      bool pinning = std::tr1::dynamic_pointer_cast<PinnedNotesNotebook>(notebook);
-
-      if(currentNotebook && !pinning) {
+      if(currentNotebook) {
         note->remove_tag (currentNotebook->get_tag());
         m_note_removed_from_notebook(*note, currentNotebook);
       }
 
       // Only attempt to add the notebook tag when this
       // menu item is not the "No notebook" menu item.
-      if(pinning) {
-        note->set_pinned(true);
-      }
-      else if(notebook && !std::tr1::dynamic_pointer_cast<SpecialNotebook>(notebook)) {
+      if(notebook) {
         note->add_tag(notebook->get_tag());
         m_note_added_to_notebook(*note, notebook);
       }
diff --git a/src/notebooks/notebookstreeview.cpp b/src/notebooks/notebookstreeview.cpp
index b6d368b..a065411 100644
--- a/src/notebooks/notebookstreeview.cpp
+++ b/src/notebooks/notebookstreeview.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2011-2012 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -85,14 +85,10 @@ namespace gnote {
         Note::Ptr note = m_note_manager.find_by_uri (uri.to_string ());
         if (!note)
           continue;
-        
+
         DBG_OUT ("Dropped into notebook: %s", note->get_title().c_str());
-        
-        // TODO: If we ever support selecting multiple notes,
-        // we may want to double-check to see if there will be
-        // any notes are already inside of a notebook.  Do we
-        // want to prompt the user to confirm this choice?
-        NotebookManager::instance().move_note_to_notebook (note, destNotebook);
+
+        destNotebook->add_note(note);
       }
 
       context->drag_finish (true, false, time_);



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