[gnote] Add TODO add-in



commit 04146441c6bb31a3f54369f8091afefcdbd9f661
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Wed Oct 16 23:25:03 2013 +0300

    Add TODO add-in

 configure.ac                      |    1 +
 po/POTFILES.in                    |    1 +
 src/addins/Makefile.am            |    1 +
 src/addins/todo/Makefile.am       |   19 ++++++
 src/addins/todo/todo.desktop.in   |    9 +++
 src/addins/todo/todonoteaddin.cpp |  110 +++++++++++++++++++++++++++++++++++++
 src/addins/todo/todonoteaddin.hpp |   61 ++++++++++++++++++++
 7 files changed, 202 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2d81cd6..9a32460 100644
--- a/configure.ac
+++ b/configure.ac
@@ -184,6 +184,7 @@ src/addins/specialnotes/Makefile
 src/addins/statistics/Makefile
 src/addins/stickynoteimport/Makefile
 src/addins/tableofcontents/Makefile
+src/addins/todo/Makefile
 src/addins/tomboyimport/Makefile
 src/addins/underline/Makefile
 src/addins/webdavsyncservice/Makefile
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f4174ed..fb414cb 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -40,6 +40,7 @@ src/addins/stickynoteimport/stickynoteimportnoteaddin.cpp
 src/addins/tableofcontents/tableofcontentsaction.cpp
 src/addins/tableofcontents/tableofcontents.desktop.in
 src/addins/tableofcontents/tableofcontentsnoteaddin.cpp
+src/addins/todo/todo.desktop.in
 src/addins/tomboyimport/tomboyimport.desktop.in
 src/addins/underline/underline.desktop.in
 src/addins/underline/underlinemenuitem.cpp
diff --git a/src/addins/Makefile.am b/src/addins/Makefile.am
index 4f785c8..1eea091 100644
--- a/src/addins/Makefile.am
+++ b/src/addins/Makefile.am
@@ -16,6 +16,7 @@ SUBDIRS = backlinks \
        statistics \
        stickynoteimport \
        tableofcontents \
+       todo \
        tomboyimport \
        underline \
        webdavsyncservice \
