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