xref: /AOO41X/main/helpauthoring/HelpAuthoring/Meta.xba (revision b2937f997bda0a05141a2d862a64f7be893955b7)
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Meta" script:language="StarBasic">REM  *****  BASIC  *****
4
5Dim oDialog AS Object
6Dim document AS Object
7
8&apos; Fetches the meta values from the document and executes the dialog
9Sub Main
10
11    If not IsHelpFile Then
12        msgbox(strErr_NoHelpFile)
13        Exit Sub
14    End If
15
16    document = StarDesktop.CurrentComponent
17
18    BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
19    oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgMeta&quot;)
20    oDialogModel = oDialog.Model
21
22    &apos;oTxtFName = oDialog.GetControl(&quot;txtFileName&quot;)
23    &apos;oTxtFName.Text = document.DocumentInfo.PropertyValues(29).Value
24    &apos;oTxtFName.Text = document.DocumentInfo.GetPropertyValue(&quot;Description&quot;)
25
26&apos;  If oTxtFName.Text = &quot;&quot; Then
27&apos;      msgbox &quot;The document must be saved first.&quot;+chr(13)+&quot;Please save the document and call this dialog again.&quot;
28&apos;      oDialog.dispose
29&apos;      Exit Sub
30&apos;  End If
31
32    oTxtTitle = oDialog.GetControl(&quot;txtTitle&quot;)
33    oTxtTitle.Text = document.DocumentInfo.Title
34
35    oOpIndInc = oDialog.GetControl(&quot;opIndexInclude&quot;)
36    oOpIndExc = oDialog.GetControl(&quot;opIndexExclude&quot;)
37
38
39    &apos;oCbFileStatus = oDialog.GetControl(&quot;cbFileStatus&quot;)
40    &apos;arItems = Array(&quot;DRAFT&quot;,&quot;FINAL&quot;,&quot;PUBLISH&quot;,&quot;STALLED&quot;,&quot;DEPRECATED&quot;)
41    &apos;oCbFileStatus.AddItems(arItems,ubound(arItems))
42    &apos;sStatus = document.DocumentInfo.GetPropertyValue(&quot;Keywords&quot;)
43    &apos;If (InStr(&quot;DRAFT FINAL PUBLISH STALLED DEPRECATED&quot;,sStatus)=0) Then
44    &apos;  oCbFileStatus.SetText(&quot;DRAFT&quot;)
45    &apos;Else
46    &apos;  oCbFileStatus.SetText(sStatus)
47    &apos;End If
48
49
50    If document.DocumentInfo.GetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;)) = &quot;exclude&quot; then
51        oOpIndExc.State = True
52    Else
53        oOpIndInc.State = True
54    End If
55
56    &apos;oTxtTopicID = oDialog.GetControl(&quot;txtTopicID&quot;)
57    &apos;oTxtTopicID.Text = document.DocumentInfo.GetUserFieldValue(1)
58
59    &apos;oTxtComment = oDialog.GetControl(&quot;txtComment&quot;)
60    &apos;oTxtComment.Text = document.DocumentInfo.GetUserFieldValue(GetUserFieldNumber(&quot;Comment&quot;))
61
62    &apos;oTxtEdited = oDialog.GetControl(&quot;txtLastEdited&quot;)
63    &apos;oTxtEdited.Text = document.DocumentInfo.GetUserFieldValue(3)
64
65    If oDialog.Execute() = 1 Then &apos; update the meta data
66        document.DocumentInfo.Title = oTxtTitle.Text
67        &apos;document.DocumentInfo.SetUserFieldValue(1,oTxtTopicID.Text)
68        &apos;document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Comment&quot;),oTxtComment.Text)
69        &apos;document.DocumentInfo.SetUserFieldValue(3,oTxtEdited.Text)
70        &apos;document.DocumentInfo.SetPropertyValue(&quot;Keywords&quot;,oCbFileStatus.Text)
71
72        &apos;If (oCbFileStatus.Text = &quot;PUBLISH&quot;) Then
73            REM... Check for paras without ID: If there are any, this cannot be PUBLISH!
74
75        &apos;End If
76
77        If oOpIndExc.State = True Then
78            document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;),&quot;exclude&quot;)
79        Else
80            document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;),&quot;include&quot;)
81        End If
82    End If
83    oDialog.dispose
84end sub
85
86&apos; Normalizes the values for title and topic id
87&apos; (if the fields are empty or contain invalid values)
88Sub NormalizeMeta (Event As Object)
89    Select Case Event.Source.Model.Name
90        Case &quot;txtTitle&quot;:
91            If Event.Source.Text = &quot;&quot; Then
92                msgbox &quot;Topic title must not be empty!&quot;+chr(13)+&quot;Resetting to default value.&quot;
93            End If
94            SetTopicTitle(Event.Source.Text)
95        Case &quot;txtTopicID&quot;:
96            If Event.Source.Text = &quot;&quot; Then
97                msgbox &quot;Topic ID must not be empty!&quot;+chr(13)+&quot;Resetting to default value.&quot;
98            End If
99            SetTopicID(Event.Source.Text)
100    End Select
101End Sub
102
103&apos; Sets the value in the Topic ID dialog field
104Sub SetTopicID(txt As String)
105    oTxtTopicID = oDialog.GetControl(&quot;txtTopicID&quot;)
106    If txt = &quot;&quot; Then
107        oTxtTopicID.Text = AlphaNum(document.DocumentInfo.PropertyValues(29).Value)
108    Else
109        oTxtTopicID.Text = AlphaNum(txt)
110    End If
111End Sub
112
113Sub Test
114    On Error Resume Next
115    document = StarDesktop.CurrentComponent
116&apos;  showprop document
117    msgbox document.URL
118
119End Sub
120
121&apos; Sets the value in the Topic title dialog field
122Sub SetTopicTitle(txt As String)
123    dim strg As String
124    oTxtTitle = oDialog.GetControl(&quot;txtTitle&quot;)
125
126    If txt =&quot;&quot; Then
127        Enum = document.Text.createEnumeration
128
129        Do While Enum.hasMoreElements
130            TextElement = Enum.nextElement
131            If TextElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
132                If Left(TextElement.ParaStyleName,8)=&quot;hlp_head&quot; Then
133                    Enum2 = TextElement.createEnumeration
134                    While Enum2.hasMoreElements
135                        TextPortion = Enum2.nextElement
136                        If Not(TextPortion.TextPortionType=&quot;TextField&quot;) Then
137                            strg = strg + TextPortion.String
138                        End If
139                    Wend
140                    oTxtTitle.Text = strg
141                    Exit Do
142                End If
143            End If
144        Loop
145    Else
146        oTxtTitle.Text = txt
147    End If
148End Sub
149
150&apos; Sets the value in the Topic title field when
151&apos; &quot;Fetch&quot; button is pressed
152Sub FetchTopicTitle
153    SetTopicTitle(&quot;&quot;)
154
155End Sub
156
157&apos; Sets the value in the Topic ID dialog field when
158&apos; &quot;Suggest&quot; button is pressed
159Sub SuggestTopicID
160    SetTopicID(&quot;&quot;)
161End Sub
162
163Sub ChangeStatus
164    oCbFileStatus = oDialog.GetControl(&quot;cbFileStatus&quot;)
165    sStatus = document.DocumentInfo.GetPropertyValue(&quot;Keywords&quot;)
166    If (oCbFileStatus.Text = &quot;PUBLISH&quot;) Then
167        nNoID = 0 &apos; DEBUG
168        If nNoID &lt;&gt; 0 Then
169            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;
170        End If
171    End If
172End Sub
173</script:module>