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="Link" script:language="StarBasic">REM  *****  BASIC  *****
4
5Dim oDialog AS Object
6Dim document AS Object
7
8
9
10Sub Main
11
12	If not IsHelpFile Then
13		msgbox(strErr_NoHelpFile)
14		Exit Sub
15	End If
16
17	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
18	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
19	Dim ListAny(0) as Long
20
21	DocRoot = ReadConfig(&quot;HelpPrefix&quot;)
22	sLastLinkDir = ReadConfig(&quot;LastLinkDir&quot;)
23	sLastLinkFile = ReadConfig(&quot;LastLinkFile&quot;)
24
25	ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
26	oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
27	oFileDialog.Initialize(ListAny())
28
29
30	If IsSubDir(sLastLinkDir,DocRoot) Then
31		oFileDialog.setDisplayDirectory(sLastLinkDir)
32		If sLastLinkFile &lt;&gt; &quot;&quot; AND Dir(sLastLinkDir+sLastLinkFile) &gt; &quot;&quot; Then
33			oFileDialog.setDefaultName(sLastLinkFile)
34		End If
35	Else
36		oFileDialog.setDisplayDirectory(DocRoot)
37	End If
38
39	oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.TypeDetection.Types/&quot;)
40	oTypes() = oMasterKey.Types
41	oFileDialog.AppendFilter(&quot;Help&quot;, &quot;*.xhp&quot;)
42
43	oFileDialog.SetTitle(&quot;Link to Help File&quot;)
44	iAccept = oFileDialog.Execute()
45
46	If iAccept = 1 Then
47		sPath = oFileDialog.Files(0)
48		sCurDir = oFileDialog.getDisplayDirectory +&quot;/&quot;
49		WriteConfig(&quot;LastLinkDir&quot;,sCurDir)
50		LastFile = Right(sPath, Len(sPath) - Len(sCurDir))
51		WriteConfig(&quot;LastLinkFile&quot;,LastFile)
52
53		If IsSubDir(sCurDir,DocRoot) Then
54			RelPath = GetRelPath(sPath, DocRoot)
55		Else
56			RelPath = sPath
57			msgbox(&quot;File is outside of your Document Root&quot;,48,&quot;Warning&quot;)
58		End If
59
60		oSel = thiscomponent.getcurrentcontroller.getselection
61		oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
62
63		oStart = oCur.getStart
64		oCurStart = oStart.getText.createTextCursorByRange(oStart)
65
66		oEnd = oCur.getEnd
67		oCurEnd = oEnd.getText.createTextCursorByRange(oEnd)
68
69		thiscomponent.getcurrentcontroller.select(oCurStart)
70		InsertTag(&quot;LINK_&quot;,&quot;&lt;LINK href=&quot;&quot;&quot; + RelPath + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_tag&quot;)
71
72		thiscomponent.getcurrentcontroller.select(oCurEnd)
73		InsertTag(&quot;_LINK&quot;,&quot;&lt;/LINK&gt;&quot;,&quot;hlp_aux_tag&quot;)
74
75		SetCharStyle(&quot;Default&quot;)
76
77	End If
78
79
80End Sub
81
82
83</script:module>