[gnote] Make use of NoteAddin functionality for callbacks in toc



commit 07b73258345a2f7b2baee12c59e2e51f8f1ed15a
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Jan 2 15:28:52 2016 +0200

    Make use of NoteAddin functionality for callbacks in toc

 .../tableofcontents/tableofcontentsnoteaddin.cpp   |   29 +++++++-------------
 .../tableofcontents/tableofcontentsnoteaddin.hpp   |    8 +-----
 2 files changed, 11 insertions(+), 26 deletions(-)
---
diff --git a/src/addins/tableofcontents/tableofcontentsnoteaddin.cpp 
b/src/addins/tableofcontents/tableofcontentsnoteaddin.cpp
index 8f2f46e..316465f 100644
--- a/src/addins/tableofcontents/tableofcontentsnoteaddin.cpp
+++ b/src/addins/tableofcontents/tableofcontentsnoteaddin.cpp
@@ -3,7 +3,7 @@
  *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
- * Copyright (C) 2013,2015 Aurimas Cernius
+ * Copyright (C) 2013,2015-2016 Aurimas Cernius <aurisc4 gmail com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -83,9 +83,17 @@ void TableofcontentsNoteAddin::on_note_opened ()
   m_toc_menu->signal_hide().connect(
     sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_menu_hidden));
 
+  register_main_window_action_callback("tableofcontents-heading1",
+    sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_level_1_action));
+  register_main_window_action_callback("tableofcontents-heading2",
+    sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_level_2_action));
+  register_main_window_action_callback("tableofcontents-help",
+    sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_toc_help_action));
+  register_main_window_action_callback("tableofcontents-goto-heading",
+    sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_goto_heading));
+
   auto win = get_window();
   win->signal_foregrounded.connect(sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_foregrounded));
-  win->signal_backgrounded.connect(sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_backgrounded));
 
   auto buffer = get_note()->get_buffer();
   if(buffer) {
@@ -110,25 +118,8 @@ void TableofcontentsNoteAddin::on_note_opened ()
 void TableofcontentsNoteAddin::on_foregrounded()
 {
   auto host = get_window()->host();
-  m_level_1_action_cid = host->find_action("tableofcontents-heading1")->signal_activate()
-    .connect(sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_level_1_action));
-  m_level_2_action_cid = host->find_action("tableofcontents-heading2")->signal_activate()
-    .connect(sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_level_2_action));
-  m_toc_help_action_cid = host->find_action("tableofcontents-help")->signal_activate()
-    .connect(sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_toc_help_action));
   auto goto_action = host->find_action("tableofcontents-goto-heading");
   goto_action->set_state(Glib::Variant<gint32>::create(-1));
-  m_goto_heading_cid = goto_action->signal_activate()
-    .connect(sigc::mem_fun(*this, &TableofcontentsNoteAddin::on_goto_heading));
-}
-
-
-void TableofcontentsNoteAddin::on_backgrounded()
-{
-  m_level_1_action_cid.disconnect();
-  m_level_2_action_cid.disconnect();
-  m_toc_help_action_cid.disconnect();
-  m_goto_heading_cid.disconnect();
 }
 
 
diff --git a/src/addins/tableofcontents/tableofcontentsnoteaddin.hpp 
b/src/addins/tableofcontents/tableofcontentsnoteaddin.hpp
index 1c1b2d1..2f7bf3f 100644
--- a/src/addins/tableofcontents/tableofcontentsnoteaddin.hpp
+++ b/src/addins/tableofcontents/tableofcontentsnoteaddin.hpp
@@ -3,7 +3,7 @@
  *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
- * Copyright (C) 2013,2015 Aurimas Cernius
+ * Copyright (C) 2013,2015-2016 Aurimas Cernius <aurisc4 gmail com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -75,7 +75,6 @@ private:
   void on_level_2_action(const Glib::VariantBase&);
   void on_toc_help_action(const Glib::VariantBase&);
   void on_foregrounded();
-  void on_backgrounded();
   void on_goto_heading(const Glib::VariantBase&);
   void on_note_changed();
 
@@ -103,11 +102,6 @@ private:
   Glib::RefPtr<Gtk::TextTag> m_tag_bold; // the tags used to mark headings
   Glib::RefPtr<Gtk::TextTag> m_tag_large;
   Glib::RefPtr<Gtk::TextTag> m_tag_huge;
-
-  sigc::connection m_level_1_action_cid;
-  sigc::connection m_level_2_action_cid;
-  sigc::connection m_toc_help_action_cid;
-  sigc::connection m_goto_heading_cid;
 };
 
 


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