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