' *** MODULE EMBED *** Dim oDialog AS Object Dim oBrowseDialog As Object Dim document AS Object Dim arParas(0) As String Dim arSecs(0) As String Dim arVars(0) As String '======================================================= ' Main '------------------------------------------------------- ' Embeds a variable or a section '======================================================= Sub Main(optional bCR As Boolean) If not IsHelpFile Then msgbox(strErr_NoHelpFile) Exit Sub End If GlobalScope.BasicLibraries.loadLibrary("Tools") document = StarDesktop.CurrentComponent BasicLibraries.LoadLibrary("HelpAuthoring") oDialog = LoadDialog("HelpAuthoring", "dlgEmbed") oDialogModel = oDialog.Model oTxtFilePath = oDialog.GetControl("txtFilePath") ' path to file, rel to Docroot oTxtID = oDialog.GetControl("txtID") ' anchor oTxtHidFName = oDialog.GetControl("txtHidFName") ' pure filename oOpVariable = oDialog.GetControl("opVariable") oOpSection = oDialog.GetControl("opSection") DocRoot = ReadConfig("HelpPrefix") EmbedFolder = ReadConfig("LastEmbedDir") EmbedFile = ReadConfig("LastEmbedFile") EmbedID = ReadConfig("LastEmbedAnchor") EmbedType = ReadConfig("LastEmbedType") If EmbedType = "Variable" Then oOpVariable.State = TRUE Else oOpVariable.State = FALSE End If SetLabel If IsSubDir(EmbedFolder,DocRoot) Then RelDir = Right(EmbedFolder,Len(EmbedFolder)-Len(DocRoot)) If Dir(DocRoot+RelDir+EmbedFile) > "" Then oTxtFilePath.Text = RelDir+EmbedFile oTxtHidFName.Text = DocRoot+RelDir+EmbedFile oTxtID.Text = EmbedID End If End If GoForIt = 1 If (oDialog.Execute() = 1 AND oTxtFilePath.Text <> "") Then ' msgbox (oTxtFilePath.Text) If oTxtID.Text = "" Then msgbox "You did not specify a section or variable to embed.",256 Else WriteConfig("LastEmbedAnchor",oTxtID.Text) If oOpVariable.State Then txtEmbed = oTxtFilePath.Text + "#" + oTxtID.Text InsertTag("EMBEDVAR","<EMBEDVAR var=""" + txtEmbed + """>","hlp_aux_tag") SetCharStyle("Default") WriteConfig("LastEmbedType","Variable") Else txtEmbed = oTxtFilePath.Text + "#" + oTxtID.Text CR SetParaStyle("hlp_aux_embed") SetCharStyle("hlp_aux_tag") InsertTag("EMBED","<EMBED href=""" + txtEmbed + """>","hlp_aux_tag") CR WriteConfig("LastEmbedType","Section") End If End If End If oDialog.dispose End Sub '======================================================= ' SetLabel '------------------------------------------------------- ' Changes the text field label in the dialog '======================================================= Sub SetLabel olblID = oDialog.GetControl("lblID") oOpVariable = oDialog.GetControl("opVariable") If oOpVariable.getState Then olblID.setText("Variable ID") oDialog.Title = "Embed Variable" Else olblID.setText("Section or Paragraph ID") oDialog.Title = "Embed Section" End If End Sub Sub GetFile Dim ListAny(0) as Long ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker") oFileDialog.Initialize(ListAny()) DocRoot = ReadConfig("HelpPrefix") sLastEmbedDir = ReadConfig("LastEmbedDir") sLastEmbedFile = ReadConfig("LastEmbedFile") If IsSubDir(sLastEmbedDir,DocRoot) Then oFileDialog.setDisplayDirectory(sLastEmbedDir) If sLastEmbedFile <> "" AND Dir(sLastEmbedDir+sLastEmbedFile) > "" Then oFileDialog.setDefaultName(sLastEmbedFile) End If Else oFileDialog.setDisplayDirectory(DocRoot) End If oMasterKey = GetRegistryKeyContent("org.openoffice.TypeDetection.Types/") oTypes() = oMasterKey.Types oFileDialog.AppendFilter("Help", "*.xhp") oFileDialog.SetTitle("Embed From Help File") iAccept = oFileDialog.Execute() If iAccept = 1 Then sPath = oFileDialog.Files(0) sCurDir = oFileDialog.getDisplayDirectory +"/" WriteConfig("LastEmbedDir",sCurDir) LastFile = Right(sPath, Len(sPath) - Len(sCurDir)) WriteConfig("LastEmbedFile",LastFile) oTxtPath = oDialog.GetControl("txtFilePath") oTxtHidFName = oDialog.GetControl("txtHidFName") oTxtHidFName.Text = sPath If IsSubDir(sCurDir,DocRoot) Then oTxtPath.Text = GetRelPath(sPath, DocRoot) Else oTxtPath.Text = sPath msgbox("File is outside of your Document Root",48,"Warning") End If oButBrowseIDs = oDialog.GetControl("butBrowseIDs") oButBrowseIDs.Enable = true End If End Sub Sub UpdateFileName oTxtPath = oDialog.GetControl("txtFilePath") ShortFName = oTxtPath.Text If ShortFName > "" Then oTxtHidFName = oDialog.GetControl("txtHidFName") FName = oTxtHidFName.Text If Right(FName, Len(ShortFName)) <> ShortFName Then ' oTxtHidFName.Text = MakeAbsPath(ShortFName) oTxtHidFName.Text = ShortFName End If oButBrowseIDs = oDialog.GetControl("butBrowseIDs") If not(FileExists(oTxtHidFName.Text)) Then msgbox oTxtHidFName.Text+" cannot be found.",48,"D'oh!" oButBrowseIDs.Enable = false Else oButBrowseIDs.Enable = true End If End If End Sub Sub BrowseEmbed BasicLibraries.LoadLibrary("HelpAuthoring") oBrowseDialog = LoadDialog("HelpAuthoring", "dlg_BrowseEmbed") oOpVariable = oDialog.GetControl("opVariable") oTxtPath = oDialog.GetControl("txtFilePath") oTxtHidFName = oDialog.GetControl("txtHidFName") filename = oTxtHidFName.Text ReDim arParas(0) ReDim arVars(0) ReDim arSecs(0) ' msgbox(filename) iNumber = Freefile If FileExists(filename) Then Dim arLines(0) As String Open filename For Input As iNumber Do While (not eof(iNumber)) Line Input #iNumber, sLine sDim = ubound(arLines())+1 ReDim Preserve arLines(sDim) arLines(sDim) = sLine Loop Close #iNumber sContent = join(arLines()," ") arTmp() = split(sContent,"<paragraph") For n=1 to ubound(arTmp()) If arTmp(n) <> "" Then arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),"id=")-3) sId = Left(arTmp(n),Instr(arTmp(n),"""")-1) arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),">")) arTmp(n) = Left(arTmp(n),Instr(arTmp(n),"</paragraph>")-1) If Len(arTmp(n) > 100) Then arTmp(n) = Left(arTmp(n),100)+"..." End If sDim = ubound(arParas()) arParas(sDim) = sId+": "+arTmp(n) sDim = ubound(arParas())+1 ReDim Preserve arParas(sDim) End If Next n arTmp() = split(sContent,"<section") For n=1 to ubound(arTmp()) If arTmp(n) <> "" Then arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),"id=")-3) sId = Left(arTmp(n),Instr(arTmp(n),"""")-1) arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),">")) If Instr(arTmp(n),"</section>")>0 Then arTmp(n) = Left(arTmp(n),Instr(arTmp(n),"</section>")-1) End If If Len(arTmp(n) > 100) Then arTmp(n) = Left(arTmp(n),100)+"..." End If sDim = ubound(arSecs()) arSecs(sDim) = sId+": "+arTmp(n) sDim = ubound(arSecs())+1 ReDim Preserve arSecs(sDim) End If Next n arTmp() = split(sContent,"<variable") For n=1 to ubound(arTmp()) If arTmp(n) <> "" Then arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),"id=")-3) sId = Left(arTmp(n),Instr(arTmp(n),"""")-1) arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),">")) arTmp(n) = Left(arTmp(n),Instr(arTmp(n),"</variable>")-1) If Len(arTmp(n) > 100) Then arTmp(n) = Left(arTmp(n),100)+"..." End If sDim = ubound(arVars()) arVars(sDim) = sId+": "+arTmp(n) sDim = ubound(arVars())+1 ReDim Preserve arVars(sDim) End If Next n ShowSecs If oBrowseDialog.Execute() = 1 Then olbElements = oBrowseDialog.GetControl("lbElements") sSelected = olbElements.SelectedItem sSelected = Left(sSelected,Instr(sSelected,":")-1) oTxtID = oDialog.GetControl("txtID") oTxtID.Text = sSelected End If Else msgbox "Cannot open "+filename,48,"Error" End If End Sub Sub UpdateLIst oOpSections = oBrowseDialog.GetControl("opSections") oOpVariables = oBrowseDialog.GetControl("opVariables") oOpParas = oBrowseDialog.GetControl("opParas") If oOpSections.getState Then ShowSecs ElseIf oOpVariables.getState Then ShowVars ElseIf oOpParas.getState Then ShowParas End If End Sub Sub ShowSecs olbElements = oBrowseDialog.GetControl("lbElements") olbElements.RemoveItems(0,olbElements.ItemCount) olbElements.AddItems(arSecs(),ubound(arSecs())) oOpSection = oDialog.GetControl("opSection") oOpSection.setState(TRUE) SetLabel End Sub Sub ShowVars olbElements = oBrowseDialog.GetControl("lbElements") olbElements.RemoveItems(0,olbElements.ItemCount) olbElements.AddItems(arVars(),ubound(arVars())) oOpVariable = oDialog.GetControl("opVariable") oOpVariable.setState(TRUE) SetLabel End Sub Sub ShowParas olbElements = oBrowseDialog.GetControl("lbElements") olbElements.RemoveItems(0,olbElements.ItemCount) olbElements.AddItems(arParas(),ubound(arParas())) oOpVariable = oDialog.GetControl("opSection") oOpVariable.setState(TRUE) SetLabel End Sub Sub CheckButton olbElements = oBrowseDialog.GetControl("lbElements") obutSelect = oBrowseDialog.GetControl("butSelect") sSelected = olbElements.SelectedItem If sSelected = "" Then oButSelect.enable = false Else oButSelect.enable = true End If End Sub Function IsSubDir(D as String, R as String) IsSubDir = (Left(D,Len(R)) = R) End Function