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