[gnote] Move backlinks menu item to gears menu
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Move backlinks menu item to gears menu
- Date: Fri, 31 May 2013 19:54:12 +0000 (UTC)
commit 2c2490ba84f9dd83ac45939a7ca97b6c1b089408
Author: Aurimas Černius <aurisc4 gmail com>
Date: Fri May 31 22:46:57 2013 +0300
Move backlinks menu item to gears menu
Part of Bug 700655.
po/POTFILES.in | 1 +
src/addins/backlinks/backlinkmenuitem.cpp | 47 ++++++++++++++++++++++
src/addins/backlinks/backlinkmenuitem.hpp | 21 +++++++++-
src/addins/backlinks/backlinksnoteaddin.cpp | 56 ++++----------------------
src/addins/backlinks/backlinksnoteaddin.hpp | 7 +---
5 files changed, 78 insertions(+), 54 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ce34cd5..c258ed2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@ data/org.gnome.gnote.gschema.xml.in
src/actionmanager.cpp
src/addininfo.cpp
src/addinmanager.cpp
+src/addins/backlinks/backlinkmenuitem.cpp
src/addins/backlinks/backlinks.desktop.in
src/addins/backlinks/backlinksnoteaddin.cpp
src/addins/bugzilla/bugzilla.desktop.in
diff --git a/src/addins/backlinks/backlinkmenuitem.cpp b/src/addins/backlinks/backlinkmenuitem.cpp
index 7d36924..7da49d2 100644
--- a/src/addins/backlinks/backlinkmenuitem.cpp
+++ b/src/addins/backlinks/backlinkmenuitem.cpp
@@ -19,6 +19,9 @@
*/
+#include <glibmm/i18n.h>
+#include <gtkmm/stock.h>
+
#include "ignote.hpp"
#include "iconmanager.hpp"
#include "notewindow.hpp"
@@ -27,6 +30,50 @@
namespace backlinks {
+Glib::RefPtr<Gtk::Action> BacklinkAction::create(const sigc::slot<void, Gtk::Menu*> & slot)
+{
+ return Glib::RefPtr<Gtk::Action>(new BacklinkAction(slot));
+}
+
+BacklinkAction::BacklinkAction(const sigc::slot<void, Gtk::Menu*> & slot)
+ : Gtk::Action("BacklinkAction", Gtk::Stock::JUMP_TO,
+ _("What links here?"), _("Which notes have links to here?"))
+ , m_update_menu_slot(slot)
+{
+}
+
+Gtk::Widget *BacklinkAction::create_menu_item_vfunc()
+{
+ m_submenu_built = false;
+ Gtk::MenuItem *menu_item = new Gtk::ImageMenuItem;
+ m_menu = manage(new Gtk::Menu);
+ m_menu->signal_hide().connect(
+ sigc::mem_fun(*this, &BacklinkAction::on_menu_hidden));
+ menu_item->set_submenu(*m_menu);
+ return menu_item;
+}
+
+void BacklinkAction::on_activate()
+{
+ Gtk::Action::on_activate();
+ if(m_submenu_built) {
+ return;
+ }
+ update_menu();
+}
+
+void BacklinkAction::on_menu_hidden()
+{
+ m_submenu_built = false;
+}
+
+void BacklinkAction::update_menu()
+{
+ m_update_menu_slot(m_menu);
+ m_submenu_built = true;
+}
+
+
Glib::RefPtr<Gdk::Pixbuf> BacklinkMenuItem::get_note_icon()
{
return gnote::IconManager::obj().get_icon(gnote::IconManager::NOTE, 16);
diff --git a/src/addins/backlinks/backlinkmenuitem.hpp b/src/addins/backlinks/backlinkmenuitem.hpp
index 984d1c0..af669da 100644
--- a/src/addins/backlinks/backlinkmenuitem.hpp
+++ b/src/addins/backlinks/backlinkmenuitem.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -29,6 +29,25 @@
namespace backlinks {
+class BacklinkAction
+ : public Gtk::Action
+{
+public:
+ static Glib::RefPtr<Gtk::Action> create(const sigc::slot<void, Gtk::Menu*> & slot);
+
+ virtual Gtk::Widget *create_menu_item_vfunc();
+protected:
+ virtual void on_activate();
+private:
+ BacklinkAction(const sigc::slot<void, Gtk::Menu*> & slot);
+ void on_menu_hidden();
+ void update_menu();
+
+ Gtk::Menu *m_menu;
+ bool m_submenu_built;
+ sigc::slot<void, Gtk::Menu*> m_update_menu_slot;
+};
+
class BacklinkMenuItem
: public Gtk::ImageMenuItem
{
diff --git a/src/addins/backlinks/backlinksnoteaddin.cpp b/src/addins/backlinks/backlinksnoteaddin.cpp
index 47a1851..aa30651 100644
--- a/src/addins/backlinks/backlinksnoteaddin.cpp
+++ b/src/addins/backlinks/backlinksnoteaddin.cpp
@@ -20,8 +20,6 @@
#include <glibmm/i18n.h>
-#include <gtkmm/stock.h>
-
#include "sharp/string.hpp"
#include "backlinksnoteaddin.hpp"
#include "backlinkmenuitem.hpp"
@@ -38,9 +36,6 @@ BacklinksModule::BacklinksModule()
BacklinksNoteAddin::BacklinksNoteAddin()
- : m_menu_item(NULL)
- , m_menu(NULL)
- , m_submenu_built(false)
{
}
@@ -57,51 +52,20 @@ void BacklinksNoteAddin::shutdown ()
void BacklinksNoteAddin::on_note_opened ()
{
- m_menu = manage(new Gtk::Menu());
- m_menu->signal_hide().connect(
- sigc::mem_fun(*this, &BacklinksNoteAddin::on_menu_hidden));
- m_menu->show_all ();
- m_menu_item = manage(new Gtk::ImageMenuItem (
- _("What links here?")));
- m_menu_item->set_image(*manage(new Gtk::Image(Gtk::Stock::JUMP_TO,
- Gtk::ICON_SIZE_MENU)));
- m_menu_item->set_submenu(*m_menu);
- m_menu_item->signal_activate().connect(
- sigc::mem_fun(*this, &BacklinksNoteAddin::on_menu_item_activated));
- m_menu_item->show ();
- add_plugin_menu_item (m_menu_item);
-}
-
-void BacklinksNoteAddin::on_menu_item_activated()
-{
- if(m_submenu_built) {
- return;
- }
- update_menu();
-}
-
-
-void BacklinksNoteAddin::on_menu_hidden()
-{
- // FIXME: Figure out how to have this function be called only when
- // the whole Tools menu is collapsed so that if a user keeps
- // toggling over the "What links here?" menu item, it doesn't
- // keep forcing the submenu to rebuild.
-
- // Force the submenu to rebuild next time it's supposed to show
- m_submenu_built = false;
+ Glib::RefPtr<Gtk::Action> action = BacklinkAction::create(
+ sigc::mem_fun(*this, &BacklinksNoteAddin::update_menu));
+ add_note_action(action, 100);
}
-
-void BacklinksNoteAddin::update_menu()
+void BacklinksNoteAddin::update_menu(Gtk::Menu *menu)
{
//
// Clear out the old list
//
- std::vector<Gtk::Widget*> menu_items = m_menu->get_children();
+ std::vector<Gtk::Widget*> menu_items = menu->get_children();
for(std::vector<Gtk::Widget*>::reverse_iterator iter = menu_items.rbegin();
iter != menu_items.rend(); ++iter) {
- m_menu->remove(**iter);
+ menu->remove(**iter);
}
//
@@ -113,18 +77,16 @@ void BacklinksNoteAddin::update_menu()
iter != items.end(); ++iter) {
BacklinkMenuItem * item(*iter);
item->show_all();
- m_menu->append (*item);
+ menu->append (*item);
}
// If nothing was found, add in a "dummy" item
- if (m_menu->get_children().size() == 0) {
+ if(menu->get_children().size() == 0) {
Gtk::MenuItem *blank_item = manage(new Gtk::MenuItem(_("(none)")));
blank_item->set_sensitive(false);
blank_item->show_all ();
- m_menu->append (*blank_item);
+ menu->append(*blank_item);
}
-
- m_submenu_built = true;
}
diff --git a/src/addins/backlinks/backlinksnoteaddin.hpp b/src/addins/backlinks/backlinksnoteaddin.hpp
index dd3bee1..bdc5a70 100644
--- a/src/addins/backlinks/backlinksnoteaddin.hpp
+++ b/src/addins/backlinks/backlinksnoteaddin.hpp
@@ -57,14 +57,9 @@ public:
virtual void shutdown ();
virtual void on_note_opened ();
private:
- void on_menu_item_activated();
- void on_menu_hidden();
- void update_menu();
+ void update_menu(Gtk::Menu *menu);
void get_backlink_menu_items(std::list<BacklinkMenuItem*> & items);
bool check_note_has_match(const gnote::Note::Ptr &, const std::string &);
- Gtk::ImageMenuItem *m_menu_item;
- Gtk::Menu *m_menu;
- bool m_submenu_built;
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]