[gnote] * Notebook addin toolbar button was inconsistent. (Closes #581213)



commit b0483c960940dfd80c1c89cb05af5953fe6f01c7
Author: Hubert Figuiere <hub figuiere net>
Date:   Mon May 4 20:46:19 2009 -0400

      * Notebook addin toolbar button was inconsistent. (Closes #581213)
---
 NEWS                                |    1 +
 src/notebooks/notebooknoteaddin.cpp |    8 +++++---
 src/notebooks/notebooknoteaddin.hpp |    3 ++-
 src/notewindow.cpp                  |   13 ++++++-------
 src/utils.cpp                       |   32 ++++++++++++++++++++++++--------
 src/utils.hpp                       |   11 ++++++++---
 6 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/NEWS b/NEWS
index 99d8b2d..5ced91f 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ Fixes:
   * .desktop has improper XFCE category and should have OnlyShowIn entry
     for GNOME and XFCE (Closes #580481)
   * Help didn't work in the Note windows. (Closes #581200)
+  * Notebook addin toolbar button was inconsistent. (Closes #581213)
 
 Translations:
 
diff --git a/src/notebooks/notebooknoteaddin.cpp b/src/notebooks/notebooknoteaddin.cpp
index 2e4ae79..cc9bd1f 100644
--- a/src/notebooks/notebooknoteaddin.cpp
+++ b/src/notebooks/notebooknoteaddin.cpp
@@ -67,7 +67,9 @@ namespace notebooks {
 
   void NotebookNoteAddin::initialize_tool_button()
   {
-    m_toolButton = manage(new Gtk::MenuToolButton(*manage(new Gtk::Image(s_notebookIcon))));
+    m_toolButton = Gtk::manage(
+      new gnote::utils::ToolMenuButton(*manage(new Gtk::Image(s_notebookIcon)), "",
+                                       m_menu));
     Gtk::Label * l = manage(new Gtk::Label());
     // Ellipsize names longer than 12 chars in length
     // TODO: Should we hardcode the ellipsized notebook name to 12 chars?
@@ -81,7 +83,7 @@ namespace notebooks {
     m_show_menu_cid = m_menu->signal_show()
       .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_menu_shown));
     m_toolButton->show_all();
-    get_note()->get_window()->toolbar()->append(*m_toolButton);
+    add_tool_item(m_toolButton, -1);
     update_notebook_button_label();
     
     m_note_added_cid = NotebookManager::instance().signal_note_added_to_notebook()
@@ -108,7 +110,7 @@ namespace notebooks {
     }
     if(!m_toolButton) {
       initialize_tool_button();
-      m_toolButton->set_menu(*m_menu);
+
       // Disable the notebook button if this note is a template note
       Tag::Ptr templateTag = TagManager::obj().get_or_create_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
       if (get_note()->contains_tag (templateTag)) {
diff --git a/src/notebooks/notebooknoteaddin.hpp b/src/notebooks/notebooknoteaddin.hpp
index 84f9a6b..dbff554 100644
--- a/src/notebooks/notebooknoteaddin.hpp
+++ b/src/notebooks/notebooknoteaddin.hpp
@@ -30,6 +30,7 @@
 #include "notebooks/notebook.hpp"
 #include "notebooks/notebookmenuitem.hpp"
 #include "note.hpp"
+#include "utils.hpp"
 
 namespace gnote {
 namespace notebooks {
@@ -56,7 +57,7 @@ namespace notebooks {
     void update_notebook_button_label(const Notebook::Ptr &);
     void update_menu();
     void get_notebook_menu_items(std::list<NotebookMenuItem*> &);
-    Gtk::MenuToolButton      *m_toolButton;
+    gnote::utils::ToolMenuButton  *m_toolButton;
     Gtk::Menu                *m_menu;
     std::list<Gtk::MenuItem *> m_menu_items;
     Gtk::RadioButtonGroup     m_radio_group;
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 6cc2aa3..1155113 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -422,9 +422,9 @@ namespace gnote {
     tb->insert(*m_link_button, -1);
 
     utils::ToolMenuButton *text_button = manage(new utils::ToolMenuButton(*tb,
-                                                            Gtk::Stock::SELECT_FONT,
-                                                            _("_Text"),
-                                                            *m_text_menu));
+                                                  Gtk::Stock::SELECT_FONT,
+                                                  _("_Text"),
+                                                  m_text_menu));
     text_button->set_use_underline(true);
     text_button->set_is_important(true);
     text_button->show_all();
@@ -432,10 +432,9 @@ namespace gnote {
     text_button->set_tooltip_text(_("Set properties of text"));
 
     utils::ToolMenuButton *plugin_button = Gtk::manage(
-      new utils::ToolMenuButton (*tb,
-                          Gtk::Stock::EXECUTE,
-                          _("T_ools"),
-                          *m_plugin_menu));
+      new utils::ToolMenuButton (*tb, Gtk::Stock::EXECUTE,
+                                 _("T_ools"),
+                                 m_plugin_menu));
     plugin_button->set_use_underline(true);
     plugin_button->show_all();
     tb->insert(*plugin_button, -1);
diff --git a/src/utils.cpp b/src/utils.cpp
index d94e55b..aaeaea4 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -695,30 +695,46 @@ namespace gnote {
     }
 
     ToolMenuButton::ToolMenuButton(Gtk::Toolbar& toolbar, const Gtk::BuiltinStockID& stock_image, 
-                                   const Glib::ustring & label, Gtk::Menu & menu)
+                                   const Glib::ustring & label, 
+                                   Gtk::Menu * menu)
       : Gtk::ToggleToolButton(label)
       ,  m_menu(menu)
     {
-      set_icon_widget(*manage(new Gtk::Image(stock_image, toolbar.get_icon_size())));
-      property_can_focus().set_value(true);
-      gtk_menu_attach_to_widget(menu.gobj(), static_cast<Gtk::Widget*>(this)->gobj(),
+      _common_init(*manage(new Gtk::Image(stock_image, toolbar.get_icon_size())));
+    }
+
+    ToolMenuButton::ToolMenuButton(Gtk::Image& image, 
+                                   const Glib::ustring & label, 
+                                   Gtk::Menu * menu)
+      : Gtk::ToggleToolButton(label)
+      ,  m_menu(menu)
+    {
+      _common_init(image);
+    }
+
+
+    void ToolMenuButton::_common_init(Gtk::Image& image)
+    {
+      set_icon_widget(image);
+      property_can_focus() = true;
+      gtk_menu_attach_to_widget(m_menu->gobj(), static_cast<Gtk::Widget*>(this)->gobj(),
                                 NULL);
 //      menu.attach_to_widget(*this);
-      menu.signal_deactivate().connect(sigc::mem_fun(*this, &ToolMenuButton::release_button));
+      m_menu->signal_deactivate().connect(sigc::mem_fun(*this, &ToolMenuButton::release_button));
       show_all();
     }
 
 
     bool ToolMenuButton::on_button_press_event(GdkEventButton *ev)
     {
-      popup_menu(m_menu, ev);
+      popup_menu(*m_menu, ev);
       return true;
     }
 
     void ToolMenuButton::on_clicked()
     {
-      m_menu.select_first(true);
-      popup_menu(m_menu, NULL);
+      m_menu->select_first(true);
+      popup_menu(*m_menu, NULL);
     }
 
     bool ToolMenuButton::on_mnemonic_activate(bool group_cycling)
diff --git a/src/utils.hpp b/src/utils.hpp
index 605578e..2f232eb 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -226,14 +226,19 @@ namespace gnote {
       : public Gtk::ToggleToolButton
     {
     public:
-      ToolMenuButton(Gtk::Toolbar& toolbar, const Gtk::BuiltinStockID& stock_image, 
-                     const Glib::ustring & label, Gtk::Menu & menu);
+      ToolMenuButton(Gtk::Toolbar& toolbar, 
+                     const Gtk::BuiltinStockID& stock_image, 
+                     const Glib::ustring & label, Gtk::Menu * menu);
+      ToolMenuButton(Gtk::Image& image, 
+                     const Glib::ustring & label, Gtk::Menu * menu);
       virtual bool on_button_press_event(GdkEventButton *);
       virtual void on_clicked();
       virtual bool on_mnemonic_activate(bool group_cycling);
 
     private:
-      Gtk::Menu &m_menu;
+      void _common_init(Gtk::Image& image);
+      // managed by gtkmm
+      Gtk::Menu *m_menu;
       void release_button();        
     };
 



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