diff --git a/src/addins/todo/Makefile.am b/src/addins/todo/Makefile.am
new file mode 100644
index 0000000..25101d8
--- /dev/null
+++ b/src/addins/todo/Makefile.am
@@ -0,0 +1,19 @@
+
+include $(builddir)/../addins.mk
+
+ INTLTOOL_DESKTOP_RULE@
+
+desktop_in_files = todo.desktop.in
+desktop_files    = $(desktop_in_files:.desktop.in=.desktop)
+
+
+addinsdir = $(ADDINSDIR)
+addins_LTLIBRARIES = todo.la
+addins_DATA = $(desktop_files)
+
+todo_la_SOURCES = \
+       todonoteaddin.hpp todonoteaddin.cpp \
+       $(NULL)
+
+EXTRA_DIST = $(desktop_in_files)
+DISTCLEANFILES = $(desktop_files)
diff --git a/src/addins/todo/todo.desktop.in b/src/addins/todo/todo.desktop.in
new file mode 100644
index 0000000..bb38a93
--- /dev/null
+++ b/src/addins/todo/todo.desktop.in
@@ -0,0 +1,9 @@
+[AddinInfo]
+Id=Todo
+_Name=TODO
+_Description=Highlight FIXME, TODO and XXX patterns in notes.
+_Authors=Aurimas Černius, Romain Tartière
+Category=Tools
+Version=0.1
+DefaultEnabled=false
+Module=todo
diff --git a/src/addins/todo/todonoteaddin.cpp b/src/addins/todo/todonoteaddin.cpp
new file mode 100644
index 0000000..71803c1
--- /dev/null
+++ b/src/addins/todo/todonoteaddin.cpp
@@ -0,0 +1,110 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (c) 2009 Romain Tartière <romain blogreen org>
+ *
+ * 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 "todonoteaddin.hpp"
+
+
+namespace todo {
+
+static std::vector<std::string> s_todo_patterns;
+
+TodoModule::TodoModule()
+{
+  if(s_todo_patterns.size() == 0) {
+    s_todo_patterns.push_back("FIXME");
+    s_todo_patterns.push_back("TODO");
+    s_todo_patterns.push_back("XXX");
+  }
+
+  ADD_INTERFACE_IMPL(Todo);
+}
+
+
+
+void Todo::initialize()
+{
+  FOREACH(const std::string & s, s_todo_patterns) {
+    if(get_note()->get_tag_table()->lookup(s) == 0) {
+      Glib::RefPtr<Gtk::TextTag> tag = Gtk::TextTag::create(s);
+      tag->property_foreground() = "#0080f0";
+      tag->property_weight() = PANGO_WEIGHT_BOLD;
+      tag->property_underline() = Pango::UNDERLINE_SINGLE;
+      get_note()->get_tag_table()->add(tag);
+    }
+  }
+}
+
+void Todo::shutdown()
+{
+}
+
+void Todo::on_note_opened()
+{
+  get_buffer()->signal_insert().connect(sigc::mem_fun(*this, &Todo::on_insert_text));
+  get_buffer()->signal_erase().connect(sigc::mem_fun(*this, &Todo::on_delete_range));
+
+  highlight_note();
+}
+
+void Todo::on_insert_text(const Gtk::TextIter & pos, const Glib::ustring & /*text*/, int /*bytes*/)
+{
+  highlight_region(pos, pos);
+}
+
+void Todo::on_delete_range(const Gtk::TextBuffer::iterator & start, const Gtk::TextBuffer::iterator & end)
+{
+  highlight_region(start, end);
+}
+
+void Todo::highlight_note()
+{
+  Gtk::TextIter start = get_buffer()->get_iter_at_offset(0);
+  Gtk::TextIter end = start;
+  end.forward_to_end();
+  highlight_region(start, end);
+}
+
+void Todo::highlight_region(Gtk::TextIter start, Gtk::TextIter end)
+{
+  if(!start.starts_line()) {
+    start.backward_line();
+  }
+  if(!end.ends_line()) {
+    end.forward_line();
+  }
+
+  FOREACH(const std::string & pattern, s_todo_patterns) {
+    highlight_region(pattern, start, end);
+  }    
+}
+
+void Todo::highlight_region(const Glib::ustring & pattern, Gtk::TextIter start, Gtk::TextIter end)
+{
+  get_buffer()->remove_tag_by_name(pattern, start, end);
+  Gtk::TextIter region_start = start;
+  while(start.forward_search(pattern + ":", Gtk::TEXT_SEARCH_TEXT_ONLY, region_start, start, end)) {
+    Gtk::TextIter region_end = start;
+    get_buffer()->apply_tag_by_name(pattern, region_start, region_end);
+  }
+}
+
+}
+
diff --git a/src/addins/todo/todonoteaddin.hpp b/src/addins/todo/todonoteaddin.hpp
new file mode 100644
index 0000000..d2c47a8
--- /dev/null
+++ b/src/addins/todo/todonoteaddin.hpp
@@ -0,0 +1,61 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (c) 2009 Romain Tartière <romain blogreen org>
+ *
+ * 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 _TODO_NOTE_ADDIN_
+#define _TODO_NOTE_ADDIN_
+
+#include "base/macros.hpp"
+#include "noteaddin.hpp"
+#include "sharp/dynamicmodule.hpp"
+
+namespace todo {
+
+class TodoModule
+  : public sharp::DynamicModule
+{
+public:
+  TodoModule();
+};
+
+DECLARE_MODULE(TodoModule);
+
+class Todo
+  : public gnote::NoteAddin
+{
+public:
+  static Todo* create()
+    { 
+      return new Todo;
+    }
+  virtual void initialize() override;
+  virtual void shutdown() override;
+  virtual void on_note_opened() override;
+private:
+  void on_insert_text(const Gtk::TextIter & pos, const Glib::ustring & text, int bytes);
+  void on_delete_range(const Gtk::TextBuffer::iterator & start, const Gtk::TextBuffer::iterator & end);
+  void highlight_note();
+  void highlight_region(Gtk::TextIter start, Gtk::TextIter end);
+  void highlight_region(const Glib::ustring & pattern, Gtk::TextIter start, Gtk::TextIter end);
+};
+
+}
+
+#endif


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