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