[gnote] Added replace title addin



commit 5ed49e0e2a376869c229aead868fa2796f398b61
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Fri Jul 29 23:01:17 2011 +0300

    Added replace title addin
    
    Thanks Pierre-Yves Luyten.
    Fixes bug 639938.

 configure.ac                                      |    1 +
 src/addins/Makefile.am                            |    3 +-
 src/addins/replacetitle/Makefile.am               |   11 ++
 src/addins/replacetitle/replacetitlenoteaddin.cpp |  115 +++++++++++++++++++++
 src/addins/replacetitle/replacetitlenoteaddin.hpp |   66 ++++++++++++
 5 files changed, 195 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 57a94eb..02732d3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -202,6 +202,7 @@ src/addins/fixedwidth/Makefile
 src/addins/inserttimestamp/Makefile
 src/addins/noteoftheday/Makefile
 src/addins/printnotes/Makefile
+src/addins/replacetitle/Makefile
 src/addins/stickynoteimport/Makefile
 src/addins/tomboyimport/Makefile
 src/addins/underline/Makefile
diff --git a/src/addins/Makefile.am b/src/addins/Makefile.am
index 45b5a82..dfa933c 100644
--- a/src/addins/Makefile.am
+++ b/src/addins/Makefile.am
@@ -8,7 +8,8 @@ SUBDIRS = backlinks \
 	inserttimestamp \
 	noteoftheday \
 	printnotes \
+	replacetitle \
 	stickynoteimport \
 	tomboyimport \
 	underline \
-	$(NULL)
\ No newline at end of file
+	$(NULL)
diff --git a/src/addins/replacetitle/Makefile.am b/src/addins/replacetitle/Makefile.am
new file mode 100644
index 0000000..fbbaf95
--- /dev/null
+++ b/src/addins/replacetitle/Makefile.am
@@ -0,0 +1,11 @@
+
+include $(builddir)/../addins.mk
+
+addinsdir = $(ADDINSDIR)
+addins_LTLIBRARIES = replacetitle.la
+
+replacetitle_la_SOURCES = \
+	replacetitlenoteaddin.cpp \
+	replacetitlenoteaddin.hpp
+
+
diff --git a/src/addins/replacetitle/replacetitlenoteaddin.cpp b/src/addins/replacetitle/replacetitlenoteaddin.cpp
new file mode 100644
index 0000000..de2ff6a
--- /dev/null
+++ b/src/addins/replacetitle/replacetitlenoteaddin.cpp
@@ -0,0 +1,115 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2011 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
+ * 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 <gtkmm/clipboard.h>
+
+#include "notewindow.hpp"
+#include "replacetitlenoteaddin.hpp"
+#include "sharp/string.hpp"
+
+namespace replacetitle {
+
+
+ReplaceTitleModule::ReplaceTitleModule()
+{
+  ADD_INTERFACE_IMPL(ReplaceTitleNoteAddin);
+}
+
+const char * ReplaceTitleModule::id() const
+{
+  return "ReplaceTitleAddin";
+}
+
+const char * ReplaceTitleModule::name() const
+{
+  return _("Replace title");
+}
+
+const char * ReplaceTitleModule::description() const
+{
+  return _("Replace title with selection.");
+}
+
+
+const char * ReplaceTitleModule::authors() const
+{
+  return _("Pierre-Yves Luyten");
+}
+
+int ReplaceTitleModule::category() const
+{
+  return gnote::ADDIN_CATEGORY_TOOLS;
+}
+
+const char * ReplaceTitleModule::version() const
+{
+  return "0.1";
+}
+
+void ReplaceTitleNoteAddin::initialize()
+{
+}
+
+void ReplaceTitleNoteAddin::shutdown()
+{
+}
+
+void ReplaceTitleNoteAddin::on_note_opened()
+{
+  Gtk::ImageMenuItem *item =  manage(new Gtk::ImageMenuItem(_("Replace title")));
+  item->set_image(*manage(new Gtk::Image(Gtk::Stock::FIND_AND_REPLACE, Gtk::ICON_SIZE_MENU)));
+  item->signal_activate().connect(
+    sigc::mem_fun(*this, &ReplaceTitleNoteAddin::replacetitle_button_clicked));
+
+  item->add_accelerator("activate",
+                        get_window()->get_accel_group(),
+                        GDK_KEY_R,
+                        Gdk::CONTROL_MASK,
+                        Gtk::ACCEL_VISIBLE);
+
+  item->show() ;
+  add_plugin_menu_item(item);
+}
+
+void ReplaceTitleNoteAddin::replacetitle_button_clicked()
+{
+  // unix primary clipboard
+  Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
+  const std::string newTitle= refClipboard->wait_for_text();
+  Glib::RefPtr<Gtk::TextBuffer> buffer = get_note()->get_buffer();
+  Gtk::TextIter iter = buffer->get_insert()->get_iter();
+  int line = iter.get_line();
+  int line_offset = iter.get_line_offset();
+
+  // replace note content
+  if(!newTitle.empty()) {
+    std::string new_content(get_note()->xml_content());
+    get_note()->set_xml_content(sharp::string_replace_first(new_content, get_note()->get_title(), newTitle));
+    if(line) {
+      iter = buffer->get_insert()->get_iter();
+      iter.set_line(line);
+      iter.set_line_offset(line_offset);
+      buffer->place_cursor(iter);
+    }
+  }
+}
+
+}
diff --git a/src/addins/replacetitle/replacetitlenoteaddin.hpp b/src/addins/replacetitle/replacetitlenoteaddin.hpp
new file mode 100644
index 0000000..685c851
--- /dev/null
+++ b/src/addins/replacetitle/replacetitlenoteaddin.hpp
@@ -0,0 +1,66 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2011 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
+ * 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 _REPLACETITLE_ADDIN_HPP_
+#define _REPLACETITLE_ADDIN_HPP_
+
+#include <gtkmm/imagemenuitem.h>
+
+#include "sharp/dynamicmodule.hpp"
+#include "note.hpp"
+#include "noteaddin.hpp"
+
+namespace replacetitle {
+
+class ReplaceTitleModule
+  : public sharp::DynamicModule
+{
+public:
+  ReplaceTitleModule();
+  virtual const char * id() const;
+  virtual const char * name() const;
+  virtual const char * description() const;
+  virtual const char * authors() const;
+  virtual int          category() const;
+  virtual const char * version() const;
+};
+  
+DECLARE_MODULE(ReplaceTitleModule);
+
+class ReplaceTitleNoteAddin
+  : public gnote::NoteAddin
+{
+public:
+  static ReplaceTitleNoteAddin * create()
+  {
+    return new ReplaceTitleNoteAddin;
+  }
+  virtual void initialize();
+  virtual void shutdown();
+  virtual void on_note_opened();
+private:
+  void replacetitle_button_clicked();
+  Gtk::ImageMenuItem * m_item ;
+};
+
+
+}
+
+#endif



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