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