xref: /AOO41X/main/helpauthoring/HelpAuthoring/_Main.xba (revision 888d597162e5dc97af679bc2cf95e7db77709d5b)
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="_Main" script:language="StarBasic">&apos; Set of Macros used for Help Authoring
4
5&apos; #**************************************************************
6&apos; #
7&apos; #  Licensed to the Apache Software Foundation (ASF) under one
8&apos; #  or more contributor license agreements.  See the NOTICE file
9&apos; #  distributed with this work for additional information
10&apos; #  regarding copyright ownership.  The ASF licenses this file
11&apos; #  to you under the Apache License, Version 2.0 (the
12&apos; #  "License"); you may not use this file except in compliance
13&apos; #  with the License.  You may obtain a copy of the License at
14&apos; #
15&apos; #    http://www.apache.org/licenses/LICENSE-2.0
16&apos; #
17&apos; #  Unless required by applicable law or agreed to in writing,
18&apos; #  software distributed under the License is distributed on an
19&apos; #  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20&apos; #  KIND, either express or implied.  See the License for the
21&apos; #  specific language governing permissions and limitations
22&apos; #  under the License.
23&apos; #
24&apos; #**************************************************************
25
26Global Const Version = &quot;3.0.1&quot;
27
28Global Const strErr_NoHelpFile = &quot;Not a Help File&quot;
29
30&apos;=======================================================
31&apos; Main
32&apos;-------------------------------------------------------
33&apos; Ensure that necessary library functions are available
34&apos;=======================================================
35Sub Main
36    GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
37End Sub
38
39&apos;=======================================================
40&apos; SetMetaDataOnSave
41&apos;-------------------------------------------------------
42&apos; Sets the document meta data. It is called when
43&apos; the document is saved. It changes the data and
44&apos; then saves it again.
45&apos;=======================================================
46Sub SetMetaDataOnSave(Path as String)
47
48    document = StarDesktop.CurrentComponent
49    sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
50
51    If Path = &quot;&quot; Then
52        Path = document.URL
53    End If
54
55    If not(IsSubDir(Path,sDocRoot)) Then &apos; doesn&apos;t work when resaving the file since it contains the OLD url (before resave)
56        msgbox(&quot;The File&quot;+chr(13)+Path+chr(13)+&quot;is outside of your Document Root&quot;+chr(13)+sDocRoot+chr(13)+chr(13)+&quot;You may want to adjust your document root settings and re-save the file.&quot;,48,&quot;Warning&quot;)
57    Else
58        Path = Right(Path,Len(Path)-Len(sDocRoot))
59    End If
60
61    document.DocumentInfo.SetUserFieldName(0,&quot;Indexer&quot;)
62    document.DocumentInfo.SetUserFieldName(1,&quot;ID&quot;)
63&apos;  document.DocumentInfo.SetUserFieldName(2,&quot;Comment&quot;)
64    document.DocumentInfo.SetPropertyValue(&quot;Subject&quot;,Path)
65
66
67End Sub
68
69&apos;=======================================================
70&apos; ValidateOnSave
71&apos;-------------------------------------------------------
72&apos; Ensures that the document is validated when saved
73&apos; should be bound to the &quot;Document Save&quot; event but
74&apos; currently isn&apos;t
75&apos;=======================================================
76Sub ValidateOnSave
77    BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
78    document = StarDesktop.CurrentComponent
79    If document.URL &lt;&gt; &quot;&quot; Then &apos; not initial save
80        If IsHelpFile Then
81            SetMetaDataOnSave(&quot;&quot;)
82            ValidateXHP
83        End If
84    End If
85End Sub
86
87
88&apos;=======================================================
89&apos; CreateFile
90&apos;-------------------------------------------------------
91&apos; Creates a new help file based on the help template
92&apos; and calls the save dialog
93&apos;=======================================================
94Sub CreateFile
95    GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
96    oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
97    arPaths = Split(oPath.Template,&quot;;&quot;)  &apos; get the paths to the templates from the configuration
98    sHelpTemplate = &quot;&quot;
99
100    &apos; change stw extension to ott extension for template
101
102    For i=0 to ubound(arPaths)  &apos; see if the template path contains the help template
103        If FileExists(arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;) Then
104            sHelpTemplate = arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;
105        End If
106    Next i
107
108    If sHelpTemplate = &quot;&quot; Then
109        msgbox &quot;Cannot find the help template.&quot;,256
110    Else
111        oDoc = StarDesktop.loadComponentFromURL(sHelpTemplate,&quot;_blank&quot;,0,Array())
112        SaveAs(oDoc)
113    End If
114
115End Sub
116
117&apos;=======================================================
118&apos; SaveAs
119&apos;-------------------------------------------------------
120&apos; Initially saves a new help file on creation.
121&apos; Is called from CreateFile
122&apos;=======================================================
123Sub SaveAs(oDoc As Object)
124Dim ListAny(0) as Long
125Dim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
126    On Local Error Goto ERRHANDLE:
127
128    sLastSaveDir = ReadConfig(&quot;LastSaveDir&quot;)
129    sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
130
131    ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
132    oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
133    oFileDialog.Initialize(ListAny())
134
135    If sLastSaveDir &lt;&gt; &quot;&quot; AND IsSubDir(sLastSaveDir,sDocRoot) Then
136        oFileDialog.setDisplayDirectory(sLastSaveDir)
137    Else
138        oFileDialog.setDisplayDirectory(sDocRoot)
139    End If
140
141    oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.Office.TypeDetection/&quot;)
142    oFilters() = oMasterKey.Filters
143    oFileDialog.AppendFilter(&quot;Help&quot;, &quot;*.xhp&quot;)
144
145    oFileDialog.SetTitle(&quot;Save Help File As&quot;)
146    iAccept = oFileDialog.Execute()
147    If iAccept = 1 Then
148        WriteConfig(&quot;LastSaveDir&quot;,oFileDialog.getDisplayDirectory+&quot;/&quot;)
149        sPath = oFileDialog.Files(0)
150        oStoreProperties(0).Name = &quot;FilterName&quot;
151        oStoreProperties(0).Value = &quot;XHP_Help&quot;
152        SetMetaDataOnSave(sPath)
153        oDoc.StoreAsUrl(sPath, oStoreProperties())
154    Else
155        msgbox &quot;You must save a help document before you can work on it.&quot;+chr(13)+&quot;This document will be disposed.&quot;, 48
156        oDoc.dispose
157    End If
158    oFileDialog.Dispose()
159
160    ERRHANDLE:
161        If Err &lt;&gt; 0 Then
162            msgbox &quot;Error: &quot;+chr(13)+ Error$+chr(13)+&quot;Cannot save file.&quot;+chr(13),48,&quot;Fatal Error&quot;
163            oDoc.dispose
164        End If
165End Sub
166
167Sub CheckOnLoad
168&apos;  oDoc = StarDesktop.CurrentComponent
169&apos;  sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
170&apos;  If sDocRoot=&quot;&quot; Then
171&apos;      msgbox(&quot;No document root set. Please set the root folder for your documents.&quot;)
172&apos;      sDocRoot = SetDocumentRoot
173&apos;  End If
174&apos;  msgbox(HasUnoInterfaces(oDoc, &quot;com.sun.star.lang.XServiceInfo&quot;))
175&apos;  sFName = oDoc.URL
176&apos;  msgbox(sFName+chr(13)+sDocRoot)
177&apos;  If not(IsSubDir(sFName,sDocRoot)) Then
178&apos;      msgbox(&quot;The file is located outside of your Document Root&quot;+chr(13)+sDocRoot+chr(13)+chr(13)+&quot;Please adjust your document root settings to avoid trouble with links, transcludes and images!&quot;,48,&quot;Warning!&quot;)
179&apos;  End If
180End Sub
181
182Sub DisplayVersion
183    msgbox &quot;OpenOffice Help Authoring Framework&quot;+chr(13)+&quot;Version &quot;+Version,256
184End Sub
185</script:module>
186