[gnote] Make TOC header items act on entire line



commit 7ce67e0224d286c7f30ef8a9f10df92637269c2a
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Fri May 31 23:15:19 2013 +0300

    Make TOC header items act on entire line
    
    Also preserves other tags and includes documentation updates.
    Fixes Bug 700612.

 help/C/gnote-addin-tableofcontent.page             |   58 +++++++++++---------
 src/addins/tableofcontent/NEWS                     |   12 ++++-
 src/addins/tableofcontent/TODO                     |   55 ++++++++++++-------
 .../tableofcontent/tableofcontent.desktop.in       |    4 +-
 src/addins/tableofcontent/tableofcontent.hpp       |    4 +-
 .../tableofcontent/tableofcontentmenuitem.cpp      |   12 ++--
 .../tableofcontent/tableofcontentmenuitem.hpp      |    4 +-
 .../tableofcontent/tableofcontentnoteaddin.cpp     |   40 +++++++++++---
 .../tableofcontent/tableofcontentnoteaddin.hpp     |    4 +-
 9 files changed, 126 insertions(+), 67 deletions(-)
---
diff --git a/help/C/gnote-addin-tableofcontent.page b/help/C/gnote-addin-tableofcontent.page
index d09da1c..e9136f0 100644
--- a/help/C/gnote-addin-tableofcontent.page
+++ b/help/C/gnote-addin-tableofcontent.page
@@ -24,7 +24,7 @@
   <info>
     <revision
       status="candidate"
-      pkgversion="gnote-addin-tableofcontent-version-0.9"
+      pkgversion="gnote-addin-tableofcontent-version-0.10"
     />
     <!-- Status:
       stub        contains little to no real content
@@ -92,15 +92,15 @@
 
 <list type="numbered">
   <item>
-    <p>A header is a full line of text, formatted with <gui>Bold+Huge</gui> or <gui>Bold+Large</gui>.</p>
+    <p>A heading is a full line of text, formatted with <gui>Bold+Huge</gui> or <gui>Bold+Large</gui>.</p>
   </item>
   <item>
-    <p>Select a full line and give it a header with
+    <p>Set headings with
        <keyseq><key>Ctrl</key><key>1</key></keyseq> or <keyseq><key>Ctrl</key><key>2</key></keyseq>.
     </p>
   </item>
   <item>
-    <p>Open the table of contents with <keyseq><key>Ctrl</key><key>Alt</key><key>1</key></keyseq>.</p>
+    <p>Open the table of contents with <keyseq><key>Ctrl</key><key>Alt</key><key>1</key></keyseq>, and jump 
to any heading.</p>
   </item>
 </list>
 
@@ -111,48 +111,56 @@
 
 <p>
 A long note may become difficult to navigate.
-It is then natural to structure the note by marking sections and subsections with headers.
+It is then natural to structure the note by
+marking sections and subsections with headings.
 </p>
 
 <p>
 This add-in makes it easy to navigate through long structured notes.
-Once you have set headers in your note, the table of contents of the note will show in a menu.
-Then you can jump directly from the menu to any header.
+Once you have set headings in your note,
+the table of contents of the note will show in a menu.
+Then you can jump directly from the menu to any heading.
 </p>
 
 </section>
 
 
-<section id="setheaders"><title>Structuring your notes with headers</title>
+<section id="setheadings"><title>Structuring your notes with headings</title>
 
 <p>
-A header is simply a complete line with specific text formatting:
+A heading is simply a complete line with specific text formatting:
 </p>
 <list>
-  <item><p>level 1 headers, for sections, are lines formatted with a <gui>Bold+Huge</gui> font</p></item>
-  <item><p>level 2 headers, for subsections, are lines formatted with a <gui>Bold+Large</gui> font</p></item>
+  <item><p>Level 1 headings, for sections, are lines formatted with a <gui>Bold+Huge</gui> font.</p></item>
+  <item><p>Level 2 headings, for subsections, are lines formatted with a <gui>Bold+Large</gui> 
font.</p></item>
 </list>
 
 
-<p>To format a header line, first select a full line of text, then either:</p>
+<p>To format a heading line, either:</p>
 
 <list>
   <item>
