[gnote] Backlinks addin.
- From: Hubert Figuière <hub src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnote] Backlinks addin.
- Date: Mon, 11 May 2009 18:27:47 -0400 (EDT)
commit 38f90b25764e616f09c9df78dedaf3570971ddde
Author: Hubert Figuiere <hub figuiere net>
Date: Thu May 7 00:41:23 2009 -0400
Backlinks addin.
---
configure.ac | 1 +
src/addins/Makefile.am | 3 +-
src/addins/backlinks/Makefile.am | 10 ++
src/addins/backlinks/backlinkmenuitem.cpp | 66 +++++++++
src/addins/backlinks/backlinkmenuitem.hpp | 51 +++++++
src/addins/backlinks/backlinksnoteaddin.cpp | 190 +++++++++++++++++++++++++++
src/addins/backlinks/backlinksnoteaddin.hpp | 78 +++++++++++
src/notewindow.cpp | 4 +-
8 files changed, 400 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index 449c497..e7819d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -208,6 +208,7 @@ libtomboy/Makefile
src/Makefile
src/addins/Makefile
src/addins/addins.mk
+src/addins/backlinks/Makefile
src/addins/bugzilla/Makefile
src/addins/fixedwidth/Makefile
src/addins/inserttimestamp/Makefile
diff --git a/src/addins/Makefile.am b/src/addins/Makefile.am
index e717a5e..ba5989e 100644
--- a/src/addins/Makefile.am
+++ b/src/addins/Makefile.am
@@ -1,7 +1,8 @@
-SUBDIRS = bugzilla \
+SUBDIRS = backlinks \
+ bugzilla \
fixedwidth \
inserttimestamp \
printnotes \
diff --git a/src/addins/backlinks/Makefile.am b/src/addins/backlinks/Makefile.am
new file mode 100644
index 0000000..e4f09c7
--- /dev/null
+++ b/src/addins/backlinks/Makefile.am
@@ -0,0 +1,10 @@
+
+include $(builddir)/../addins.mk
+
+addinsdir = $(ADDINSDIR)
+addins_LTLIBRARIES = backlinks.la
+
+
+backlinks_la_SOURCES = backlinksnoteaddin.hpp backlinksnoteaddin.cpp \
+ backlinkmenuitem.hpp backlinkmenuitem.cpp \
+ $(NULL)
diff --git a/src/addins/backlinks/backlinkmenuitem.cpp b/src/addins/backlinks/backlinkmenuitem.cpp
new file mode 100644
index 0000000..83d5286
--- /dev/null
+++ b/src/addins/backlinks/backlinkmenuitem.cpp
@@ -0,0 +1,66 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "notewindow.hpp"
+
+#include "backlinkmenuitem.hpp"
+
+namespace backlinks {
+
+Glib::RefPtr<Gdk::Pixbuf> BacklinkMenuItem::s_note_icon;
+
+
+const Glib::RefPtr<Gdk::Pixbuf> & BacklinkMenuItem::get_note_icon()
+{
+ if(!s_note_icon) {
+ s_note_icon = gnote::utils::get_icon("note", 16);
+ }
+ return s_note_icon;
+}
+
+
+BacklinkMenuItem::BacklinkMenuItem(const gnote::Note::Ptr & note,
+ const std::string & title_search)
+ : Gtk::ImageMenuItem(note->get_title())
+ , m_note(note)
+ , m_title_search(title_search)
+{
+ set_image(*manage(new Gtk::Image(get_note_icon())));
+}
+
+
+void BacklinkMenuItem::on_activate()
+{
+ if (!m_note) {
+ return;
+ }
+
+ // Show the title of the note
+ // where the user just came from.
+ gnote::NoteFindBar & find = m_note->get_window()->get_find_bar();
+ find.show_all ();
+ find.property_visible() = true;
+ find.set_search_text(m_title_search);
+
+ m_note->get_window()->present ();
+}
+
+
+}
diff --git a/src/addins/backlinks/backlinkmenuitem.hpp b/src/addins/backlinks/backlinkmenuitem.hpp
new file mode 100644
index 0000000..c1cb7ba
--- /dev/null
+++ b/src/addins/backlinks/backlinkmenuitem.hpp
@@ -0,0 +1,51 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __BACKLINK_MENU_ITEM_HPP_
+#define __BACKLINK_MENU_ITEM_HPP_
+
+#include <string>
+#include <gtkmm/imagemenuitem.h>
+
+#include "note.hpp"
+
+namespace backlinks {
+
+class BacklinkMenuItem
+ : public Gtk::ImageMenuItem
+{
+public:
+ BacklinkMenuItem(const gnote::Note::Ptr &, const std::string &);
+
+ gnote::Note::Ptr get_note()
+ { return m_note; }
+protected:
+ virtual void on_activate();
+private:
+ gnote::Note::Ptr m_note;
+ std::string m_title_search;
+
+ static const Glib::RefPtr<Gdk::Pixbuf> & get_note_icon();
+ static Glib::RefPtr<Gdk::Pixbuf> s_note_icon;
+};
+
+}
+
+#endif
diff --git a/src/addins/backlinks/backlinksnoteaddin.cpp b/src/addins/backlinks/backlinksnoteaddin.cpp
new file mode 100644
index 0000000..d61fd34
--- /dev/null
+++ b/src/addins/backlinks/backlinksnoteaddin.cpp
@@ -0,0 +1,190 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glibmm/i18n.h>
+
+#include <gtkmm/stock.h>
+
+#include "sharp/string.hpp"
+#include "backlinksnoteaddin.hpp"
+#include "backlinkmenuitem.hpp"
+#include "notemanager.hpp"
+#include "utils.hpp"
+
+namespace backlinks {
+
+BacklinksModule::BacklinksModule()
+{
+ ADD_INTERFACE_IMPL(BacklinksNoteAddin);
+}
+const char * BacklinksModule::id() const
+{
+ return "BacklinksAddin";
+}
+const char * BacklinksModule::name() const
+{
+ return _("Backlinks");
+}
+const char * BacklinksModule::description() const
+{
+ return _("See which notes link to the one you're currently viewing.");
+}
+const char * BacklinksModule::authors() const
+{
+ return _("Hubert Figuiere and Tomboy Project");
+}
+const char * BacklinksModule::category() const
+{
+ return "Tools";
+}
+const char * BacklinksModule::version() const
+{
+ return "0.1";
+}
+
+
+
+BacklinksNoteAddin::BacklinksNoteAddin()
+ : m_menu_item(NULL)
+ , m_menu(NULL)
+ , m_submenu_built(false)
+{
+}
+
+
+void BacklinksNoteAddin::initialize ()
+{
+}
+
+
+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;
+}
+
+
+void BacklinksNoteAddin::update_menu()
+{
+ //
+ // Clear out the old list
+ //
+ Gtk::MenuShell::MenuList menu_items = m_menu->items();
+ for(Gtk::MenuShell::MenuList::reverse_iterator iter = menu_items.rbegin();
+ iter != menu_items.rend(); ++iter) {
+ m_menu->remove(*iter);
+ }
+
+ //
+ // Build a new list
+ //
+ std::list<BacklinkMenuItem*> items;
+ get_backlink_menu_items(items);
+ for(std::list<BacklinkMenuItem*>::iterator iter = items.begin();
+ iter != items.end(); ++iter) {
+ BacklinkMenuItem * item(*iter);
+ item->show_all();
+ m_menu->append (*item);
+ }
+
+ // If nothing was found, add in a "dummy" item
+ if (m_menu->items().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);
+ }
+
+ m_submenu_built = true;
+}
+
+
+void BacklinksNoteAddin::get_backlink_menu_items(std::list<BacklinkMenuItem*> & items)
+{
+ std::string search_title = get_note()->get_title();
+ std::string encoded_title
+ = gnote::utils::XmlEncoder::encode(sharp::string_to_lower(search_title));
+
+ // Go through each note looking for
+ // notes that link to this one.
+ const gnote::Note::List & list = get_note()->manager().get_notes();
+ for(gnote::Note::List::const_iterator iter = list.begin();
+ iter != list.end(); ++iter) {
+ const gnote::Note::Ptr & note(*iter);
+ if (note != get_note() // don't match ourself
+ && check_note_has_match (note, encoded_title)) {
+ BacklinkMenuItem *item = manage(new BacklinkMenuItem (note, search_title));
+
+ items.push_back(item);
+ }
+ }
+
+ items.sort();
+}
+
+
+bool BacklinksNoteAddin::check_note_has_match(const gnote::Note::Ptr & note,
+ const std::string & encoded_title)
+{
+ std::string note_text = sharp::string_to_lower(note->xml_content());
+ if (sharp::string_index_of(note_text, encoded_title) < 0)
+ return false;
+
+ return true;
+}
+
+
+
+}
diff --git a/src/addins/backlinks/backlinksnoteaddin.hpp b/src/addins/backlinks/backlinksnoteaddin.hpp
new file mode 100644
index 0000000..d2fbeb4
--- /dev/null
+++ b/src/addins/backlinks/backlinksnoteaddin.hpp
@@ -0,0 +1,78 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __BACKLINKS_NOTEADDIN_HPP_
+#define __BACKLINKS_NOTEADDIN_HPP_
+
+#include <list>
+
+#include <gtkmm/imagemenuitem.h>
+#include <gtkmm/menu.h>
+
+#include "sharp/dynamicmodule.hpp"
+#include "note.hpp"
+#include "noteaddin.hpp"
+
+namespace backlinks {
+
+class BacklinksModule
+ : public sharp::DynamicModule
+{
+public:
+ BacklinksModule();
+ virtual const char * id() const;
+ virtual const char * name() const;
+ virtual const char * description() const;
+ virtual const char * authors() const;
+ virtual const char * category() const;
+ virtual const char * version() const;
+};
+
+DECLARE_MODULE(BacklinksModule);
+
+class BacklinkMenuItem;
+
+class BacklinksNoteAddin
+ : public gnote::NoteAddin
+{
+public:
+ static BacklinksNoteAddin *create()
+ {
+ return new BacklinksNoteAddin;
+ }
+ BacklinksNoteAddin();
+
+ virtual void initialize ();
+ virtual void shutdown ();
+ virtual void on_note_opened ();
+private:
+ void on_menu_item_activated();
+ void on_menu_hidden();
+ void update_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;
+};
+
+}
+
+#endif
+
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 1155113..53e79f6 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -109,7 +109,7 @@ namespace gnote {
set_focus_child(*m_editor);
m_find_bar = manage(new NoteFindBar(note));
- m_find_bar->property_visible().set_value(false);
+ m_find_bar->property_visible() = false;
m_find_bar->set_no_show_all(true);
m_find_bar->signal_hide().connect(sigc::mem_fun(*this, &NoteWindow::find_bar_hidden));
@@ -538,7 +538,7 @@ namespace gnote {
void NoteWindow::find_button_clicked()
{
get_find_bar().show_all();
- get_find_bar().property_visible().set_value(true);
+ get_find_bar().property_visible() = true;
get_find_bar().set_search_text(m_note.get_buffer()->get_selection());
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]