1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<!--*********************************************************** 4 * 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * 22 ***********************************************************--> 23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Embed" script:language="StarBasic">' *** MODULE EMBED *** 24 25Dim oDialog AS Object 26Dim oBrowseDialog As Object 27Dim document AS Object 28Dim arParas(0) As String 29Dim arSecs(0) As String 30Dim arVars(0) As String 31 32'======================================================= 33' Main 34'------------------------------------------------------- 35' Embeds a variable or a section 36'======================================================= 37Sub Main(optional bCR As Boolean) 38 39 If not IsHelpFile Then 40 msgbox(strErr_NoHelpFile) 41 Exit Sub 42 End If 43 44 GlobalScope.BasicLibraries.loadLibrary("Tools") 45 46 document = StarDesktop.CurrentComponent 47 48 BasicLibraries.LoadLibrary("HelpAuthoring") 49 oDialog = LoadDialog("HelpAuthoring", "dlgEmbed") 50 oDialogModel = oDialog.Model 51 52 oTxtFilePath = oDialog.GetControl("txtFilePath") ' path to file, rel to Docroot 53 oTxtID = oDialog.GetControl("txtID") ' anchor 54 oTxtHidFName = oDialog.GetControl("txtHidFName") ' pure filename 55 oOpVariable = oDialog.GetControl("opVariable") 56 oOpSection = oDialog.GetControl("opSection") 57 58 DocRoot = ReadConfig("HelpPrefix") 59 EmbedFolder = ReadConfig("LastEmbedDir") 60 EmbedFile = ReadConfig("LastEmbedFile") 61 EmbedID = ReadConfig("LastEmbedAnchor") 62 EmbedType = ReadConfig("LastEmbedType") 63 If EmbedType = "Variable" Then 64 oOpVariable.State = TRUE 65 Else 66 oOpVariable.State = FALSE 67 End If 68 SetLabel 69 70 If IsSubDir(EmbedFolder,DocRoot) Then 71 RelDir = Right(EmbedFolder,Len(EmbedFolder)-Len(DocRoot)) 72 If Dir(DocRoot+RelDir+EmbedFile) > "" Then 73 oTxtFilePath.Text = RelDir+EmbedFile 74 oTxtHidFName.Text = DocRoot+RelDir+EmbedFile 75 oTxtID.Text = EmbedID 76 End If 77 End If 78 79 80 GoForIt = 1 81 82 If (oDialog.Execute() = 1 AND oTxtFilePath.Text <> "") Then 83' msgbox (oTxtFilePath.Text) 84 85 If oTxtID.Text = "" Then 86 msgbox "You did not specify a section or variable to embed.",256 87 Else 88 WriteConfig("LastEmbedAnchor",oTxtID.Text) 89 If oOpVariable.State Then 90 txtEmbed = oTxtFilePath.Text + "#" + oTxtID.Text 91 InsertTag("EMBEDVAR","<EMBEDVAR var=""" + txtEmbed + """>","hlp_aux_tag") 92 SetCharStyle("Default") 93 WriteConfig("LastEmbedType","Variable") 94 Else 95 txtEmbed = oTxtFilePath.Text + "#" + oTxtID.Text 96 CR 97 SetParaStyle("hlp_aux_embed") 98 SetCharStyle("hlp_aux_tag") 99 InsertTag("EMBED","<EMBED href=""" + txtEmbed + """>","hlp_aux_tag") 100 CR 101 WriteConfig("LastEmbedType","Section") 102 End If 103 End If 104 End If 105 oDialog.dispose 106End Sub 107 108'======================================================= 109' SetLabel 110'------------------------------------------------------- 111' Changes the text field label in the dialog 112'======================================================= 113Sub SetLabel 114 olblID = oDialog.GetControl("lblID") 115 oOpVariable = oDialog.GetControl("opVariable") 116 If oOpVariable.getState Then 117 olblID.setText("Variable ID") 118 oDialog.Title = "Embed Variable" 119 Else 120 olblID.setText("Section or Paragraph ID") 121 oDialog.Title = "Embed Section" 122 End If 123End Sub 124 125Sub GetFile 126Dim ListAny(0) as Long 127 ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE 128 oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker") 129 oFileDialog.Initialize(ListAny()) 130 131 DocRoot = ReadConfig("HelpPrefix") 132 sLastEmbedDir = ReadConfig("LastEmbedDir") 133 sLastEmbedFile = ReadConfig("LastEmbedFile") 134 135 If IsSubDir(sLastEmbedDir,DocRoot) Then 136 oFileDialog.setDisplayDirectory(sLastEmbedDir) 137 If sLastEmbedFile <> "" AND Dir(sLastEmbedDir+sLastEmbedFile) > "" Then 138 oFileDialog.setDefaultName(sLastEmbedFile) 139 End If 140 Else 141 oFileDialog.setDisplayDirectory(DocRoot) 142 End If 143 144 oMasterKey = GetRegistryKeyContent("org.openoffice.TypeDetection.Types/") 145 oTypes() = oMasterKey.Types 146 oFileDialog.AppendFilter("Help", "*.xhp") 147 148 oFileDialog.SetTitle("Embed From Help File") 149 iAccept = oFileDialog.Execute() 150 If iAccept = 1 Then 151 sPath = oFileDialog.Files(0) 152 sCurDir = oFileDialog.getDisplayDirectory +"/" 153 WriteConfig("LastEmbedDir",sCurDir) 154 LastFile = Right(sPath, Len(sPath) - Len(sCurDir)) 155 WriteConfig("LastEmbedFile",LastFile) 156 157 oTxtPath = oDialog.GetControl("txtFilePath") 158 oTxtHidFName = oDialog.GetControl("txtHidFName") 159 oTxtHidFName.Text = sPath 160 161 If IsSubDir(sCurDir,DocRoot) Then 162 oTxtPath.Text = GetRelPath(sPath, DocRoot) 163 Else 164 oTxtPath.Text = sPath 165 msgbox("File is outside of your Document Root",48,"Warning") 166 End If 167 168 oButBrowseIDs = oDialog.GetControl("butBrowseIDs") 169 oButBrowseIDs.Enable = true 170 End If 171 172End Sub 173 174Sub UpdateFileName 175 oTxtPath = oDialog.GetControl("txtFilePath") 176 ShortFName = oTxtPath.Text 177 178 If ShortFName > "" Then 179 180 oTxtHidFName = oDialog.GetControl("txtHidFName") 181 FName = oTxtHidFName.Text 182 183 If Right(FName, Len(ShortFName)) <> ShortFName Then 184 ' oTxtHidFName.Text = MakeAbsPath(ShortFName) 185 oTxtHidFName.Text = ShortFName 186 End If 187 188 oButBrowseIDs = oDialog.GetControl("butBrowseIDs") 189 If not(FileExists(oTxtHidFName.Text)) Then 190 msgbox oTxtHidFName.Text+" cannot be found.",48,"D'oh!" 191 oButBrowseIDs.Enable = false 192 Else 193 oButBrowseIDs.Enable = true 194 End If 195 End If 196End Sub 197 198Sub BrowseEmbed 199 BasicLibraries.LoadLibrary("HelpAuthoring") 200 oBrowseDialog = LoadDialog("HelpAuthoring", "dlg_BrowseEmbed") 201 oOpVariable = oDialog.GetControl("opVariable") 202 oTxtPath = oDialog.GetControl("txtFilePath") 203 oTxtHidFName = oDialog.GetControl("txtHidFName") 204 filename = oTxtHidFName.Text 205 206 ReDim arParas(0) 207 ReDim arVars(0) 208 ReDim arSecs(0) 209 210' msgbox(filename) 211 212 iNumber = Freefile 213 If FileExists(filename) Then 214 Dim arLines(0) As String 215 Open filename For Input As iNumber 216 Do While (not eof(iNumber)) 217 Line Input #iNumber, sLine 218 sDim = ubound(arLines())+1 219 ReDim Preserve arLines(sDim) 220 arLines(sDim) = sLine 221 Loop 222 Close #iNumber 223 sContent = join(arLines()," ") 224 225 arTmp() = split(sContent,"<paragraph") 226 For n=1 to ubound(arTmp()) 227 If arTmp(n) <> "" Then 228 arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),"id=")-3) 229 sId = Left(arTmp(n),Instr(arTmp(n),"""")-1) 230 arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),">")) 231 arTmp(n) = Left(arTmp(n),Instr(arTmp(n),"</paragraph>")-1) 232 If Len(arTmp(n) > 100) Then 233 arTmp(n) = Left(arTmp(n),100)+"..." 234 End If 235 sDim = ubound(arParas()) 236 arParas(sDim) = sId+": "+arTmp(n) 237 sDim = ubound(arParas())+1 238 ReDim Preserve arParas(sDim) 239 End If 240 Next n 241 242 arTmp() = split(sContent,"<section") 243 For n=1 to ubound(arTmp()) 244 If arTmp(n) <> "" Then 245 arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),"id=")-3) 246 sId = Left(arTmp(n),Instr(arTmp(n),"""")-1) 247 arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),">")) 248 If Instr(arTmp(n),"</section>")>0 Then 249 arTmp(n) = Left(arTmp(n),Instr(arTmp(n),"</section>")-1) 250 End If 251 If Len(arTmp(n) > 100) Then 252 arTmp(n) = Left(arTmp(n),100)+"..." 253 End If 254 sDim = ubound(arSecs()) 255 arSecs(sDim) = sId+": "+arTmp(n) 256 sDim = ubound(arSecs())+1 257 ReDim Preserve arSecs(sDim) 258 End If 259 Next n 260 261 arTmp() = split(sContent,"<variable") 262 For n=1 to ubound(arTmp()) 263 If arTmp(n) <> "" Then 264 arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),"id=")-3) 265 sId = Left(arTmp(n),Instr(arTmp(n),"""")-1) 266 arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),">")) 267 arTmp(n) = Left(arTmp(n),Instr(arTmp(n),"</variable>")-1) 268 If Len(arTmp(n) > 100) Then 269 arTmp(n) = Left(arTmp(n),100)+"..." 270 End If 271 sDim = ubound(arVars()) 272 arVars(sDim) = sId+": "+arTmp(n) 273 sDim = ubound(arVars())+1 274 ReDim Preserve arVars(sDim) 275 End If 276 Next n 277 278 ShowSecs 279 280 If oBrowseDialog.Execute() = 1 Then 281 olbElements = oBrowseDialog.GetControl("lbElements") 282 sSelected = olbElements.SelectedItem 283 sSelected = Left(sSelected,Instr(sSelected,":")-1) 284 oTxtID = oDialog.GetControl("txtID") 285 oTxtID.Text = sSelected 286 End If 287 Else 288 msgbox "Cannot open "+filename,48,"Error" 289 End If 290End Sub 291 292Sub UpdateLIst 293 oOpSections = oBrowseDialog.GetControl("opSections") 294 oOpVariables = oBrowseDialog.GetControl("opVariables") 295 oOpParas = oBrowseDialog.GetControl("opParas") 296 If oOpSections.getState Then 297 ShowSecs 298 ElseIf oOpVariables.getState Then 299 ShowVars 300 ElseIf oOpParas.getState Then 301 ShowParas 302 End If 303End Sub 304 305Sub ShowSecs 306 olbElements = oBrowseDialog.GetControl("lbElements") 307 olbElements.RemoveItems(0,olbElements.ItemCount) 308 olbElements.AddItems(arSecs(),ubound(arSecs())) 309 oOpSection = oDialog.GetControl("opSection") 310 oOpSection.setState(TRUE) 311 SetLabel 312End Sub 313 314Sub ShowVars 315 olbElements = oBrowseDialog.GetControl("lbElements") 316 olbElements.RemoveItems(0,olbElements.ItemCount) 317 olbElements.AddItems(arVars(),ubound(arVars())) 318 oOpVariable = oDialog.GetControl("opVariable") 319 oOpVariable.setState(TRUE) 320 SetLabel 321End Sub 322 323Sub ShowParas 324 olbElements = oBrowseDialog.GetControl("lbElements") 325 olbElements.RemoveItems(0,olbElements.ItemCount) 326 olbElements.AddItems(arParas(),ubound(arParas())) 327 oOpVariable = oDialog.GetControl("opSection") 328 oOpVariable.setState(TRUE) 329 SetLabel 330End Sub 331 332Sub CheckButton 333 olbElements = oBrowseDialog.GetControl("lbElements") 334 obutSelect = oBrowseDialog.GetControl("butSelect") 335 sSelected = olbElements.SelectedItem 336 If sSelected = "" Then 337 oButSelect.enable = false 338 Else 339 oButSelect.enable = true 340 End If 341End Sub 342 343 344Function IsSubDir(D as String, R as String) 345 IsSubDir = (Left(D,Len(R)) = R) 346End Function 347</script:module> 348