[gnote] Move TOC menu item to gears menu



commit 34e089c5ece1c2ec485353dcac05cddbb41c3cb5
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Jun 1 21:52:38 2013 +0300

    Move TOC menu item to gears menu
    
    Part of Bug 700655.

 .../tableofcontent/tableofcontentmenuitem.cpp      |   45 +++++++++++++++++++-
 .../tableofcontent/tableofcontentmenuitem.hpp      |   21 +++++++++-
 .../tableofcontent/tableofcontentnoteaddin.cpp     |   32 +++++---------
 .../tableofcontent/tableofcontentnoteaddin.hpp     |    8 ++--
 4 files changed, 79 insertions(+), 27 deletions(-)
---
diff --git a/src/addins/tableofcontent/tableofcontentmenuitem.cpp 
b/src/addins/tableofcontent/tableofcontentmenuitem.cpp
index b255590..590fcbf 100644
--- a/src/addins/tableofcontent/tableofcontentmenuitem.cpp
+++ b/src/addins/tableofcontent/tableofcontentmenuitem.cpp
@@ -3,6 +3,7 @@
  *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
+ * Copyright (C) 2013 Aurimas Cernius
  *
  * 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
@@ -20,6 +21,8 @@
 
 /* A subclass of ImageMenuItem to show a toc menu item */
 
+#include <glibmm/i18n.h>
+
 #include <gtkmm/stock.h>
 
 #include "iconmanager.hpp"
@@ -31,6 +34,46 @@
 namespace tableofcontent {
 
 
+Glib::RefPtr<Gtk::Action> TableofcontentAction::create(const sigc::slot<void, Gtk::Menu*> & slot)
+{
+  return Glib::RefPtr<Gtk::Action>(new TableofcontentAction(slot));
+}
+
+TableofcontentAction::TableofcontentAction(const sigc::slot<void, Gtk::Menu*> & slot)
+  : Gtk::Action("TableofcontentAction", Gtk::Stock::JUMP_TO, _("Table of Contents"), _("Table of Contents"))
+  , m_update_menu_slot(slot)
+{
+}
+
+Gtk::Widget *TableofcontentAction::create_menu_item_vfunc()
+{
+  m_submenu_built = false;
+  Gtk::ImageMenuItem *menu_item = new Gtk::ImageMenuItem;
+  m_menu = manage(new Gtk::Menu);
+  m_menu->signal_hide().connect(
+    sigc::mem_fun(*this, &TableofcontentAction::on_menu_hidden));
+  menu_item->set_submenu(*m_menu);
+  return menu_item;
+}
+
+void TableofcontentAction::on_activate()
+{
+  Gtk::Action::on_activate();
+  update_menu();
+}
+
+void TableofcontentAction::update_menu()
+{
+  m_update_menu_slot(m_menu);
+  m_submenu_built = true;
+}
+
+void TableofcontentAction::on_menu_hidden()
+{
+  m_submenu_built = false;
+}
+
+
 TableofcontentMenuItem::TableofcontentMenuItem (
                             const gnote::Note::Ptr & note,
                             const std::string      & header,
@@ -85,4 +128,4 @@ void TableofcontentMenuItem::on_activate ()
 }
 
 
-} //namespace
\ No newline at end of file
+} //namespace
diff --git a/src/addins/tableofcontent/tableofcontentmenuitem.hpp 
b/src/addins/tableofcontent/tableofcontentmenuitem.hpp
index 89ff6b8..3f13e53 100644
--- a/src/addins/tableofcontent/tableofcontentmenuitem.hpp
+++ b/src/addins/tableofcontent/tableofcontentmenuitem.hpp
@@ -3,6 +3,7 @@
  *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
+ * Copyright (C) 2013 Aurimas Cernius
  *
  * 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
