[gnote/stable-0.7] Optimize note creation, renaming and deletion
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote/stable-0.7] Optimize note creation, renaming and deletion
- Date: Sat, 15 Oct 2011 19:22:02 +0000 (UTC)
commit 9fa870a358553a4aed36aa3973d99d0c1f21fb16
Author: Debarshi Ray <debarshir src gnome org>
Date: Sun Oct 2 02:36:37 2011 +0300
Optimize note creation, renaming and deletion
With a large number of notes, Gnote becomes very slow at creating,
renaming and deleting notes.
First, there is no need to throw away the whole trie and re-create it
from scratch when a new note is being created. The title of the new
note can be added to the existing trie.
Secondly there is no need to throw away and re-create the
Gtk::ListStore within the recent changes window from scratch when a
note has been created, renamed or deleted. Instead, the existing model
can be edited.
Fixes: https://bugzilla.gnome.org/660663
src/notemanager.cpp | 11 ++++++++-
src/recentchanges.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++-----
src/recentchanges.hpp | 6 ++++-
3 files changed, 62 insertions(+), 9 deletions(-)
---
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index a5d3a7e..4bc2608 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -58,6 +58,7 @@ namespace gnote {
TrieController(NoteManager &);
~TrieController();
+ void add_note(const Note::Ptr & note);
void update();
TrieTree<Note::WeakPtr> *title_trie() const
{
@@ -749,9 +750,9 @@ namespace gnote {
delete m_title_trie;
}
- void TrieController::on_note_added (const Note::Ptr & )
+ void TrieController::on_note_added (const Note::Ptr & note)
{
- update ();
+ add_note (note);
}
void TrieController::on_note_deleted (const Note::Ptr & )
@@ -764,6 +765,12 @@ namespace gnote {
update ();
}
+ void TrieController::add_note(const Note::Ptr & note)
+ {
+ m_title_trie->add_keyword (note->get_title(), note);
+ m_title_trie->compute_failure_graph();
+ }
+
void TrieController::update ()
{
if(m_title_trie) {
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index f1bbee6..0c6295c 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -166,8 +166,8 @@ namespace gnote {
m_status_bar.show();
// Update on changes to notes
- m.signal_note_deleted.connect(sigc::mem_fun(*this, &NoteRecentChanges::on_notes_changed));
- m.signal_note_added.connect(sigc::mem_fun(*this, &NoteRecentChanges::on_notes_changed));
+ m.signal_note_deleted.connect(sigc::mem_fun(*this, &NoteRecentChanges::on_note_deleted));
+ m.signal_note_added.connect(sigc::mem_fun(*this, &NoteRecentChanges::on_note_added));
m.signal_note_renamed.connect(sigc::mem_fun(*this, &NoteRecentChanges::on_note_renamed));
m.signal_note_saved.connect(sigc::mem_fun(*this, &NoteRecentChanges::on_note_saved));
@@ -390,6 +390,42 @@ namespace gnote {
m_tree->append_column (*change);
}
+ void NoteRecentChanges::add_note(const Note::Ptr & note)
+ {
+ std::string nice_date =
+ utils::get_pretty_print_date(note->change_date(), true);
+ Gtk::TreeIter iter = m_store->append();
+ iter->set_value(m_column_types.icon, s_note_icon);
+ iter->set_value(m_column_types.title, note->get_title());
+ iter->set_value(m_column_types.change_date, nice_date);
+ iter->set_value(m_column_types.note, note);
+ }
+
+ void NoteRecentChanges::delete_note(const Note::Ptr & note)
+ {
+ Gtk::TreeModel::Children rows = m_store->children();
+
+ for (Gtk::TreeModel::iterator iter = rows.begin();
+ rows.end() != iter; iter++) {
+ if (note == iter->get_value(m_column_types.note)) {
+ m_store->erase(iter);
+ break;
+ }
+ }
+ }
+
+ void NoteRecentChanges::rename_note(const Note::Ptr & note)
+ {
+ Gtk::TreeModel::Children rows = m_store->children();
+
+ for (Gtk::TreeModel::iterator iter = rows.begin();
+ rows.end() != iter; iter++) {
+ if (note == iter->get_value(m_column_types.note)) {
+ iter->set_value(m_column_types.title, note->get_title());
+ break;
+ }
+ }
+ }
void NoteRecentChanges::update_results()
{
@@ -707,14 +743,20 @@ namespace gnote {
perform_search ();
}
- void NoteRecentChanges::on_notes_changed(const Note::Ptr &)
+ void NoteRecentChanges::on_note_added(const Note::Ptr & note)
{
- update_results ();
+ add_note(note);
}
- void NoteRecentChanges::on_note_renamed(const Note::Ptr&, const std::string&)
+ void NoteRecentChanges::on_note_deleted(const Note::Ptr & note)
{
- update_results ();
+ delete_note(note);
+ }
+
+ void NoteRecentChanges::on_note_renamed(const Note::Ptr & note,
+ const std::string &)
+ {
+ rename_note(note);
}
void NoteRecentChanges::on_note_saved(const Note::Ptr&)
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index f8212b6..28d4418 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -78,6 +78,9 @@ private:
Gtk::MenuBar *create_menu_bar ();
Gtk::Widget *make_notebooks_pane();
void make_recent_tree ();
+ void add_note(const Note::Ptr & note);
+ void delete_note(const Note::Ptr & note);
+ void rename_note(const Note::Ptr & note);
void update_results();
void select_notes(const Note::List &);
static void scroll_to_iter (Gtk::TreeView & tree, const Gtk::TreeIter & iter);
@@ -92,7 +95,8 @@ private:
bool filter_by_tag (const Note::Ptr &);
bool filter_by_search(const Note::Ptr &);
void on_case_sensitive_toggled();
- void on_notes_changed(const Note::Ptr &);
+ void on_note_added(const Note::Ptr & note);
+ void on_note_deleted(const Note::Ptr & note);
void on_note_renamed(const Note::Ptr&, const std::string&);
void on_note_saved(const Note::Ptr&);
void on_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext> &,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]