1*1ecadb57SMathias Bauer<?xml version="1.0" encoding="UTF-8"?> 2*1ecadb57SMathias Bauer<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*1ecadb57SMathias Bauer<script:module xmlns:script="http://openoffice.org/2000/script" script:name="_Main" script:language="StarBasic">' Set of Macros used for Help Authoring 4*1ecadb57SMathias Bauer' ===================================== 5*1ecadb57SMathias Bauer' Version 6*1ecadb57SMathias Bauer' ------------------------------------- 7*1ecadb57SMathias Bauer' 8*1ecadb57SMathias Bauer 9*1ecadb57SMathias Bauer' *********************************************************************** 10*1ecadb57SMathias Bauer' * 11*1ecadb57SMathias Bauer' * The Contents of this file are made available subject to the terms of 12*1ecadb57SMathias Bauer' * either of the following licenses 13*1ecadb57SMathias Bauer' * 14*1ecadb57SMathias Bauer' * - GNU Lesser General Public License Version 2.1 15*1ecadb57SMathias Bauer' * - Sun Industry Standards Source License Version 1.1 16*1ecadb57SMathias Bauer' * 17*1ecadb57SMathias Bauer' * Sun Microsystems Inc., October, 2000 18*1ecadb57SMathias Bauer' * 19*1ecadb57SMathias Bauer' * GNU Lesser General Public License Version 2.1 20*1ecadb57SMathias Bauer' * ============================================= 21*1ecadb57SMathias Bauer' * Copyright 2000 by Sun Microsystems, Inc. 22*1ecadb57SMathias Bauer' * 901 San Antonio Road, Palo Alto, CA 94303, USA 23*1ecadb57SMathias Bauer' * 24*1ecadb57SMathias Bauer' * This library is free software; you can redistribute it and/or 25*1ecadb57SMathias Bauer' * modify it under the terms of the GNU Lesser General Public 26*1ecadb57SMathias Bauer' * License version 2.1, as published by the Free Software Foundation. 27*1ecadb57SMathias Bauer' * 28*1ecadb57SMathias Bauer' * This library is distributed in the hope that it will be useful, 29*1ecadb57SMathias Bauer' * but WITHOUT ANY WARRANTY; without even the implied warranty of 30*1ecadb57SMathias Bauer' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 31*1ecadb57SMathias Bauer' * Lesser General Public License for more details. 32*1ecadb57SMathias Bauer' * 33*1ecadb57SMathias Bauer' * You should have received a copy of the GNU Lesser General Public 34*1ecadb57SMathias Bauer' * License along with this library; if not, write to the Free Software 35*1ecadb57SMathias Bauer' * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 36*1ecadb57SMathias Bauer' * MA 02111-1307 USA 37*1ecadb57SMathias Bauer' * 38*1ecadb57SMathias Bauer' * 39*1ecadb57SMathias Bauer' * Sun Industry Standards Source License Version 1.1 40*1ecadb57SMathias Bauer' * ================================================= 41*1ecadb57SMathias Bauer' * The contents of this file are subject to the Sun Industry Standards 42*1ecadb57SMathias Bauer' * Source License Version 1.1 (the "License"); You may not use this file 43*1ecadb57SMathias Bauer' * except in compliance with the License. You may obtain a copy of the 44*1ecadb57SMathias Bauer' * License at http://www.openoffice.org/license.html. 45*1ecadb57SMathias Bauer' * 46*1ecadb57SMathias Bauer' * Software provided under this License is provided on an "AS IS" basis, 47*1ecadb57SMathias Bauer' * WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, 48*1ecadb57SMathias Bauer' * WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, 49*1ecadb57SMathias Bauer' * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. 50*1ecadb57SMathias Bauer' * See the License for the specific provisions governing your rights and 51*1ecadb57SMathias Bauer' * obligations concerning the Software. 52*1ecadb57SMathias Bauer' * 53*1ecadb57SMathias Bauer' * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. 54*1ecadb57SMathias Bauer' * 55*1ecadb57SMathias Bauer' * Copyright: 2000 by Sun Microsystems, Inc. 56*1ecadb57SMathias Bauer' * 57*1ecadb57SMathias Bauer' * All Rights Reserved. 58*1ecadb57SMathias Bauer' * 59*1ecadb57SMathias Bauer' * Contributor(s): _______________________________________ 60*1ecadb57SMathias Bauer' * 61*1ecadb57SMathias Bauer' * 62*1ecadb57SMathias Bauer' ************************************************************************ 63*1ecadb57SMathias Bauer 64*1ecadb57SMathias BauerGlobal Const Version = "v3.20100805" 65*1ecadb57SMathias Bauer 66*1ecadb57SMathias BauerGlobal Const strErr_NoHelpFile = "Not a Help File" 67*1ecadb57SMathias Bauer 68*1ecadb57SMathias Bauer'======================================================= 69*1ecadb57SMathias Bauer' Main 70*1ecadb57SMathias Bauer'------------------------------------------------------- 71*1ecadb57SMathias Bauer' Ensure that necessary library functions are available 72*1ecadb57SMathias Bauer'======================================================= 73*1ecadb57SMathias BauerSub Main 74*1ecadb57SMathias Bauer GlobalScope.BasicLibraries.loadLibrary("Tools") 75*1ecadb57SMathias BauerEnd Sub 76*1ecadb57SMathias Bauer 77*1ecadb57SMathias Bauer'======================================================= 78*1ecadb57SMathias Bauer' SetMetaDataOnSave 79*1ecadb57SMathias Bauer'------------------------------------------------------- 80*1ecadb57SMathias Bauer' Sets the document meta data. It is called when 81*1ecadb57SMathias Bauer' the document is saved. It changes the data and 82*1ecadb57SMathias Bauer' then saves it again. 83*1ecadb57SMathias Bauer'======================================================= 84*1ecadb57SMathias BauerSub SetMetaDataOnSave(Path as String) 85*1ecadb57SMathias Bauer 86*1ecadb57SMathias Bauer document = StarDesktop.CurrentComponent 87*1ecadb57SMathias Bauer sDocRoot = ReadConfig("HelpPrefix") 88*1ecadb57SMathias Bauer 89*1ecadb57SMathias Bauer If Path = "" Then 90*1ecadb57SMathias Bauer Path = document.URL 91*1ecadb57SMathias Bauer End If 92*1ecadb57SMathias Bauer 93*1ecadb57SMathias Bauer If not(IsSubDir(Path,sDocRoot)) Then ' doesn'tr work when resaving the file since it contains the OLD url (before resave) 94*1ecadb57SMathias 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") 95*1ecadb57SMathias Bauer Else 96*1ecadb57SMathias Bauer Path = Right(Path,Len(Path)-Len(sDocRoot)) 97*1ecadb57SMathias Bauer End If 98*1ecadb57SMathias Bauer 99*1ecadb57SMathias Bauer document.DocumentInfo.SetUserFieldName(0,"Indexer") 100*1ecadb57SMathias Bauer document.DocumentInfo.SetUserFieldName(1,"ID") 101*1ecadb57SMathias Bauer' document.DocumentInfo.SetUserFieldName(2,"Comment") 102*1ecadb57SMathias Bauer document.DocumentInfo.SetPropertyValue("Subject",Path) 103*1ecadb57SMathias Bauer 104*1ecadb57SMathias Bauer 105*1ecadb57SMathias BauerEnd Sub 106*1ecadb57SMathias Bauer 107*1ecadb57SMathias Bauer'======================================================= 108*1ecadb57SMathias Bauer' ValidateOnSave 109*1ecadb57SMathias Bauer'------------------------------------------------------- 110*1ecadb57SMathias Bauer' Ensures that the document is validated when saved 111*1ecadb57SMathias Bauer' should be bound to the "Document Save" event but 112*1ecadb57SMathias Bauer' currently isn't 113*1ecadb57SMathias Bauer'======================================================= 114*1ecadb57SMathias BauerSub ValidateOnSave 115*1ecadb57SMathias Bauer BasicLibraries.LoadLibrary("HelpAuthoring") 116*1ecadb57SMathias Bauer document = StarDesktop.CurrentComponent 117*1ecadb57SMathias Bauer If document.URL <> "" Then ' not initial save 118*1ecadb57SMathias Bauer If IsHelpFile Then 119*1ecadb57SMathias Bauer SetMetaDataOnSave("") 120*1ecadb57SMathias Bauer ValidateXHP 121*1ecadb57SMathias Bauer End If 122*1ecadb57SMathias Bauer End If 123*1ecadb57SMathias BauerEnd Sub 124*1ecadb57SMathias Bauer 125*1ecadb57SMathias Bauer 126*1ecadb57SMathias Bauer'======================================================= 127*1ecadb57SMathias Bauer' CreateFile 128*1ecadb57SMathias Bauer'------------------------------------------------------- 129*1ecadb57SMathias Bauer' Creates a new help file based on the help template 130*1ecadb57SMathias Bauer' and calls the save dialog 131*1ecadb57SMathias Bauer'======================================================= 132*1ecadb57SMathias BauerSub CreateFile 133*1ecadb57SMathias Bauer GlobalScope.BasicLibraries.loadLibrary("Tools") 134*1ecadb57SMathias Bauer oPath = createUNOService("com.sun.star.util.PathSettings") 135*1ecadb57SMathias Bauer arPaths = Split(oPath.Template,";") ' get the paths to the templates from the configuration 136*1ecadb57SMathias Bauer sHelpTemplate = "" 137*1ecadb57SMathias Bauer 138*1ecadb57SMathias Bauer ' change stw extension to ott extension for template 139*1ecadb57SMathias Bauer 140*1ecadb57SMathias Bauer For i=0 to ubound(arPaths) ' see if the template path contains the help template 141*1ecadb57SMathias Bauer If FileExists(arPaths(i)+"/Help/xmlhelptemplate.ott") Then 142*1ecadb57SMathias Bauer sHelpTemplate = arPaths(i)+"/Help/xmlhelptemplate.ott" 143*1ecadb57SMathias Bauer End If 144*1ecadb57SMathias Bauer Next i 145*1ecadb57SMathias Bauer 146*1ecadb57SMathias Bauer If sHelpTemplate = "" Then 147*1ecadb57SMathias Bauer msgbox "Cannot find the help template.",256 148*1ecadb57SMathias Bauer Else 149*1ecadb57SMathias Bauer oDoc = StarDesktop.loadComponentFromURL(sHelpTemplate,"_blank",0,Array()) 150*1ecadb57SMathias Bauer SaveAs(oDoc) 151*1ecadb57SMathias Bauer End If 152*1ecadb57SMathias Bauer 153*1ecadb57SMathias BauerEnd Sub 154*1ecadb57SMathias Bauer 155*1ecadb57SMathias Bauer'======================================================= 156*1ecadb57SMathias Bauer' SaveAs 157*1ecadb57SMathias Bauer'------------------------------------------------------- 158*1ecadb57SMathias Bauer' Initially saves a new help file on creation. 159*1ecadb57SMathias Bauer' Is called from CreateFile 160*1ecadb57SMathias Bauer'======================================================= 161*1ecadb57SMathias BauerSub SaveAs(oDoc As Object) 162*1ecadb57SMathias BauerDim ListAny(0) as Long 163*1ecadb57SMathias BauerDim oStoreProperties(0) as New com.sun.star.beans.PropertyValue 164*1ecadb57SMathias Bauer On Local Error Goto ERRHANDLE: 165*1ecadb57SMathias Bauer 166*1ecadb57SMathias Bauer sLastSaveDir = ReadConfig("LastSaveDir") 167*1ecadb57SMathias Bauer sDocRoot = ReadConfig("HelpPrefix") 168*1ecadb57SMathias Bauer 169*1ecadb57SMathias Bauer ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD 170*1ecadb57SMathias Bauer oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker") 171*1ecadb57SMathias Bauer oFileDialog.Initialize(ListAny()) 172*1ecadb57SMathias Bauer 173*1ecadb57SMathias Bauer If sLastSaveDir <> "" AND IsSubDir(sLastSaveDir,sDocRoot) Then 174*1ecadb57SMathias Bauer oFileDialog.setDisplayDirectory(sLastSaveDir) 175*1ecadb57SMathias Bauer Else 176*1ecadb57SMathias Bauer oFileDialog.setDisplayDirectory(sDocRoot) 177*1ecadb57SMathias Bauer End If 178*1ecadb57SMathias Bauer 179*1ecadb57SMathias Bauer oMasterKey = GetRegistryKeyContent("org.openoffice.Office.TypeDetection/") 180*1ecadb57SMathias Bauer oFilters() = oMasterKey.Filters 181*1ecadb57SMathias Bauer oFileDialog.AppendFilter("Help", "*.xhp") 182*1ecadb57SMathias Bauer 183*1ecadb57SMathias Bauer oFileDialog.SetTitle("Save Help File As") 184*1ecadb57SMathias Bauer iAccept = oFileDialog.Execute() 185*1ecadb57SMathias Bauer If iAccept = 1 Then 186*1ecadb57SMathias Bauer WriteConfig("LastSaveDir",oFileDialog.getDisplayDirectory+"/") 187*1ecadb57SMathias Bauer sPath = oFileDialog.Files(0) 188*1ecadb57SMathias Bauer oStoreProperties(0).Name = "FilterName" 189*1ecadb57SMathias Bauer oStoreProperties(0).Value = "XHP_Help" 190*1ecadb57SMathias Bauer SetMetaDataOnSave(sPath) 191*1ecadb57SMathias Bauer oDoc.StoreAsUrl(sPath, oStoreProperties()) 192*1ecadb57SMathias Bauer Else 193*1ecadb57SMathias Bauer msgbox "You must save a help document before you can work on it."+chr(13)+"This document will be disposed.", 48 194*1ecadb57SMathias Bauer oDoc.dispose 195*1ecadb57SMathias Bauer End If 196*1ecadb57SMathias Bauer oFileDialog.Dispose() 197*1ecadb57SMathias Bauer 198*1ecadb57SMathias Bauer ERRHANDLE: 199*1ecadb57SMathias Bauer If Err <> 0 Then 200*1ecadb57SMathias Bauer msgbox "Error: "+chr(13)+ Error$+chr(13)+"Cannot save file."+chr(13),48,"Fatal Error" 201*1ecadb57SMathias Bauer oDoc.dispose 202*1ecadb57SMathias Bauer End If 203*1ecadb57SMathias BauerEnd Sub 204*1ecadb57SMathias Bauer 205*1ecadb57SMathias BauerSub CheckOnLoad 206*1ecadb57SMathias Bauer' oDoc = StarDesktop.CurrentComponent 207*1ecadb57SMathias Bauer' sDocRoot = ReadConfig("HelpPrefix") 208*1ecadb57SMathias Bauer' If sDocRoot="" Then 209*1ecadb57SMathias Bauer' msgbox("No document root set. Please set the root folder for your documents.") 210*1ecadb57SMathias Bauer' sDocRoot = SetDocumentRoot 211*1ecadb57SMathias Bauer' End If 212*1ecadb57SMathias Bauer' msgbox(HasUnoInterfaces(oDoc, "com.sun.star.lang.XServiceInfo")) 213*1ecadb57SMathias Bauer' sFName = oDoc.URL 214*1ecadb57SMathias Bauer' msgbox(sFName+chr(13)+sDocRoot) 215*1ecadb57SMathias Bauer' If not(IsSubDir(sFName,sDocRoot)) Then 216*1ecadb57SMathias 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!") 217*1ecadb57SMathias Bauer' End If 218*1ecadb57SMathias BauerEnd Sub 219*1ecadb57SMathias Bauer 220*1ecadb57SMathias BauerSub DisplayVersion 221*1ecadb57SMathias Bauer msgbox "OpenOffice.org Help Authoring Framework"+chr(13)+"Version "+Version+chr(13)+chr(13)+"(c) 2010 Oracle, Licensed under LGPL",256 222*1ecadb57SMathias BauerEnd Sub 223*1ecadb57SMathias Bauer</script:module>