[gnote] Add special notebook for pinned notes
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Add special notebook for pinned notes
- Date: Sat, 3 Nov 2012 18:35:02 +0000 (UTC)
commit 54decd490c453923e67dfe04f700279088118dd7
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Fri Nov 2 20:36:54 2012 +0200
Add special notebook for pinned notes
* Add special notebook PinnedNotesNotebook
* Add signal to NotebookManager for note pin status change
* Emit signal when note is pinned
* Pin note when drag&drop to special notebook
* Add pin button to note window
src/note.cpp | 2 +
src/notebooks/notebook.cpp | 13 ++++++++-
src/notebooks/notebook.hpp | 13 ++++++++-
src/notebooks/notebookmanager.cpp | 27 +++++++++++++------
src/notebooks/notebookmanager.hpp | 2 +
src/notewindow.cpp | 51 +++++++++++++++++++++++++++++++++++++
src/notewindow.hpp | 9 ++++++
src/searchnoteswidget.cpp | 19 +++++++++++++
src/searchnoteswidget.hpp | 2 +
9 files changed, 126 insertions(+), 12 deletions(-)
---
diff --git a/src/note.cpp b/src/note.cpp
index fa95538..c3fc361 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -46,6 +46,7 @@
#include "tagmanager.hpp"
#include "utils.hpp"
#include "debug.hpp"
+#include "notebooks/notebookmanager.hpp"
#include "sharp/exception.hpp"
#include "sharp/fileinfo.hpp"
#include "sharp/files.hpp"
@@ -1076,6 +1077,7 @@ namespace gnote {
}
}
settings->set_string(Preferences::MENU_PINNED_NOTES, new_pinned);
+ notebooks::NotebookManager::instance().signal_note_pin_status_changed(*this, pinned);
}
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index 61f7d5a..fea0575 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -225,5 +225,16 @@ namespace notebooks {
return "___NotebookManager___UnfiledNotes__Notebook___";
}
+
+ PinnedNotesNotebook::PinnedNotesNotebook()
+ : SpecialNotebook(_("Pinned Notes"))
+ {
+ }
+
+ std::string PinnedNotesNotebook::get_notmalized_name() const
+ {
+ return "___NotebookManager___PinnedNotes__Notebook___";
+ }
+
}
}
diff --git a/src/notebooks/notebook.hpp b/src/notebooks/notebook.hpp
index 30fcc11..d22edcb 100644
--- a/src/notebooks/notebook.hpp
+++ b/src/notebooks/notebook.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -116,7 +116,16 @@ public:
UnfiledNotesNotebook();
virtual std::string get_normalized_name() const;
};
-
+
+
+class PinnedNotesNotebook
+ : public SpecialNotebook
+{
+public:
+ typedef std::tr1::shared_ptr<PinnedNotesNotebook> Ptr;
+ PinnedNotesNotebook();
+ virtual std::string get_notmalized_name() const;
+};
}
diff --git a/src/notebooks/notebookmanager.cpp b/src/notebooks/notebookmanager.cpp
index 78bb1d8..a36b4cb 100644
--- a/src/notebooks/notebookmanager.cpp
+++ b/src/notebooks/notebookmanager.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
* Copyright (C) 2010 Debarshi Ray
* Copyright (C) 2009 Hubert Figuiere
*
@@ -61,6 +61,10 @@ namespace gnote {
iter = m_notebooks->append ();
iter->set_value(0, Notebook::Ptr(unfiledNotesNotebook));
+ Notebook::Ptr pinned_notes_notebook(new PinnedNotesNotebook);
+ iter = m_notebooks->append();
+ iter->set_value(0, pinned_notes_notebook);
+
load_notebooks ();
}
@@ -376,28 +380,33 @@ namespace gnote {
if (!note) {
return false;
}
-
+
// NOTE: In the future we may want to allow notes
// to exist in multiple notebooks. For now, to
// alleviate the confusion, only allow a note to
// exist in one notebook at a time.
-
+
Notebook::Ptr currentNotebook = get_notebook_from_note (note);
if (currentNotebook == notebook)
return true; // It's already there.
-
- if (currentNotebook) {
+
+ bool pinning = std::tr1::dynamic_pointer_cast<PinnedNotesNotebook>(notebook);
+
+ if(currentNotebook && !pinning) {
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 (notebook && !std::tr1::dynamic_pointer_cast<SpecialNotebook>(notebook)) {
- note->add_tag (notebook->get_tag());
+ if(pinning) {
+ note->set_pinned(true);
+ }
+ else if(notebook && !std::tr1::dynamic_pointer_cast<SpecialNotebook>(notebook)) {
+ note->add_tag(notebook->get_tag());
m_note_added_to_notebook(*note, notebook);
}
-
+
return true;
}
diff --git a/src/notebooks/notebookmanager.hpp b/src/notebooks/notebookmanager.hpp
index c5fdaa8..e253d64 100644
--- a/src/notebooks/notebookmanager.hpp
+++ b/src/notebooks/notebookmanager.hpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -89,6 +90,7 @@ public:
NotebookEventHandler & signal_note_removed_from_notebook()
{ return m_note_removed_from_notebook; }
+ sigc::signal<void, const Note &, bool> signal_note_pin_status_changed;
private:
NotebookManager();
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 06e4277..166e7b9 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -45,12 +45,29 @@
#include "search.hpp"
#include "actionmanager.hpp"
#include "tagmanager.hpp"
+#include "notebooks/notebookmanager.hpp"
#include "sharp/exception.hpp"
#include "sharp/string.hpp"
namespace gnote {
+ bool NoteWindow::s_static_inited = false;
+ Glib::RefPtr<Gio::Icon> NoteWindow::s_icon_pin_active;
+ Glib::RefPtr<Gio::Icon> NoteWindow::s_icon_pin_down;
+
+ void NoteWindow::_init_static()
+ {
+ if(!s_static_inited) {
+ s_static_inited = true;
+
+ s_icon_pin_active = utils::get_icon("pin-active", 22);
+ s_icon_pin_down = utils::get_icon("pin-down", 22);
+ }
+ }
+
+
+
NoteWindow::NoteWindow(Note & note)
: Gtk::VBox(false, 2)
, m_note(note)
@@ -61,6 +78,8 @@ namespace gnote {
, m_y(-1)
, m_global_keys(NULL)
{
+ _init_static();
+
m_template_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
m_template_save_size_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
m_template_save_selection_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
@@ -351,6 +370,20 @@ namespace gnote {
{
Gtk::Toolbar *tb = new Gtk::Toolbar();
+ m_pin_image = manage(new Gtk::Image);
+ if(m_note.is_pinned()) {
+ m_pin_image->property_gicon() = s_icon_pin_down;
+ }
+ else {
+ m_pin_image->property_gicon() = s_icon_pin_active;
+ }
+
+ m_pin_button = manage(new Gtk::ToolButton(*m_pin_image, _("Pin")));
+ m_pin_button->signal_clicked().connect(sigc::mem_fun(*this, &NoteWindow::on_pin_button_clicked));
+ tb->insert(*m_pin_button, -1);
+ notebooks::NotebookManager::instance().signal_note_pin_status_changed
+ .connect(sigc::mem_fun(*this, &NoteWindow::on_pin_status_changed));
+
m_link_button = manage(new Gtk::ToolButton(
*manage(new Gtk::Image (Gtk::Stock::JUMP_TO, tb->get_icon_size())),
_("Link")));
@@ -641,6 +674,24 @@ namespace gnote {
Glib::RefPtr<NoteBuffer>::cast_static(m_editor->get_buffer())->change_cursor_depth_directional(false);
}
+ void NoteWindow::on_pin_status_changed(const Note & note, bool pinned)
+ {
+ if(&m_note != ¬e) {
+ return;
+ }
+ if(pinned) {
+ m_pin_image->property_gicon() = s_icon_pin_down;
+ }
+ else {
+ m_pin_image->property_gicon() = s_icon_pin_active;
+ }
+ }
+
+ void NoteWindow::on_pin_button_clicked()
+ {
+ m_note.set_pinned(!m_note.is_pinned());
+ }
+
NoteFindBar::NoteFindBar(Note & note)
: Gtk::HBox(false, 0)
diff --git a/src/notewindow.hpp b/src/notewindow.hpp
index 2b1b684..d452dda 100644
--- a/src/notewindow.hpp
+++ b/src/notewindow.hpp
@@ -154,6 +154,11 @@ public:
return *m_find_bar;
}
private:
+ static void _init_static();
+ static bool s_static_inited;
+ static Glib::RefPtr<Gio::Icon> s_icon_pin_active;
+ static Glib::RefPtr<Gio::Icon> s_icon_pin_down;
+
bool on_key_pressed(GdkEventKey*);
void on_delete_button_clicked();
void on_selection_mark_set(const Gtk::TextIter&, const Glib::RefPtr<Gtk::TextMark>&);
@@ -179,6 +184,8 @@ private:
void change_depth_left_handler();
void add_accel_group(Gtk::Window &);
void remove_accel_group(Gtk::Window &);
+ void on_pin_status_changed(const Note &, bool);
+ void on_pin_button_clicked();
Note & m_note;
std::string m_name;
@@ -188,6 +195,8 @@ private:
int m_y;
Glib::RefPtr<Gtk::AccelGroup> m_accel_group;
Gtk::Toolbar *m_toolbar;
+ Gtk::Image *m_pin_image;
+ Gtk::ToolButton *m_pin_button;
Gtk::ToolButton *m_link_button;
NoteTextMenu *m_text_menu;
Gtk::Menu *m_plugin_menu;
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index 8b0f708..32cecb7 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -46,6 +46,7 @@ bool SearchNotesWidget::s_static_inited = false;
Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_note_icon;
Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_all_notes_icon;
Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_unfiled_notes_icon;
+Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_pinned_notes_icon;
Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::s_notebook_icon;
void SearchNotesWidget::_init_static()
@@ -56,6 +57,7 @@ void SearchNotesWidget::_init_static()
s_note_icon = utils::get_icon ("note", 22);
s_all_notes_icon = utils::get_icon ("filter-note-all", 22);
s_unfiled_notes_icon = utils::get_icon ("filter-note-unfiled", 22);
+ s_pinned_notes_icon = utils::get_icon ("pin-down", 22);
s_notebook_icon = utils::get_icon ("notebook", 22);
s_static_inited = true;
}
@@ -156,6 +158,8 @@ SearchNotesWidget::SearchNotesWidget(NoteManager & m)
.connect(sigc::mem_fun(*this, &SearchNotesWidget::on_note_added_to_notebook));
notebooks::NotebookManager::instance().signal_note_removed_from_notebook()
.connect(sigc::mem_fun(*this, &SearchNotesWidget::on_note_removed_from_notebook));
+ notebooks::NotebookManager::instance().signal_note_pin_status_changed
+ .connect(sigc::mem_fun(*this, &SearchNotesWidget::on_note_pin_status_changed));
// Set the focus chain for the top-most containers
std::vector<Gtk::Widget*> focus_chain;
@@ -487,6 +491,9 @@ void SearchNotesWidget::notebook_pixbuf_cell_data_func(Gtk::CellRenderer * rende
else if(std::tr1::dynamic_pointer_cast<notebooks::UnfiledNotesNotebook>(notebook)) {
crp->property_pixbuf() = s_unfiled_notes_icon;
}
+ else if(std::tr1::dynamic_pointer_cast<notebooks::PinnedNotesNotebook>(notebook)) {
+ crp->property_pixbuf() = s_pinned_notes_icon;
+ }
else {
crp->property_pixbuf() = s_notebook_icon;
}
@@ -769,6 +776,12 @@ bool SearchNotesWidget::filter_notes(const Gtk::TreeIter & iter)
return false;
}
}
+ else if(std::tr1::dynamic_pointer_cast<notebooks::PinnedNotesNotebook>(selected_notebook)) {
+ // Filter out unpinned notes
+ if(!note->is_pinned()) {
+ return false;
+ }
+ }
bool passes_search_filter = filter_by_search(note);
if(passes_search_filter == false) {
@@ -1464,6 +1477,12 @@ void SearchNotesWidget::on_note_removed_from_notebook(const Note &,
update_results();
}
+void SearchNotesWidget::on_note_pin_status_changed(const Note &, bool)
+{
+ restore_matches_window();
+ update_results();
+}
+
Gtk::Menu *SearchNotesWidget::get_note_list_context_menu()
{
if(!m_note_list_context_menu) {
diff --git a/src/searchnoteswidget.hpp b/src/searchnoteswidget.hpp
index 1151b7d..3ffba32 100644
--- a/src/searchnoteswidget.hpp
+++ b/src/searchnoteswidget.hpp
@@ -117,6 +117,7 @@ private:
Gtk::Window *get_owning_window();
void on_note_added_to_notebook(const Note & note, const notebooks::Notebook::Ptr & notebook);
void on_note_removed_from_notebook(const Note & note, const notebooks::Notebook::Ptr & notebook);
+ void on_note_pin_status_changed(const Note &, bool);
Gtk::Menu *get_note_list_context_menu();
Gtk::Menu *get_notebook_list_context_menu();
void on_open_notebook_template_note();
@@ -184,6 +185,7 @@ private:
static Glib::RefPtr<Gdk::Pixbuf> s_note_icon;
static Glib::RefPtr<Gdk::Pixbuf> s_all_notes_icon;
static Glib::RefPtr<Gdk::Pixbuf> s_unfiled_notes_icon;
+ static Glib::RefPtr<Gdk::Pixbuf> s_pinned_notes_icon;
static Glib::RefPtr<Gdk::Pixbuf> s_notebook_icon;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]