Пример #1
0
void TableofcontentsNoteAddin::get_toc_items(std::vector<TocItem> & items) const
{
  Gtk::TextIter iter, iter_end, eol;

  //for each line of the buffer,
  //check if the full line has bold and (large or huge) tags
  iter     = get_note()->get_buffer()->begin();
  iter_end = get_note()->get_buffer()->end();

  while (iter != iter_end) {
    eol = iter;
    eol.forward_to_line_end();

    TocItem item;
    item.heading_level = get_heading_level_for_range (iter, eol);

    if (item.heading_level == Heading::Level_1 || item.heading_level == Heading::Level_2) {
      item.heading_position = iter.get_offset();
      item.heading          = iter.get_text(eol);

      items.push_back(item);
    }
    iter.forward_visible_line(); //next line
  }
}
Пример #2
0
void TableofcontentsNoteAddin::headification_switch (Heading::Type heading_request)
//apply the correct heading 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;

    //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 heading tags
    Heading::Type current_heading = get_heading_level_for_range (start, end);

    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_heading == Heading::Level_1 && heading_request == Heading::Level_2) { //existing vs requested
        buffer->set_active_tag ("bold");
        buffer->set_active_tag ("size:large");
    }
    else if( current_heading == Heading::Level_2 && heading_request == Heading::Level_1) {
        buffer->set_active_tag ("bold");
        buffer->set_active_tag ("size:huge");
    }
    else if( current_heading == Heading::None) {
        buffer->set_active_tag ("bold");
        buffer->set_active_tag ( (heading_request == Heading::Level_1)?"size:huge":"size:large");
    }

    //restore selection
    if (has_selection == TRUE) {
        buffer->select_range (selection_start, selection_end);
    }
}
Пример #3
0
void TableofcontentsNoteAddin::get_tableofcontents_menu_items(std::list<TableofcontentsMenuItem*> & items)
//go through the note text, and list all lines tagged as heading,
//and for each heading, create a new TableofcontentsMenuItem.
{
    TableofcontentsMenuItem *item = NULL;

    std::string    heading;
    Heading::Type  heading_level;
    int            heading_position;

    Gtk::TextIter iter, iter_end, eol;

    //for each line of the buffer,
    //check if the full line has bold and (large or huge) tags
    iter     = get_note()->get_buffer()->begin();
    iter_end = get_note()->get_buffer()->end();

    while (iter != iter_end) {
        eol = iter;
        eol.forward_to_line_end();

        heading_level = get_heading_level_for_range (iter, eol);

        if (heading_level == Heading::Level_1 || heading_level == Heading::Level_2) {
            heading_position = iter.get_offset();
            heading          = iter.get_text(eol);

            if (items.size() == 0) {
                //It's the first heading found,
                //we also insert an entry linked to the Note's title:
                item = manage(new TableofcontentsMenuItem (get_note(), get_note()->get_title(), Heading::Title, 0));
                items.push_back(item);
            }
            item = manage(new TableofcontentsMenuItem (get_note(), heading, heading_level, heading_position));
            items.push_back(item);
        }
        iter.forward_visible_line(); //next line
    }
}