summaryrefslogtreecommitdiff
path: root/helpauthoring/HelpAuthoring/Meta.xba
blob: 57d9b1cddd8af2a0e080c4a5feb5fe5c3a4be58d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Meta" script:language="StarBasic">REM  *****  BASIC  *****
&apos; #
&apos; # This file is part of the LibreOffice project.
&apos; #
&apos; # This Source Code Form is subject to the terms of the Mozilla Public
&apos; # License, v. 2.0. If a copy of the MPL was not distributed with this
&apos; # file, You can obtain one at http://mozilla.org/MPL/2.0/.
&apos; #
&apos; # This file incorporates work covered by the following license notice:
&apos; #
&apos; #   Licensed to the Apache Software Foundation (ASF) under one or more
&apos; #   contributor license agreements. See the NOTICE file distributed
&apos; #   with this work for additional information regarding copyright
&apos; #   ownership. The ASF licenses this file to you under the Apache
&apos; #   License, Version 2.0 (the &quot;License&quot;); you may not use this file
&apos; #   except in compliance with the License. You may obtain a copy of
&apos; #   the License at http://www.apache.org/licenses/LICENSE-2.0 .
&apos; #

Dim oDialog AS Object
Dim document AS Object

&apos; Fetches the meta values from the document and executes the dialog
Sub Main

    If not IsHelpFile Then
        msgbox(strErr_NoHelpFile)
        Exit Sub
    End If

    document = StarDesktop.CurrentComponent

    BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
    oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgMeta&quot;)
    oDialogModel = oDialog.Model

    &apos;oTxtFName = oDialog.GetControl(&quot;txtFileName&quot;)
    &apos;oTxtFName.Text = document.DocumentInfo.PropertyValues(29).Value
    &apos;oTxtFName.Text = document.DocumentInfo.GetPropertyValue(&quot;Description&quot;)

&apos;    If oTxtFName.Text = &quot;&quot; Then
&apos;        msgbox &quot;The document must be saved first.&quot;+chr(13)+&quot;Please save the document and call this dialog again.&quot;
&apos;        oDialog.dispose
&apos;        Exit Sub
&apos;    End If

    oTxtTitle = oDialog.GetControl(&quot;txtTitle&quot;)
    oTxtTitle.Text = document.DocumentProperties.Title

    oOpIndInc = oDialog.GetControl(&quot;opIndexInclude&quot;)
    oOpIndExc = oDialog.GetControl(&quot;opIndexExclude&quot;)


    &apos;oCbFileStatus = oDialog.GetControl(&quot;cbFileStatus&quot;)
    &apos;arItems = Array(&quot;DRAFT&quot;,&quot;FINAL&quot;,&quot;PUBLISH&quot;,&quot;STALLED&quot;,&quot;DEPRECATED&quot;)
    &apos;oCbFileStatus.AddItems(arItems,ubound(arItems))
    &apos;sStatus = document.DocumentInfo.GetPropertyValue(&quot;Keywords&quot;)
    &apos;If (InStr(&quot;DRAFT FINAL PUBLISH STALLED DEPRECATED&quot;,sStatus)=0) Then
    &apos;    oCbFileStatus.SetText(&quot;DRAFT&quot;)
    &apos;Else
    &apos;    oCbFileStatus.SetText(sStatus)
    &apos;End If



&apos;    If document.DocumentInfo.GetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;)) = &quot;exclude&quot; then
    If document.DocumentProperties.UserDefinedProperties.Indexer = &quot;exclude&quot; then

        oOpIndExc.State = True
    Else
        oOpIndInc.State = True
    End If

    &apos;oTxtTopicID = oDialog.GetControl(&quot;txtTopicID&quot;)
    &apos;oTxtTopicID.Text = document.DocumentInfo.GetUserFieldValue(1)

    &apos;oTxtComment = oDialog.GetControl(&quot;txtComment&quot;)
    &apos;oTxtComment.Text = document.DocumentInfo.GetUserFieldValue(GetUserFieldNumber(&quot;Comment&quot;))

    &apos;oTxtEdited = oDialog.GetControl(&quot;txtLastEdited&quot;)
    &apos;oTxtEdited.Text = document.DocumentInfo.GetUserFieldValue(3)

    If oDialog.Execute() = 1 Then &apos; update the meta data
        document.DocumentProperties.Title = oTxtTitle.Text
        &apos;document.DocumentInfo.SetUserFieldValue(1,oTxtTopicID.Text)
        &apos;document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Comment&quot;),oTxtComment.Text)
        &apos;document.DocumentInfo.SetUserFieldValue(3,oTxtEdited.Text)
        &apos;document.DocumentInfo.SetPropertyValue(&quot;Keywords&quot;,oCbFileStatus.Text)

        &apos;If (oCbFileStatus.Text = &quot;PUBLISH&quot;) Then
            REM... Check for paras without ID: If there are any, this cannot be PUBLISH!

        &apos;End If

        If oOpIndExc.State = True Then
            &apos;document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;),&quot;exclude&quot;)
            document.DocumentProperties.UserDefinedProperties.Indexer = &quot;exclude&quot;
        Else
