[gnote] Add Active Notes notebook
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Add Active Notes notebook
- Date: Sun, 18 Nov 2012 16:03:32 +0000 (UTC)
commit 924815b0ab75fcf5c30b321039269d562d68fbe3
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Sun Nov 18 17:28:06 2012 +0200
Add Active Notes notebook
A special notebook that holds all notes, open in current session.
Only visible if contains any notes.
src/note.cpp | 2 +
src/notebooks/notebook.cpp | 41 +++++++++++++++++++++++++++++++++
src/notebooks/notebook.hpp | 23 ++++++++++++++++++
src/notebooks/notebookmanager.cpp | 46 +++++++++++++++++++++++++++---------
src/notebooks/notebookmanager.hpp | 11 ++++++++-
5 files changed, 110 insertions(+), 13 deletions(-)
---
diff --git a/src/note.cpp b/src/note.cpp
index c3fc361..a2b4a32 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -1031,6 +1031,8 @@ namespace gnote {
process_child_widget_queue();
m_note_window_embeded = true;
}
+
+ notebooks::NotebookManager::instance().active_notes_notebook()->add_note(shared_from_this());
}
bool Note::is_special() const
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index 1a45cea..9e64272 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -301,5 +301,46 @@ namespace notebooks {
return IconManager::obj().get_icon(IconManager::PIN_DOWN, 22);
}
+
+ ActiveNotesNotebook::ActiveNotesNotebook()
+ : SpecialNotebook(_("Active Notes"))
+ {
+ Gnote::obj().default_note_manager().signal_note_deleted
+ .connect(sigc::mem_fun(*this, &ActiveNotesNotebook::on_note_deleted));
+ }
+
+ std::string ActiveNotesNotebook::get_normalized_name() const
+ {
+ return "___NotebookManager___ActiveNotes__Notebook___";
+ }
+
+ bool ActiveNotesNotebook::contains_note(const Note::Ptr & note)
+ {
+ return m_notes.find(note) != m_notes.end();
+ }
+
+ bool ActiveNotesNotebook::add_note(const Note::Ptr & note)
+ {
+ if(m_notes.insert(note).second) {
+ signal_size_changed();
+ }
+
+ return true;
+ }
+
+ Glib::RefPtr<Gdk::Pixbuf> ActiveNotesNotebook::get_icon()
+ {
+ return IconManager::obj().get_icon(IconManager::NOTE, 22);
+ }
+
+ void ActiveNotesNotebook::on_note_deleted(const Note::Ptr & note)
+ {
+ std::set<Note::Ptr>::iterator iter = m_notes.find(note);
+ if(iter != m_notes.end()) {
+ m_notes.erase(iter);
+ signal_size_changed();
+ }
+ }
+
}
}
diff --git a/src/notebooks/notebook.hpp b/src/notebooks/notebook.hpp
index bac1793..6837efb 100644
--- a/src/notebooks/notebook.hpp
+++ b/src/notebooks/notebook.hpp
@@ -23,6 +23,7 @@
#ifndef __NOTEBOOKS_NOTEBOOK_HPP_
#define __NOTEBOOKS_NOTEBOOK_HPP_
+#include <set>
#include <string>
#include <tr1/memory>
@@ -140,6 +141,28 @@ public:
};
+class ActiveNotesNotebook
+ : public SpecialNotebook
+{
+public:
+ typedef std::tr1::shared_ptr<ActiveNotesNotebook> Ptr;
+ ActiveNotesNotebook();
+ virtual std::string get_normalized_name() const;
+ virtual bool contains_note(const Note::Ptr &);
+ virtual bool add_note(const Note::Ptr &);
+ virtual Glib::RefPtr<Gdk::Pixbuf> get_icon();
+ bool empty()
+ {
+ return m_notes.size() == 0;
+ }
+ sigc::signal<void> signal_size_changed;
+private:
+ void on_note_deleted(const Note::Ptr & note);
+
+ std::set<Note::Ptr> m_notes;
+};
+
+
}
}
diff --git a/src/notebooks/notebookmanager.cpp b/src/notebooks/notebookmanager.cpp
index 5d6f508..c07eb9c 100644
--- a/src/notebooks/notebookmanager.cpp
+++ b/src/notebooks/notebookmanager.cpp
@@ -41,6 +41,7 @@ namespace gnote {
NotebookManager::NotebookManager()
: m_adding_notebook(false)
+ , m_active_notes(new ActiveNotesNotebook)
{
m_notebooks = Gtk::ListStore::create(m_column_types);
@@ -48,6 +49,10 @@ namespace gnote {
m_sortedNotebooks->set_sort_func (
0, sigc::ptr_fun(&NotebookManager::compare_notebooks_sort_func));
m_sortedNotebooks->set_sort_column (0, Gtk::SORT_ASCENDING);
+
+ m_notebooks_to_display = Gtk::TreeModelFilter::create(m_sortedNotebooks);
+ m_notebooks_to_display->set_visible_func(
+ sigc::mem_fun(*this, &NotebookManager::filter_notebooks_to_display));
m_filteredNotebooks = Gtk::TreeModelFilter::create (m_sortedNotebooks);
m_filteredNotebooks->set_visible_func(
@@ -65,6 +70,11 @@ namespace gnote {
iter = m_notebooks->append();
iter->set_value(0, pinned_notes_notebook);
+ iter = m_notebooks->append();
+ iter->set_value(0, m_active_notes);
+ std::tr1::static_pointer_cast<ActiveNotesNotebook>(m_active_notes)->signal_size_changed
+ .connect(sigc::mem_fun(*this, &NotebookManager::on_active_notes_size_changed));
+
load_notebooks ();
}
@@ -416,20 +426,16 @@ namespace gnote {
if (!notebook_a || !notebook_b)
return 0;
-
- if (std::tr1::dynamic_pointer_cast<SpecialNotebook>(notebook_a)
- && std::tr1::dynamic_pointer_cast<SpecialNotebook>(notebook_b)) {
- if (std::tr1::dynamic_pointer_cast<AllNotesNotebook>(notebook_a)) {
- return -1;
- }
- else {
- return 1;
- }
- }
- else if (std::tr1::dynamic_pointer_cast<SpecialNotebook>(notebook_a)) {
+
+ SpecialNotebook::Ptr spec_a = std::tr1::dynamic_pointer_cast<SpecialNotebook>(notebook_a);
+ SpecialNotebook::Ptr spec_b = std::tr1::dynamic_pointer_cast<SpecialNotebook>(notebook_b);
+ if(spec_a != 0 && spec_b != 0) {
+ return strcmp(spec_a->get_normalized_name().c_str(), spec_b->get_normalized_name().c_str());
+ }
+ else if(spec_a != 0) {
return -1;
}
- else if (std::tr1::dynamic_pointer_cast<SpecialNotebook>(notebook_b)) {
+ else if(spec_b != 0) {
return 1;
}
@@ -476,6 +482,22 @@ namespace gnote {
return true;
}
+ bool NotebookManager::filter_notebooks_to_display(const Gtk::TreeIter & iter)
+ {
+ Notebook::Ptr notebook;
+ iter->get_value(0, notebook);
+ if(notebook == m_active_notes) {
+ return !std::tr1::static_pointer_cast<ActiveNotesNotebook>(m_active_notes)->empty();
+ }
+
+ return true;
+ }
+
+ void NotebookManager::on_active_notes_size_changed()
+ {
+ m_notebooks_to_display->refilter();
+ }
+
}
}
diff --git a/src/notebooks/notebookmanager.hpp b/src/notebooks/notebookmanager.hpp
index e253d64..c515714 100644
--- a/src/notebooks/notebookmanager.hpp
+++ b/src/notebooks/notebookmanager.hpp
@@ -68,7 +68,7 @@ public:
/// A <see cref="Notebook"/>
/// </returns>
Glib::RefPtr<Gtk::TreeModel> get_notebooks_with_special_items()
- { return m_sortedNotebooks; }
+ { return m_notebooks_to_display; }
Notebook::Ptr get_notebook(const std::string & notebookName) const;
bool notebook_exists(const std::string & notebookName) const;
@@ -90,12 +90,19 @@ public:
NotebookEventHandler & signal_note_removed_from_notebook()
{ return m_note_removed_from_notebook; }
+ Notebook::Ptr & active_notes_notebook()
+ {
+ return m_active_notes;
+ }
+
sigc::signal<void, const Note &, bool> signal_note_pin_status_changed;
private:
NotebookManager();
static int compare_notebooks_sort_func(const Gtk::TreeIter &, const Gtk::TreeIter &);
void load_notebooks();
+ bool filter_notebooks_to_display(const Gtk::TreeIter &);
+ void on_active_notes_size_changed();
static bool filter_notebooks(const Gtk::TreeIter &);
class ColumnRecord
@@ -110,6 +117,7 @@ private:
ColumnRecord m_column_types;
Glib::RefPtr<Gtk::ListStore> m_notebooks;
Glib::RefPtr<Gtk::TreeModelSort> m_sortedNotebooks;
+ Glib::RefPtr<Gtk::TreeModelFilter> m_notebooks_to_display;
Glib::RefPtr<Gtk::TreeModelFilter> m_filteredNotebooks;
// <summary>
// The key for this dictionary is Notebook.Name.ToLower ().
@@ -119,6 +127,7 @@ private:
bool m_adding_notebook;
NotebookEventHandler m_note_added_to_notebook;
NotebookEventHandler m_note_removed_from_notebook;
+ Notebook::Ptr m_active_notes;
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]