@@ -32,6 +33,24 @@
 
 namespace tableofcontent {
 
+class TableofcontentAction
+  : public Gtk::Action
+{
+public:
+  static Glib::RefPtr<Gtk::Action> create(const sigc::slot<void, Gtk::Menu*> & slot);
+protected:
+  virtual Gtk::Widget *create_menu_item_vfunc();
+  virtual void on_activate();
+private:
+  TableofcontentAction(const sigc::slot<void, Gtk::Menu*> & slot);
+  void update_menu();
+  void on_menu_hidden();
+
+  bool m_submenu_built;
+  Gtk::Menu *m_menu;
+  sigc::slot<void, Gtk::Menu*> m_update_menu_slot;
+};
+
 class TableofcontentMenuItem : public Gtk::ImageMenuItem
 {
 public:
@@ -53,4 +72,4 @@ private:
 
 }
 
-#endif
\ No newline at end of file
+#endif
diff --git a/src/addins/tableofcontent/tableofcontentnoteaddin.cpp 
b/src/addins/tableofcontent/tableofcontentnoteaddin.cpp
index 15574f1..d69b307 100644
--- a/src/addins/tableofcontent/tableofcontentnoteaddin.cpp
+++ b/src/addins/tableofcontent/tableofcontentnoteaddin.cpp
@@ -3,6 +3,7 @@
  *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
+ * Copyright (C) 2013 Aurimas Cernius
  *
  * 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
@@ -45,8 +46,7 @@ TableofcontentModule::TableofcontentModule()
 
 
 TableofcontentNoteAddin::TableofcontentNoteAddin()
-  : m_menu_item      (NULL)
-  , m_toc_menu       (NULL)
+  : m_toc_menu       (NULL)
   , m_toc_menu_built (false)
 {
 }
@@ -76,19 +76,13 @@ Gtk::ImageMenuItem * new_toc_menu_item ()
 
 void TableofcontentNoteAddin::on_note_opened ()
 {
-  // TOC menu
-  m_toc_menu = manage(new Gtk::Menu());
+  m_toc_menu = manage(new Gtk::Menu);
   m_toc_menu->signal_hide().connect(
-                sigc::mem_fun(*this, &TableofcontentNoteAddin::on_menu_hidden));
-  m_toc_menu->show_all ();
+    sigc::mem_fun(*this, &TableofcontentNoteAddin::on_menu_hidden));
 
-  m_menu_item = new_toc_menu_item ();
-  m_menu_item->set_submenu(*m_toc_menu);
-  m_menu_item->signal_activate().connect(
-                 sigc::mem_fun(*this, &TableofcontentNoteAddin::on_menu_item_activated));
-  m_menu_item->show ();
-
-  add_plugin_menu_item (m_menu_item);
+  Glib::RefPtr<Gtk::Action> action = TableofcontentAction::create(
+    sigc::mem_fun(*this, &TableofcontentNoteAddin::update_menu));
+  add_note_action(action, 600);
 
   // Reacts to key press events
   get_note()->get_window()->signal_key_press_event().connect(
@@ -105,17 +99,13 @@ void TableofcontentNoteAddin::on_note_opened ()
 }
 
 
-void TableofcontentNoteAddin::on_menu_item_activated ()
+void TableofcontentNoteAddin::update_menu(Gtk::Menu *menu)
 {
-  if(m_toc_menu_built) {
-    return;
-  }
-  populate_toc_menu (m_toc_menu);
-  m_toc_menu_built = true;
+  populate_toc_menu(menu);
 }
 
 
-void TableofcontentNoteAddin::on_menu_hidden ()
+void TableofcontentNoteAddin::on_menu_hidden()
 {
   m_toc_menu_built = false; //force the submenu to rebuild next time it's supposed to show
 }
@@ -391,4 +381,4 @@ void TableofcontentNoteAddin::headification_switch (Header::Type header_request)
 }
 
 
-} //namespace
\ No newline at end of file
+} //namespace
diff --git a/src/addins/tableofcontent/tableofcontentnoteaddin.hpp 
b/src/addins/tableofcontent/tableofcontentnoteaddin.hpp
index 66eb813..c7372db 100644
--- a/src/addins/tableofcontent/tableofcontentnoteaddin.hpp
+++ b/src/addins/tableofcontent/tableofcontentnoteaddin.hpp
@@ -3,6 +3,7 @@
  *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
+ * Copyright (C) 2013 Aurimas Cernius
  *
  * 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
@@ -61,8 +62,8 @@ public:
   virtual void on_note_opened ();
 
 private:
-  void on_menu_item_activated ();
-  void on_menu_hidden ();
+  void update_menu(Gtk::Menu *menu);
+  void on_menu_hidden();
   bool on_key_pressed (GdkEventKey *ev);
   void on_populate_popup (Gtk::Menu* popup_menu);
   void on_level_1_activated ();
@@ -80,7 +81,6 @@ private:
 
   void headification_switch (Header::Type header_request);
 
-  Gtk::ImageMenuItem *m_menu_item;       // the TOC menu item, in the Tools menu
   Gtk::Menu          *m_toc_menu;        // the TOC submenu, containing the TOC
   bool                m_toc_menu_built;  // whereas toc_menu is already built
 
@@ -92,4 +92,4 @@ private:
 
 }
 
-#endif
\ No newline at end of file
+#endif


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