-    <p>use the commands <gui>Level 1 Header</gui> and <gui>Level 2 Header</gui>
-       in the <guiseq><gui>Tools</gui><gui>Table of Contents</gui></guiseq> menu</p>
+    <p>Use the commands <gui>Heading 1</gui> and <gui>Heading 2</gui>
+       in the <guiseq><gui>Tools</gui><gui>Table of Contents</gui></guiseq> menu.</p>
   </item>
 
   <item>
-    <p>use the keyboard shortcuts <keyseq><key>Ctrl</key><key>1</key></keyseq> for level 1 headers,
-    and <keyseq><key>Ctrl</key><key>2</key></keyseq> for level 2 headers</p>
+    <p>Use the keyboard shortcuts <keyseq><key>Ctrl</key><key>1</key></keyseq>
+    and <keyseq><key>Ctrl</key><key>2</key></keyseq> for headings of level 1 and 2.</p>
  </item>
 </list>
 
-<p>Alternatively, on a new line, activate a header command and then enter the header title.</p>
+<note><p>
+  These commands apply the formatting to the complete line.
+  You don't need to select it first.
+  It is enough if the cursor is on the line.
+</p><p>
+  Alternatively, with the cursor on a new line, activate the heading command and then enter the heading 
title.
+</p></note>
 
 <p>You can even use the normal formatting commands from the <gui>Text</gui> menu:
     <gui>Bold</gui>, <gui>Large</gui> and <gui>Huge</gui>, and their respective keyboard shortcuts.
-    If, for example, your header line is already formatted as <gui>Huge</gui>, then you just need to make it 
also <gui>Bold</gui> to turn it into a header of level 1.
+    If, for example, your heading line is already formatted as <gui>Huge</gui>, then you just need to make 
it also <gui>Bold</gui> to turn it into a heading 1.
     See <link xref="editing-notes"/> to learn how to set text styles.
 </p>
 
@@ -163,10 +171,10 @@ A header is simply a complete line with specific text formatting:
 
 <p>You can access the table of contents either:</p>
 <list>
-<item><p>in the <guiseq><gui>toolbar</gui><gui>Tools</gui><gui>Table of Contents</gui></guiseq> 
menu</p></item>
-<item><p>via <guiseq><gui>context menu</gui><gui>Table of Contents</gui></guiseq> 
(<keyseq>right-click</keyseq> on the note window)</p></item>
-<item><p>in a <gui>popup menu</gui>, with the keyboard shortcut 
<keyseq><key>Ctrl</key><key>Alt</key><key>1</key></keyseq></p></item>
-<p>Then you can navigate up and down with the <gui>arrow keys</gui> and jump to the selected header with 
<key>enter</key>. Or just <keyseq>click</keyseq> with your mouse on the header to jump to.</p>
+<item><p>In the menu <guiseq><gui>toolbar</gui><gui>Tools</gui><gui>Table of 
Contents</gui></guiseq>.</p></item>
+<item><p>In <guiseq><gui>context menu</gui><gui>Table of Contents</gui></guiseq> 
(<keyseq>right-click</keyseq> on the note window).</p></item>
+<item><p>In a <gui>popup menu</gui>, with the keyboard shortcut 
<keyseq><key>Ctrl</key><key>Alt</key><key>1</key></keyseq>.</p></item>
+<p>Then you can navigate up and down with the <gui>arrow keys</gui> and jump to the selected heading with 
<key>enter</key>. Or just <keyseq>click</keyseq> with your mouse on the heading to jump to.</p>
 </list>
 
 </section>
@@ -174,11 +182,11 @@ A header is simply a complete line with specific text formatting:
 
 <section id="troubleshooting"><title>Troubleshooting</title>
 <terms>
-  <item><title><em style="strong">One header does not show in the table of contents</em></title><p>
-    There might be some characters in the header line, such as whitespace characters, which are not 
formatted as a header. Make sure that <em>the whole line</em> is formatted as a header. See <link 
xref="#setheaders"/>.</p>
+  <item><title><em style="strong">One heading does not show in the table of contents</em></title><p>
+    There might be some characters in the heading line, such as whitespace characters, which are not 
formatted as a heading. Make sure that <em>the whole line</em> is formatted as a heading. See <link 
xref="#setheadings"/>.</p>
   </item>
   <item><title><em style="strong">There is an empty line in the table of contents</em></title><p>
-    An empty line, possibly including whitespace, is formatted as a header. Jump to this line and delete the 
area.</p>
+    An empty line, possibly including whitespaces, is formatted as a heading. Jump to this line and delete 
the area.</p>
   </item>
 
   <item><title></title><p>
