[gnote] Make selection saving work reliably
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Make selection saving work reliably
- Date: Sat, 13 Jul 2013 21:40:25 +0000 (UTC)
commit 63ca10291975f37bd702493632ca4b4f769d9ac1
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Jul 14 00:38:07 2013 +0300
Make selection saving work reliably
Fixes Bug 700553.
src/note.cpp | 42 ++++++++++++++++++++++++++++++++++++------
src/note.hpp | 4 ++++
2 files changed, 40 insertions(+), 6 deletions(-)
---
diff --git a/src/note.cpp b/src/note.cpp
index 44e84f9..9576272 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -447,11 +447,13 @@ namespace gnote {
void Note::on_buffer_mark_set(const Gtk::TextBuffer::iterator & iter,
const Glib::RefPtr<Gtk::TextBuffer::Mark> & insert)
{
- if(insert == m_buffer->get_insert()) {
- m_data.data().set_cursor_position(iter.get_offset());
+ Gtk::TextIter start, end;
+ if(m_buffer->get_selection_bounds(start, end)) {
+ m_data.data().set_cursor_position(start.get_offset());
+ m_data.data().set_selection_bound_position(end.get_offset());
}
- else if(insert == m_buffer->get_selection_bound()) {
- m_data.data().set_selection_bound_position(iter.get_offset());
+ else if(insert->get_name() == "insert") {
+ m_data.data().set_cursor_position(iter.get_offset());
}
else {
return;
@@ -992,9 +994,9 @@ namespace gnote {
sigc::mem_fun(*this, &Note::on_buffer_tag_applied));
m_buffer->signal_remove_tag().connect(
sigc::mem_fun(*this, &Note::on_buffer_tag_removed));
- m_buffer->signal_mark_set().connect(
+ m_mark_set_conn = m_buffer->signal_mark_set().connect(
sigc::mem_fun(*this, &Note::on_buffer_mark_set));
- m_buffer->signal_mark_deleted().connect(
+ m_mark_deleted_conn = m_buffer->signal_mark_deleted().connect(
sigc::mem_fun(*this, &Note::on_buffer_mark_deleted));
}
return m_buffer;
@@ -1014,6 +1016,7 @@ namespace gnote {
}
m_window->signal_embedded.connect(sigc::mem_fun(*this, &Note::on_note_window_embedded));
+ m_window->signal_foregrounded.connect(sigc::mem_fun(*this, &Note::on_note_window_foregrounded));
}
return m_window;
}
@@ -1034,6 +1037,33 @@ namespace gnote {
notebooks::NotebookManager::obj().active_notes_notebook()->add_note(shared_from_this());
}
+ void Note::on_note_window_foregrounded()
+ {
+ m_mark_set_conn.block();
+ m_mark_deleted_conn.block();
+
+ Gtk::TextIter cursor;
+ if(m_data.data().cursor_position() != 0) {
+ // Move cursor to last-saved position
+ cursor = m_buffer->get_iter_at_offset (m_data.data().cursor_position());
+ }
+ else {
+ // Avoid title line
+ cursor = m_buffer->get_iter_at_line(2);
+ }
+ m_buffer->place_cursor(cursor);
+
+ if(m_data.data().selection_bound_position() >= 0) {
+ // Move selection bound to last-saved position
+ Gtk::TextIter selection_bound;
+ selection_bound = m_buffer->get_iter_at_offset(m_data.data().selection_bound_position());
+ m_buffer->move_mark(m_buffer->get_selection_bound(), selection_bound);
+ }
+
+ m_mark_set_conn.unblock();
+ m_mark_deleted_conn.unblock();
+ }
+
bool Note::is_special() const
{
return (m_manager.start_note_uri() == m_data.data().uri());
diff --git a/src/note.hpp b/src/note.hpp
index 39b7c2e..6d871a3 100644
--- a/src/note.hpp
+++ b/src/note.hpp
@@ -357,6 +357,7 @@ private:
void remove_links(const std::string & old_title,
const Ptr & renamed);
void on_note_window_embedded();
+ void on_note_window_foregrounded();
Note(NoteData * data, const std::string & filepath, NoteManager & manager);
@@ -394,6 +395,9 @@ private:
TagAddedHandler m_signal_tag_added;
TagRemovingHandler m_signal_tag_removing;
TagRemovedHandler m_signal_tag_removed;
+
+ sigc::connection m_mark_set_conn;
+ sigc::connection m_mark_deleted_conn;
};
class NoteArchiver
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]