1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="AutoText" script:language="StarBasic">&apos; BASIC
24Option Explicit
25Dim oDocument as Object
26Dim sDocumentTitle as String
27
28
29Sub Main()
30Dim oTable as Object
31Dim oRows as Object
32Dim oDocuText as Object
33Dim oAutoTextCursor as Object
34Dim oAutoTextContainer as Object
35Dim oAutogroup as Object
36Dim oAutoText as Object
37Dim oCharStyles as Object
38Dim oContentStyle as Object
39Dim oHeaderStyle as Object
40Dim oGroupTitleStyle as Object
41Dim n, m, iAutoCount as Integer
42	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
43	sDocumentTitle = &quot;Installed AutoTexts&quot;
44
45	&apos; Open a new empty document
46	oDocument = CreateNewDocument(&quot;swriter&quot;)
47	If Not IsNull(oDocument) Then
48		oDocument.DocumentProperties.Title = sDocumentTitle
49		oDocuText = oDocument.Text
50
51		&apos; Create The Character-templates
52		oCharStyles = oDocument.StyleFamilies.GetByName(&quot;CharacterStyles&quot;)
53
54		&apos; The Characterstyle for the Header that describes the Title of Autotextgroups
55		oGroupTitleStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
56		oCharStyles.InsertbyName(&quot;AutoTextGroupTitle&quot;, oGroupTitleStyle)
57
58		oGroupTitleStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
59		oGroupTitleStyle.CharHeight = 14
60
61		&apos; The Characterstyle for the Header that describes the Title of Autotextgroups
62		oHeaderStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
63		oCharStyles.InsertbyName(&quot;AutoTextHeading&quot;, oHeaderStyle)
64		oHeaderStyle.CharWeight = com.sun.star.awt.FontWeight.BOLD
65
66		&apos; &quot;Ordinary&quot; Table Content
67		oContentStyle = oDocument.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
68		oCharStyles.InsertbyName(&quot;TableContent&quot;, oContentStyle)
69
70		oAutoTextContainer = CreateUnoService(&quot;com.sun.star.text.AutoTextContainer&quot;)
71
72		oAutoTextCursor = oDocuText.CreateTextCursor()
73
74		oAutoTextCursor.CharStyleName = &quot;AutoTextGroupTitle&quot;
75		&apos; Link the Title with the following table
76		oAutoTextCursor.ParaKeepTogether = True
77
78		For n = 0 To oAutoTextContainer.Count - 1
79			oAutoGroup = oAutoTextContainer.GetByIndex(n)
80
81			oAutoTextCursor.SetString(oAutoGroup.Title)
82			oAutoTextCursor.CollapseToEnd()
83   			oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
84			oTable = oDocument.CreateInstance(&quot;com.sun.star.text.TextTable&quot;)
85			&apos; Divide the table if necessary
86			oTable.Split = True
87&apos;			oTable.KeepTogether = False
88			oTable.RepeatHeadLine = True
89			oAutoTextCursor.Text.InsertTextContent(oAutoTextCursor,oTable,False)
90			InsertStringToCell(&quot;AutoText Name&quot;,oTable.GetCellbyPosition(0,0), &quot;AutoTextHeading&quot;)
91			InsertStringToCell(&quot;AutoText Shortcut&quot;,oTable.GetCellbyPosition(1,0), &quot;AutoTextHeading&quot;)
92			&apos; Insert one row at the bottom of the table
93			oRows = oTable.Rows
94			iAutoCount = oAutoGroup.Count
95			For m = 0 To iAutoCount-1
96				&apos; Insert the name and the title of all Autotexts
97				oAutoText = oAutoGroup.GetByIndex(m)
98				InsertStringToCell(oAutoGroup.Titles(m), oTable.GetCellbyPosition(0, m + 1), &quot;TableContent&quot;)
99				InsertStringToCell(oAutoGroup.ElementNames(m), oTable.GetCellbyPosition(1, m + 1), &quot;TableContent&quot;)
100				If m &lt; iAutoCount-1 Then
101					oRows.InsertbyIndex(m + 2,1)
102				End If
103			Next m
104	   		oDocuText.insertControlCharacter(oAutoTextCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
105			oAutoTextCursor.CollapseToEnd()
106		Next n
107	End If
108End Sub
109
110
111Sub InsertStringToCell(sCellString as String, oCell as Object, sCellStyle as String)
112Dim oCellCursor as Object
113	oCellCursor = oCell.CreateTextCursor()
114	oCellCursor.CharStyleName = sCellStyle
115	oCell.Text.insertString(oCellCursor,sCellString,False)
116	oDocument.CurrentController.Select(oCellCursor)
117End Sub</script:module>
118