&apos;            document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;),&quot;include&quot;)
            document.DocumentProperties.UserDefinedProperties.Indexer = &quot;include&quot;
        End If
    End If
    oDialog.dispose
end sub

&apos; Normalizes the values for title and topic id
&apos; (if the fields are empty or contain invalid values)
Sub NormalizeMeta (Event As Object)
    Select Case Event.Source.Model.Name
        Case &quot;txtTitle&quot;:
            If Event.Source.Text = &quot;&quot; Then
                msgbox &quot;Topic title must not be empty!&quot;+chr(13)+&quot;Resetting to default value.&quot;
            End If
            SetTopicTitle(Event.Source.Text)
        Case &quot;txtTopicID&quot;:
            If Event.Source.Text = &quot;&quot; Then
                msgbox &quot;Topic ID must not be empty!&quot;+chr(13)+&quot;Resetting to default value.&quot;
            End If
            SetTopicID(Event.Source.Text)
    End Select
End Sub

&apos; Sets the value in the Topic ID dialog field
Sub SetTopicID(txt As String)
    oTxtTopicID = oDialog.GetControl(&quot;txtTopicID&quot;)
    If txt = &quot;&quot; Then
        oTxtTopicID.Text = AlphaNum(document.DocumentInfo.PropertyValues(29).Value)
&apos;        oTxtTopicID.Text = AlphaNum(document.DocumentProperties.UserDefinedProperties.Comments) &apos; OH need to find what is this...
    Else
        oTxtTopicID.Text = AlphaNum(txt)
    End If
End Sub

Sub Test
    On Error Resume Next
    document = StarDesktop.CurrentComponent
&apos;    showprop document
    msgbox document.URL

End Sub

&apos; Sets the value in the Topic title dialog field
Sub SetTopicTitle(txt As String)
    dim strg As String
    oTxtTitle = oDialog.GetControl(&quot;txtTitle&quot;)

    If txt =&quot;&quot; Then
        Enum = document.Text.createEnumeration

        Do While Enum.hasMoreElements
            TextElement = Enum.nextElement
            If TextElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
                If Left(TextElement.ParaStyleName,8)=&quot;hlp_head&quot; Then
                    Enum2 = TextElement.createEnumeration
                    While Enum2.hasMoreElements
                        TextPortion = Enum2.nextElement
                        If Not(TextPortion.TextPortionType=&quot;TextField&quot;) Then
                            strg = strg + TextPortion.String
                        End If
                    Wend
                    oTxtTitle.Text = strg
                    Exit Do
                End If
            End If
        Loop
    Else
        oTxtTitle.Text = txt
    End If
End Sub

&apos; Sets the value in the Topic title field when
&apos; &quot;Fetch&quot; button is pressed
Sub FetchTopicTitle
    SetTopicTitle(&quot;&quot;)

End Sub

&apos; Sets the value in the Topic ID dialog field when
&apos; &quot;Suggest&quot; button is pressed
Sub SuggestTopicID
    SetTopicID(&quot;&quot;)
End Sub

Sub ChangeStatus
    oCbFileStatus = oDialog.GetControl(&quot;cbFileStatus&quot;)
    sStatus = document.DocumentInfo.GetPropertyValue(&quot;Keywords&quot;)
    If (oCbFileStatus.Text = &quot;PUBLISH&quot;) Then
        nNoID = 0 &apos; DEBUG
        If nNoID &lt;&gt; 0 Then
            msgbox &quot;There are &quot;+nNoID+&quot; new paragraphs in the file.&quot;+chr(13)+&quot;File status PUBLISH invalid.&quot;+chr(13)+&quot;Setting back to &quot;+sStatus, 48, &quot;D&apos;oh!&quot;
        End If
    End If
End Sub
</script:module>