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