blob: 551dd5ca71821e34d06ab8d95d2f382a965f14d8 [file] [log] [blame]
<?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="_Main" script:language="StarBasic">&apos; Set of Macros used for Help Authoring
&apos; =====================================
&apos; Version
&apos; -------------------------------------
&apos;
&apos; #**************************************************************
&apos; #
&apos; # Licensed to the Apache Software Foundation (ASF) under one
&apos; # or more contributor license agreements. See the NOTICE file
&apos; # distributed with this work for additional information
&apos; # regarding copyright ownership. The ASF licenses this file
&apos; # to you under the Apache License, Version 2.0 (the
&apos; # "License"); you may not use this file except in compliance
&apos; # with the License. You may obtain a copy of the License at
&apos; #
&apos; # http://www.apache.org/licenses/LICENSE-2.0
&apos; #
&apos; # Unless required by applicable law or agreed to in writing,
&apos; # software distributed under the License is distributed on an
&apos; # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
&apos; # KIND, either express or implied. See the License for the
&apos; # specific language governing permissions and limitations
&apos; # under the License.
&apos; #
&apos; #**************************************************************
Global Const Version = &quot;v3.20100805&quot;
Global Const strErr_NoHelpFile = &quot;Not a Help File&quot;
&apos;=======================================================
&apos; Main
&apos;-------------------------------------------------------
&apos; Ensure that necessary library functions are available
&apos;=======================================================
Sub Main
GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
End Sub
&apos;=======================================================
&apos; SetMetaDataOnSave
&apos;-------------------------------------------------------
&apos; Sets the document meta data. It is called when
&apos; the document is saved. It changes the data and
&apos; then saves it again.
&apos;=======================================================
Sub SetMetaDataOnSave(Path as String)
document = StarDesktop.CurrentComponent
sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
If Path = &quot;&quot; Then
Path = document.URL
End If
If not(IsSubDir(Path,sDocRoot)) Then &apos; doesn&apos;tr work when resaving the file since it contains the OLD url (before resave)
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;)
Else
Path = Right(Path,Len(Path)-Len(sDocRoot))
End If
document.DocumentInfo.SetUserFieldName(0,&quot;Indexer&quot;)
document.DocumentInfo.SetUserFieldName(1,&quot;ID&quot;)
&apos; document.DocumentInfo.SetUserFieldName(2,&quot;Comment&quot;)
document.DocumentInfo.SetPropertyValue(&quot;Subject&quot;,Path)
End Sub
&apos;=======================================================
&apos; ValidateOnSave
&apos;-------------------------------------------------------
&apos; Ensures that the document is validated when saved
&apos; should be bound to the &quot;Document Save&quot; event but
&apos; currently isn&apos;t
&apos;=======================================================
Sub ValidateOnSave
BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
document = StarDesktop.CurrentComponent
If document.URL &lt;&gt; &quot;&quot; Then &apos; not initial save
If IsHelpFile Then
SetMetaDataOnSave(&quot;&quot;)
ValidateXHP
End If
End If
End Sub
&apos;=======================================================
&apos; CreateFile
&apos;-------------------------------------------------------
&apos; Creates a new help file based on the help template
&apos; and calls the save dialog
&apos;=======================================================
Sub CreateFile
GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
arPaths = Split(oPath.Template,&quot;;&quot;) &apos; get the paths to the templates from the configuration
sHelpTemplate = &quot;&quot;
&apos; change stw extension to ott extension for template
For i=0 to ubound(arPaths) &apos; see if the template path contains the help template
If FileExists(arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;) Then
sHelpTemplate = arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;
End If
Next i
If sHelpTemplate = &quot;&quot; Then
msgbox &quot;Cannot find the help template.&quot;,256
Else
oDoc = StarDesktop.loadComponentFromURL(sHelpTemplate,&quot;_blank&quot;,0,Array())
SaveAs(oDoc)
End If
End Sub
&apos;=======================================================
&apos; SaveAs
&apos;-------------------------------------------------------
&apos; Initially saves a new help file on creation.
&apos; Is called from CreateFile
&apos;=======================================================
Sub SaveAs(oDoc As Object)
Dim ListAny(0) as Long
Dim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
On Local Error Goto ERRHANDLE:
sLastSaveDir = ReadConfig(&quot;LastSaveDir&quot;)
sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
oFileDialog.Initialize(ListAny())
If sLastSaveDir &lt;&gt; &quot;&quot; AND IsSubDir(sLastSaveDir,sDocRoot) Then
oFileDialog.setDisplayDirectory(sLastSaveDir)
Else
oFileDialog.setDisplayDirectory(sDocRoot)
End If
oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.Office.TypeDetection/&quot;)
oFilters() = oMasterKey.Filters
oFileDialog.AppendFilter(&quot;Help&quot;, &quot;*.xhp&quot;)
oFileDialog.SetTitle(&quot;Save Help File As&quot;)
iAccept = oFileDialog.Execute()
If iAccept = 1 Then
WriteConfig(&quot;LastSaveDir&quot;,oFileDialog.getDisplayDirectory+&quot;/&quot;)
sPath = oFileDialog.Files(0)
oStoreProperties(0).Name = &quot;FilterName&quot;
oStoreProperties(0).Value = &quot;XHP_Help&quot;
SetMetaDataOnSave(sPath)
oDoc.StoreAsUrl(sPath, oStoreProperties())
Else
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
oDoc.dispose
End If
oFileDialog.Dispose()
ERRHANDLE:
If Err &lt;&gt; 0 Then
msgbox &quot;Error: &quot;+chr(13)+ Error$+chr(13)+&quot;Cannot save file.&quot;+chr(13),48,&quot;Fatal Error&quot;
oDoc.dispose
End If
End Sub
Sub CheckOnLoad
&apos; oDoc = StarDesktop.CurrentComponent
&apos; sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
&apos; If sDocRoot=&quot;&quot; Then
&apos; msgbox(&quot;No document root set. Please set the root folder for your documents.&quot;)
&apos; sDocRoot = SetDocumentRoot
&apos; End If
&apos; msgbox(HasUnoInterfaces(oDoc, &quot;com.sun.star.lang.XServiceInfo&quot;))
&apos; sFName = oDoc.URL
&apos; msgbox(sFName+chr(13)+sDocRoot)
&apos; If not(IsSubDir(sFName,sDocRoot)) Then
&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;)
&apos; End If
End Sub
Sub DisplayVersion
msgbox &quot;OpenOffice.org Help Authoring Framework&quot;+chr(13)+&quot;Version &quot;+Version,256
End Sub
</script:module>