[gnote/tabbed] Fix link creation menu item not always having correct state



commit 5b27c3fe6d39c301a7079c7403d3200d4d3365e7
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Fri Dec 10 21:47:09 2021 +0200

    Fix link creation menu item not always having correct state

 src/notewindow.cpp | 20 ++++++++++++++++----
 src/notewindow.hpp |  2 ++
 2 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index a7d7a926..52c14c8f 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -90,8 +90,9 @@ namespace gnote {
     m_editor->signal_populate_popup().connect(sigc::mem_fun(*this, &NoteWindow::on_populate_popup));
     m_editor->show();
 
-    note.get_buffer()->signal_mark_set().connect(
-      sigc::mem_fun(*this, &NoteWindow::on_selection_mark_set));
+    note.get_buffer()->signal_mark_set().connect(sigc::mem_fun(*this, &NoteWindow::on_selection_mark_set));
+    note.get_buffer()->signal_mark_deleted().connect(sigc::mem_fun(*this, 
&NoteWindow::on_selection_mark_deleted));
+    note.get_buffer()->signal_changed().connect(sigc::mem_fun(*this, &NoteWindow::on_buffer_changed));
 
     // FIXME: I think it would be really nice to let the
     //        window get bigger up till it grows more than
@@ -156,6 +157,7 @@ namespace gnote {
     m_gnote.notebook_manager().signal_note_pin_status_changed
       .connect(sigc::mem_fun(*this, &NoteWindow::on_pin_status_changed));
 
+    m_text_menu->refresh_state();
   }
 
   void NoteWindow::background()
@@ -304,12 +306,22 @@ namespace gnote {
 
   void NoteWindow::on_selection_mark_set(const Gtk::TextIter&, const Glib::RefPtr<Gtk::TextMark> & mark)
   {
-    auto mark_name = mark->get_name();
-    if(mark_name == "insert" || mark_name == "selection_bound") {
+    on_selection_mark_deleted(mark);
+  }
+
+  void NoteWindow::on_selection_mark_deleted(const Glib::RefPtr<Gtk::TextMark> & mark)
+  {
+    auto buffer = m_note.get_buffer();
+    if(mark == buffer->get_insert() || mark == buffer->get_selection_bound()) {
       m_text_menu->refresh_state();
     }
   }
 
+  void NoteWindow::on_buffer_changed()
+  {
+    m_text_menu->refresh_state();
+  }
+
   void NoteWindow::on_populate_popup(Gtk::Menu* menu)
   {
     menu->set_accel_group(m_accel_group);
diff --git a/src/notewindow.hpp b/src/notewindow.hpp
index 2998436b..1be54bff 100644
--- a/src/notewindow.hpp
+++ b/src/notewindow.hpp
@@ -185,6 +185,8 @@ private:
 
   void on_delete_button_clicked(const Glib::VariantBase&);
   void on_selection_mark_set(const Gtk::TextIter&, const Glib::RefPtr<Gtk::TextMark>&);
+  void on_selection_mark_deleted(const Glib::RefPtr<Gtk::TextMark>&);
+  void on_buffer_changed();
   void on_populate_popup(Gtk::Menu*);
   Gtk::Grid *make_toolbar();
   Gtk::Grid * make_template_bar();


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