xref: /trunk/main/helpauthoring/HelpAuthoring/Meta.xba (revision 66b843ff8f1eedd2e69941f1ea52fa080f01ec28)
11ecadb57SMathias Bauer<?xml version="1.0" encoding="UTF-8"?>
21ecadb57SMathias Bauer<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
231ecadb57SMathias Bauer<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Meta" script:language="StarBasic">REM  *****  BASIC  *****
241ecadb57SMathias Bauer
251ecadb57SMathias BauerDim oDialog AS Object
261ecadb57SMathias BauerDim document AS Object
271ecadb57SMathias Bauer
281ecadb57SMathias Bauer&apos; Fetches the meta values from the document and executes the dialog
291ecadb57SMathias BauerSub Main
301ecadb57SMathias Bauer
311ecadb57SMathias Bauer    If not IsHelpFile Then
321ecadb57SMathias Bauer        msgbox(strErr_NoHelpFile)
331ecadb57SMathias Bauer        Exit Sub
341ecadb57SMathias Bauer    End If
351ecadb57SMathias Bauer
361ecadb57SMathias Bauer    document = StarDesktop.CurrentComponent
371ecadb57SMathias Bauer
381ecadb57SMathias Bauer    BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
391ecadb57SMathias Bauer    oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgMeta&quot;)
401ecadb57SMathias Bauer    oDialogModel = oDialog.Model
411ecadb57SMathias Bauer
421ecadb57SMathias Bauer    &apos;oTxtFName = oDialog.GetControl(&quot;txtFileName&quot;)
431ecadb57SMathias Bauer    &apos;oTxtFName.Text = document.DocumentInfo.PropertyValues(29).Value
441ecadb57SMathias Bauer    &apos;oTxtFName.Text = document.DocumentInfo.GetPropertyValue(&quot;Description&quot;)
451ecadb57SMathias Bauer
461ecadb57SMathias Bauer&apos;  If oTxtFName.Text = &quot;&quot; Then
471ecadb57SMathias Bauer&apos;      msgbox &quot;The document must be saved first.&quot;+chr(13)+&quot;Please save the document and call this dialog again.&quot;
481ecadb57SMathias Bauer&apos;      oDialog.dispose
491ecadb57SMathias Bauer&apos;      Exit Sub
501ecadb57SMathias Bauer&apos;  End If
511ecadb57SMathias Bauer
521ecadb57SMathias Bauer    oTxtTitle = oDialog.GetControl(&quot;txtTitle&quot;)
531ecadb57SMathias Bauer    oTxtTitle.Text = document.DocumentInfo.Title
541ecadb57SMathias Bauer
551ecadb57SMathias Bauer    oOpIndInc = oDialog.GetControl(&quot;opIndexInclude&quot;)
561ecadb57SMathias Bauer    oOpIndExc = oDialog.GetControl(&quot;opIndexExclude&quot;)
571ecadb57SMathias Bauer
581ecadb57SMathias Bauer
591ecadb57SMathias Bauer    &apos;oCbFileStatus = oDialog.GetControl(&quot;cbFileStatus&quot;)
601ecadb57SMathias Bauer    &apos;arItems = Array(&quot;DRAFT&quot;,&quot;FINAL&quot;,&quot;PUBLISH&quot;,&quot;STALLED&quot;,&quot;DEPRECATED&quot;)
611ecadb57SMathias Bauer    &apos;oCbFileStatus.AddItems(arItems,ubound(arItems))
621ecadb57SMathias Bauer    &apos;sStatus = document.DocumentInfo.GetPropertyValue(&quot;Keywords&quot;)
631ecadb57SMathias Bauer    &apos;If (InStr(&quot;DRAFT FINAL PUBLISH STALLED DEPRECATED&quot;,sStatus)=0) Then
641ecadb57SMathias Bauer    &apos;  oCbFileStatus.SetText(&quot;DRAFT&quot;)
651ecadb57SMathias Bauer    &apos;Else
661ecadb57SMathias Bauer    &apos;  oCbFileStatus.SetText(sStatus)
671ecadb57SMathias Bauer    &apos;End If
681ecadb57SMathias Bauer
691ecadb57SMathias Bauer
701ecadb57SMathias Bauer    If document.DocumentInfo.GetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;)) = &quot;exclude&quot; then
711ecadb57SMathias Bauer        oOpIndExc.State = True
721ecadb57SMathias Bauer    Else
731ecadb57SMathias Bauer        oOpIndInc.State = True
741ecadb57SMathias Bauer    End If
751ecadb57SMathias Bauer
761ecadb57SMathias Bauer    &apos;oTxtTopicID = oDialog.GetControl(&quot;txtTopicID&quot;)
771ecadb57SMathias Bauer    &apos;oTxtTopicID.Text = document.DocumentInfo.GetUserFieldValue(1)
781ecadb57SMathias Bauer
791ecadb57SMathias Bauer    &apos;oTxtComment = oDialog.GetControl(&quot;txtComment&quot;)
801ecadb57SMathias Bauer    &apos;oTxtComment.Text = document.DocumentInfo.GetUserFieldValue(GetUserFieldNumber(&quot;Comment&quot;))
811ecadb57SMathias Bauer
821ecadb57SMathias Bauer    &apos;oTxtEdited = oDialog.GetControl(&quot;txtLastEdited&quot;)
831ecadb57SMathias Bauer    &apos;oTxtEdited.Text = document.DocumentInfo.GetUserFieldValue(3)
841ecadb57SMathias Bauer
851ecadb57SMathias Bauer    If oDialog.Execute() = 1 Then &apos; update the meta data
861ecadb57SMathias Bauer        document.DocumentInfo.Title = oTxtTitle.Text
871ecadb57SMathias Bauer        &apos;document.DocumentInfo.SetUserFieldValue(1,oTxtTopicID.Text)
881ecadb57SMathias Bauer        &apos;document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Comment&quot;),oTxtComment.Text)
891ecadb57SMathias Bauer        &apos;document.DocumentInfo.SetUserFieldValue(3,oTxtEdited.Text)
901ecadb57SMathias Bauer        &apos;document.DocumentInfo.SetPropertyValue(&quot;Keywords&quot;,oCbFileStatus.Text)
911ecadb57SMathias Bauer
921ecadb57SMathias Bauer        &apos;If (oCbFileStatus.Text = &quot;PUBLISH&quot;) Then
931ecadb57SMathias Bauer            REM... Check for paras without ID: If there are any, this cannot be PUBLISH!
941ecadb57SMathias Bauer
951ecadb57SMathias Bauer        &apos;End If
961ecadb57SMathias Bauer
971ecadb57SMathias Bauer        If oOpIndExc.State = True Then
981ecadb57SMathias Bauer            document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;),&quot;exclude&quot;)
991ecadb57SMathias Bauer        Else
1001ecadb57SMathias Bauer            document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;),&quot;include&quot;)
1011ecadb57SMathias Bauer        End If
1021ecadb57SMathias Bauer    End If
1031ecadb57SMathias Bauer    oDialog.dispose
1041ecadb57SMathias Bauerend sub
1051ecadb57SMathias Bauer
1061ecadb57SMathias Bauer&apos; Normalizes the values for title and topic id
1071ecadb57SMathias Bauer&apos; (if the fields are empty or contain invalid values)
1081ecadb57SMathias BauerSub NormalizeMeta (Event As Object)
1091ecadb57SMathias Bauer    Select Case Event.Source.Model.Name
1101ecadb57SMathias Bauer        Case &quot;txtTitle&quot;:
1111ecadb57SMathias Bauer            If Event.Source.Text = &quot;&quot; Then
1121ecadb57SMathias Bauer                msgbox &quot;Topic title must not be empty!&quot;+chr(13)+&quot;Resetting to default value.&quot;
1131ecadb57SMathias Bauer            End If
1141ecadb57SMathias Bauer            SetTopicTitle(Event.Source.Text)
1151ecadb57SMathias Bauer        Case &quot;txtTopicID&quot;:
1161ecadb57SMathias Bauer            If Event.Source.Text = &quot;&quot; Then
1171ecadb57SMathias Bauer                msgbox &quot;Topic ID must not be empty!&quot;+chr(13)+&quot;Resetting to default value.&quot;
1181ecadb57SMathias Bauer            End If
1191ecadb57SMathias Bauer            SetTopicID(Event.Source.Text)
1201ecadb57SMathias Bauer    End Select
1211ecadb57SMathias BauerEnd Sub
1221ecadb57SMathias Bauer
1231ecadb57SMathias Bauer&apos; Sets the value in the Topic ID dialog field
1241ecadb57SMathias BauerSub SetTopicID(txt As String)
1251ecadb57SMathias Bauer    oTxtTopicID = oDialog.GetControl(&quot;txtTopicID&quot;)
1261ecadb57SMathias Bauer    If txt = &quot;&quot; Then
1271ecadb57SMathias Bauer        oTxtTopicID.Text = AlphaNum(document.DocumentInfo.PropertyValues(29).Value)
1281ecadb57SMathias Bauer    Else
1291ecadb57SMathias Bauer        oTxtTopicID.Text = AlphaNum(txt)
1301ecadb57SMathias Bauer    End If
1311ecadb57SMathias BauerEnd Sub
1321ecadb57SMathias Bauer
1331ecadb57SMathias BauerSub Test
1341ecadb57SMathias Bauer    On Error Resume Next
1351ecadb57SMathias Bauer    document = StarDesktop.CurrentComponent
1361ecadb57SMathias Bauer&apos;  showprop document
1371ecadb57SMathias Bauer    msgbox document.URL
1381ecadb57SMathias Bauer
1391ecadb57SMathias BauerEnd Sub
1401ecadb57SMathias Bauer
1411ecadb57SMathias Bauer&apos; Sets the value in the Topic title dialog field
1421ecadb57SMathias BauerSub SetTopicTitle(txt As String)
1431ecadb57SMathias Bauer    dim strg As String
1441ecadb57SMathias Bauer    oTxtTitle = oDialog.GetControl(&quot;txtTitle&quot;)
1451ecadb57SMathias Bauer
1461ecadb57SMathias Bauer    If txt =&quot;&quot; Then
1471ecadb57SMathias Bauer        Enum = document.Text.createEnumeration
1481ecadb57SMathias Bauer
1491ecadb57SMathias Bauer        Do While Enum.hasMoreElements
1501ecadb57SMathias Bauer            TextElement = Enum.nextElement
1511ecadb57SMathias Bauer            If TextElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
1521ecadb57SMathias Bauer                If Left(TextElement.ParaStyleName,8)=&quot;hlp_head&quot; Then
1531ecadb57SMathias Bauer                    Enum2 = TextElement.createEnumeration
1541ecadb57SMathias Bauer                    While Enum2.hasMoreElements
1551ecadb57SMathias Bauer                        TextPortion = Enum2.nextElement
1561ecadb57SMathias Bauer                        If Not(TextPortion.TextPortionType=&quot;TextField&quot;) Then
1571ecadb57SMathias Bauer                            strg = strg + TextPortion.String
1581ecadb57SMathias Bauer                        End If
1591ecadb57SMathias Bauer                    Wend
1601ecadb57SMathias Bauer                    oTxtTitle.Text = strg
1611ecadb57SMathias Bauer                    Exit Do
1621ecadb57SMathias Bauer                End If
1631ecadb57SMathias Bauer            End If
1641ecadb57SMathias Bauer        Loop
1651ecadb57SMathias Bauer    Else
1661ecadb57SMathias Bauer        oTxtTitle.Text = txt
1671ecadb57SMathias Bauer    End If
1681ecadb57SMathias BauerEnd Sub
1691ecadb57SMathias Bauer
1701ecadb57SMathias Bauer&apos; Sets the value in the Topic title field when
1711ecadb57SMathias Bauer&apos; &quot;Fetch&quot; button is pressed
1721ecadb57SMathias BauerSub FetchTopicTitle
1731ecadb57SMathias Bauer    SetTopicTitle(&quot;&quot;)
1741ecadb57SMathias Bauer
1751ecadb57SMathias BauerEnd Sub
1761ecadb57SMathias Bauer
1771ecadb57SMathias Bauer&apos; Sets the value in the Topic ID dialog field when
1781ecadb57SMathias Bauer&apos; &quot;Suggest&quot; button is pressed
1791ecadb57SMathias BauerSub SuggestTopicID
1801ecadb57SMathias Bauer    SetTopicID(&quot;&quot;)
1811ecadb57SMathias BauerEnd Sub
1821ecadb57SMathias Bauer
1831ecadb57SMathias BauerSub ChangeStatus
1841ecadb57SMathias Bauer    oCbFileStatus = oDialog.GetControl(&quot;cbFileStatus&quot;)
1851ecadb57SMathias Bauer    sStatus = document.DocumentInfo.GetPropertyValue(&quot;Keywords&quot;)
1861ecadb57SMathias Bauer    If (oCbFileStatus.Text = &quot;PUBLISH&quot;) Then
1871ecadb57SMathias Bauer        nNoID = 0 &apos; DEBUG
1881ecadb57SMathias Bauer        If nNoID &lt;&gt; 0 Then
1891ecadb57SMathias Bauer            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;
1901ecadb57SMathias Bauer        End If
1911ecadb57SMathias Bauer    End If
1921ecadb57SMathias BauerEnd Sub
1931ecadb57SMathias Bauer</script:module>
194