Bug 158420 - com.sun.star.text.ContentIndex seems to be missing boolean to enable AdditionalStyles
Summary: com.sun.star.text.ContentIndex seems to be missing boolean to enable Addition...
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
Version:
(earliest affected)
7.6.3.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-28 14:49 UTC by jimmy1
Modified: 2024-04-08 20:39 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jimmy1 2023-11-28 14:49:41 UTC
Description:
When adding a Table of Contents (TOC) I use com.sun.star.text.ContentIndex together with the property LevelParagraphStyles to add a heading style to the TOC. 

Example:
oIndex = ThisComponent.createInstance("com.sun.star.text.ContentIndex")
oIndex.CreateFromOutline = True
oIndex.LevelParagraphStyles.replaceByIndex(0, Array("Heading 1"))

However, there seems to be no property to enable "Additional Styles" (you can only set the heading with levelParagraphStyles), present in the Table of Contents dialog. There is a boolean for CreateFromOutline, CreateFromMarks, but no CreateFromParagraphStyles.

Steps to Reproduce:
1. Have a document with "Microsoft Word headings", so a paragraph with the styling "Heading 1".
2. Insert --> Table of Contents and Indexes --> Tables of Contents, Index or Bibliography...
3. See a default unchecked additional styles.
4. Run the following code snippet and see that the boolean is still false, while the additional styles are set.


Sub InsertATOCWithHyperlinks
  REM Author: Andrew Pitonyak
  Dim oCurs      'Used to insert the text content.
  Dim oIndexes   'All of the existing indexes.
  Dim oIndex     'TOC if it exists and a new one if not.
  Dim i%         'Find an existing TOC.
  Dim bIndexFound As Boolean 'Flag to track if the TOC was found.
  Dim iLevel

  REM Find TOC if it exists.
  oIndexes = ThisComponent.getDocumentIndexes()
  bIndexFound = False
  For i = 0 To oIndexes.getCount() - 1
    oIndex = oIndexes.getByIndex(i)
    If oIndex.supportsService("com.sun.star.text.ContentIndex") Then
      bIndexFound = True
      Exit For
    End If
  Next
  If Not bIndexFound Then
    REM Create and insert a new TOC.
    REM The new TOC must be created by the document that will contain the TOC.
    oIndex = ThisComponent.createInstance("com.sun.star.text.ContentIndex")

    oIndex.CreateFromOutline = True
    oIndex.LevelParagraphStyles.replaceByIndex(0, Array("Heading 1"))    
    ' Ignore level 0
    For iLevel = 1 To oIndex.LevelFormat.getCount() - 1
      oIndex.LevelFormat.replaceByIndex(iLevel, CreateTOCColumnEntries())
    Next
    
    oCurs = ThisComponent.getText().createTextCursor()
    oCurs.gotoRange(ThisComponent.CurrentController.ViewCursor, False)
    ThisComponent.getText().insertTextContent(oCurs, oIndex, False)
  End If
  REM Even the newly inserted index is not updated until right HERE!
  oIndex.update()
End Sub

Function CreateTOCColumnEntries()
  Dim o
  o = Array( Array(MakeProperty("TokenType", "TokenEntryNumber"), _
                   MakeProperty("CharacterStyleName", "")), _
             Array(MakeProperty("TokenType", "TokenHyperlinkStart"), _
                   MakeProperty("CharacterStyleName", "Internet link")), _
             Array(MakeProperty("TokenType", "TokenEntryText"), _
                   MakeProperty("CharacterStyleName", "")), _
             Array(MakeProperty("TokenType", "TokenHyperlinkEnd")), _
             Array(MakeProperty("TokenType", "TokenTabStop"), _
                   MakeProperty("TabStopRightAligned", TRUE), _
                   MakeProperty("TabStopFillCharacter", "."), _
                   MakeProperty("CharacterStyleName", ""),  _
                   MakeProperty("WithTab", TRUE)), _
             Array(MakeProperty("TokenType", "TokenPageNumber"), _
                   MakeProperty("CharacterStyleName", "")))
  CreateTOCColumnEntries() = o
End Function

Function MakeProperty(sName$, value)
  Dim oProp
  oProp = CreateObject("com.sun.star.beans.PropertyValue")
  oProp.Name = sName
  oProp.Value = value
  MakeProperty = oProp
End Function


-------------------------------

You get a TOC, but when you right click on the TOC and click on "Edit index" the additional styles boolean is still set to false. If manually set to true and you look into the styles you see that "Heading 1" is set to level 1.

The problem: how to set the additional styles boolean? It seems to be missing.



Actual Results:
A TOC is generated without the boolean "Additional styles" set to true.

Expected Results:
A way to set "Additional styles" to true, as you can also set the other properties.


Reproducible: Always


User Profile Reset: Yes

Additional Info:
I tried this in multiple OS'es (linux and windows) on the LibreOffice 6.2.3 and 5.8 with clean profiles.
Comment 1 jimmy1 2023-12-13 08:49:40 UTC
I found out that the boolean I'm searching for is: `CreateFromLevelParagraphStyles`.

Enabling this property works, but I had to dig into the LibreOffice source code to find it. It's missing within the official docs.

So my follow-up question is: could this be added to the documentation?
Comment 2 Buovjaga 2024-01-16 17:30:55 UTC
(In reply to jimmy1 from comment #1)
> I found out that the boolean I'm searching for is:
> `CreateFromLevelParagraphStyles`.
> 
> Enabling this property works, but I had to dig into the LibreOffice source
> code to find it. It's missing within the official docs.
> 
> So my follow-up question is: could this be added to the documentation?

Yeah, I can't find it in https://api.libreoffice.org/docs/idl/ref/index.html
Comment 3 Olivier Hallot 2024-04-08 20:39:08 UTC
(In reply to Buovjaga from comment #2)
> (In reply to jimmy1 from comment #1)
> > I found out that the boolean I'm searching for is:
> > `CreateFromLevelParagraphStyles`.
> > 
> > Enabling this property works, but I had to dig into the LibreOffice source
> > code to find it. It's missing within the official docs.
> > 
> > So my follow-up question is: could this be added to the documentation?
> 
> Yeah, I can't find it in https://api.libreoffice.org/docs/idl/ref/index.html

The argument seems to be LevelParagraphStyles in 

https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1text_1_1ContentIndex.html