diff --git a/src/addins/tableofcontent/NEWS b/src/addins/tableofcontent/NEWS
index cf71afe..06ab2cf 100644
--- a/src/addins/tableofcontent/NEWS
+++ b/src/addins/tableofcontent/NEWS
@@ -5,10 +5,20 @@ NEWS for Add-in: Table of Content
  update NEWS + .desktop version/enabled=false + help topic status/pkgversion ==> commit -m "version x.y")
 
 
+== 0.10
+- fix: header-2 arrow, 2 chars does not match with some fonts.
+       Use a single char one.
+- fix: toggling Header 1/2 must preserve other tags.
+- new: Ctrl-1/2 toggle header for the complete line(s) (that include the selection)
+       (bug #700612)
+- fix: language update (s/header/heading/, etc.)
+
 == 0.9
 - renamed labels "Level 1 Header" to "Header Level 1" (resp. 2)
+- help topic major update
 - set help topic status to "candidate"
-- typo in .desktop description
+- updated description in .desktop
+- TODO major update from my local notes, see: Todo, Maybe and Maybe not
 - code: general code review, various minor updates in code, including:
   - add-in description in copyright headers
   - various code comments
diff --git a/src/addins/tableofcontent/TODO b/src/addins/tableofcontent/TODO
index dfd45b6..bbfc97a 100644
--- a/src/addins/tableofcontent/TODO
+++ b/src/addins/tableofcontent/TODO
@@ -1,10 +1,25 @@
 TODO for Add-in: Table of Content
 =================================
 
+== Now
 
-- On Ctrl-1/2 toggle, toggle only B/L/H tags, not all tags
-  (this is a bug!)
-  ex: within all fixed width text, setting a header, the header must remain also fixed width
+- header --> heading, also in code
+- rename files before 3.10, tableofcontent_S_
+
+- Ctrl-1/2 Ctrl-Alt-1 has no effect, before toc is opened once
+  gnote bug?
+
+- check GFDL usage in:
+      help/C/gnote-addin-tableofcontent.page:
+      FIXME: is this true? (no invariant, no front, no back?)
+      FIXME: does the statement have to show in the rendered document?
+      FIXME: is this true? Is there a (GNOME? Yelp?) common GFDL topic?
+
+- add a screenshot to the help page (?)
+
+
+
+== Later
 
 - Huge is not huge enough
     There is little visual difference between large and huge
@@ -17,34 +32,22 @@ TODO for Add-in: Table of Content
     Could also be: general config options for font sizes/factor (for S/N/L/H)
     Could also be: allow any sizes <size:n>, with n = factor (not only S/N/L/H)
 
-- Highlight the header when jumping to it
-    ==> More visual, especially when the header does not scroll up to the head of the window
-    remove highlight as soon as cursor moved
-    (like search results, for example)
-
 - When no headers, still show the note title in toc
   this is usefull to jump to the top of a long (unstructured) note
 
-- Check all FIXMEs, and more code cleanup
 
 
 == Maybe
 
+- Highlight the header when jumping to it
+    ==> More visual, especially when the header does not scroll up to the head of the window
+    remove highlight as soon as cursor moved
+    (like search results, for example)
+
 - Undo as a single user action, when setting headers
     Note: tomboy/gnote handles poorly undo/redo,
     this item may need to upgrade the undo system
 
-- When entering header text, stop formatting on 'enter'
-  UC: 1. cursor at beginning of a line
-      2. Ctrl-1/2
-      3. enter header title
-      4. press 'enter'
-      --> currently: if you keep typing text, the new line keep being bold+huge/large
-      --> wanted: stop formatting as a header.
-      /!\ this conflicts with a user who actually *wants* to type bold+huge/large *text* with new lines
-      ==> when entering a header, to move back to text formatting: arrow down, or Ctrl-1/2
-          TO CHECK: does the later actually works?
-
 - Set where the toc menu item appears in the Tools menu
     --> next to "What Links Here?"
     (I think there is a way to say where)
@@ -74,6 +77,16 @@ TODO for Add-in: Table of Content
 
   Todo: make code generic + (g)settings + preference UI + help topic
 
+- Print/export the table of content
+  if Table of Content is enabled, it could be added to the content when printing or exporting (to HTML)
+  HTML export:
+    - add toc below title
+    - mark headers as H2 and H3
+  Print
+    - add toc below title
+    - print to PDF (?)
+
+
 
 == Maybe not
 
@@ -104,5 +117,7 @@ TODO for Add-in: Table of Content
        Ctrl-shift-B-H
        (update: I don't remember what it's meant to do! Need to check Tomboy mailinglist)
     (update: I think it's from the time where Ctrl-1 would set the whole line(s) where the cursor or 
selection is. So these shortcuts would set the whole line(s) with corresponding formatting tags)
+    --> format the whole line as... (or lineS if several are selected)
     Then we could have Ctrl-Shift-1 and Ctrl-Shift-2
     Though I disabled this because of some misfunction(?) (or a just bug?)(?)
+
diff --git a/src/addins/tableofcontent/tableofcontent.desktop.in 
b/src/addins/tableofcontent/tableofcontent.desktop.in
index a48ceb5..67db07b 100644
--- a/src/addins/tableofcontent/tableofcontent.desktop.in
+++ b/src/addins/tableofcontent/tableofcontent.desktop.in
@@ -1,10 +1,10 @@
 [AddinInfo]
 Id=TableofcontentAddin
 _Name=Table of Contents
-_Description=Navigate long structured notes. Set section and subsection headers in your note, and the Table 
of Contents will show in a menu.
+_Description=Navigate long structured notes. Set section and subsection headings in your note, and the Table 
of Contents will show in a menu.
 _Authors=Luc Pionchon
 Category=Tools
-Version=0.9
+Version=0.10
 DefaultEnabled=false
 Module=tableofcontent
 _Copyright=© 2013 Luc Pionchon
diff --git a/src/addins/tableofcontent/tableofcontent.hpp b/src/addins/tableofcontent/tableofcontent.hpp
index 7257858..660b576 100644
--- a/src/addins/tableofcontent/tableofcontent.hpp
+++ b/src/addins/tableofcontent/tableofcontent.hpp
@@ -1,6 +1,6 @@
 /*
- * "Table of Content" is a Note add-in for Gnote.
- *  It lists Note's table of content in a menu.
+ * "Table of Contents" is a Note add-in for Gnote.
+ *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
  *
diff --git a/src/addins/tableofcontent/tableofcontentmenuitem.cpp 
b/src/addins/tableofcontent/tableofcontentmenuitem.cpp
index c63c1db..b255590 100644
--- a/src/addins/tableofcontent/tableofcontentmenuitem.cpp
+++ b/src/addins/tableofcontent/tableofcontentmenuitem.cpp
@@ -1,6 +1,6 @@
 /*
- * "Table of Content" is a Note add-in for Gnote.
- *  It lists Note's table of content in a menu.
+ * "Table of Contents" is a Note add-in for Gnote.
+ *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
  *
@@ -44,9 +44,9 @@ TableofcontentMenuItem::TableofcontentMenuItem (
      |[] NOTE TITLE    | <---- Title     == note icon  + bold note title
      | > Header 1      | <---- Level_1   == arrow icon + header title
      | > Header 1      |
-     |   └→ header 2   | <---- Level_2   == (no icon)  + indent string + header title
-     |   └→ header 2   |
-     |   └→ header 2   |
+     |   → header 2    | <---- Level_2   == (no icon)  + indent string + header title
+     |   → header 2    |
+     |   → header 2    |
      | > Header 1      |
      +-----------------+
    */
@@ -63,7 +63,7 @@ TableofcontentMenuItem::TableofcontentMenuItem (
     set_label(header);
   }
   else if (header_level == Header::Level_2) {
-    set_label("└→  " + header);
+    set_label("→  " + header);
   }
 }
 
