# -*- coding: UTF-8 -*-
# Copyright (C) 2009 Itaapy, ArsAperta, Pierlis, Talend

# Import from lpod
from element import register_element_class, odf_element


class odf_toc(odf_element):

    def get_formated_text(self, context):
        index_body = self.get_element('text:index-body')

        if index_body is None:
            return u''

        result = []
        for element in index_body.get_children():
            if element.get_name() == 'text:index-title':
                for element in element.get_children():
                    result.append(element.get_formated_text(context))
                result.append(u'\n')
            else:
                result.append(element.get_formated_text(context))
        result.append('\n')
        return u''.join(result)



register_element_class('text:table-of-content', odf_toc)

@@ -145,16 +145,596 @@
 odf_
+create_element, odf_element%0Afrom element import FIRST_CHILD%0Afrom utils import Boolean%0A%0A%0Adef odf_create_toc(name=u%22Table of content%22, protected=True, style=None,%0A                   outline_level=10):%0A    data = '%3Ctext:table-of-content/%3E'%0A    element = odf_create_element(data)%0A    if name:%0A        element.set_attribute('text:name', name)%0A    element.set_attribute('text:protected', Boolean.encode(protected))%0A    if style:%0A        element.set_attribute('text:style-name', style)%0A    # A TOC is quite a complex hierarchy%0A    element.set_toc_outline_level(outline_level)%0A    return 
 element%0A
 %0A%0Acl
@@ -729,18 +729,19 @@
 element%0A
-
 %0A%0A
+%0A
 class od
@@ -1313,24 +1313,24 @@
 ppend('%5Cn')%0A
-
         retu
@@ -1351,16 +1351,555 @@
 sult)%0A%0A%0A
+    def get_toc_outline_level(self):%0A        source = self.get_element('text:table-of-content-source')%0A        if source is None:%0A            return None%0A        return source.get_attribute('text:outline-level')%0A%0A%0A    def set_toc_outline_level(self, level):%0A        source = self.get_element('text:table-of-content-source')%0A        if source is None:%0A            source = odf_create_element('%3Ctext:table-of-content-source/%3E')%0A            self.insert_element(source, FIRST_CHILD)%0A        source.set_attribute('text:outline-level', level)%0A%0A%0A
 %0Aregiste

create the minimal toc structure that just works