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