diff --git a/src/addins/tableofcontent/tableofcontentmenuitem.hpp 
b/src/addins/tableofcontent/tableofcontentmenuitem.hpp
index e1d92f8..89ff6b8 100644
--- a/src/addins/tableofcontent/tableofcontentmenuitem.hpp
+++ b/src/addins/tableofcontent/tableofcontentmenuitem.hpp
@@ -1,6 +1,6 @@
 /*
- * "Table of Content" is a Note add-in for Gnote.
- *  It lists Note's table of content in a menu.
+ * "Table of Contents" is a Note add-in for Gnote.
+ *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
  *
diff --git a/src/addins/tableofcontent/tableofcontentnoteaddin.cpp 
b/src/addins/tableofcontent/tableofcontentnoteaddin.cpp
index b4fe2fb..15574f1 100644
--- a/src/addins/tableofcontent/tableofcontentnoteaddin.cpp
+++ b/src/addins/tableofcontent/tableofcontentnoteaddin.cpp
@@ -1,6 +1,6 @@
 /*
- * "Table of Content" is a Note add-in for Gnote.
- *  It lists Note's table of content in a menu.
+ * "Table of Contents" is a Note add-in for Gnote.
+ *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
  *
@@ -160,13 +160,13 @@ void TableofcontentNoteAddin::populate_toc_menu (Gtk::Menu *toc_menu, bool has_a
       toc_menu->append(*item);
     }
 
-    item = manage(new Gtk::MenuItem (_("Header Level 1")));
+    item = manage(new Gtk::MenuItem (_("Heading 1")));
     item->add_accelerator("activate", get_note()->get_window()->get_accel_group(), GDK_KEY_1, 
Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);
     item->signal_activate().connect(sigc::mem_fun(*this, &TableofcontentNoteAddin::on_level_1_activated));
     item->show ();
     toc_menu->append(*item);
 
-    item = manage(new Gtk::MenuItem (_("Header Level 2")));
+    item = manage(new Gtk::MenuItem (_("Heading 2")));
     item->add_accelerator("activate", get_note()->get_window()->get_accel_group(), GDK_KEY_2, 
Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);
     item->signal_activate().connect(sigc::mem_fun(*this, &TableofcontentNoteAddin::on_level_2_activated));
     item->show ();
@@ -337,17 +337,39 @@ bool TableofcontentNoteAddin::on_key_pressed(GdkEventKey *ev)
 
 
 void TableofcontentNoteAddin::headification_switch (Header::Type header_request)
-//apply the correct header style to the current selection
+//apply the correct header style to the current line(s) including the selection
 //switch:  Level_1 <--> Level_2 <--> text
 {
   Glib::RefPtr<gnote::NoteBuffer> buffer = get_note()->get_buffer();
   Gtk::TextIter start, end;
+  Gtk::TextIter selection_start, selection_end;
+  bool has_selection;
 
-  buffer->get_selection_bounds (start, end);
+  //get selection
+  has_selection = buffer->get_selection_bounds (start, end);
+  selection_start = start;
+  selection_end   = end;
 
+  //grab the complete lines
+  while (start.starts_line() == FALSE) {
+    start.backward_char();
+  }
+  if (end.starts_line() && end != start){ // Home + Shift-down: don't take last line.
+    end.backward_char();
+  }
+  while (end.ends_line() == FALSE) {
+    end.forward_char();
+  }
+
+  //expand the selection to complete lines
+  buffer->select_range (start, end);
+
+  //set the header tags
   Header::Type current_header = get_header_level_for_range (start, end);
 
-  buffer->remove_all_tags (start, end);//reset all tags
+  buffer->remove_tag (m_tag_bold,  start, end);
+  buffer->remove_tag (m_tag_large, start, end);
+  buffer->remove_tag (m_tag_huge,  start, end);
 
   if( current_header == Header::Level_1 && header_request == Header::Level_2) { //existing vs requested
     buffer->set_active_tag ("bold");
@@ -362,6 +384,10 @@ void TableofcontentNoteAddin::headification_switch (Header::Type header_request)
     buffer->set_active_tag ( (header_request == Header::Level_1)?"size:huge":"size:large");
   }
 
+  //restore selection
+  if (has_selection == TRUE) {
+    buffer->select_range (selection_start, selection_end);
+  }
 }
 
 
diff --git a/src/addins/tableofcontent/tableofcontentnoteaddin.hpp 
b/src/addins/tableofcontent/tableofcontentnoteaddin.hpp
index 7a799a8..66eb813 100644
--- a/src/addins/tableofcontent/tableofcontentnoteaddin.hpp
+++ b/src/addins/tableofcontent/tableofcontentnoteaddin.hpp
@@ -1,6 +1,6 @@
 /*
- * "Table of Content" is a Note add-in for Gnote.
- *  It lists Note's table of content in a menu.
+ * "Table of Contents" is a Note add-in for Gnote.
+ *  It lists note's table of contents in a menu.
  *
  * Copyright (C) 2013 Luc Pionchon <pionchon luc gmail com>
  *


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