blob: 1682a190bf4e39349044e73fec4e678ddfc1e311 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<!--***********************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
***********************************************************-->
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Embed" script:language="StarBasic">&apos; *** 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
&apos;=======================================================
&apos; Main
&apos;-------------------------------------------------------
&apos; Embeds a variable or a section
&apos;=======================================================
Sub Main(optional bCR As Boolean)
If not IsHelpFile Then
msgbox(strErr_NoHelpFile)
Exit Sub
End If
GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
document = StarDesktop.CurrentComponent
BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgEmbed&quot;)
oDialogModel = oDialog.Model
oTxtFilePath = oDialog.GetControl(&quot;txtFilePath&quot;) &apos; path to file, rel to Docroot
oTxtID = oDialog.GetControl(&quot;txtID&quot;) &apos; anchor
oTxtHidFName = oDialog.GetControl(&quot;txtHidFName&quot;) &apos; pure filename
oOpVariable = oDialog.GetControl(&quot;opVariable&quot;)
oOpSection = oDialog.GetControl(&quot;opSection&quot;)
DocRoot = ReadConfig(&quot;HelpPrefix&quot;)
EmbedFolder = ReadConfig(&quot;LastEmbedDir&quot;)
EmbedFile = ReadConfig(&quot;LastEmbedFile&quot;)
EmbedID = ReadConfig(&quot;LastEmbedAnchor&quot;)
EmbedType = ReadConfig(&quot;LastEmbedType&quot;)
If EmbedType = &quot;Variable&quot; 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) &gt; &quot;&quot; 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 &lt;&gt; &quot;&quot;) Then
&apos; msgbox (oTxtFilePath.Text)
If oTxtID.Text = &quot;&quot; Then
msgbox &quot;You did not specify a section or variable to embed.&quot;,256
Else
WriteConfig(&quot;LastEmbedAnchor&quot;,oTxtID.Text)
If oOpVariable.State Then
txtEmbed = oTxtFilePath.Text + &quot;#&quot; + oTxtID.Text
InsertTag(&quot;EMBEDVAR&quot;,&quot;&lt;EMBEDVAR var=&quot;&quot;&quot; + txtEmbed + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_tag&quot;)
SetCharStyle(&quot;Default&quot;)
WriteConfig(&quot;LastEmbedType&quot;,&quot;Variable&quot;)
Else
txtEmbed = oTxtFilePath.Text + &quot;#&quot; + oTxtID.Text
CR
SetParaStyle(&quot;hlp_aux_embed&quot;)
SetCharStyle(&quot;hlp_aux_tag&quot;)
InsertTag(&quot;EMBED&quot;,&quot;&lt;EMBED href=&quot;&quot;&quot; + txtEmbed + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_tag&quot;)
CR
WriteConfig(&quot;LastEmbedType&quot;,&quot;Section&quot;)
End If
End If
End If
oDialog.dispose
End Sub
&apos;=======================================================
&apos; SetLabel
&apos;-------------------------------------------------------
&apos; Changes the text field label in the dialog
&apos;=======================================================
Sub SetLabel
olblID = oDialog.GetControl(&quot;lblID&quot;)
oOpVariable = oDialog.GetControl(&quot;opVariable&quot;)
If oOpVariable.getState Then
olblID.setText(&quot;Variable ID&quot;)
oDialog.Title = &quot;Embed Variable&quot;
Else
olblID.setText(&quot;Section or Paragraph ID&quot;)
oDialog.Title = &quot;Embed Section&quot;
End If
End Sub
Sub GetFile
Dim ListAny(0) as Long
ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
oFileDialog.Initialize(ListAny())
DocRoot = ReadConfig(&quot;HelpPrefix&quot;)
sLastEmbedDir = ReadConfig(&quot;LastEmbedDir&quot;)
sLastEmbedFile = ReadConfig(&quot;LastEmbedFile&quot;)
If IsSubDir(sLastEmbedDir,DocRoot) Then
oFileDialog.setDisplayDirectory(sLastEmbedDir)
If sLastEmbedFile &lt;&gt; &quot;&quot; AND Dir(sLastEmbedDir+sLastEmbedFile) &gt; &quot;&quot; Then
oFileDialog.setDefaultName(sLastEmbedFile)
End If
Else
oFileDialog.setDisplayDirectory(DocRoot)
End If
oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.TypeDetection.Types/&quot;)
oTypes() = oMasterKey.Types
oFileDialog.AppendFilter(&quot;Help&quot;, &quot;*.xhp&quot;)
oFileDialog.SetTitle(&quot;Embed From Help File&quot;)
iAccept = oFileDialog.Execute()
If iAccept = 1 Then
sPath = oFileDialog.Files(0)
sCurDir = oFileDialog.getDisplayDirectory +&quot;/&quot;
WriteConfig(&quot;LastEmbedDir&quot;,sCurDir)
LastFile = Right(sPath, Len(sPath) - Len(sCurDir))
WriteConfig(&quot;LastEmbedFile&quot;,LastFile)
oTxtPath = oDialog.GetControl(&quot;txtFilePath&quot;)
oTxtHidFName = oDialog.GetControl(&quot;txtHidFName&quot;)
oTxtHidFName.Text = sPath
If IsSubDir(sCurDir,DocRoot) Then
oTxtPath.Text = GetRelPath(sPath, DocRoot)
Else
oTxtPath.Text = sPath
msgbox(&quot;File is outside of your Document Root&quot;,48,&quot;Warning&quot;)
End If
oButBrowseIDs = oDialog.GetControl(&quot;butBrowseIDs&quot;)
oButBrowseIDs.Enable = true
End If
End Sub
Sub UpdateFileName
oTxtPath = oDialog.GetControl(&quot;txtFilePath&quot;)
ShortFName = oTxtPath.Text
If ShortFName &gt; &quot;&quot; Then
oTxtHidFName = oDialog.GetControl(&quot;txtHidFName&quot;)
FName = oTxtHidFName.Text
If Right(FName, Len(ShortFName)) &lt;&gt; ShortFName Then
&apos; oTxtHidFName.Text = MakeAbsPath(ShortFName)
oTxtHidFName.Text = ShortFName
End If
oButBrowseIDs = oDialog.GetControl(&quot;butBrowseIDs&quot;)
If not(FileExists(oTxtHidFName.Text)) Then
msgbox oTxtHidFName.Text+&quot; cannot be found.&quot;,48,&quot;D&apos;oh!&quot;
oButBrowseIDs.Enable = false
Else
oButBrowseIDs.Enable = true
End If
End If
End Sub
Sub BrowseEmbed
BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
oBrowseDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlg_BrowseEmbed&quot;)
oOpVariable = oDialog.GetControl(&quot;opVariable&quot;)
oTxtPath = oDialog.GetControl(&quot;txtFilePath&quot;)
oTxtHidFName = oDialog.GetControl(&quot;txtHidFName&quot;)
filename = oTxtHidFName.Text
ReDim arParas(0)
ReDim arVars(0)
ReDim arSecs(0)
&apos; 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(),&quot; &quot;)
arTmp() = split(sContent,&quot;&lt;paragraph&quot;)
For n=1 to ubound(arTmp())
If arTmp(n) &lt;&gt; &quot;&quot; Then
arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),&quot;id=&quot;)-3)
sId = Left(arTmp(n),Instr(arTmp(n),&quot;&quot;&quot;&quot;)-1)
arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),&quot;&gt;&quot;))
arTmp(n) = Left(arTmp(n),Instr(arTmp(n),&quot;&lt;/paragraph&gt;&quot;)-1)
If Len(arTmp(n) &gt; 100) Then
arTmp(n) = Left(arTmp(n),100)+&quot;...&quot;
End If
sDim = ubound(arParas())
arParas(sDim) = sId+&quot;: &quot;+arTmp(n)
sDim = ubound(arParas())+1
ReDim Preserve arParas(sDim)
End If
Next n
arTmp() = split(sContent,&quot;&lt;section&quot;)
For n=1 to ubound(arTmp())
If arTmp(n) &lt;&gt; &quot;&quot; Then
arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),&quot;id=&quot;)-3)
sId = Left(arTmp(n),Instr(arTmp(n),&quot;&quot;&quot;&quot;)-1)
arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),&quot;&gt;&quot;))
If Instr(arTmp(n),&quot;&lt;/section&gt;&quot;)&gt;0 Then
arTmp(n) = Left(arTmp(n),Instr(arTmp(n),&quot;&lt;/section&gt;&quot;)-1)
End If
If Len(arTmp(n) &gt; 100) Then
arTmp(n) = Left(arTmp(n),100)+&quot;...&quot;
End If
sDim = ubound(arSecs())
arSecs(sDim) = sId+&quot;: &quot;+arTmp(n)
sDim = ubound(arSecs())+1
ReDim Preserve arSecs(sDim)
End If
Next n
arTmp() = split(sContent,&quot;&lt;variable&quot;)
For n=1 to ubound(arTmp())
If arTmp(n) &lt;&gt; &quot;&quot; Then
arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),&quot;id=&quot;)-3)
sId = Left(arTmp(n),Instr(arTmp(n),&quot;&quot;&quot;&quot;)-1)
arTmp(n) = Right(arTmp(n),Len(arTmp(n))-Instr(arTmp(n),&quot;&gt;&quot;))
arTmp(n) = Left(arTmp(n),Instr(arTmp(n),&quot;&lt;/variable&gt;&quot;)-1)
If Len(arTmp(n) &gt; 100) Then
arTmp(n) = Left(arTmp(n),100)+&quot;...&quot;
End If
sDim = ubound(arVars())
arVars(sDim) = sId+&quot;: &quot;+arTmp(n)
sDim = ubound(arVars())+1
ReDim Preserve arVars(sDim)
End If
Next n
ShowSecs
If oBrowseDialog.Execute() = 1 Then
olbElements = oBrowseDialog.GetControl(&quot;lbElements&quot;)
sSelected = olbElements.SelectedItem
sSelected = Left(sSelected,Instr(sSelected,&quot;:&quot;)-1)
oTxtID = oDialog.GetControl(&quot;txtID&quot;)
oTxtID.Text = sSelected
End If
Else
msgbox &quot;Cannot open &quot;+filename,48,&quot;Error&quot;
End If
End Sub
Sub UpdateLIst
oOpSections = oBrowseDialog.GetControl(&quot;opSections&quot;)
oOpVariables = oBrowseDialog.GetControl(&quot;opVariables&quot;)
oOpParas = oBrowseDialog.GetControl(&quot;opParas&quot;)
If oOpSections.getState Then
ShowSecs
ElseIf oOpVariables.getState Then
ShowVars
ElseIf oOpParas.getState Then
ShowParas
End If
End Sub
Sub ShowSecs
olbElements = oBrowseDialog.GetControl(&quot;lbElements&quot;)
olbElements.RemoveItems(0,olbElements.ItemCount)
olbElements.AddItems(arSecs(),ubound(arSecs()))
oOpSection = oDialog.GetControl(&quot;opSection&quot;)
oOpSection.setState(TRUE)
SetLabel
End Sub
Sub ShowVars
olbElements = oBrowseDialog.GetControl(&quot;lbElements&quot;)
olbElements.RemoveItems(0,olbElements.ItemCount)
olbElements.AddItems(arVars(),ubound(arVars()))
oOpVariable = oDialog.GetControl(&quot;opVariable&quot;)
oOpVariable.setState(TRUE)
SetLabel
End Sub
Sub ShowParas
olbElements = oBrowseDialog.GetControl(&quot;lbElements&quot;)
olbElements.RemoveItems(0,olbElements.ItemCount)
olbElements.AddItems(arParas(),ubound(arParas()))
oOpVariable = oDialog.GetControl(&quot;opSection&quot;)
oOpVariable.setState(TRUE)
SetLabel
End Sub
Sub CheckButton
olbElements = oBrowseDialog.GetControl(&quot;lbElements&quot;)
obutSelect = oBrowseDialog.GetControl(&quot;butSelect&quot;)
sSelected = olbElements.SelectedItem
If sSelected = &quot;&quot; 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
</script:module>