1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Link" script:language="StarBasic">REM  *****  BASIC  *****
24
25Dim oDialog AS Object
26Dim document AS Object
27
28
29
30Sub Main
31
32	If not IsHelpFile Then
33		msgbox(strErr_NoHelpFile)
34		Exit Sub
35	End If
36
37	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
38	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
39	Dim ListAny(0) as Long
40
41	DocRoot = ReadConfig(&quot;HelpPrefix&quot;)
42	sLastLinkDir = ReadConfig(&quot;LastLinkDir&quot;)
43	sLastLinkFile = ReadConfig(&quot;LastLinkFile&quot;)
44
45	ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
46	oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
47	oFileDialog.Initialize(ListAny())
48
49
50	If IsSubDir(sLastLinkDir,DocRoot) Then
51		oFileDialog.setDisplayDirectory(sLastLinkDir)
52		If sLastLinkFile &lt;&gt; &quot;&quot; AND Dir(sLastLinkDir+sLastLinkFile) &gt; &quot;&quot; Then
53			oFileDialog.setDefaultName(sLastLinkFile)
54		End If
55	Else
56		oFileDialog.setDisplayDirectory(DocRoot)
57	End If
58
59	oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.TypeDetection.Types/&quot;)
60	oTypes() = oMasterKey.Types
61	oFileDialog.AppendFilter(&quot;Help&quot;, &quot;*.xhp&quot;)
62
63	oFileDialog.SetTitle(&quot;Link to Help File&quot;)
64	iAccept = oFileDialog.Execute()
65
66	If iAccept = 1 Then
67		sPath = oFileDialog.Files(0)
68		sCurDir = oFileDialog.getDisplayDirectory +&quot;/&quot;
69		WriteConfig(&quot;LastLinkDir&quot;,sCurDir)
70		LastFile = Right(sPath, Len(sPath) - Len(sCurDir))
71		WriteConfig(&quot;LastLinkFile&quot;,LastFile)
72
73		If IsSubDir(sCurDir,DocRoot) Then
74			RelPath = GetRelPath(sPath, DocRoot)
75		Else
76			RelPath = sPath
77			msgbox(&quot;File is outside of your Document Root&quot;,48,&quot;Warning&quot;)
78		End If
79
80		oSel = thiscomponent.getcurrentcontroller.getselection
81		oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
82
83		oStart = oCur.getStart
84		oCurStart = oStart.getText.createTextCursorByRange(oStart)
85
86		oEnd = oCur.getEnd
87		oCurEnd = oEnd.getText.createTextCursorByRange(oEnd)
88
89		thiscomponent.getcurrentcontroller.select(oCurStart)
90		InsertTag(&quot;LINK_&quot;,&quot;&lt;LINK href=&quot;&quot;&quot; + RelPath + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_tag&quot;)
91
92		thiscomponent.getcurrentcontroller.select(oCurEnd)
93		InsertTag(&quot;_LINK&quot;,&quot;&lt;/LINK&gt;&quot;,&quot;hlp_aux_tag&quot;)
94
95		SetCharStyle(&quot;Default&quot;)
96
97	End If
98
99
100End Sub
101
102
103</script:module>
104