11ecadb57SMathias Bauer<?xml version="1.0" encoding="UTF-8"?>
21ecadb57SMathias Bauer<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
31ecadb57SMathias Bauer<script:module xmlns:script="http://openoffice.org/2000/script" script:name="_Main" script:language="StarBasic">&apos; Set of Macros used for Help Authoring
41ecadb57SMathias Bauer
5841807c9SAndrew Rist&apos; #**************************************************************
6*4fec54abSmseidel&apos; #
7841807c9SAndrew Rist&apos; #  Licensed to the Apache Software Foundation (ASF) under one
8841807c9SAndrew Rist&apos; #  or more contributor license agreements.  See the NOTICE file
9841807c9SAndrew Rist&apos; #  distributed with this work for additional information
10841807c9SAndrew Rist&apos; #  regarding copyright ownership.  The ASF licenses this file
11841807c9SAndrew Rist&apos; #  to you under the Apache License, Version 2.0 (the
12841807c9SAndrew Rist&apos; #  "License"); you may not use this file except in compliance
13841807c9SAndrew Rist&apos; #  with the License.  You may obtain a copy of the License at
14*4fec54abSmseidel&apos; #
15841807c9SAndrew Rist&apos; #    http://www.apache.org/licenses/LICENSE-2.0
16*4fec54abSmseidel&apos; #
17841807c9SAndrew Rist&apos; #  Unless required by applicable law or agreed to in writing,
18841807c9SAndrew Rist&apos; #  software distributed under the License is distributed on an
19841807c9SAndrew Rist&apos; #  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20841807c9SAndrew Rist&apos; #  KIND, either express or implied.  See the License for the
21841807c9SAndrew Rist&apos; #  specific language governing permissions and limitations
22841807c9SAndrew Rist&apos; #  under the License.
23*4fec54abSmseidel&apos; #
24841807c9SAndrew Rist&apos; #**************************************************************
251ecadb57SMathias Bauer
26*4fec54abSmseidelGlobal Const Version = &quot;3.0.1&quot;
271ecadb57SMathias Bauer
281ecadb57SMathias BauerGlobal Const strErr_NoHelpFile = &quot;Not a Help File&quot;
291ecadb57SMathias Bauer
301ecadb57SMathias Bauer&apos;=======================================================
311ecadb57SMathias Bauer&apos; Main
321ecadb57SMathias Bauer&apos;-------------------------------------------------------
331ecadb57SMathias Bauer&apos; Ensure that necessary library functions are available
341ecadb57SMathias Bauer&apos;=======================================================
351ecadb57SMathias BauerSub Main
361ecadb57SMathias Bauer	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
371ecadb57SMathias BauerEnd Sub
381ecadb57SMathias Bauer
391ecadb57SMathias Bauer&apos;=======================================================
401ecadb57SMathias Bauer&apos; SetMetaDataOnSave
411ecadb57SMathias Bauer&apos;-------------------------------------------------------
421ecadb57SMathias Bauer&apos; Sets the document meta data. It is called when
431ecadb57SMathias Bauer&apos; the document is saved. It changes the data and
441ecadb57SMathias Bauer&apos; then saves it again.
451ecadb57SMathias Bauer&apos;=======================================================
461ecadb57SMathias BauerSub SetMetaDataOnSave(Path as String)
471ecadb57SMathias Bauer
481ecadb57SMathias Bauer	document = StarDesktop.CurrentComponent
491ecadb57SMathias Bauer	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
501ecadb57SMathias Bauer
511ecadb57SMathias Bauer	If Path = &quot;&quot; Then
521ecadb57SMathias Bauer		Path = document.URL
531ecadb57SMathias Bauer	End If
541ecadb57SMathias Bauer
55*4fec54abSmseidel	If not(IsSubDir(Path,sDocRoot)) Then &apos; doesn&apos;t work when resaving the file since it contains the OLD url (before resave)
561ecadb57SMathias Bauer		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;)
571ecadb57SMathias Bauer	Else
581ecadb57SMathias Bauer		Path = Right(Path,Len(Path)-Len(sDocRoot))
591ecadb57SMathias Bauer	End If
601ecadb57SMathias Bauer
611ecadb57SMathias Bauer	document.DocumentInfo.SetUserFieldName(0,&quot;Indexer&quot;)
621ecadb57SMathias Bauer	document.DocumentInfo.SetUserFieldName(1,&quot;ID&quot;)
631ecadb57SMathias Bauer&apos;	document.DocumentInfo.SetUserFieldName(2,&quot;Comment&quot;)
641ecadb57SMathias Bauer	document.DocumentInfo.SetPropertyValue(&quot;Subject&quot;,Path)
65*4fec54abSmseidel
661ecadb57SMathias Bauer
671ecadb57SMathias BauerEnd Sub
681ecadb57SMathias Bauer
691ecadb57SMathias Bauer&apos;=======================================================
701ecadb57SMathias Bauer&apos; ValidateOnSave
711ecadb57SMathias Bauer&apos;-------------------------------------------------------
721ecadb57SMathias Bauer&apos; Ensures that the document is validated when saved
731ecadb57SMathias Bauer&apos; should be bound to the &quot;Document Save&quot; event but
741ecadb57SMathias Bauer&apos; currently isn&apos;t
751ecadb57SMathias Bauer&apos;=======================================================
761ecadb57SMathias BauerSub ValidateOnSave
771ecadb57SMathias Bauer	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
781ecadb57SMathias Bauer	document = StarDesktop.CurrentComponent
791ecadb57SMathias Bauer	If document.URL &lt;&gt; &quot;&quot; Then &apos; not initial save
801ecadb57SMathias Bauer		If IsHelpFile Then
811ecadb57SMathias Bauer			SetMetaDataOnSave(&quot;&quot;)
821ecadb57SMathias Bauer			ValidateXHP
831ecadb57SMathias Bauer		End If
841ecadb57SMathias Bauer	End If
851ecadb57SMathias BauerEnd Sub
861ecadb57SMathias Bauer
871ecadb57SMathias Bauer
881ecadb57SMathias Bauer&apos;=======================================================
891ecadb57SMathias Bauer&apos; CreateFile
901ecadb57SMathias Bauer&apos;-------------------------------------------------------
911ecadb57SMathias Bauer&apos; Creates a new help file based on the help template
921ecadb57SMathias Bauer&apos; and calls the save dialog
931ecadb57SMathias Bauer&apos;=======================================================
941ecadb57SMathias BauerSub CreateFile
951ecadb57SMathias Bauer	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
961ecadb57SMathias Bauer	oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
971ecadb57SMathias Bauer	arPaths = Split(oPath.Template,&quot;;&quot;)  &apos; get the paths to the templates from the configuration
981ecadb57SMathias Bauer	sHelpTemplate = &quot;&quot;
991ecadb57SMathias Bauer
1001ecadb57SMathias Bauer	&apos; change stw extension to ott extension for template
1011ecadb57SMathias Bauer
1021ecadb57SMathias Bauer	For i=0 to ubound(arPaths)  &apos; see if the template path contains the help template
1031ecadb57SMathias Bauer		If FileExists(arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;) Then
1041ecadb57SMathias Bauer			sHelpTemplate = arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;
1051ecadb57SMathias Bauer		End If
1061ecadb57SMathias Bauer	Next i
1071ecadb57SMathias Bauer
1081ecadb57SMathias Bauer	If sHelpTemplate = &quot;&quot; Then
1091ecadb57SMathias Bauer		msgbox &quot;Cannot find the help template.&quot;,256
1101ecadb57SMathias Bauer	Else
1111ecadb57SMathias Bauer		oDoc = StarDesktop.loadComponentFromURL(sHelpTemplate,&quot;_blank&quot;,0,Array())
1121ecadb57SMathias Bauer		SaveAs(oDoc)
1131ecadb57SMathias Bauer	End If
1141ecadb57SMathias Bauer
1151ecadb57SMathias BauerEnd Sub
1161ecadb57SMathias Bauer
1171ecadb57SMathias Bauer&apos;=======================================================
1181ecadb57SMathias Bauer&apos; SaveAs
1191ecadb57SMathias Bauer&apos;-------------------------------------------------------
1201ecadb57SMathias Bauer&apos; Initially saves a new help file on creation.
1211ecadb57SMathias Bauer&apos; Is called from CreateFile
1221ecadb57SMathias Bauer&apos;=======================================================
1231ecadb57SMathias BauerSub SaveAs(oDoc As Object)
1241ecadb57SMathias BauerDim ListAny(0) as Long
1251ecadb57SMathias BauerDim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
1261ecadb57SMathias Bauer	On Local Error Goto ERRHANDLE:
1271ecadb57SMathias Bauer
1281ecadb57SMathias Bauer	sLastSaveDir = ReadConfig(&quot;LastSaveDir&quot;)
1291ecadb57SMathias Bauer	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
1301ecadb57SMathias Bauer
1311ecadb57SMathias Bauer	ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
1321ecadb57SMathias Bauer	oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
1331ecadb57SMathias Bauer	oFileDialog.Initialize(ListAny())
1341ecadb57SMathias Bauer
1351ecadb57SMathias Bauer	If sLastSaveDir &lt;&gt; &quot;&quot; AND IsSubDir(sLastSaveDir,sDocRoot) Then
1361ecadb57SMathias Bauer		oFileDialog.setDisplayDirectory(sLastSaveDir)
1371ecadb57SMathias Bauer	Else
1381ecadb57SMathias Bauer		oFileDialog.setDisplayDirectory(sDocRoot)
1391ecadb57SMathias Bauer	End If
1401ecadb57SMathias Bauer
1411ecadb57SMathias Bauer	oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.Office.TypeDetection/&quot;)
1421ecadb57SMathias Bauer	oFilters() = oMasterKey.Filters
1431ecadb57SMathias Bauer	oFileDialog.AppendFilter(&quot;Help&quot;, &quot;*.xhp&quot;)
1441ecadb57SMathias Bauer
1451ecadb57SMathias Bauer	oFileDialog.SetTitle(&quot;Save Help File As&quot;)
1461ecadb57SMathias Bauer	iAccept = oFileDialog.Execute()
1471ecadb57SMathias Bauer	If iAccept = 1 Then
1481ecadb57SMathias Bauer		WriteConfig(&quot;LastSaveDir&quot;,oFileDialog.getDisplayDirectory+&quot;/&quot;)
1491ecadb57SMathias Bauer		sPath = oFileDialog.Files(0)
1501ecadb57SMathias Bauer		oStoreProperties(0).Name = &quot;FilterName&quot;
1511ecadb57SMathias Bauer		oStoreProperties(0).Value = &quot;XHP_Help&quot;
1521ecadb57SMathias Bauer		SetMetaDataOnSave(sPath)
1531ecadb57SMathias Bauer		oDoc.StoreAsUrl(sPath, oStoreProperties())
1541ecadb57SMathias Bauer	Else
1551ecadb57SMathias Bauer		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
1561ecadb57SMathias Bauer		oDoc.dispose
1571ecadb57SMathias Bauer	End If
1581ecadb57SMathias Bauer	oFileDialog.Dispose()
1591ecadb57SMathias Bauer
1601ecadb57SMathias Bauer	ERRHANDLE:
1611ecadb57SMathias Bauer		If Err &lt;&gt; 0 Then
1621ecadb57SMathias Bauer			msgbox &quot;Error: &quot;+chr(13)+ Error$+chr(13)+&quot;Cannot save file.&quot;+chr(13),48,&quot;Fatal Error&quot;
1631ecadb57SMathias Bauer			oDoc.dispose
1641ecadb57SMathias Bauer		End If
1651ecadb57SMathias BauerEnd Sub
1661ecadb57SMathias Bauer
1671ecadb57SMathias BauerSub CheckOnLoad
1681ecadb57SMathias Bauer&apos;	oDoc = StarDesktop.CurrentComponent
1691ecadb57SMathias Bauer&apos;	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
1701ecadb57SMathias Bauer&apos;	If sDocRoot=&quot;&quot; Then
1711ecadb57SMathias Bauer&apos;		msgbox(&quot;No document root set. Please set the root folder for your documents.&quot;)
1721ecadb57SMathias Bauer&apos;		sDocRoot = SetDocumentRoot
1731ecadb57SMathias Bauer&apos;	End If
1741ecadb57SMathias Bauer&apos;	msgbox(HasUnoInterfaces(oDoc, &quot;com.sun.star.lang.XServiceInfo&quot;))
1751ecadb57SMathias Bauer&apos;	sFName = oDoc.URL
1761ecadb57SMathias Bauer&apos;	msgbox(sFName+chr(13)+sDocRoot)
1771ecadb57SMathias Bauer&apos;	If not(IsSubDir(sFName,sDocRoot)) Then
1781ecadb57SMathias Bauer&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;)
1791ecadb57SMathias Bauer&apos;	End If
1801ecadb57SMathias BauerEnd Sub
1811ecadb57SMathias Bauer
1821ecadb57SMathias BauerSub DisplayVersion
183*4fec54abSmseidel	msgbox &quot;OpenOffice Help Authoring Framework&quot;+chr(13)+&quot;Version &quot;+Version,256
1841ecadb57SMathias BauerEnd Sub
185841807c9SAndrew Rist</script:module>
186