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