[gnote] Refactor move to header to fuction in separate file



commit 468a1315034f9132d8ea27369db11659d4b42d04
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Wed Dec 30 20:34:12 2015 +0200

    Refactor move to header to fuction in separate file

 src/addins/tableofcontents/Makefile.am             |    2 +
 .../tableofcontents/tableofcontentsmenuitem.cpp    |   15 +-----
 .../tableofcontents/tableofcontentsutils.cpp       |   45 ++++++++++++++++++++
 .../tableofcontents/tableofcontentsutils.hpp       |   33 ++++++++++++++
 4 files changed, 83 insertions(+), 12 deletions(-)
---
diff --git a/src/addins/tableofcontents/Makefile.am b/src/addins/tableofcontents/Makefile.am
index 2b208d3..af481e8 100644
--- a/src/addins/tableofcontents/Makefile.am
+++ b/src/addins/tableofcontents/Makefile.am
@@ -19,6 +19,8 @@ tableofcontents_la_SOURCES = \
        tableofcontentsmenuitem.cpp  \
        tableofcontentsaction.hpp    \
        tableofcontentsaction.cpp    \
+       tableofcontentsutils.hpp     \
+       tableofcontentsutils.cpp     \
        $(NULL)
 
 EXTRA_DIST     = $(desktop_in_files)
diff --git a/src/addins/tableofcontents/tableofcontentsmenuitem.cpp 
b/src/addins/tableofcontents/tableofcontentsmenuitem.cpp
index dace129..e880c4e 100644
--- a/src/addins/tableofcontents/tableofcontentsmenuitem.cpp
+++ b/src/addins/tableofcontents/tableofcontentsmenuitem.cpp
@@ -2,6 +2,7 @@
  * "Table of Contents" is a Note add-in for Gnote.
  *  It lists note's table of contents in a menu.
  *
+ * Copyright (C) 2015 Aurimas Cernius <aurisc4 gmail com>
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
  *
  * This program is free software: you can redistribute it and/or modify
@@ -29,6 +30,7 @@
 
 #include "tableofcontentsmenuitem.hpp"
 #include "tableofcontents.hpp"
+#include "tableofcontentsutils.hpp"
 
 namespace tableofcontents {
 
@@ -72,18 +74,7 @@ TableofcontentsMenuItem::TableofcontentsMenuItem (
 
 void TableofcontentsMenuItem::on_activate ()
 {
-  if (!m_note) {
-    return;
-  }
-
-  // Scroll the TextView and place the cursor on the heading
-  Gtk::TextIter heading_iter;
-  heading_iter = m_note->get_buffer()->get_iter_at_offset (m_heading_position);
-  m_note->get_window()->editor()->scroll_to (heading_iter,
-                                              0.0, //[0.0,0.5] within_margin, margin as a fraction of screen 
size.
-                                              0.0, //[0.0,1.0] horizontal alignment of mark within visible 
area.
-                                              0.0);//[0.0,1.0] vertical alignment of mark within visible 
area.
-  m_note->get_buffer()->place_cursor (heading_iter);
+  goto_heading(m_note, m_heading_position);
 }
 
 
diff --git a/src/addins/tableofcontents/tableofcontentsutils.cpp 
b/src/addins/tableofcontents/tableofcontentsutils.cpp
new file mode 100644
index 0000000..84ab5b2
--- /dev/null
+++ b/src/addins/tableofcontents/tableofcontentsutils.cpp
@@ -0,0 +1,45 @@
+/*
+ * "Table of Contents" is a Note add-in for Gnote.
+ *  It lists note's table of contents in a menu.
+ *
+ * Copyright (C) 2013,2015 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 "notewindow.hpp"
+#include "tableofcontentsutils.hpp"
+
+
+namespace tableofcontents {
+
+void goto_heading(const gnote::Note::Ptr & note, int heading_position)
+{
+  if(!note) {
+    return;
+  }
+
+  // Scroll the TextView and place the cursor on the heading
+  Gtk::TextIter heading_iter;
+  heading_iter = note->get_buffer()->get_iter_at_offset(heading_position);
+  note->get_window()->editor()->scroll_to(heading_iter,
+                                          0.0, //[0.0,0.5] within_margin, margin as a fraction of screen 
size.
+                                          0.0, //[0.0,1.0] horizontal alignment of mark within visible area.
+                                          0.0);//[0.0,1.0] vertical alignment of mark within visible area.
+  note->get_buffer()->place_cursor(heading_iter);
+}
+
+}
+
diff --git a/src/addins/tableofcontents/tableofcontentsutils.hpp 
b/src/addins/tableofcontents/tableofcontentsutils.hpp
new file mode 100644
index 0000000..b08df6a
--- /dev/null
+++ b/src/addins/tableofcontents/tableofcontentsutils.hpp
@@ -0,0 +1,33 @@
+/*
+ * "Table of Contents" is a Note add-in for Gnote.
+ *  It lists note's table of contents in a menu.
+ *
+ * Copyright (C) 2013,2015 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 _TABLEOFCONTENTS_TABLEOFCONTENTSUTILS_HPP_
+#define _TABLEOFCONTENTS_TABLEOFCONTENTSUTILS_HPP_
+
+#include "note.hpp"
+
+namespace tableofcontents {
+
+void goto_heading(const gnote::Note::Ptr & note, int heading_position);
+
+}
+
+#endif


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