1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ScriptBinding" script:language="StarBasic">REM  *****  BASIC  *****
4*cdf0e10cSrcweir
5*cdf0e10cSrcweirREM ----- Global Variables -----
6*cdf0e10cSrcweir
7*cdf0e10cSrcweir&apos;bindingDialog can refer to either KeyBinding or MenuBinding dialog
8*cdf0e10cSrcweirprivate languages() as String
9*cdf0e10cSrcweirprivate extensions() as Object
10*cdf0e10cSrcweirprivate locations() as String
11*cdf0e10cSrcweirprivate filesysScripts() as String
12*cdf0e10cSrcweirprivate filesysCount as integer
13*cdf0e10cSrcweirprivate bindingDialog as object
14*cdf0e10cSrcweirprivate helpDialog as object
15*cdf0e10cSrcweir&apos;Couldn&apos;t get redim to work, so scriptDisplayList is and array of arrays
16*cdf0e10cSrcweir&apos;where the one and only array in scriptDisplayList is an array
17*cdf0e10cSrcweir&apos;of com.sun.star.beans.PropertyValue, where Name = [logicalName][FunctionName]
18*cdf0e10cSrcweir&apos;and value is ScriptStorage object
19*cdf0e10cSrcweirprivate scriptDisplayList(0)
20*cdf0e10cSrcweirprivate testArray() as String
21*cdf0e10cSrcweir&apos;Array to store lines from the xml file
22*cdf0e10cSrcweirprivate xmlFile() as string
23*cdf0e10cSrcweir&apos;Name of the xml file [writer/calc][menubar/keybindings].xml
24*cdf0e10cSrcweirprivate xmlFileName as string
25*cdf0e10cSrcweir&apos;Number of lines in the xml file
26*cdf0e10cSrcweirprivate numberOfLines as integer
27*cdf0e10cSrcweir
28*cdf0e10cSrcweir&apos;Parallel arrays to store all top-level menu names and line positions
29*cdf0e10cSrcweirprivate menuItems() as string
30*cdf0e10cSrcweirprivate menuItemLinePosition() as integer
31*cdf0e10cSrcweir&apos;Counter for the number of top-level menus
32*cdf0e10cSrcweirprivate menuCount as integer
33*cdf0e10cSrcweir
34*cdf0e10cSrcweir&apos;Parallel arrays to store all sub-menu names and line positions for a particular top-level menu
35*cdf0e10cSrcweirprivate subMenuItems() as string
36*cdf0e10cSrcweirprivate subMenuItemLinePosition() as integer
37*cdf0e10cSrcweir&apos;Counter for the number of sub-menus
38*cdf0e10cSrcweirprivate subMenuCount as integer
39*cdf0e10cSrcweir
40*cdf0e10cSrcweir&apos;Parallel arrays to store all script names and line positions
41*cdf0e10cSrcweirprivate scriptNames() as string
42*cdf0e10cSrcweirprivate scriptLinePosition() as integer
43*cdf0e10cSrcweir&apos;Counter for the number of scripts
44*cdf0e10cSrcweirprivate scriptCount as integer
45*cdf0e10cSrcweir
46*cdf0e10cSrcweir&apos;Array to store all combinations of key bindings
47*cdf0e10cSrcweirprivate allKeyBindings() as string
48*cdf0e10cSrcweir
49*cdf0e10cSrcweir&apos;Array of Arrays
50*cdf0e10cSrcweir&apos;KeyBindArrayOfArrays(0)  contains array of &quot;SHIFT + CONTROL + F Keys&quot; data
51*cdf0e10cSrcweir&apos;Similarly
52*cdf0e10cSrcweir&apos;KeyBindArrayOfArrays(1) contains SHIFT + CONTROL + digits
53*cdf0e10cSrcweir&apos;KeyBindArrayOfArrays(2) contains SHIFT + CONTROL + letters
54*cdf0e10cSrcweir&apos;KeyBindArrayOfArrays(3) contains CONTROL + F keys
55*cdf0e10cSrcweir&apos;KeyBindArrayOfArrays(4) contains CONTROL + digits
56*cdf0e10cSrcweir&apos;KeyBindArrayOfArrays(5) contains CONTROL + letters
57*cdf0e10cSrcweir&apos;KeyBindArrayOfArrays(6) contains SHIFT + F keys
58*cdf0e10cSrcweirprivate KeyBindArrayOfArrays(6)
59*cdf0e10cSrcweir
60*cdf0e10cSrcweir&apos;Each PropertyValue represents a key, Name member contains the script (if a binding exists)
61*cdf0e10cSrcweir&apos; the Value contains and integer
62*cdf0e10cSrcweir&apos;       0  means no script bound
63*cdf0e10cSrcweir&apos;       1  script is bound to an office function
64*cdf0e10cSrcweir&apos;       &gt;1 line number of entry in xmlfile array
65*cdf0e10cSrcweirprivate keyAllocationMap(6,25) as new com.sun.star.beans.PropertyValue
66*cdf0e10cSrcweir&apos;array to store key group descriptions
67*cdf0e10cSrcweirprivate AllKeyGroupsArray(6) as String
68*cdf0e10cSrcweir
69*cdf0e10cSrcweir
70*cdf0e10cSrcweir&apos;Array of props to store all event bindings for the Applications
71*cdf0e10cSrcweirprivate	allEventTypesApp( 14 ) as new com.sun.star.beans.PropertyValue
72*cdf0e10cSrcweir&apos;Array of props to store all event bindings for the Document
73*cdf0e10cSrcweirprivate	allEventTypesDoc( 14 ) as new com.sun.star.beans.PropertyValue
74*cdf0e10cSrcweir&apos;Array of props to store all event types (Name) and textual description (Value)
75*cdf0e10cSrcweirprivate allEventTypes( 14 ) as new com.sun.star.beans.PropertyValue
76*cdf0e10cSrcweir
77*cdf0e10cSrcweir
78*cdf0e10cSrcweirprivate dialogName as String
79*cdf0e10cSrcweirREM ------ Storage Refresh Function ------
80*cdf0e10cSrcweir
81*cdf0e10cSrcweir
82*cdf0e10cSrcweirsub RefreshUserScripts()
83*cdf0e10cSrcweir&apos; TDB - change Menu bindings to allow user to refresh all, user, share or document script
84*cdf0e10cSrcweir   RefreshAppScripts( &quot;USER&quot; )
85*cdf0e10cSrcweirend sub
86*cdf0e10cSrcweir
87*cdf0e10cSrcweirsub RefreshAllScripts()
88*cdf0e10cSrcweir   RefreshAppScripts( &quot;USER&quot; )
89*cdf0e10cSrcweir   RefreshAppScripts( &quot;SHARE&quot; )
90*cdf0e10cSrcweir   RefreshDocumentScripts
91*cdf0e10cSrcweirend sub
92*cdf0e10cSrcweir
93*cdf0e10cSrcweirsub RefreshAppScripts( appName as String )
94*cdf0e10cSrcweir   On Error Goto ErrorHandler
95*cdf0e10cSrcweir   smgr = getProcessServiceManager()
96*cdf0e10cSrcweir   context = smgr.getPropertyValue( &quot;DefaultContext&quot; )
97*cdf0e10cSrcweir   scriptstoragemgr = context.getValueByName( &quot;/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager&quot; )
98*cdf0e10cSrcweir
99*cdf0e10cSrcweir   scriptstoragemgr.refreshScriptStorage( appName )
100*cdf0e10cSrcweir
101*cdf0e10cSrcweir   Exit sub
102*cdf0e10cSrcweir
103*cdf0e10cSrcweir   ErrorHandler:
104*cdf0e10cSrcweir   reset
105*cdf0e10cSrcweir   MsgBox (&quot;Error: Unable to refresh Java (scripts)&quot; + chr$(10) + chr$(10)+ &quot;Detail: &quot; &amp; error$ + chr$(10) + chr$(10)+ &quot;Action: Please restart Office&quot;,0,&quot;Error&quot; )
106*cdf0e10cSrcweir
107*cdf0e10cSrcweirend sub
108*cdf0e10cSrcweir
109*cdf0e10cSrcweirsub RefreshDocumentScripts()
110*cdf0e10cSrcweir   On Error Goto ErrorHandler
111*cdf0e10cSrcweir   smgr = getProcessServiceManager()
112*cdf0e10cSrcweir   context = smgr.getPropertyValue( &quot;DefaultContext&quot; )
113*cdf0e10cSrcweir   scriptstoragemgr = context.getValueByName( &quot;/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager&quot; )
114*cdf0e10cSrcweir
115*cdf0e10cSrcweir   oDocURL = ThisComponent.GetCurrentController.getModel.getURL
116*cdf0e10cSrcweir
117*cdf0e10cSrcweir   On Error Goto ErrorHandlerDoc
118*cdf0e10cSrcweir   scriptstoragemgr.refreshScriptStorage( oDocURL )
119*cdf0e10cSrcweir
120*cdf0e10cSrcweir   Exit sub
121*cdf0e10cSrcweir
122*cdf0e10cSrcweir   ErrorHandlerDoc:
123*cdf0e10cSrcweir   reset
124*cdf0e10cSrcweir   &apos; Ignore document script errors as it will happen when refreshing an unsaved doc
125*cdf0e10cSrcweir   Exit sub
126*cdf0e10cSrcweir
127*cdf0e10cSrcweir   ErrorHandler:
128*cdf0e10cSrcweir   reset
129*cdf0e10cSrcweir   MsgBox (&quot;Error: Unable to refresh Java (scripts)&quot; + chr$(10) + chr$(10)+ &quot;Detail: &quot; &amp; error$ + chr$(10) + chr$(10)+ &quot;Action: Please restart Office&quot;,0,&quot;Error&quot; )
130*cdf0e10cSrcweir
131*cdf0e10cSrcweirend sub
132*cdf0e10cSrcweir
133*cdf0e10cSrcweir
134*cdf0e10cSrcweirREM ----- Launch Functions -----
135*cdf0e10cSrcweir
136*cdf0e10cSrcweirSub createAndPopulateKeyArrays()
137*cdf0e10cSrcweir	&apos;Create SHIFT + CONTROL + F keys array
138*cdf0e10cSrcweir	&apos;Dim keyGroupProp as new com.sun.star.beans.PropertyValue
139*cdf0e10cSrcweir
140*cdf0e10cSrcweir	Dim SCFKey( 11 )
141*cdf0e10cSrcweir	for FKey = 1 to 12
142*cdf0e10cSrcweir		SCFKey( FKey - 1 ) = &quot;SHIFT + CONTROL + F&quot; + FKey
143*cdf0e10cSrcweir	next FKey
144*cdf0e10cSrcweir
145*cdf0e10cSrcweir	KeyBindArrayOfArrays(0) = SCFKey()
146*cdf0e10cSrcweir
147*cdf0e10cSrcweir	&apos;Create SHIFT + CONTROL + digits
148*cdf0e10cSrcweir	Dim SCDKey( 9 )
149*cdf0e10cSrcweir	for Digit = 0 to 9
150*cdf0e10cSrcweir		SCDKey( Digit ) = &quot;SHIFT + CONTROL + &quot; + Digit
151*cdf0e10cSrcweir	next Digit
152*cdf0e10cSrcweir	KeyBindArrayOfArrays(1) = SCDKey()
153*cdf0e10cSrcweir
154*cdf0e10cSrcweir	&apos;Create SHIFT + CONTROL + letters
155*cdf0e10cSrcweir
156*cdf0e10cSrcweir	Dim SCLKey( 25 )
157*cdf0e10cSrcweir	for Alpha = 65 to 90
158*cdf0e10cSrcweir		SCLKey( Alpha - 65 ) = &quot;SHIFT + CONTROL + &quot; + chr$( Alpha )
159*cdf0e10cSrcweir	next Alpha
160*cdf0e10cSrcweir	KeyBindArrayOfArrays(2) = SCLKey()
161*cdf0e10cSrcweir
162*cdf0e10cSrcweir	&apos;Create CONTROL + F keys
163*cdf0e10cSrcweir	Dim CFKey( 11 )
164*cdf0e10cSrcweir	for FKey = 1 to 12
165*cdf0e10cSrcweir		CFKey( Fkey - 1 ) = &quot;CONTROL + F&quot; + FKey
166*cdf0e10cSrcweir	next FKey
167*cdf0e10cSrcweir	KeyBindArrayOfArrays(3) = CFKey()
168*cdf0e10cSrcweir
169*cdf0e10cSrcweir	&apos;Create CONTROL + digits
170*cdf0e10cSrcweir	Dim CDKey( 9 )
171*cdf0e10cSrcweir	for Digit = 0 to 9
172*cdf0e10cSrcweir		CDKey( Digit ) = &quot;CONTROL + &quot; + Digit
173*cdf0e10cSrcweir	next Digit
174*cdf0e10cSrcweir	KeyBindArrayOfArrays(4) = CDKey()
175*cdf0e10cSrcweir
176*cdf0e10cSrcweir	&apos;Create CONTROL + letters
177*cdf0e10cSrcweir	Dim CLKey( 25 )
178*cdf0e10cSrcweir	for Alpha = 65 to 90
179*cdf0e10cSrcweir		CLKey( Alpha - 65 ) = &quot;CONTROL + &quot; + chr$( Alpha )
180*cdf0e10cSrcweir	next Alpha
181*cdf0e10cSrcweir	KeyBindArrayOfArrays(5) = CLKey()
182*cdf0e10cSrcweir
183*cdf0e10cSrcweir	&apos;Create SHIFT + F Keys
184*cdf0e10cSrcweir	Dim SFKey( 11 )
185*cdf0e10cSrcweir	for FKey = 1 to 12
186*cdf0e10cSrcweir		SFKey( Fkey - 1 ) = &quot;SHIFT + F&quot; + FKey
187*cdf0e10cSrcweir	next FKey
188*cdf0e10cSrcweir	KeyBindArrayOfArrays(6) = SFKey()
189*cdf0e10cSrcweir
190*cdf0e10cSrcweirEnd Sub
191*cdf0e10cSrcweir
192*cdf0e10cSrcweirSub updateMapWithDisabledKeys()
193*cdf0e10cSrcweir	&apos;disable CONTROL + F1 &amp;
194*cdf0e10cSrcweir	keyAllocationMap( 3, 0 ).Value = 1
195*cdf0e10cSrcweir	keyAllocationMap( 3, 0 ).Name = &quot;&quot;
196*cdf0e10cSrcweir	&apos;disable CONTROL + F4 &amp;
197*cdf0e10cSrcweir	keyAllocationMap( 3, 3 ).Value = 1
198*cdf0e10cSrcweir	keyAllocationMap( 3, 3 ).Name = &quot;&quot;
199*cdf0e10cSrcweir	&apos;disable CONTROL + F6
200*cdf0e10cSrcweir	keyAllocationMap( 3, 5 ).Value = 1
201*cdf0e10cSrcweir	keyAllocationMap( 3, 5 ).Name = &quot;&quot;
202*cdf0e10cSrcweir
203*cdf0e10cSrcweir
204*cdf0e10cSrcweir	&apos;disable SHIFT + F1 &amp;
205*cdf0e10cSrcweir	keyAllocationMap( 6, 0 ).Value = 1
206*cdf0e10cSrcweir	keyAllocationMap( 6, 0 ).Name = &quot;&quot;
207*cdf0e10cSrcweir	&apos;disable SHIFT + F2 &amp;
208*cdf0e10cSrcweir	keyAllocationMap( 6, 1 ).Value = 1
209*cdf0e10cSrcweir	keyAllocationMap( 6, 1 ).Name = &quot;&quot;
210*cdf0e10cSrcweir	&apos;disable SHIFT + F6 &amp;
211*cdf0e10cSrcweir	keyAllocationMap( 6, 5 ).Value = 1
212*cdf0e10cSrcweir	keyAllocationMap( 6, 5 ).Name = &quot;&quot;
213*cdf0e10cSrcweir
214*cdf0e10cSrcweirEnd Sub
215*cdf0e10cSrcweir
216*cdf0e10cSrcweirSub initialiseFileExtensions()
217*cdf0e10cSrcweir	ReDim extensions(ubound(languages())+1) as Object
218*cdf0e10cSrcweir	oConfigProvider = CreateUnoService( &quot;com.sun.star.configuration.ConfigurationProvider&quot; )
219*cdf0e10cSrcweir    Dim configArgs(1) as new com.sun.star.beans.PropertyValue
220*cdf0e10cSrcweir    configargs(0).Name = &quot;nodepath&quot;
221*cdf0e10cSrcweir    configArgs(0).Value = &quot;org.openoffice.Office.Scripting/ScriptRuntimes&quot;
222*cdf0e10cSrcweir    configargs(1).Name = &quot;lazywrite&quot;
223*cdf0e10cSrcweir    configArgs(1).Value = false
224*cdf0e10cSrcweir    oConfigAccess = oConfigProvider.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationAccess&quot;, configArgs())
225*cdf0e10cSrcweir    for index = 0 to ubound(languages())
226*cdf0e10cSrcweir    		if(languages(index) &lt;&gt; &quot;Java&quot;) then
227*cdf0e10cSrcweir            	xPropSet = oConfigAccess.getByName(languages(index))
228*cdf0e10cSrcweir            	extns() = xPropSet.getPropertyValue(&quot;SupportedFileExtensions&quot;)
229*cdf0e10cSrcweir            	extensions(index) = extns()
230*cdf0e10cSrcweir            endif
231*cdf0e10cSrcweir    next index
232*cdf0e10cSrcweirend sub
233*cdf0e10cSrcweir
234*cdf0e10cSrcweirSub ExecuteEditDebug()
235*cdf0e10cSrcweir
236*cdf0e10cSrcweir	locations = Array ( &quot;User&quot;, &quot;Share&quot;, &quot;Document&quot;, &quot;Filesystem&quot; )
237*cdf0e10cSrcweir	languages = Array ( &quot;BeanShell&quot;, &quot;JavaScript&quot; )
238*cdf0e10cSrcweir	dialogName = &quot;EditDebug&quot;
239*cdf0e10cSrcweir	initialiseFileExtensions()
240*cdf0e10cSrcweir	bindingDialog = LoadDialog( &quot;ScriptBindingLibrary&quot;, &quot;EditDebug&quot; )
241*cdf0e10cSrcweir
242*cdf0e10cSrcweir	PopulateLanguageCombo()
243*cdf0e10cSrcweir	PopulateLocationCombo()
244*cdf0e10cSrcweir	PopulateScriptList( languages(0), locations(0) )
245*cdf0e10cSrcweir
246*cdf0e10cSrcweir	bindingDialog.execute()
247*cdf0e10cSrcweirEnd Sub
248*cdf0e10cSrcweir
249*cdf0e10cSrcweirSub ExecuteKeyBinding()
250*cdf0e10cSrcweir	dialogName = &quot;Key&quot;
251*cdf0e10cSrcweir    createAndPopulateKeyArrays()
252*cdf0e10cSrcweir    updateMapWithDisabledKeys()
253*cdf0e10cSrcweir	xmlFileName = GetDocumentType( &quot;Key&quot; )
254*cdf0e10cSrcweir
255*cdf0e10cSrcweir	if not (ReadXMLToArray( &quot;Key&quot; )) then
256*cdf0e10cSrcweir		Exit Sub
257*cdf0e10cSrcweir	endif
258*cdf0e10cSrcweir
259*cdf0e10cSrcweir	bindingDialog = LoadDialog( &quot;ScriptBindingLibrary&quot;, &quot;KeyBinding&quot; )
260*cdf0e10cSrcweir	PopulateKeyBindingList(0)
261*cdf0e10cSrcweir	initialiseNavigationComboArrays()
262*cdf0e10cSrcweir    PopulateLanguageCombo()
263*cdf0e10cSrcweir    PopulateLocationCombo()
264*cdf0e10cSrcweir	PopulateScriptList( languages(0), locations(0) )
265*cdf0e10cSrcweir	PopulateTopLevelKeyBindingList()
266*cdf0e10cSrcweir	bindingDialog.execute()
267*cdf0e10cSrcweirend Sub
268*cdf0e10cSrcweir
269*cdf0e10cSrcweir
270*cdf0e10cSrcweirSub initialiseNavigationComboArrays()
271*cdf0e10cSrcweir    locations = Array ( &quot;User&quot;, &quot;Share&quot;, &quot;Document&quot;, &quot;Filesystem&quot; )
272*cdf0e10cSrcweir    ReDim languages(0) as String
273*cdf0e10cSrcweir    ReDim extensions(0) as Object
274*cdf0e10cSrcweir	languages(0) = &quot;Java&quot;
275*cdf0e10cSrcweir	REM extensions(0) = &quot;&quot;
276*cdf0e10cSrcweir
277*cdf0e10cSrcweir    &apos; Setup languages array for all supported languages
278*cdf0e10cSrcweir    oServiceManager = GetProcessServiceManager()
279*cdf0e10cSrcweir    svrArray = oServiceManager.getAvailableServiceNames
280*cdf0e10cSrcweir
281*cdf0e10cSrcweir    langCount = 1
282*cdf0e10cSrcweir    for index = 0 to ubound(svrArray)
283*cdf0e10cSrcweir        iPos = inStr(svrArray(index), &quot;ScriptProviderFor&quot;)
284*cdf0e10cSrcweir
285*cdf0e10cSrcweir        if (iPos &gt; 0) then
286*cdf0e10cSrcweir            lang = Mid(svrArray(index), iPos + Len(&quot;ScriptProviderFor&quot;)
287*cdf0e10cSrcweir
288*cdf0e10cSrcweir            if not (lang = &quot;Java&quot;) then
289*cdf0e10cSrcweir                &apos;Add to language vector
290*cdf0e10cSrcweir                ReDim Preserve languages(langCount) as String
291*cdf0e10cSrcweir                languages(langCount) = lang
292*cdf0e10cSrcweir                langCount = langCount + 1
293*cdf0e10cSrcweir            endif
294*cdf0e10cSrcweir        endif
295*cdf0e10cSrcweir    next index
296*cdf0e10cSrcweir    initialiseFileExtensions()
297*cdf0e10cSrcweirEnd Sub
298*cdf0e10cSrcweir
299*cdf0e10cSrcweir
300*cdf0e10cSrcweirSub ExecuteEventBinding
301*cdf0e10cSrcweir	dialogName = &quot;Event&quot;
302*cdf0e10cSrcweir	createAllEventTypes()
303*cdf0e10cSrcweir	createAllEventBindings()
304*cdf0e10cSrcweir
305*cdf0e10cSrcweir	&apos;Populate application event bindings array (from config xml file)
306*cdf0e10cSrcweir	if not (ReadXMLToArray( &quot;Event&quot; )) then
307*cdf0e10cSrcweir		Exit Sub
308*cdf0e10cSrcweir	endif
309*cdf0e10cSrcweir	&apos;Populate document event bindings array (using Office API calls)
310*cdf0e10cSrcweir	ReadEventsFromDoc()
311*cdf0e10cSrcweir
312*cdf0e10cSrcweir	bindingDialog = LoadDialog( &quot;ScriptBindingLibrary&quot;, &quot;EventsBinding&quot; )
313*cdf0e10cSrcweir	initialiseNavigationComboArrays()
314*cdf0e10cSrcweir    PopulateLanguageCombo()
315*cdf0e10cSrcweir    PopulateLocationCombo()
316*cdf0e10cSrcweir	PopulateScriptList( languages(0), locations(0) )
317*cdf0e10cSrcweir	populateEventList( 0 )
318*cdf0e10cSrcweir	EventListListener()
319*cdf0e10cSrcweir	bindingDialog.execute()
320*cdf0e10cSrcweirEnd Sub
321*cdf0e10cSrcweir
322*cdf0e10cSrcweirSub ExecuteMenuBinding()
323*cdf0e10cSrcweir	dialogName = &quot;Menu&quot;
324*cdf0e10cSrcweir	xmlFileName = GetDocumentType( &quot;Menu&quot; )
325*cdf0e10cSrcweir	if not (ReadXMLToArray( &quot;Menu&quot; )) then
326*cdf0e10cSrcweir		Exit Sub
327*cdf0e10cSrcweir	endif
328*cdf0e10cSrcweir
329*cdf0e10cSrcweir	bindingDialog = LoadDialog( &quot;ScriptBindingLibrary&quot;, &quot;MenuBinding&quot; )
330*cdf0e10cSrcweir	initialiseNavigationComboArrays()
331*cdf0e10cSrcweir    PopulateLanguageCombo()
332*cdf0e10cSrcweir    PopulateLocationCombo()
333*cdf0e10cSrcweir	PopulateScriptList( languages(0), locations(0) )
334*cdf0e10cSrcweir	PopulateMenuCombo()
335*cdf0e10cSrcweir	PopulateSubMenuList( 1 )
336*cdf0e10cSrcweir
337*cdf0e10cSrcweir	subMenuList = bindingDialog.getControl(&quot;SubMenuList&quot;)
338*cdf0e10cSrcweir
339*cdf0e10cSrcweir	subMenuList.selectItemPos( 0, true )
340*cdf0e10cSrcweir
341*cdf0e10cSrcweir	bindingDialog.execute()
342*cdf0e10cSrcweirend Sub
343*cdf0e10cSrcweir
344*cdf0e10cSrcweir
345*cdf0e10cSrcweirREM ----- Initialising functions -----
346*cdf0e10cSrcweir
347*cdf0e10cSrcweir
348*cdf0e10cSrcweirfunction LoadDialog( libName as string, dialogName as string ) as object
349*cdf0e10cSrcweir	dim library as object
350*cdf0e10cSrcweir	dim libDialog as object
351*cdf0e10cSrcweir	dim runtimeDialog as object
352*cdf0e10cSrcweir	libContainer = DialogLibraries
353*cdf0e10cSrcweir	libContainer.LoadLibrary( libName )
354*cdf0e10cSrcweir	library = libContainer.getByName( libname )
355*cdf0e10cSrcweir	libDialog = library.getByName( dialogName )
356*cdf0e10cSrcweir	runtimeDialog = CreateUnoDialog( libDialog )
357*cdf0e10cSrcweir	LoadDialog() = runtimeDialog
358*cdf0e10cSrcweir
359*cdf0e10cSrcweirend function
360*cdf0e10cSrcweir
361*cdf0e10cSrcweir
362*cdf0e10cSrcweirfunction GetDocumentType( bindingType as string ) as string
363*cdf0e10cSrcweir	document = StarDesktop.ActiveFrame.Controller.Model
364*cdf0e10cSrcweir	Dim errornumber As Integer
365*cdf0e10cSrcweir	errornumber = 111
366*cdf0e10cSrcweir	Error errornumber
367*cdf0e10cSrcweir	if document.SupportsService(&quot;com.sun.star.sheet.SpreadsheetDocument&quot;) then
368*cdf0e10cSrcweir		if bindingType = &quot;Key&quot; then
369*cdf0e10cSrcweir			GetDocumentType() = &quot;calckeybinding.xml&quot;
370*cdf0e10cSrcweir		else
371*cdf0e10cSrcweir			if bindingType = &quot;Menu&quot; then
372*cdf0e10cSrcweir				GetDocumentType() = &quot;calcmenubar.xml&quot;
373*cdf0e10cSrcweir			end if
374*cdf0e10cSrcweir		end if
375*cdf0e10cSrcweir	elseif document.SupportsService(&quot;com.sun.star.text.TextDocument&quot;) then
376*cdf0e10cSrcweir		if bindingType = &quot;Key&quot; then
377*cdf0e10cSrcweir			GetDocumentType() = &quot;writerkeybinding.xml&quot;
378*cdf0e10cSrcweir		else
379*cdf0e10cSrcweir			if bindingType = &quot;Menu&quot; then
380*cdf0e10cSrcweir				GetDocumentType() = &quot;writermenubar.xml&quot;
381*cdf0e10cSrcweir			end if
382*cdf0e10cSrcweir		end if
383*cdf0e10cSrcweir	elseif document.SupportsService(&quot;com.sun.star.presentation.PresentationDocument&quot;) then
384*cdf0e10cSrcweir		if bindingType = &quot;Key&quot; then
385*cdf0e10cSrcweir			GetDocumentType() = &quot;impresskeybinding.xml&quot;
386*cdf0e10cSrcweir		else
387*cdf0e10cSrcweir			if bindingType = &quot;Menu&quot; then
388*cdf0e10cSrcweir				GetDocumentType() = &quot;impressmenubar.xml&quot;
389*cdf0e10cSrcweir			end if
390*cdf0e10cSrcweir		end if
391*cdf0e10cSrcweir	elseif document.SupportsService(&quot;com.sun.star.presentation.PresentationDocument&quot;) then
392*cdf0e10cSrcweir		if bindingType = &quot;Key&quot; then
393*cdf0e10cSrcweir			GetDocumentType() = &quot;impresskeybinding.xml&quot;
394*cdf0e10cSrcweir		else
395*cdf0e10cSrcweir			if bindingType = &quot;Menu&quot; then
396*cdf0e10cSrcweir				GetDocumentType() = &quot;impressmenubar.xml&quot;
397*cdf0e10cSrcweir			end if
398*cdf0e10cSrcweir		end if
399*cdf0e10cSrcweir	elseif document.SupportsService(&quot;com.sun.star.drawing.DrawingDocument&quot;) then
400*cdf0e10cSrcweir		if bindingType = &quot;Key&quot; then
401*cdf0e10cSrcweir			GetDocumentType() = &quot;drawkeybinding.xml&quot;
402*cdf0e10cSrcweir		else
403*cdf0e10cSrcweir			if bindingType = &quot;Menu&quot; then
404*cdf0e10cSrcweir				GetDocumentType() = &quot;drawmenubar.xml&quot;
405*cdf0e10cSrcweir			end if
406*cdf0e10cSrcweir		end if
407*cdf0e10cSrcweir	else
408*cdf0e10cSrcweir		MsgBox (&quot;Error: Couldn&apos;t determine configuration file type&quot; + chr$(10) + chr$(10) + &quot;Action: Please reinstall Scripting Framework&quot;,0,&quot;Error&quot; )
409*cdf0e10cSrcweir	end if
410*cdf0e10cSrcweirend function
411*cdf0e10cSrcweir
412*cdf0e10cSrcweirfunction lastIndexOf( targetStr as String, substr as String ) as Integer
413*cdf0e10cSrcweir	copyStr = targetStr
414*cdf0e10cSrcweir	while instr(copyStr, substr) &gt; 0
415*cdf0e10cSrcweir		pos = instr(copyStr, substr)
416*cdf0e10cSrcweir		tpos = tpos + pos
417*cdf0e10cSrcweir		copyStr = mid(copyStr, pos+1, len(copyStr)-pos )
418*cdf0e10cSrcweir	wend
419*cdf0e10cSrcweir	lastIndexOf() = tpos
420*cdf0e10cSrcweirend function
421*cdf0e10cSrcweir
422*cdf0e10cSrcweirfunction getScriptURI( selectedScript as String ) as String
423*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;LocationCombo&quot; )
424*cdf0e10cSrcweir	location = combo.text
425*cdf0e10cSrcweir	if ( location = &quot;User&quot; ) then
426*cdf0e10cSrcweir		location = &quot;user&quot;
427*cdf0e10cSrcweir	elseif ( location = &quot;Share&quot; ) then
428*cdf0e10cSrcweir		location = &quot;share&quot;
429*cdf0e10cSrcweir	elseif ( location = &quot;Filesystem&quot; ) then
430*cdf0e10cSrcweir		location = &quot;filesystem&quot;
431*cdf0e10cSrcweir	else
432*cdf0e10cSrcweir		location = &quot;document&quot;
433*cdf0e10cSrcweir	end if
434*cdf0e10cSrcweir
435*cdf0e10cSrcweir
436*cdf0e10cSrcweir
437*cdf0e10cSrcweir	if ( location = &quot;filesystem&quot; ) then
438*cdf0e10cSrcweir		REM need to build URI here - dcf
439*cdf0e10cSrcweir		combo = bindingDialog.getControl( &quot;LanguageCombo&quot; )
440*cdf0e10cSrcweir		language = combo.text
441*cdf0e10cSrcweir		url = selectedscript
442*cdf0e10cSrcweir		pos = lastIndexOf( url, &quot;/&quot; )
443*cdf0e10cSrcweir		locationPath =  mid( url, 1, pos)
444*cdf0e10cSrcweir        url = mid( url, pos+1, len( url ) - pos )
445*cdf0e10cSrcweir		functionName = url
446*cdf0e10cSrcweir		pos = lastIndexOf( url, &quot;.&quot; )
447*cdf0e10cSrcweir		logicalName = mid( url, 1, pos - 1 )
448*cdf0e10cSrcweir		getScriptURI() = &quot;script://&quot; + logicalName + &quot;?language=&quot; _
449*cdf0e10cSrcweir			+ language + &quot;&amp;amp;function=&quot; + functionName _
450*cdf0e10cSrcweir			+ &quot;&amp;amp;location=filesystem:&quot; + locationPath
451*cdf0e10cSrcweir	else
452*cdf0e10cSrcweir		Dim scriptInfo as Object
453*cdf0e10cSrcweir		scripts() = scriptDisplayList(0)
454*cdf0e10cSrcweir		for n = LBOUND( scripts() ) to UBOUND( scripts() )
455*cdf0e10cSrcweir
456*cdf0e10cSrcweir			if ( scripts( n ).Name = selectedScript ) then
457*cdf0e10cSrcweir				scriptInfo = scripts( n ).Value
458*cdf0e10cSrcweir				exit for
459*cdf0e10cSrcweir			end if
460*cdf0e10cSrcweir		next n
461*cdf0e10cSrcweir		getScriptURI() = &quot;script://&quot; + scriptInfo.getLogicalName + &quot;?language=&quot; _
462*cdf0e10cSrcweir			+ scriptInfo.getLanguage() + &quot;&amp;amp;function=&quot; + _
463*cdf0e10cSrcweir			scriptInfo.getFunctionName() + &quot;&amp;amp;location=&quot; + location
464*cdf0e10cSrcweir	end if
465*cdf0e10cSrcweir
466*cdf0e10cSrcweirend function
467*cdf0e10cSrcweir
468*cdf0e10cSrcweirfunction GetOfficePath() as string
469*cdf0e10cSrcweir	REM Error check and prompt user to manually input Office Path
470*cdf0e10cSrcweir	settings =  CreateUnoService( &quot;com.sun.star.frame.Settings&quot; )
471*cdf0e10cSrcweir	path = settings.getByName( &quot;PathSettings&quot; )
472*cdf0e10cSrcweir	unformattedOfficePath = path.getPropertyValue( &quot;UserPath&quot; )
473*cdf0e10cSrcweir
474*cdf0e10cSrcweir	dim officePath as string
475*cdf0e10cSrcweir	const removeFromEnd = &quot;/user&quot;
476*cdf0e10cSrcweir	const removeFromEndWindows = &quot;\user&quot;
477*cdf0e10cSrcweir
478*cdf0e10cSrcweir	REM If Solaris or Linux
479*cdf0e10cSrcweir	if not ( instr( unformattedOfficePath, removeFromEnd ) = 0 ) then
480*cdf0e10cSrcweir		endPosition = instr( unformattedOfficePath, removeFromEnd )
481*cdf0e10cSrcweir		officePath = mid( unformattedOfficePath, 1, endPosition )
482*cdf0e10cSrcweir	REM If Windows
483*cdf0e10cSrcweir	else if not ( instr( unformattedOfficePath, removeFromEndWindows ) = 0 ) then
484*cdf0e10cSrcweir			endPosition = instr( unformattedOfficePath, removeFromEndWindows )
485*cdf0e10cSrcweir			officePath = mid( unformattedOfficePath, 1, endPosition )
486*cdf0e10cSrcweir			while instr( officePath, &quot;\&quot; ) &gt; 0
487*cdf0e10cSrcweir				backSlash = instr( officePath, &quot;\&quot; )
488*cdf0e10cSrcweir				startPath = mid( officePath, 1, backSlash - 1 )
489*cdf0e10cSrcweir				endPath = mid( officePath, backslash + 1, len( officePath ) - backSlash )
490*cdf0e10cSrcweir				officePath = startPath + &quot;/&quot; + endPath
491*cdf0e10cSrcweir			wend
492*cdf0e10cSrcweir		else
493*cdf0e10cSrcweir			MsgBox (&quot;Error: Office path not found&quot; + chr$(10) + chr$(10) + &quot;Action: Please reinstall Scripting Framework&quot;,0,&quot;Error&quot; )
494*cdf0e10cSrcweir			REM Prompt user
495*cdf0e10cSrcweir		end if
496*cdf0e10cSrcweir	end if
497*cdf0e10cSrcweir
498*cdf0e10cSrcweir	GetOfficePath() = officePath
499*cdf0e10cSrcweirend function
500*cdf0e10cSrcweir
501*cdf0e10cSrcweir
502*cdf0e10cSrcweir
503*cdf0e10cSrcweirREM ----- File I/O functions -----
504*cdf0e10cSrcweir
505*cdf0e10cSrcweir
506*cdf0e10cSrcweirfunction ReadXMLToArray( bindingType as string ) as boolean
507*cdf0e10cSrcweir	On Error Goto ErrorHandler
508*cdf0e10cSrcweir	if ( bindingType = &quot;Event&quot; ) then
509*cdf0e10cSrcweir		xmlfilename = &quot;eventbindings.xml&quot;
510*cdf0e10cSrcweir	endif
511*cdf0e10cSrcweir
512*cdf0e10cSrcweir	simplefileaccess = CreateUnoService( &quot;com.sun.star.ucb.SimpleFileAccess&quot; )
513*cdf0e10cSrcweir	filestream = simplefileaccess.openFileRead( &quot;file://&quot; + GetOfficePath() + &quot;user/config/soffice.cfg/&quot; + xmlFileName )
514*cdf0e10cSrcweir
515*cdf0e10cSrcweir    textin = CreateUnoService( &quot;com.sun.star.io.TextInputStream&quot; )
516*cdf0e10cSrcweir    textin.setInputStream( filestream )
517*cdf0e10cSrcweir
518*cdf0e10cSrcweir    redim xmlFile( 400 ) as String
519*cdf0e10cSrcweir    redim menuItems( 30 ) as String
520*cdf0e10cSrcweir    redim menuItemLinePosition( 30 ) as Integer
521*cdf0e10cSrcweir    redim scriptNames( 120 ) as string
522*cdf0e10cSrcweir    redim scriptLinePosition( 120) as integer
523*cdf0e10cSrcweir
524*cdf0e10cSrcweir    lineCount = 1
525*cdf0e10cSrcweir    menuCount = 1
526*cdf0e10cSrcweir    scriptCount = 1
527*cdf0e10cSrcweir
528*cdf0e10cSrcweir    do while not textin.isEOF()
529*cdf0e10cSrcweir    	xmlline = textin.readLine()
530*cdf0e10cSrcweir    	xmlFile( lineCount ) = xmlline
531*cdf0e10cSrcweir
532*cdf0e10cSrcweir 		const menuItemWhiteSpace = 2
533*cdf0e10cSrcweir 		const menuXMLTag = &quot;&lt;menu:menu&quot;
534*cdf0e10cSrcweir
535*cdf0e10cSrcweir		if bindingType = &quot;Menu&quot; then
536*cdf0e10cSrcweir			evaluateForMenu( xmlline, lineCount )
537*cdf0e10cSrcweir		elseif bindingType = &quot;Key&quot; then
538*cdf0e10cSrcweir			processKeyXMLLine( lineCount, xmlline )
539*cdf0e10cSrcweir		elseif bindingType = &quot;Event&quot; then
540*cdf0e10cSrcweir			evaluateForEvent( xmlline, lineCount )
541*cdf0e10cSrcweir		else
542*cdf0e10cSrcweir			MsgBox (&quot;Error: Couldn&apos;t determine file type&quot; + chr$(10) + chr$(10) + &quot;Action: Please reinstall Scripting Framework&quot;,0,&quot;Error&quot; )
543*cdf0e10cSrcweir		end if
544*cdf0e10cSrcweir        lineCount = lineCount + 1
545*cdf0e10cSrcweir    loop
546*cdf0e10cSrcweir
547*cdf0e10cSrcweir	&apos;Set global variable numberOfLines (lineCount is one too many at end of the loop)
548*cdf0e10cSrcweir	numberOfLines = lineCount - 1
549*cdf0e10cSrcweir	&apos;Set global variable menuCount (it is one too many at end of the loop)
550*cdf0e10cSrcweir	menuCount = menuCount - 1
551*cdf0e10cSrcweir
552*cdf0e10cSrcweir    filestream.closeInput()
553*cdf0e10cSrcweir    ReadXMLToArray( ) = true
554*cdf0e10cSrcweir	Exit function
555*cdf0e10cSrcweir
556*cdf0e10cSrcweir	ErrorHandler:
557*cdf0e10cSrcweir	reset
558*cdf0e10cSrcweir	MsgBox (&quot;Error: Unable to read Star Office configuration file - &quot; + xmlFileName + chr$(10) + chr$(10) + &quot;Action: Please reinstall Scripting Framework&quot;,0,&quot;Error&quot; )
559*cdf0e10cSrcweir    ReadXMLToArray( ) = false
560*cdf0e10cSrcweirend function
561*cdf0e10cSrcweir
562*cdf0e10cSrcweir
563*cdf0e10cSrcweir
564*cdf0e10cSrcweirsub evaluateForMenu( xmlline as string, lineCount as integer )
565*cdf0e10cSrcweir	const menuItemWhiteSpace = 2
566*cdf0e10cSrcweir 	const menuXMLTag = &quot;&lt;menu:menu&quot;
567*cdf0e10cSrcweir	&apos;If the xml line is a top-level menu
568*cdf0e10cSrcweir	if instr( xmlline, menuXMLTag ) = menuItemWhiteSpace then
569*cdf0e10cSrcweir		menuLabel = ExtractLabelFromXMLLine( xmlline )
570*cdf0e10cSrcweir		menuItems( menuCount ) = menuLabel
571*cdf0e10cSrcweir		menuItemLinePosition( menuCount ) = lineCount
572*cdf0e10cSrcweir		menuCount = menuCount + 1
573*cdf0e10cSrcweir	end if
574*cdf0e10cSrcweirend sub
575*cdf0e10cSrcweir
576*cdf0e10cSrcweirsub evaluateForEvent( xmlline as string, lineCount as integer )
577*cdf0e10cSrcweir	dim eventName as String
578*cdf0e10cSrcweir	&apos;if the xml line identifies a script or SB macro
579*cdf0e10cSrcweir	dim scriptName as string
580*cdf0e10cSrcweir	dim lineNumber as integer
581*cdf0e10cSrcweir	if instr( xmlline, &quot;event:language=&quot; + chr$(34) + &quot;Script&quot; ) &gt; 0 then
582*cdf0e10cSrcweir		eventName = ExtractEventNameFromXMLLine( xmlline )
583*cdf0e10cSrcweir		scriptName = ExtractEventScriptFromXMLLine( xmlline )
584*cdf0e10cSrcweir		lineNumber = lineCount
585*cdf0e10cSrcweir	elseif instr( xmlline, &quot;event:language=&quot; + chr$(34) + &quot;StarBasic&quot; ) &gt; 0 then
586*cdf0e10cSrcweir		eventName = ExtractEventNameFromXMLLine( xmlline )
587*cdf0e10cSrcweir		scriptName = &quot;Allocated to Office function&quot;
588*cdf0e10cSrcweir		lineNumber = 1
589*cdf0e10cSrcweir	end if
590*cdf0e10cSrcweir
591*cdf0e10cSrcweir	&apos;Need to sequence to find the corresponding index for the event type
592*cdf0e10cSrcweir	for n = 0 to ubound( allEventTypesApp() )
593*cdf0e10cSrcweir		if ( eventName = allEventTypes( n ).Name ) then
594*cdf0e10cSrcweir			allEventTypesApp( n ).Name = scriptName
595*cdf0e10cSrcweir			allEventTypesApp( n ).Value = lineNumber
596*cdf0e10cSrcweir		end if
597*cdf0e10cSrcweir	next n
598*cdf0e10cSrcweirend sub
599*cdf0e10cSrcweir
600*cdf0e10cSrcweir
601*cdf0e10cSrcweirfunction isOKscriptProps( props() as Object, eventName as string ) as Boolean
602*cdf0e10cSrcweir	On Error Goto ErrorHandler
603*cdf0e10cSrcweir	props  = ThisComponent.getEvents().getByName( eventName )
604*cdf0e10cSrcweir	test = ubound( props() )
605*cdf0e10cSrcweir	isOKscriptProps() = true
606*cdf0e10cSrcweir	exit function
607*cdf0e10cSrcweir
608*cdf0e10cSrcweir	ErrorHandler:
609*cdf0e10cSrcweir	isOKscriptProps() = false
610*cdf0e10cSrcweirend function
611*cdf0e10cSrcweir
612*cdf0e10cSrcweirsub ReadEventsFromDoc()
613*cdf0e10cSrcweir	On Error Goto ErrorHandler
614*cdf0e10cSrcweir
615*cdf0e10cSrcweir	eventSupplier = ThisComponent
616*cdf0e10cSrcweir	for n = 0 to ubound( allEventTypes() )
617*cdf0e10cSrcweir		Dim scriptProps() as Object
618*cdf0e10cSrcweir		if (isOKscriptProps( scriptProps(), allEventTypes( n ).Name) ) then
619*cdf0e10cSrcweir			if ( ubound( scriptProps ) &gt; 0 ) then
620*cdf0e10cSrcweir				if ( scriptProps(0).Value = &quot;Script&quot; ) then
621*cdf0e10cSrcweir					&apos;Script binding
622*cdf0e10cSrcweir					allEventTypesDoc(n).Name = scriptProps(1).Value
623*cdf0e10cSrcweir					allEventTypesDoc(n).value = 2
624*cdf0e10cSrcweir				elseif( scriptProps(0).Value = &quot;StarBasic&quot; ) then
625*cdf0e10cSrcweir					&apos;StarBasic macro
626*cdf0e10cSrcweir					allEventTypesDoc(n).Name = &quot;Allocated to Office function&quot;
627*cdf0e10cSrcweir					allEventTypesDoc(n).value = 1
628*cdf0e10cSrcweir				end if
629*cdf0e10cSrcweir			end if
630*cdf0e10cSrcweir		end if
631*cdf0e10cSrcweir	next n
632*cdf0e10cSrcweir
633*cdf0e10cSrcweir	exit sub
634*cdf0e10cSrcweir
635*cdf0e10cSrcweir	&apos; eventProps is undefined if there are no event bindings in the doc
636*cdf0e10cSrcweir	ErrorHandler:
637*cdf0e10cSrcweir	reset
638*cdf0e10cSrcweirend sub
639*cdf0e10cSrcweir
640*cdf0e10cSrcweir
641*cdf0e10cSrcweirsub WriteEventsToDoc()
642*cdf0e10cSrcweir	On Error Goto ErrorHandler
643*cdf0e10cSrcweir
644*cdf0e10cSrcweir	eventSupplier = ThisComponent
645*cdf0e10cSrcweir	for n = 0 to ubound( allEventTypes() )
646*cdf0e10cSrcweir		scriptName = allEventTypesDoc( n ).Name
647*cdf0e10cSrcweir		eventName = allEventTypes( n ).Name
648*cdf0e10cSrcweir		if( allEventTypesDoc( n ).Value &gt; 1 ) then &apos;script
649*cdf0e10cSrcweir			&apos;add to doc
650*cdf0e10cSrcweir			AddEventToDocViaAPI( scriptName, eventName )
651*cdf0e10cSrcweir		elseif( allEventTypesDoc( n ).Value = 0 ) then &apos;blank (this will &quot;remove&quot; already blank entries)
652*cdf0e10cSrcweir			&apos;remove from doc
653*cdf0e10cSrcweir			RemoveEventFromDocViaAPI( eventName )
654*cdf0e10cSrcweir		endif
655*cdf0e10cSrcweir		&apos;Otherwise it is a StarBasic binding - leave alone
656*cdf0e10cSrcweir	next n
657*cdf0e10cSrcweir	&apos;Mark document as modified ( should happen automatically as a result of calling the API )
658*cdf0e10cSrcweir	ThisComponent.CurrentController.getModel().setModified( True )
659*cdf0e10cSrcweir	exit sub
660*cdf0e10cSrcweir
661*cdf0e10cSrcweir	ErrorHandler:
662*cdf0e10cSrcweir	reset
663*cdf0e10cSrcweir	msgbox( &quot;Error calling UNO API for writing event bindings to the document&quot; )
664*cdf0e10cSrcweirend sub
665*cdf0e10cSrcweir
666*cdf0e10cSrcweir
667*cdf0e10cSrcweirsub RemoveEventFromDocViaAPI( event as string )
668*cdf0e10cSrcweir	dim document   as object
669*cdf0e10cSrcweir	dim dispatcher as object
670*cdf0e10cSrcweir	dim parser     as object
671*cdf0e10cSrcweir	dim url        as new com.sun.star.util.URL
672*cdf0e10cSrcweir
673*cdf0e10cSrcweir	document = ThisComponent.CurrentController.Frame
674*cdf0e10cSrcweir	parser   = createUnoService(&quot;com.sun.star.util.URLTransformer&quot;)
675*cdf0e10cSrcweir	dim args(0) as new com.sun.star.beans.PropertyValue
676*cdf0e10cSrcweir	args(0).Name = &quot;&quot;
677*cdf0e10cSrcweir	args(0).Value = event
678*cdf0e10cSrcweir
679*cdf0e10cSrcweir	url.Complete = &quot;script://_$ScriptFrmwrkHelper.removeEvent?&quot; _
680*cdf0e10cSrcweir					+ &quot;language=Java&amp;function=ScriptFrmwrkHelper.removeEvent&quot; _
681*cdf0e10cSrcweir					+ &quot;&amp;location=share&quot;
682*cdf0e10cSrcweir
683*cdf0e10cSrcweir	parser.parseStrict(url)
684*cdf0e10cSrcweir	disp = document.queryDispatch(url,&quot;&quot;,0)
685*cdf0e10cSrcweir	disp.dispatch(url,args())
686*cdf0e10cSrcweirend sub
687*cdf0e10cSrcweir
688*cdf0e10cSrcweir
689*cdf0e10cSrcweirsub AddEventToDocViaAPI( scriptName as string, eventName as string )
690*cdf0e10cSrcweir	dim properties( 1 ) as new com.sun.star.beans.PropertyValue
691*cdf0e10cSrcweir	properties( 0 ).Name = &quot;EventType&quot;
692*cdf0e10cSrcweir	properties( 0 ).Value = &quot;Script&quot;
693*cdf0e10cSrcweir	properties( 1 ).Name = &quot;Script&quot;
694*cdf0e10cSrcweir	properties( 1 ).Value = scriptName
695*cdf0e10cSrcweir
696*cdf0e10cSrcweir	eventSupplier = ThisComponent
697*cdf0e10cSrcweir	nameReplace = eventSupplier.getEvents()
698*cdf0e10cSrcweir	nameReplace.replaceByName( eventName, properties() )
699*cdf0e10cSrcweirend sub
700*cdf0e10cSrcweir
701*cdf0e10cSrcweir
702*cdf0e10cSrcweir&apos; returns 0 for Fkey
703*cdf0e10cSrcweir&apos;         1 for digit
704*cdf0e10cSrcweir&apos;         2 for letter
705*cdf0e10cSrcweir
706*cdf0e10cSrcweirfunction getKeyTypeOffset( key as String ) as integer
707*cdf0e10cSrcweir	length = Len( key )
708*cdf0e10cSrcweir	if ( length &gt; 1 ) then
709*cdf0e10cSrcweir 		getKeyTypeOffset() = 0
710*cdf0e10cSrcweir
711*cdf0e10cSrcweir	elseif  ( key &gt;= &quot;0&quot; AND key &lt;= &quot;9&quot; )  then
712*cdf0e10cSrcweir 		getKeyTypeOffset() = 1
713*cdf0e10cSrcweir	else
714*cdf0e10cSrcweir 		getKeyTypeOffset() = 2
715*cdf0e10cSrcweir 	end if
716*cdf0e10cSrcweirend function
717*cdf0e10cSrcweir
718*cdf0e10cSrcweirfunction getKeyGroupIndex( key as String, offset as Integer ) as Integer
719*cdf0e10cSrcweir    &apos; Keys we are interested in are A - Z, F2 - F12, 0 - 9 anything else should
720*cdf0e10cSrcweir    &apos; ensure -1 is returned
721*cdf0e10cSrcweir	cutKey = mid( key,2 )
722*cdf0e10cSrcweir
723*cdf0e10cSrcweir	if ( cutKey &lt;&gt; &quot;&quot; ) then
724*cdf0e10cSrcweir		acode = asc ( mid( cutKey,1,1) )
725*cdf0e10cSrcweir        if ( acode &gt; 57 ) then
726*cdf0e10cSrcweir			getKeyGroupIndex() = -1
727*cdf0e10cSrcweir			exit function
728*cdf0e10cSrcweir		end if
729*cdf0e10cSrcweir	end if
730*cdf0e10cSrcweir
731*cdf0e10cSrcweir	select case offset
732*cdf0e10cSrcweir	case 0:
733*cdf0e10cSrcweir			num = cint( cutKey )
734*cdf0e10cSrcweir			getKeyGroupIndex() = num - 1
735*cdf0e10cSrcweir			exit function
736*cdf0e10cSrcweir	case 1:
737*cdf0e10cSrcweir			num = asc( key ) - 48
738*cdf0e10cSrcweir			getKeyGroupIndex() = num
739*cdf0e10cSrcweir			exit function
740*cdf0e10cSrcweir	case 2:
741*cdf0e10cSrcweir			num = asc( key ) - 65
742*cdf0e10cSrcweir			getKeyGroupIndex() = num
743*cdf0e10cSrcweir			exit function
744*cdf0e10cSrcweir	end select
745*cdf0e10cSrcweir	getKeyGroupIndex() = -1
746*cdf0e10cSrcweirend function
747*cdf0e10cSrcweir
748*cdf0e10cSrcweirSub processKeyXMLLine( lineCount as Integer, xmlline as String )
749*cdf0e10cSrcweir
750*cdf0e10cSrcweir	if instr( xmlline, &quot;&lt;accel:item&quot; ) &gt; 0 then
751*cdf0e10cSrcweir		shift = false
752*cdf0e10cSrcweir		control = false
753*cdf0e10cSrcweir		if instr( xmlline, &quot;accel:shift=&quot;+chr$(34)+&quot;true&quot;+chr$(34) ) &gt; 0 then
754*cdf0e10cSrcweir			shift = true
755*cdf0e10cSrcweir		end if
756*cdf0e10cSrcweir		if instr( xmlFile( lineCount ), &quot;accel:mod1=&quot;+chr$(34)+&quot;true&quot;+chr$(34) ) &gt; 0 then
757*cdf0e10cSrcweir			control = true
758*cdf0e10cSrcweir		end if
759*cdf0e10cSrcweir		offsetIntoArrayOfArrays = -1 &apos;default unknown
760*cdf0e10cSrcweir		if ( control AND shift ) then
761*cdf0e10cSrcweir			offsetIntoArrayOfArrays = 0
762*cdf0e10cSrcweir		elseif ( control ) then
763*cdf0e10cSrcweir			offsetIntoArrayOfArrays = 3
764*cdf0e10cSrcweir		elseif ( shift ) then
765*cdf0e10cSrcweir			offsetIntoArrayOfArrays = 6
766*cdf0e10cSrcweir		endif
767*cdf0e10cSrcweir		&apos; Calculate which of the 7 key group arrays we need to point to
768*cdf0e10cSrcweir		key = ExtractKeyCodeFromXMLLine( xmlline )
769*cdf0e10cSrcweir		keyTypeOffset = getKeyTypeOffset( key  )
770*cdf0e10cSrcweir		offsetIntoArrayOfArrays = offsetIntoArrayOfArrays + keyTypeOffset
771*cdf0e10cSrcweir
772*cdf0e10cSrcweir		&apos; Calculate from the key the offset into key group array we need to point to
773*cdf0e10cSrcweir		KeyGroupIndex = getKeyGroupIndex( key, keyTypeOffset )
774*cdf0e10cSrcweir		if ( offsetIntoArrayOfArrays = -1 ) then
775*cdf0e10cSrcweir			&apos;Unknown key group, no processing necessary
776*cdf0e10cSrcweir			Exit Sub
777*cdf0e10cSrcweir		end if
778*cdf0e10cSrcweir		if ( KeyGroupIndex &gt; -1 ) then
779*cdf0e10cSrcweir
780*cdf0e10cSrcweir			&apos; Determine if a script framework binding is present or not
781*cdf0e10cSrcweir			if  instr( xmlline, &quot;script://&quot; ) &gt; 0 then
782*cdf0e10cSrcweir				&apos; its one of ours so update its details
783*cdf0e10cSrcweir				scriptName = ExtractScriptIdFromXMLLine( xmlline )
784*cdf0e10cSrcweir
785*cdf0e10cSrcweir				keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value = lineCount
786*cdf0e10cSrcweir				keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Name = scriptName
787*cdf0e10cSrcweir			else
788*cdf0e10cSrcweir				keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value = 1
789*cdf0e10cSrcweir				keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Name = &quot;&quot;
790*cdf0e10cSrcweir
791*cdf0e10cSrcweir			end if
792*cdf0e10cSrcweir		end if
793*cdf0e10cSrcweir	end if
794*cdf0e10cSrcweirEnd Sub
795*cdf0e10cSrcweir
796*cdf0e10cSrcweirSub WriteXMLFromArray()
797*cdf0e10cSrcweir	On Error Goto ErrorHandler
798*cdf0e10cSrcweir	cfgFile =  GetOfficePath() + &quot;user/config/soffice.cfg/&quot; + xmlFileName
799*cdf0e10cSrcweir	updateCfgFile( cfgFile )
800*cdf0e10cSrcweir	&apos;if ( false ) then&apos; config stuff not in build yet
801*cdf0e10cSrcweir	if ( true ) then
802*cdf0e10cSrcweir		updateConfig( xmlFileName )
803*cdf0e10cSrcweir	else
804*cdf0e10cSrcweir		msgbox (&quot;Office must be restarted before your changes will take effect.&quot;+ chr$(10)+&quot;Also close the Office QuickStarter (Windows and Linux)&quot;, 48, &quot;Assign Script (Java) To Menu&quot; )
805*cdf0e10cSrcweir	endif
806*cdf0e10cSrcweir	Exit Sub
807*cdf0e10cSrcweir
808*cdf0e10cSrcweir	ErrorHandler:
809*cdf0e10cSrcweir	reset
810*cdf0e10cSrcweir	MsgBox (&quot;Error: Unable to write to Star Office configuration file&quot; + chr$(10) + &quot;/&quot; + GetOfficePath() + &quot;user/config/soffice.cfg/&quot; +xmlFileName + chr$(10) + chr$(10) + &quot;Action: Please make sure you have write access to this file&quot;,0,&quot;Error&quot; )
811*cdf0e10cSrcweirend Sub
812*cdf0e10cSrcweir
813*cdf0e10cSrcweir
814*cdf0e10cSrcweirSub UpdateCfgFile ( fileName as String )
815*cdf0e10cSrcweir	dim ScriptProvider as Object
816*cdf0e10cSrcweir	dim Script as Object
817*cdf0e10cSrcweir	dim args(1)
818*cdf0e10cSrcweir	dim displayDialogFlag as boolean
819*cdf0e10cSrcweir	displayDialogFlag = false
820*cdf0e10cSrcweir	args(0) = ThisComponent
821*cdf0e10cSrcweir	args(1) = displayDialogFlag
822*cdf0e10cSrcweir
823*cdf0e10cSrcweir	ScriptProvider = createUnoService(&quot;drafts.com.sun.star.script.framework.provider.MasterScriptProvider&quot;)
824*cdf0e10cSrcweir	ScriptProvider.initialize( args() )
825*cdf0e10cSrcweir	Script = ScriptProvider.getScript(&quot;script://_$ScriptFrmwrkHelper.updateCfgFile?&quot; _
826*cdf0e10cSrcweir		+ &quot;language=Java&amp;function=ScriptFrmwrkHelper.updateCfgFile&amp;location=share&quot;)
827*cdf0e10cSrcweir	Dim inArgs(2)
828*cdf0e10cSrcweir	Dim outArgs()
829*cdf0e10cSrcweir	Dim outIndex()
830*cdf0e10cSrcweir	dim localNumLines as integer
831*cdf0e10cSrcweir
832*cdf0e10cSrcweir	inArgs(0) = xmlFile()
833*cdf0e10cSrcweir	inArgs(1) = fileName
834*cdf0e10cSrcweir	inArgs(2) = numberOfLines
835*cdf0e10cSrcweir	Script.invoke( inArgs(), outIndex(), outArgs() )
836*cdf0e10cSrcweirEnd Sub
837*cdf0e10cSrcweir
838*cdf0e10cSrcweirsub UpdateConfig( a$ )
839*cdf0e10cSrcweir       dim document   as object
840*cdf0e10cSrcweir       dim dispatcher as object
841*cdf0e10cSrcweir       dim parser     as object
842*cdf0e10cSrcweir       dim disp     as object
843*cdf0e10cSrcweir       dim url        as new com.sun.star.util.URL
844*cdf0e10cSrcweir       document = ThisComponent.CurrentController.Frame
845*cdf0e10cSrcweir       parser   = createUnoService(&quot;com.sun.star.util.URLTransformer&quot;)
846*cdf0e10cSrcweir       dim args1(0) as new com.sun.star.beans.PropertyValue
847*cdf0e10cSrcweir       args1(0).Name = &quot;StreamName&quot;
848*cdf0e10cSrcweir       args1(0).Value = a$
849*cdf0e10cSrcweir       url.Complete = &quot;.uno:UpdateConfiguration&quot;
850*cdf0e10cSrcweir       parser.parseStrict(url)
851*cdf0e10cSrcweir       disp = document.queryDispatch(url,&quot;&quot;,0)
852*cdf0e10cSrcweir       disp.dispatch(url,args1())
853*cdf0e10cSrcweir
854*cdf0e10cSrcweirEnd Sub
855*cdf0e10cSrcweir
856*cdf0e10cSrcweir
857*cdf0e10cSrcweirsub AddNewEventBinding( scriptName as string, eventPosition as integer, isApp as boolean )
858*cdf0e10cSrcweir	event = allEventTypes( eventPosition ).Name
859*cdf0e10cSrcweir	&apos;dim scriptProp as new com.sun.star.beans.PropertyValue
860*cdf0e10cSrcweir	if isApp then
861*cdf0e10cSrcweir		&apos;scriptProp.Name = scriptName
862*cdf0e10cSrcweir		&apos;scriptProp.Value = numberOfLines
863*cdf0e10cSrcweir		allEventTypesApp( eventPosition ).Name = scriptName
864*cdf0e10cSrcweir		allEventTypesApp( eventPosition ).Value = numberOfLines
865*cdf0e10cSrcweir
866*cdf0e10cSrcweir		newline = &quot; &lt;event:event event:name=&quot; + chr$(34) + event + chr$(34)
867*cdf0e10cSrcweir		newline = newline + &quot; event:language=&quot; + chr$(34) + &quot;Script&quot; + chr$(34) + &quot; xlink:href=&quot; + chr$(34)
868*cdf0e10cSrcweir		newline = newline + scriptName + chr$(34) + &quot; xlink:type=&quot; + chr$(34) + &quot;simple&quot; + chr$(34) + &quot;/&gt;&quot;
869*cdf0e10cSrcweir		xmlFile( numberOfLines ) = newline
870*cdf0e10cSrcweir		xmlFile( numberOfLines + 1 ) = &quot;&lt;/event:events&gt;&quot;
871*cdf0e10cSrcweir		numberOfLines = numberOfLines + 1
872*cdf0e10cSrcweir	else
873*cdf0e10cSrcweir		&apos;scriptProp.Name = scriptName
874*cdf0e10cSrcweir		&apos;scriptProp.Value = 2
875*cdf0e10cSrcweir		allEventTypesDoc( eventPosition ).Name = scriptName
876*cdf0e10cSrcweir		allEventTypesDoc( eventPosition ).Value = 2
877*cdf0e10cSrcweir	end if
878*cdf0e10cSrcweirend sub
879*cdf0e10cSrcweir
880*cdf0e10cSrcweirREM ----- Array update functions -----
881*cdf0e10cSrcweir
882*cdf0e10cSrcweir
883*cdf0e10cSrcweirsub AddNewMenuBinding( newScript as string, newMenuLabel as string, newLinePosition as integer )
884*cdf0e10cSrcweir	dim newXmlFile( 400 ) as string
885*cdf0e10cSrcweir	dim newLineInserted as boolean
886*cdf0e10cSrcweir	dim lineCounter as integer
887*cdf0e10cSrcweir	lineCounter = 1
888*cdf0e10cSrcweir
889*cdf0e10cSrcweir	do while lineCounter &lt;= numberOfLines
890*cdf0e10cSrcweir		if not newLineInserted then
891*cdf0e10cSrcweir			REM If the line number is the position at which to insert the new line
892*cdf0e10cSrcweir			if lineCounter = newLinePosition then
893*cdf0e10cSrcweir				if( instr( xmlFile( lineCounter ), &quot;&lt;menu:menupopup&gt;&quot; ) &gt; 0 ) then
894*cdf0e10cSrcweir					indent = GetMenuWhiteSpace( xmlFile( newLinePosition + 1 ) )
895*cdf0e10cSrcweir					newXmlFile( lineCounter ) = xmlFile( lineCounter )
896*cdf0e10cSrcweir					newXmlFile( lineCounter + 1 ) = ( indent + &quot;&lt;menu:menuitem menu:id=&quot;+chr$(34) + newScript + chr$(34)+&quot; menu:helpid=&quot;+chr$(34)+&quot;1929&quot;+chr$(34)+&quot; menu:label=&quot;+chr$(34)+ newMenuLabel + chr$(34)+&quot;/&gt;&quot; )
897*cdf0e10cSrcweir				else
898*cdf0e10cSrcweir					indent = GetMenuWhiteSpace( xmlFile( newLinePosition - 1 ) )
899*cdf0e10cSrcweir					newXmlFile( lineCounter ) = ( indent + &quot;&lt;menu:menuitem menu:id=&quot;+chr$(34) + newScript + chr$(34)+&quot; menu:helpid=&quot;+chr$(34)+&quot;1929&quot;+chr$(34)+&quot; menu:label=&quot;+chr$(34)+ newMenuLabel + chr$(34)+&quot;/&gt;&quot; )
900*cdf0e10cSrcweir					newXmlFile( lineCounter + 1 ) = xmlFile( lineCounter )
901*cdf0e10cSrcweir				end if
902*cdf0e10cSrcweir			REM added -1 for debug --&gt;
903*cdf0e10cSrcweir			&apos;	indent = GetMenuWhiteSpace( xmlFile( newLinePosition ) )
904*cdf0e10cSrcweir			&apos;	newXmlFile( lineCounter ) = ( indent + &quot;&lt;menu:menuitem menu:id=&quot;+chr$(34)+&quot;script://&quot; + newScript + chr$(34)+&quot; menu:helpid=&quot;+chr$(34)+&quot;1929&quot;+chr$(34)+&quot; menu:label=&quot;+chr$(34)+ newMenuLabel + chr$(34)+&quot;/&gt;&quot; )
905*cdf0e10cSrcweir			&apos;	newXmlFile( lineCounter + 1 ) = xmlFile( lineCounter )
906*cdf0e10cSrcweir				newLineInserted = true
907*cdf0e10cSrcweir			else
908*cdf0e10cSrcweir				newXmlFile( lineCounter ) = xmlFile( lineCounter )
909*cdf0e10cSrcweir			end if
910*cdf0e10cSrcweir		else
911*cdf0e10cSrcweir			REM if the new line has been inserted the read from one position behind
912*cdf0e10cSrcweir			newXmlFile( lineCounter + 1 ) = xmlFile( lineCounter )
913*cdf0e10cSrcweir		end if
914*cdf0e10cSrcweir		lineCounter = lineCounter + 1
915*cdf0e10cSrcweir	loop
916*cdf0e10cSrcweir
917*cdf0e10cSrcweir	numberOfLines = numberOfLines + 1
918*cdf0e10cSrcweir
919*cdf0e10cSrcweir	REM read the new file into the global array
920*cdf0e10cSrcweir	for n = 1 to numberOfLines
921*cdf0e10cSrcweir		xmlFile( n ) = newXmlFile( n )
922*cdf0e10cSrcweir	next n
923*cdf0e10cSrcweir
924*cdf0e10cSrcweirend sub
925*cdf0e10cSrcweir
926*cdf0e10cSrcweir
927*cdf0e10cSrcweirsub AddNewKeyBinding( scriptName as string, shift as boolean, control as boolean, key as string )
928*cdf0e10cSrcweir
929*cdf0e10cSrcweir	dim keyCombo as string
930*cdf0e10cSrcweir	newLine = &quot; &lt;accel:item accel:code=&quot;+chr$(34)+&quot;KEY_&quot; + key +chr$(34)
931*cdf0e10cSrcweir	if shift then
932*cdf0e10cSrcweir		keyCombo = &quot;SHIFT + &quot;
933*cdf0e10cSrcweir		newLine = newLine + &quot; accel:shift=&quot;+chr$(34)+&quot;true&quot;+chr$(34)
934*cdf0e10cSrcweir	end if
935*cdf0e10cSrcweir	if control then
936*cdf0e10cSrcweir		keyCombo = keyCombo + &quot;CONTROL + &quot;
937*cdf0e10cSrcweir		newLine = newLine + &quot; accel:mod1=&quot;+chr$(34)+&quot;true&quot;+chr$(34)
938*cdf0e10cSrcweir	end if
939*cdf0e10cSrcweir	keyCombo = keyCombo + key
940*cdf0e10cSrcweir	newLine = newLine + &quot; xlink:href=&quot;+chr$(34)+ scriptName +chr$(34) +&quot;/&gt;&quot;
941*cdf0e10cSrcweir
942*cdf0e10cSrcweir	if ( control AND shift ) then
943*cdf0e10cSrcweir		offsetIntoArrayOfArrays = 0
944*cdf0e10cSrcweir	elseif ( control ) then
945*cdf0e10cSrcweir		offsetIntoArrayOfArrays = 3
946*cdf0e10cSrcweir	elseif ( shift ) then
947*cdf0e10cSrcweir		offsetIntoArrayOfArrays = 6
948*cdf0e10cSrcweir	endif
949*cdf0e10cSrcweir
950*cdf0e10cSrcweir	keyTypeOffset = getKeyTypeOffset( key  )
951*cdf0e10cSrcweir	offsetIntoArrayOfArrays = offsetIntoArrayOfArrays + keyTypeOffset
952*cdf0e10cSrcweir	&apos; Calculate from the key the offset into key group array we need to point to
953*cdf0e10cSrcweir	KeyGroupIndex = getKeyGroupIndex( key, keyTypeOffset )
954*cdf0e10cSrcweir
955*cdf0e10cSrcweir	&apos; if key is allready allocated to a script then just reallocate
956*cdf0e10cSrcweir	if ( keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value &gt; 1 ) then
957*cdf0e10cSrcweir
958*cdf0e10cSrcweir		keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Name = scriptName
959*cdf0e10cSrcweir		&apos;replace line in xml file
960*cdf0e10cSrcweir		xmlFile( keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value ) = newLine
961*cdf0e10cSrcweir	else
962*cdf0e10cSrcweir		&apos; this is a new binding, create a new line in xml file
963*cdf0e10cSrcweir		for n = 1 to numberOfLines
964*cdf0e10cSrcweir			if n = numberOfLines then
965*cdf0e10cSrcweir				xmlFile( n ) = newLine
966*cdf0e10cSrcweir				xmlFile( n + 1 ) = &quot;&lt;/accel:acceleratorlist&gt;&quot;
967*cdf0e10cSrcweir				exit for
968*cdf0e10cSrcweir			else
969*cdf0e10cSrcweir				xmlFile( n ) = xmlFile( n )
970*cdf0e10cSrcweir			end if
971*cdf0e10cSrcweir		next n
972*cdf0e10cSrcweir
973*cdf0e10cSrcweir		keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Value = n
974*cdf0e10cSrcweir		keyAllocationMap( offsetIntoArrayOfArrays, KeyGroupIndex ).Name = scriptName
975*cdf0e10cSrcweir		numberOfLines = numberOfLines + 1
976*cdf0e10cSrcweir	endif
977*cdf0e10cSrcweir
978*cdf0e10cSrcweirend sub
979*cdf0e10cSrcweir
980*cdf0e10cSrcweir
981*cdf0e10cSrcweirSub RemoveBinding( lineToRemove as Integer )
982*cdf0e10cSrcweir	xmlFile( lineToRemove ) = &quot;&quot;
983*cdf0e10cSrcweirend Sub
984*cdf0e10cSrcweir
985*cdf0e10cSrcweirREM Adds or removes the starting xml line positions for each top-level menu after the menu with the added script
986*cdf0e10cSrcweirsub UpdateTopLevelMenus( topLevelMenuPosition as integer, addLine as boolean )
987*cdf0e10cSrcweir	for n = topLevelMenuPosition to 8
988*cdf0e10cSrcweir		if addLine then
989*cdf0e10cSrcweir			menuItemLinePosition( n ) = menuItemLinePosition( n ) + 1
990*cdf0e10cSrcweir
991*cdf0e10cSrcweir		end if
992*cdf0e10cSrcweir	next n
993*cdf0e10cSrcweirend sub
994*cdf0e10cSrcweir
995*cdf0e10cSrcweir
996*cdf0e10cSrcweirREM Remove scriptNames and scriptLinePosition entries
997*cdf0e10cSrcweirsub RemoveScriptNameAndPosition( keyComboPosition )
998*cdf0e10cSrcweir	dim updatedScriptNames( 120 ) as string
999*cdf0e10cSrcweir	dim updatedScriptLinePosition( 120 ) as integer
1000*cdf0e10cSrcweir	dim removedScript as boolean
1001*cdf0e10cSrcweir	removedScript = false
1002*cdf0e10cSrcweir
1003*cdf0e10cSrcweir	for n = 1 to scriptCount
1004*cdf0e10cSrcweir		if not removedScript then
1005*cdf0e10cSrcweir			if not( n = keyComboPosition ) then
1006*cdf0e10cSrcweir				updatedScriptNames( n ) = scriptNames( n )
1007*cdf0e10cSrcweir			else
1008*cdf0e10cSrcweir				removedScript = true
1009*cdf0e10cSrcweir			end if
1010*cdf0e10cSrcweir		else
1011*cdf0e10cSrcweir			updatedScriptNames( n - 1 ) = scriptNames( n )
1012*cdf0e10cSrcweir		end if
1013*cdf0e10cSrcweir	next n
1014*cdf0e10cSrcweir	scriptCount = scriptCount - 1
1015*cdf0e10cSrcweir
1016*cdf0e10cSrcweir	for n = 1 to scriptCount
1017*cdf0e10cSrcweir		scriptNames( n ) = updatedScriptNames( n )
1018*cdf0e10cSrcweir	next n
1019*cdf0e10cSrcweirend sub
1020*cdf0e10cSrcweir
1021*cdf0e10cSrcweir
1022*cdf0e10cSrcweir
1023*cdf0e10cSrcweirREM ----- Populating Dialog Controls -----
1024*cdf0e10cSrcweir
1025*cdf0e10cSrcweirSub PopulateLanguageCombo()
1026*cdf0e10cSrcweir	langCombo =  bindingDialog.getControl( &quot;LanguageCombo&quot; )
1027*cdf0e10cSrcweir	langCombo.removeItems( 0, langCombo.getItemCount() )
1028*cdf0e10cSrcweir	for n = LBOUND( languages() ) to UBOUND ( languages() )
1029*cdf0e10cSrcweir		langCombo.addItem( languages( n ), n )
1030*cdf0e10cSrcweir	next n
1031*cdf0e10cSrcweir	langCombo.setDropDownLineCount( n )
1032*cdf0e10cSrcweir	langCombo.text = langCombo.getItem( 0 )
1033*cdf0e10cSrcweirEnd Sub
1034*cdf0e10cSrcweir
1035*cdf0e10cSrcweirSub PopulateLocationCombo()
1036*cdf0e10cSrcweir	dim ScriptProvider as Object
1037*cdf0e10cSrcweir	dim args(1)
1038*cdf0e10cSrcweir	dim displayDialogFlag as boolean
1039*cdf0e10cSrcweir	displayDialogFlag = false
1040*cdf0e10cSrcweir	args(0) = ThisComponent
1041*cdf0e10cSrcweir	args(1) = displayDialogFlag
1042*cdf0e10cSrcweir
1043*cdf0e10cSrcweir	ScriptProvider = createUnoService(&quot;drafts.com.sun.star.script.framework.provider.MasterScriptProvider&quot;)
1044*cdf0e10cSrcweir	ScriptProvider.initialize( args() )
1045*cdf0e10cSrcweir
1046*cdf0e10cSrcweir	locCombo =  bindingDialog.getControl( &quot;LocationCombo&quot; )
1047*cdf0e10cSrcweir	locCombo.removeItems( 0, locCombo.getItemCount() )
1048*cdf0e10cSrcweir	for n = LBOUND( locations() ) to UBOUND ( locations() )
1049*cdf0e10cSrcweir		locCombo.addItem( locations( n ), n )
1050*cdf0e10cSrcweir	next n
1051*cdf0e10cSrcweir	locCombo.setDropDownLineCount( n )
1052*cdf0e10cSrcweir	locCombo.text = locCombo.getItem( 0 )
1053*cdf0e10cSrcweirEnd Sub
1054*cdf0e10cSrcweir
1055*cdf0e10cSrcweirsub PopulateScriptList( lang as String, loc as String )
1056*cdf0e10cSrcweir    Dim detailedView as boolean
1057*cdf0e10cSrcweir    detailedView = bindingDialog.Model.detail.state
1058*cdf0e10cSrcweir	scriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
1059*cdf0e10cSrcweir	scriptList.removeItems( 0, scriptList.getItemCount() )
1060*cdf0e10cSrcweir
1061*cdf0e10cSrcweir	smgr = getProcessServiceManager()
1062*cdf0e10cSrcweir   	context = smgr.getPropertyValue( &quot;DefaultContext&quot; )
1063*cdf0e10cSrcweir   	scriptstoragemgr = context.getValueByName( &quot;/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager&quot; )
1064*cdf0e10cSrcweir	scriptLocationURI = &quot;USER&quot;
1065*cdf0e10cSrcweir	if ( loc = &quot;Share&quot; ) then
1066*cdf0e10cSrcweir		scriptLocationURI = &quot;SHARE&quot;
1067*cdf0e10cSrcweir	elseif ( loc = &quot;Document&quot; )then
1068*cdf0e10cSrcweir		document = StarDesktop.ActiveFrame.Controller.Model
1069*cdf0e10cSrcweir		scriptLocationURI = document.getURL()
1070*cdf0e10cSrcweir	elseif ( loc = &quot;Filesystem&quot; ) then
1071*cdf0e10cSrcweir		REM populate the list from the filesysScripts list
1072*cdf0e10cSrcweir		if(lang = &quot;Java&quot; ) then
1073*cdf0e10cSrcweir			exit sub
1074*cdf0e10cSrcweir		endif
1075*cdf0e10cSrcweir		length = UBOUND( filesysScripts() )
1076*cdf0e10cSrcweir		if(length = -1) then
1077*cdf0e10cSrcweir			exit sub
1078*cdf0e10cSrcweir		endif
1079*cdf0e10cSrcweir        for langIndex = lbound(languages()) to ubound(languages())
1080*cdf0e10cSrcweir            if ( lang = languages(langIndex)) then
1081*cdf0e10cSrcweir                extns = extensions(langIndex)
1082*cdf0e10cSrcweir                exit for
1083*cdf0e10cSrcweir            endif
1084*cdf0e10cSrcweir        next langIndex
1085*cdf0e10cSrcweir		dim locnDisplayList( length ) as new com.sun.star.beans.PropertyValue
1086*cdf0e10cSrcweir		for index = lbound(filesysScripts()) to ubound(filesysScripts())
1087*cdf0e10cSrcweir			scriptextn = filesysScripts( index )
1088*cdf0e10cSrcweir			pos = lastIndexOf( scriptextn, &quot;.&quot; )
1089*cdf0e10cSrcweir            scriptextn = mid( scriptextn, pos + 1, len( scriptextn ) - pos )
1090*cdf0e10cSrcweir
1091*cdf0e10cSrcweir            for extnsIndex = lbound(extns()) to ubound(extns())
1092*cdf0e10cSrcweir                extn = extns(extnsIndex)
1093*cdf0e10cSrcweir                if ( scriptextn = extn ) then
1094*cdf0e10cSrcweir                	if ( detailedView ) then
1095*cdf0e10cSrcweir                    	locnDisplayList( index ).Name = filesysScripts( index )
1096*cdf0e10cSrcweir                    	locnDisplayList( index ).Value = filesysScripts( index )
1097*cdf0e10cSrcweir                	else
1098*cdf0e10cSrcweir						REM replace name with simplified view
1099*cdf0e10cSrcweir						locnDisplayList( index ).Name = filesysScripts( index )
1100*cdf0e10cSrcweir						locnDisplayList( index ).Value = filesysScripts( index )
1101*cdf0e10cSrcweir					end if
1102*cdf0e10cSrcweir				scriptList.addItem( locnDisplayList( index ).Name, index )
1103*cdf0e10cSrcweir				exit for
1104*cdf0e10cSrcweir                end if
1105*cdf0e10cSrcweir            next extnsIndex
1106*cdf0e10cSrcweir		next index
1107*cdf0e10cSrcweir		ScriptDisplayList(0) = locnDisplayList()
1108*cdf0e10cSrcweir		scriptList.selectItemPos( 0, true )
1109*cdf0e10cSrcweir
1110*cdf0e10cSrcweir        REM !!!!At this point we exit the sub!!!!
1111*cdf0e10cSrcweir		exit sub
1112*cdf0e10cSrcweir
1113*cdf0e10cSrcweir	endif
1114*cdf0e10cSrcweir
1115*cdf0e10cSrcweir	scriptStorageID = scriptstoragemgr.getScriptStorageID( scriptLocationURI )
1116*cdf0e10cSrcweir	dim resultList() as Object
1117*cdf0e10cSrcweir	if ( scriptStorageID &gt; -1 ) then
1118*cdf0e10cSrcweir		storage = scriptstoragemgr.getScriptStorage( scriptStorageID )
1119*cdf0e10cSrcweir		implementations() = storage.getAllImplementations()
1120*cdf0e10cSrcweir		length = UBOUND( implementations() )
1121*cdf0e10cSrcweir		reservedScriptTag = &quot;_$&quot;
1122*cdf0e10cSrcweir    	if ( length &gt; -1 ) then
1123*cdf0e10cSrcweir    		dim tempDisplayList( length ) as new com.sun.star.beans.PropertyValue
1124*cdf0e10cSrcweir			for n = LBOUND( implementations() ) to UBOUND( implementations() )
1125*cdf0e10cSrcweir				logicalName = implementations( n ).getLogicalName()
1126*cdf0e10cSrcweir				firstTwoChars = LEFT( logicalName, 2 )
1127*cdf0e10cSrcweir				&apos;Only display scripts whose logicalnames don&apos;t begin with &quot;_$&quot;
1128*cdf0e10cSrcweir				if ( firstTwoChars &lt;&gt; reservedScriptTag ) then
1129*cdf0e10cSrcweir					if ( lang = implementations( n ).getLanguage() ) then
1130*cdf0e10cSrcweir						if ( detailedView ) then
1131*cdf0e10cSrcweir							tempDisplayList( n ).Name = logicalName _
1132*cdf0e10cSrcweir								+ &quot; [&quot; + implementations( n ).getFunctionName() + &quot;]&quot;
1133*cdf0e10cSrcweir							tempDisplayList( n ).Value = implementations( n )
1134*cdf0e10cSrcweir						else
1135*cdf0e10cSrcweir							tempDisplayList( n ).Name = logicalName
1136*cdf0e10cSrcweir							tempDisplayList( n ).Value = implementations( n )
1137*cdf0e10cSrcweir						endif
1138*cdf0e10cSrcweir						scriptList.addItem( tempDisplayList( n ).Name, n )
1139*cdf0e10cSrcweir					endif
1140*cdf0e10cSrcweir				endif
1141*cdf0e10cSrcweir			next n
1142*cdf0e10cSrcweir			resultList = tempDisplayList()
1143*cdf0e10cSrcweir		endif
1144*cdf0e10cSrcweir	ScriptDisplayList(0) = resultList()
1145*cdf0e10cSrcweir	endif
1146*cdf0e10cSrcweir	scriptList.selectItemPos( 0, true )
1147*cdf0e10cSrcweir
1148*cdf0e10cSrcweirend sub
1149*cdf0e10cSrcweir
1150*cdf0e10cSrcweirsub PopulateMenuCombo()
1151*cdf0e10cSrcweir	menuComboBox = bindingDialog.getControl( &quot;MenuCombo&quot; )
1152*cdf0e10cSrcweir	menuComboBox.removeItems( 0, menuComboBox.getItemCount() )
1153*cdf0e10cSrcweir	for n = 1 to menuCount
1154*cdf0e10cSrcweir		menuComboBox.addItem( menuItems( n ), n - 1 )
1155*cdf0e10cSrcweir	next n
1156*cdf0e10cSrcweir	menuComboBox.setDropDownLineCount( 8 )
1157*cdf0e10cSrcweir	menuComboBox.text = menuComboBox.getItem( 0 )
1158*cdf0e10cSrcweirend sub
1159*cdf0e10cSrcweir
1160*cdf0e10cSrcweir
1161*cdf0e10cSrcweirsub PopulateSubMenuList( menuItemPosition as integer )
1162*cdf0e10cSrcweir	redim subMenuItems( 100 ) as string
1163*cdf0e10cSrcweir	redim subMenuItemLinePosition( 100 ) as integer
1164*cdf0e10cSrcweir	dim lineNumber as integer
1165*cdf0e10cSrcweir	const menuItemWhiteSpace = 4
1166*cdf0e10cSrcweir	const menuXMLTag = &quot;&lt;menu:menu&quot;
1167*cdf0e10cSrcweir	subMenuCount = 1
1168*cdf0e10cSrcweir
1169*cdf0e10cSrcweir	REM xmlStartLine and xmlEndLine refer to the first and last lines
1170*cdf0e10cSrcweir	&apos; menuItemPosition of a top-level menu ( 1=File to 8=Help ) add one line
1171*cdf0e10cSrcweir	xmlStartLine = menuItemLinePosition( menuItemPosition ) + 1
1172*cdf0e10cSrcweir
1173*cdf0e10cSrcweir	REM If last menu item is chosen
1174*cdf0e10cSrcweir	if menuItemPosition = menuCount then
1175*cdf0e10cSrcweir		xmlEndLine = numberOfLines
1176*cdf0e10cSrcweir	else
1177*cdf0e10cSrcweir		REM Other wise get the line before the next top-level menu begins
1178*cdf0e10cSrcweir		xmlEndLine = menuItemLinePosition( menuItemPosition + 1 ) - 1
1179*cdf0e10cSrcweir	end if
1180*cdf0e10cSrcweir
1181*cdf0e10cSrcweir	for lineNumber = xmlStartLine to xmlEndLine
1182*cdf0e10cSrcweir		REM Insert all sub-menus and sub-popupmenus
1183*cdf0e10cSrcweir		if not( instr( xmlFile( lineNumber ), menuXMLTag ) = 0 ) and instr( xmlFile( lineNumber ), &quot;menupopup&quot;) = 0 then
1184*cdf0e10cSrcweir			subMenuIndent = GetMenuWhiteSpace( xmlFile( lineNumber ) )
1185*cdf0e10cSrcweir			if subMenuIndent = &quot; &quot; then
1186*cdf0e10cSrcweir				subMenuIndent = &quot;&quot;
1187*cdf0e10cSrcweir			else
1188*cdf0e10cSrcweir				subMenuIndent = subMenuIndent + subMenuIndent
1189*cdf0e10cSrcweir			end if
1190*cdf0e10cSrcweir			if not( instr( xmlFile( lineNumber ), &quot;menuseparator&quot; ) = 0 ) then
1191*cdf0e10cSrcweir				subMenuItems( subMenuCount ) = subMenuIndent + &quot;----------------&quot;
1192*cdf0e10cSrcweir			else
1193*cdf0e10cSrcweir				subMenuName = ExtractLabelFromXMLLine( xmlFile( lineNumber ) )
1194*cdf0e10cSrcweir				REM Add script Name if there is one bound to menu item
1195*cdf0e10cSrcweir				if instr( xmlFile( lineNumber ), &quot;script://&quot; ) &gt; 0 then
1196*cdf0e10cSrcweir					script = ExtractScriptIdFromXMLLine( xmlFile( lineNumber ) )
1197*cdf0e10cSrcweir					subMenuItems( subMenuCount ) = ( subMenuIndent + subMenuName + &quot; [&quot; + script + &quot;]&quot; )
1198*cdf0e10cSrcweir				else
1199*cdf0e10cSrcweir					subMenuItems( subMenuCount ) = subMenuIndent + subMenuName
1200*cdf0e10cSrcweir				end if
1201*cdf0e10cSrcweir			end if
1202*cdf0e10cSrcweir			subMenuItemLinePosition( subMenuCount ) = lineNumber
1203*cdf0e10cSrcweir			subMenuCount = subMenuCount + 1
1204*cdf0e10cSrcweir		end if
1205*cdf0e10cSrcweir	next lineNumber
1206*cdf0e10cSrcweir
1207*cdf0e10cSrcweir	subMenuList = bindingDialog.getControl( &quot;SubMenuList&quot; )
1208*cdf0e10cSrcweir
1209*cdf0e10cSrcweir	currentPosition = subMenuList.getSelectedItemPos()
1210*cdf0e10cSrcweir
1211*cdf0e10cSrcweir	subMenuList.removeItems( 0, subMenuList.getItemCount() )
1212*cdf0e10cSrcweir	&apos;If there are no sub-menus i.e. a dynamically generated menu like Format
1213*cdf0e10cSrcweir	&apos;if subMenuCount = 1 then
1214*cdf0e10cSrcweir	if menuItems( menuItemPosition ) = &quot;Format&quot; then
1215*cdf0e10cSrcweir			subMenuList.addItem( &quot;Unable to Assign Scripts to this menu&quot;, 0 )
1216*cdf0e10cSrcweir	else
1217*cdf0e10cSrcweir		for n = 1 to subMenuCount - 1
1218*cdf0e10cSrcweir			subMenuList.addItem( subMenuItems( n ), n - 1 )
1219*cdf0e10cSrcweir		next n
1220*cdf0e10cSrcweir	end if
1221*cdf0e10cSrcweir
1222*cdf0e10cSrcweir	subMenuList.selectItemPos( currentPosition, true )
1223*cdf0e10cSrcweir
1224*cdf0e10cSrcweir	SubMenuListListener()
1225*cdf0e10cSrcweir	MenuLabelBoxListener()
1226*cdf0e10cSrcweirend sub
1227*cdf0e10cSrcweir
1228*cdf0e10cSrcweir
1229*cdf0e10cSrcweir
1230*cdf0e10cSrcweirsub PopulateTopLevelKeyBindingList()
1231*cdf0e10cSrcweir
1232*cdf0e10cSrcweir    allKeyGroupsArray(0) =  &quot;SHIFT + CONTROL + F keys&quot;
1233*cdf0e10cSrcweir	allKeyGroupsArray(1) = &quot;SHIFT + CONTROL + digits&quot; &apos; CURRENTLY DISABLED
1234*cdf0e10cSrcweir	allKeyGroupsArray(2) = &quot;SHIFT + CONTROL + letters&quot;
1235*cdf0e10cSrcweir	allKeyGroupsArray(3) = &quot;CONTROL + F keys&quot;
1236*cdf0e10cSrcweir	allKeyGroupsArray(4) = &quot;CONTROL + digits&quot;
1237*cdf0e10cSrcweir	allKeyGroupsArray(5) = &quot;CONTROL + letters&quot;
1238*cdf0e10cSrcweir	allKeyGroupsArray(6) = &quot;SHIFT + F keys&quot;
1239*cdf0e10cSrcweir
1240*cdf0e10cSrcweir	keyCombo = bindingDialog.getControl( &quot;KeyCombo&quot; )
1241*cdf0e10cSrcweir	keyCombo.removeItems( 0, keyCombo.getItemCount() )
1242*cdf0e10cSrcweir	pos = 0
1243*cdf0e10cSrcweir	for n = LBOUND( allKeyGroupsArray() ) to UBOUND( allKeyGroupsArray() )
1244*cdf0e10cSrcweir	&apos; SHIFT + CONTROL + digits group is disabled at the moment, so skip
1245*cdf0e10cSrcweir	&apos; it
1246*cdf0e10cSrcweir		if ( n &lt;&gt; 1 ) then
1247*cdf0e10cSrcweir			keyCombo.addItem( allKeyGroupsArray( n ), pos )
1248*cdf0e10cSrcweir			pos = pos +1
1249*cdf0e10cSrcweir		endif
1250*cdf0e10cSrcweir	next n
1251*cdf0e10cSrcweir	keyCombo.text = keyCombo.getItem( 0 )
1252*cdf0e10cSrcweirend sub
1253*cdf0e10cSrcweir
1254*cdf0e10cSrcweirsub PopulateKeyBindingList( keyGroupIndex as Integer )
1255*cdf0e10cSrcweir	keyList = bindingDialog.getControl( &quot;KeyList&quot; )
1256*cdf0e10cSrcweir	selectedPos = keyList.getSelectedItemPos()
1257*cdf0e10cSrcweir	keyList.removeItems( 0, keyList.getItemCount() )
1258*cdf0e10cSrcweir
1259*cdf0e10cSrcweir	ShortCutKeyArray() = KeyBindArrayOfArrays( keyGroupIndex )
1260*cdf0e10cSrcweir
1261*cdf0e10cSrcweir	Dim keyProp as new com.sun.star.beans.PropertyValue
1262*cdf0e10cSrcweir	for n = lbound( ShortCutKeyArray() )  to ubound( ShortCutKeyArray() )
1263*cdf0e10cSrcweir		keyName = ShortCutKeyArray( n )
1264*cdf0e10cSrcweir		if ( keyAllocationMap( keyGroupIndex, n ).Value = 1 ) then
1265*cdf0e10cSrcweir			keyName = keyName + &quot; [Allocated to Office function]&quot;
1266*cdf0e10cSrcweir
1267*cdf0e10cSrcweir		elseif ( keyAllocationMap( keyGroupIndex, n ).Value &gt; 1 ) then
1268*cdf0e10cSrcweir			keyName = keyName + &quot; &quot; + keyAllocationMap( keyGroupIndex, n ).Name
1269*cdf0e10cSrcweir		endif
1270*cdf0e10cSrcweir		keyList.addItem( keyName, n )
1271*cdf0e10cSrcweir	next n
1272*cdf0e10cSrcweir
1273*cdf0e10cSrcweir	if ( selectedPos &lt;&gt; -1 )then
1274*cdf0e10cSrcweir		keyList.selectItemPos( selectedPos, true )
1275*cdf0e10cSrcweir	else
1276*cdf0e10cSrcweir		keyList.selectItemPos( 0, true )
1277*cdf0e10cSrcweir	end if
1278*cdf0e10cSrcweir	KeyListListener()
1279*cdf0e10cSrcweirend sub
1280*cdf0e10cSrcweir
1281*cdf0e10cSrcweirsub populateEventList( focusPosition as integer )
1282*cdf0e10cSrcweir	allApps = bindingDialog.getControl( &quot;AllAppsOption&quot; )
1283*cdf0e10cSrcweir	eventList = bindingDialog.getControl( &quot;EventList&quot; )
1284*cdf0e10cSrcweir	eventList.removeItems( 0, eventList.getItemCount() )
1285*cdf0e10cSrcweir
1286*cdf0e10cSrcweir	dim isApp as boolean
1287*cdf0e10cSrcweir	if allApps.state = true then  &apos; Application event
1288*cdf0e10cSrcweir		isApp = true
1289*cdf0e10cSrcweir	else
1290*cdf0e10cSrcweir		isApp = false
1291*cdf0e10cSrcweir	end if
1292*cdf0e10cSrcweir
1293*cdf0e10cSrcweir	&apos; use allEventTypes() to fill list box
1294*cdf0e10cSrcweir	&apos; for each element compare with allEventTypesApp
1295*cdf0e10cSrcweir	dim scriptName as string
1296*cdf0e10cSrcweir	dim lineNumber as integer
1297*cdf0e10cSrcweir	for n = 0 to ubound( allEventTypes() )
1298*cdf0e10cSrcweir		&apos; If the line number is 1 then SB macro
1299*cdf0e10cSrcweir		&apos; more than 1 it is the line number of the script
1300*cdf0e10cSrcweir		if isApp and n &gt; 12 then
1301*cdf0e10cSrcweir			exit for
1302*cdf0e10cSrcweir		endif
1303*cdf0e10cSrcweir		if isApp then
1304*cdf0e10cSrcweir			lineNumber = allEventTypesApp( n ).Value
1305*cdf0e10cSrcweir			scriptName = allEventTypesApp( n ).Name
1306*cdf0e10cSrcweir		else
1307*cdf0e10cSrcweir			lineNumber = allEventTypesDoc( n ).Value
1308*cdf0e10cSrcweir			scriptName = allEventTypesDoc( n ).Name
1309*cdf0e10cSrcweir		end if
1310*cdf0e10cSrcweir		stringToAdd = &quot;&quot;
1311*cdf0e10cSrcweir		if ( lineNumber &gt;= 1 ) then
1312*cdf0e10cSrcweir			stringToAdd = &quot; [&quot; + scriptName + &quot;]&quot;
1313*cdf0e10cSrcweir		end if
1314*cdf0e10cSrcweir		eventList.addItem( allEventTypes( n ).Value + &quot; &quot; + stringToAdd, n )
1315*cdf0e10cSrcweir	next n
1316*cdf0e10cSrcweir
1317*cdf0e10cSrcweir	eventList.selectItemPos( focusPosition, true )
1318*cdf0e10cSrcweirend sub
1319*cdf0e10cSrcweir
1320*cdf0e10cSrcweir
1321*cdf0e10cSrcweir
1322*cdf0e10cSrcweirsub CreateAllKeyBindings()
1323*cdf0e10cSrcweir	reDim allKeyBindings( 105 ) as string
1324*cdf0e10cSrcweir	keyBindingPosition = 1
1325*cdf0e10cSrcweir
1326*cdf0e10cSrcweir	for FKey = 2 to 12
1327*cdf0e10cSrcweir		allKeyBindings( keyBindingPosition ) = &quot;SHIFT + CONTROL + F&quot; + FKey
1328*cdf0e10cSrcweir		keyBindingPosition = keyBindingPosition + 1
1329*cdf0e10cSrcweir	next FKey
1330*cdf0e10cSrcweir	for Digit = 0 to 9
1331*cdf0e10cSrcweir		allKeyBindings( keyBindingPosition ) = &quot;SHIFT + CONTROL + &quot; + Digit
1332*cdf0e10cSrcweir			keyBindingPosition = keyBindingPosition + 1
1333*cdf0e10cSrcweir	next Digit
1334*cdf0e10cSrcweir	for Alpha = 65 to 90
1335*cdf0e10cSrcweir		allKeyBindings( keyBindingPosition ) = &quot;SHIFT + CONTROL + &quot; + chr$( Alpha )
1336*cdf0e10cSrcweir		keyBindingPosition = keyBindingPosition + 1
1337*cdf0e10cSrcweir	next Alpha
1338*cdf0e10cSrcweir
1339*cdf0e10cSrcweir	for FKey = 2 to 12
1340*cdf0e10cSrcweir		allKeyBindings( keyBindingPosition ) = &quot;CONTROL + F&quot; + FKey
1341*cdf0e10cSrcweir		keyBindingPosition = keyBindingPosition + 1
1342*cdf0e10cSrcweir	next FKey
1343*cdf0e10cSrcweir	for Digit = 0 to 9
1344*cdf0e10cSrcweir		allKeyBindings( keyBindingPosition ) = &quot;CONTROL + &quot; + Digit
1345*cdf0e10cSrcweir		keyBindingPosition = keyBindingPosition + 1
1346*cdf0e10cSrcweir	next Digit
1347*cdf0e10cSrcweir	for Alpha = 65 to 90
1348*cdf0e10cSrcweir		allKeyBindings( keyBindingPosition ) = &quot;CONTROL + &quot; + chr$( Alpha )
1349*cdf0e10cSrcweir		keyBindingPosition = keyBindingPosition + 1
1350*cdf0e10cSrcweir	next Alpha
1351*cdf0e10cSrcweir
1352*cdf0e10cSrcweir	for FKey = 2 to 12
1353*cdf0e10cSrcweir		allKeyBindings( keyBindingPosition ) = &quot;SHIFT + F&quot; + FKey
1354*cdf0e10cSrcweir		keyBindingPosition = keyBindingPosition + 1
1355*cdf0e10cSrcweir	next FKey
1356*cdf0e10cSrcweirend sub
1357*cdf0e10cSrcweir
1358*cdf0e10cSrcweir
1359*cdf0e10cSrcweirsub createAllEventTypes()
1360*cdf0e10cSrcweir	allEventTypes( 0 ).Name = &quot;OnStartApp&quot;
1361*cdf0e10cSrcweir	allEventTypes( 0 ).Value = &quot;Start Application&quot;
1362*cdf0e10cSrcweir	allEventTypes( 1 ).Name = &quot;OnCloseApp&quot;
1363*cdf0e10cSrcweir	allEventTypes( 1 ).Value = &quot;Close Application&quot;
1364*cdf0e10cSrcweir	allEventTypes( 2 ).Name = &quot;OnNew&quot;
1365*cdf0e10cSrcweir	allEventTypes( 2 ).Value = &quot;Create Document&quot;
1366*cdf0e10cSrcweir	allEventTypes( 3 ).Name = &quot;OnLoad&quot;
1367*cdf0e10cSrcweir	allEventTypes( 3 ).Value = &quot;Open Document&quot;
1368*cdf0e10cSrcweir	allEventTypes( 4 ).Name = &quot;OnSaveAs&quot;
1369*cdf0e10cSrcweir	allEventTypes( 4 ).Value = &quot;Save Document As&quot;
1370*cdf0e10cSrcweir	allEventTypes( 5 ).Name = &quot;OnSaveAsDone&quot;
1371*cdf0e10cSrcweir	allEventTypes( 5 ).Value = &quot;Document has been saved as&quot;
1372*cdf0e10cSrcweir	allEventTypes( 6 ).Name = &quot;OnSave&quot;
1373*cdf0e10cSrcweir	allEventTypes( 6 ).Value = &quot;Save Document&quot;
1374*cdf0e10cSrcweir	allEventTypes( 7 ).Name = &quot;OnSaveDone&quot;
1375*cdf0e10cSrcweir	allEventTypes( 7 ).Value = &quot;Document has been saved&quot;
1376*cdf0e10cSrcweir	allEventTypes( 8 ).Name = &quot;OnPrepareUnload&quot;
1377*cdf0e10cSrcweir	allEventTypes( 8 ).Value = &quot;Close Document&quot;
1378*cdf0e10cSrcweir	allEventTypes( 9 ).Name = &quot;OnUnload&quot;
1379*cdf0e10cSrcweir	allEventTypes( 9 ).Value = &quot;Close Document&quot;
1380*cdf0e10cSrcweir	allEventTypes( 10 ).Name = &quot;OnFocus&quot;
1381*cdf0e10cSrcweir	allEventTypes( 10 ).Value = &quot;Activate document&quot;
1382*cdf0e10cSrcweir	allEventTypes( 11 ).Name = &quot;OnUnfocus&quot;
1383*cdf0e10cSrcweir	allEventTypes( 11 ).Value = &quot;DeActivate document&quot;
1384*cdf0e10cSrcweir	allEventTypes( 12 ).Name = &quot;OnPrint&quot;
1385*cdf0e10cSrcweir	allEventTypes( 12 ).Value = &quot;Print Document&quot;
1386*cdf0e10cSrcweir	REM The following are document-only events
1387*cdf0e10cSrcweir	allEventTypes( 13 ).Name = &quot;OnMailMerge&quot;
1388*cdf0e10cSrcweir	allEventTypes( 13 ).Value = &quot;Print form letters&quot;
1389*cdf0e10cSrcweir	allEventTypes( 14 ).Name = &quot;OnPageCountChange&quot;
1390*cdf0e10cSrcweir	allEventTypes( 14 ).Value = &quot;Changing the page count&quot;
1391*cdf0e10cSrcweirend sub
1392*cdf0e10cSrcweir
1393*cdf0e10cSrcweir
1394*cdf0e10cSrcweirsub createAllEventBindings()
1395*cdf0e10cSrcweir	&apos;dim props as new com.sun.star.beans.PropertyValue
1396*cdf0e10cSrcweir	&apos;props.Name = &quot;&quot; &apos;Name = script name
1397*cdf0e10cSrcweir	&apos;props.Value = 0 &apos;Value = 0 for empty, 1 for macro, linenumber for script
1398*cdf0e10cSrcweir
1399*cdf0e10cSrcweir	&apos; Creates all types of event bindings for both Application and Document
1400*cdf0e10cSrcweir	&apos; Initially both arrays have no bindings allocated to the events
1401*cdf0e10cSrcweir	&apos; The value for Doc is only Script/macro name (no need for line number)
1402*cdf0e10cSrcweir	for n = 0 to ubound( allEventTypes() )
1403*cdf0e10cSrcweir		allEventTypesApp( n ).Name = &quot;&quot;
1404*cdf0e10cSrcweir		allEventTypesApp( n ).Value = 0
1405*cdf0e10cSrcweir		allEventTypesDoc( n ).Name = &quot;&quot;
1406*cdf0e10cSrcweir		allEventTypesDoc( n ).Value = 0
1407*cdf0e10cSrcweir	next n
1408*cdf0e10cSrcweirend sub
1409*cdf0e10cSrcweir
1410*cdf0e10cSrcweir
1411*cdf0e10cSrcweirREM ----- Text Handling Functions -----
1412*cdf0e10cSrcweir
1413*cdf0e10cSrcweir
1414*cdf0e10cSrcweirfunction ExtractLabelFromXMLLine( XMLLine as string ) as string
1415*cdf0e10cSrcweir	labelStart = instr( XMLLine, &quot;label=&quot;+chr$(34)) + 7
1416*cdf0e10cSrcweir	labelEnd = instr( XMLLine, chr$(34)+&quot;&gt;&quot; )
1417*cdf0e10cSrcweir	if labelEnd = 0 then
1418*cdf0e10cSrcweir	    labelEnd = instr( XMLLine, chr$(34)+&quot;/&gt;&quot; )
1419*cdf0e10cSrcweir	end if
1420*cdf0e10cSrcweir	labelLength = labelEnd - labelStart
1421*cdf0e10cSrcweir
1422*cdf0e10cSrcweir	menuLabelUnformatted = mid( XMLLine, labelStart, labelLength )
1423*cdf0e10cSrcweir	tildePosition = instr( menuLabelUnformatted, &quot;~&quot; )
1424*cdf0e10cSrcweir	select case tildePosition
1425*cdf0e10cSrcweir		case 0
1426*cdf0e10cSrcweir			menuLabel = menuLabelUnformatted
1427*cdf0e10cSrcweir		case 1
1428*cdf0e10cSrcweir			menuLabel = right( menuLabelUnformatted, labelLength - 1 )
1429*cdf0e10cSrcweir		case else
1430*cdf0e10cSrcweir			menuLabelLeft = left( menuLabelUnformatted, tildePosition - 1 )
1431*cdf0e10cSrcweir			menuLabelRight = right( menuLabelUnformatted, labelLength - tildePosition )
1432*cdf0e10cSrcweir			menuLabel = menuLabelLeft + menuLabelRight
1433*cdf0e10cSrcweir	end select
1434*cdf0e10cSrcweir
1435*cdf0e10cSrcweir	ExtractLabelFromXMLLine() = menuLabel
1436*cdf0e10cSrcweirend function
1437*cdf0e10cSrcweir
1438*cdf0e10cSrcweir
1439*cdf0e10cSrcweirfunction ExtractScriptIdFromXMLLine( XMLLine as string ) as string
1440*cdf0e10cSrcweir	idStart = instr( XMLLine, &quot;script://&quot;) + 9
1441*cdf0e10cSrcweir	if instr( XMLLine, chr$(34)+&quot; menu:helpid=&quot; ) = 0 then
1442*cdf0e10cSrcweir		idEnd = instr( XMLLIne, &quot;?location=&quot; )
1443*cdf0e10cSrcweir	else
1444*cdf0e10cSrcweir		idEnd = instr( XMLLine, &quot;&quot;+chr$(34)+&quot; menu:helpid=&quot; )
1445*cdf0e10cSrcweir	end if
1446*cdf0e10cSrcweir	idLength = idEnd - idStart
1447*cdf0e10cSrcweir	scriptId = mid( XMLLine, idStart, idLength )
1448*cdf0e10cSrcweir
1449*cdf0e10cSrcweir	ExtractScriptIdFromXMLLine() = scriptId
1450*cdf0e10cSrcweirend function
1451*cdf0e10cSrcweir
1452*cdf0e10cSrcweirfunction ExtractEventScriptFromXMLLine( xmlline as string )
1453*cdf0e10cSrcweir	if instr( xmlline, &quot;script://&quot; ) &gt; 0 then
1454*cdf0e10cSrcweir		idStart = instr( xmlline, &quot;script://&quot;) + 9
1455*cdf0e10cSrcweir		idEnd = instr( xmlline, chr$(34)+&quot; xlink:type=&quot; )
1456*cdf0e10cSrcweir		idLength = idEnd - idStart
1457*cdf0e10cSrcweir		scriptId = mid( xmlline, idStart, idLength )
1458*cdf0e10cSrcweir	end if
1459*cdf0e10cSrcweir	ExtractEventScriptFromXMLLine() = scriptId
1460*cdf0e10cSrcweirend function
1461*cdf0e10cSrcweir
1462*cdf0e10cSrcweir
1463*cdf0e10cSrcweirfunction ExtractEventNameFromXMLLine(  xmlline as string )
1464*cdf0e10cSrcweir	idStart = instr( xmlline, &quot;event:name=&quot; + chr$(34) ) + 12
1465*cdf0e10cSrcweir	idEnd = instr( xmlline, chr$(34)+&quot; event:language&quot; )
1466*cdf0e10cSrcweir	idLength = idEnd - idStart
1467*cdf0e10cSrcweir	event =  mid( xmlline, idStart, idLength )
1468*cdf0e10cSrcweir
1469*cdf0e10cSrcweir	ExtractEventNameFromXMLLine() = event
1470*cdf0e10cSrcweirend function
1471*cdf0e10cSrcweir
1472*cdf0e10cSrcweirfunction ExtractKeyCodeFromXMLLine( XMLLine as string ) as string
1473*cdf0e10cSrcweir	keyStart = instr( XMLLine, &quot;code=&quot;+chr$(34)+&quot;KEY_&quot;) + 10
1474*cdf0e10cSrcweir	keyCode = mid( XMLLine, keyStart, ( len( XMLLine ) - keyStart ) )
1475*cdf0e10cSrcweir	keyEnd = instr( keyCode, chr$(34) )
1476*cdf0e10cSrcweir	keyCode = mid( keyCode, 1, keyEnd - 1 )
1477*cdf0e10cSrcweir
1478*cdf0e10cSrcweir	ExtractKeyCodeFromXMLLine() = keyCode
1479*cdf0e10cSrcweirend function
1480*cdf0e10cSrcweir
1481*cdf0e10cSrcweir
1482*cdf0e10cSrcweirfunction GetMenuWhiteSpace( MenuXMLLine as string ) as string
1483*cdf0e10cSrcweir	whiteSpace = &quot;&quot;
1484*cdf0e10cSrcweir	numberOfSpaces = instr( MenuXMLLine, &quot;&lt;&quot; ) - 1
1485*cdf0e10cSrcweir	for i = 1 to numberOfSpaces
1486*cdf0e10cSrcweir		whiteSpace = whiteSpace + &quot; &quot;
1487*cdf0e10cSrcweir	next i
1488*cdf0e10cSrcweir
1489*cdf0e10cSrcweir	GetMenuWhiteSpace() = whiteSpace
1490*cdf0e10cSrcweirend function
1491*cdf0e10cSrcweir
1492*cdf0e10cSrcweirfunction IsAllocatedMenuItem( script as string ) as boolean
1493*cdf0e10cSrcweir	foundMenuItem = false
1494*cdf0e10cSrcweir	Allocated = false
1495*cdf0e10cSrcweir	count = 0
1496*cdf0e10cSrcweir	do
1497*cdf0e10cSrcweir		count = count + 1
1498*cdf0e10cSrcweir		if strcomp( script, subMenuItems( count ) ) = 0 then
1499*cdf0e10cSrcweir			foundMenuItem = true
1500*cdf0e10cSrcweir		end if
1501*cdf0e10cSrcweir	loop while not( foundMenuItem ) and count &lt; subMenuCount
1502*cdf0e10cSrcweir
1503*cdf0e10cSrcweir	linePosition = subMenuItemLinePosition( count )
1504*cdf0e10cSrcweir
1505*cdf0e10cSrcweir	if not( instr( xmlFile( linePosition ), &quot;script://&quot; ) = 0 ) then
1506*cdf0e10cSrcweir		Allocated = true
1507*cdf0e10cSrcweir	end if
1508*cdf0e10cSrcweir
1509*cdf0e10cSrcweir	isAllocatedMenuItem() = Allocated
1510*cdf0e10cSrcweirend Function
1511*cdf0e10cSrcweir
1512*cdf0e10cSrcweir
1513*cdf0e10cSrcweirfunction HasShiftKey( keyCombo ) as boolean
1514*cdf0e10cSrcweir	if instr( keyCombo, &quot;SHIFT&quot; ) = 0 then
1515*cdf0e10cSrcweir		hasShift = false
1516*cdf0e10cSrcweir	else
1517*cdf0e10cSrcweir		hasShift = true
1518*cdf0e10cSrcweir	end if
1519*cdf0e10cSrcweir
1520*cdf0e10cSrcweir	HasShiftKey = hasShift
1521*cdf0e10cSrcweirend function
1522*cdf0e10cSrcweir
1523*cdf0e10cSrcweir
1524*cdf0e10cSrcweirfunction HasControlKey( keyCombo ) as boolean
1525*cdf0e10cSrcweir	if instr( keyCombo, &quot;CONTROL&quot; ) = 0 then
1526*cdf0e10cSrcweir		hasControl = false
1527*cdf0e10cSrcweir	else
1528*cdf0e10cSrcweir		hasControl = true
1529*cdf0e10cSrcweir	end if
1530*cdf0e10cSrcweir
1531*cdf0e10cSrcweir	HasControlKey = hasControl
1532*cdf0e10cSrcweirend function
1533*cdf0e10cSrcweir
1534*cdf0e10cSrcweir
1535*cdf0e10cSrcweirfunction ExtractKeyFromCombo( keyString as string ) as string
1536*cdf0e10cSrcweir	while not( instr( keyString, &quot;+&quot; ) = 0 )
1537*cdf0e10cSrcweir		removeTo = instr( keyString, &quot;+ &quot; ) + 2
1538*cdf0e10cSrcweir		keyString = mid( keyString, removeTo, ( len( keyString ) - removeTo ) + 1 )
1539*cdf0e10cSrcweir	wend
1540*cdf0e10cSrcweir	ExtractKeyFromCombo() = keyString
1541*cdf0e10cSrcweirend function
1542*cdf0e10cSrcweir
1543*cdf0e10cSrcweir
1544*cdf0e10cSrcweir
1545*cdf0e10cSrcweirREM ------ Event Handling Functions (Listeners) ------
1546*cdf0e10cSrcweir
1547*cdf0e10cSrcweir
1548*cdf0e10cSrcweirsub KeyListListener()
1549*cdf0e10cSrcweir	keyShortCutList = bindingDialog.getControl( &quot;KeyList&quot; )
1550*cdf0e10cSrcweir	selectedShortCut = keyShortCutList.getSelectedItem()
1551*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;KeyCombo&quot; )
1552*cdf0e10cSrcweir
1553*cdf0e10cSrcweir	menuScriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
1554*cdf0e10cSrcweir	selectedScript = menuScriptList.getSelectedItem()
1555*cdf0e10cSrcweir
1556*cdf0e10cSrcweir	keyGroup = combo.text
1557*cdf0e10cSrcweir    dim keyGroupIndex as Integer
1558*cdf0e10cSrcweir    dim selectedKeyIndex as Integer
1559*cdf0e10cSrcweir	for n = lbound ( allKeyGroupsArray() ) to ubound ( allKeyGroupsArray() )
1560*cdf0e10cSrcweir		if ( allKeyGroupsArray( n ) = keyGroup )then
1561*cdf0e10cSrcweir			keyGroupIndex = n
1562*cdf0e10cSrcweir			exit for
1563*cdf0e10cSrcweir		end if
1564*cdf0e10cSrcweir    next n
1565*cdf0e10cSrcweir    selectedKeyIndex = keyShortCutList.getSelectedItemPos()
1566*cdf0e10cSrcweir
1567*cdf0e10cSrcweir	if  keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Value &gt; 1 then
1568*cdf0e10cSrcweir		bindingDialog.Model.Delete.enabled = true
1569*cdf0e10cSrcweir		bindingDialog.Model.AddOn.enabled = true
1570*cdf0e10cSrcweir		if selectedScript &lt;&gt; &quot;&quot; then
1571*cdf0e10cSrcweir			bindingDialog.Model.NewButton.enabled = true
1572*cdf0e10cSrcweir		endif
1573*cdf0e10cSrcweir
1574*cdf0e10cSrcweir	else
1575*cdf0e10cSrcweir
1576*cdf0e10cSrcweir		if keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Value  = 1 then
1577*cdf0e10cSrcweir			bindingDialog.Model.Delete.enabled = false
1578*cdf0e10cSrcweir			bindingDialog.Model.AddOn.enabled = false
1579*cdf0e10cSrcweir			bindingDialog.Model.NewButton.enabled = false
1580*cdf0e10cSrcweir		else
1581*cdf0e10cSrcweir			bindingDialog.Model.Delete.enabled = false
1582*cdf0e10cSrcweir			bindingDialog.Model.AddOn.enabled = false
1583*cdf0e10cSrcweir			if selectedScript &lt;&gt; &quot;&quot; then
1584*cdf0e10cSrcweir				bindingDialog.Model.NewButton.enabled = true
1585*cdf0e10cSrcweir			end if
1586*cdf0e10cSrcweir		end if
1587*cdf0e10cSrcweir	end if
1588*cdf0e10cSrcweirend sub
1589*cdf0e10cSrcweir
1590*cdf0e10cSrcweir
1591*cdf0e10cSrcweirsub SubMenuListListener()
1592*cdf0e10cSrcweir	scriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
1593*cdf0e10cSrcweir	subMenuList = bindingDialog.getControl( &quot;SubMenuList&quot; )
1594*cdf0e10cSrcweir	selectedMenuItem = subMenuList.getSelectedItem()
1595*cdf0e10cSrcweir	if IsAllocatedMenuItem( selectedMenuItem ) then
1596*cdf0e10cSrcweir		bindingDialog.Model.Delete.enabled = true
1597*cdf0e10cSrcweir		bindingDialog.Model.AddOn.enabled = true
1598*cdf0e10cSrcweir	else
1599*cdf0e10cSrcweir		bindingDialog.Model.Delete.enabled = false
1600*cdf0e10cSrcweir		bindingDialog.Model.AddOn.enabled = false
1601*cdf0e10cSrcweir	end if
1602*cdf0e10cSrcweirend sub
1603*cdf0e10cSrcweir
1604*cdf0e10cSrcweirREM a keypress listener that in turn fires the MenuCL on a return key even only
1605*cdf0e10cSrcweirsub fireMenuComboListernerOnRet( eventobj as object )
1606*cdf0e10cSrcweir	if (eventobj.KeyCode = 1280 ) then
1607*cdf0e10cSrcweir		MenuComboListener()
1608*cdf0e10cSrcweir	endif
1609*cdf0e10cSrcweirend sub
1610*cdf0e10cSrcweir
1611*cdf0e10cSrcweir&apos;Populates the SubMenuList with the appropriate menu items from the Top-level menu selected from the combo box
1612*cdf0e10cSrcweirsub MenuComboListener()
1613*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;MenuCombo&quot; )
1614*cdf0e10cSrcweir	newToplevelMenu = combo.text
1615*cdf0e10cSrcweir	counter = 0
1616*cdf0e10cSrcweir	do
1617*cdf0e10cSrcweir		counter = counter + 1
1618*cdf0e10cSrcweir	loop while not( newToplevelMenu = menuItems( counter ) )
1619*cdf0e10cSrcweir
1620*cdf0e10cSrcweir	PopulateSubMenuList( counter )
1621*cdf0e10cSrcweirend sub
1622*cdf0e10cSrcweir
1623*cdf0e10cSrcweirREM a keypress listener that in turn fires the LLCL on a return key even only
1624*cdf0e10cSrcweirsub fireLangLocComboListernerOnRet( eventobj as object )
1625*cdf0e10cSrcweir	if (eventobj.KeyCode = 1280 ) then
1626*cdf0e10cSrcweir		LangLocComboListener()
1627*cdf0e10cSrcweir	endif
1628*cdf0e10cSrcweirend sub
1629*cdf0e10cSrcweir
1630*cdf0e10cSrcweirsub LangLocComboListener()
1631*cdf0e10cSrcweir
1632*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;LanguageCombo&quot; )
1633*cdf0e10cSrcweir	language = combo.text
1634*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;LocationCombo&quot; )
1635*cdf0e10cSrcweir	location = combo.text
1636*cdf0e10cSrcweir
1637*cdf0e10cSrcweir	PopulateScriptList( language,location )
1638*cdf0e10cSrcweir
1639*cdf0e10cSrcweir    &apos;Enable/disable Assign button
1640*cdf0e10cSrcweir    scriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
1641*cdf0e10cSrcweir    if not (dialogName = &quot;EditDebug&quot;) then
1642*cdf0e10cSrcweir        if scriptList.getSelectedItem() = &quot;&quot; then
1643*cdf0e10cSrcweir            bindingDialog.Model.NewButton.enabled = false
1644*cdf0e10cSrcweir        end if
1645*cdf0e10cSrcweir    end if
1646*cdf0e10cSrcweir
1647*cdf0e10cSrcweir    if ( location = &quot;Filesystem&quot; ) and ( language &lt;&gt; &quot;Java&quot; ) then
1648*cdf0e10cSrcweir    	bindingDialog.Model.Browse.enabled = true
1649*cdf0e10cSrcweir    	if not (dialogName = &quot;EditDebug&quot;) then
1650*cdf0e10cSrcweir    		bindingDialog.Model.fsonly.enabled = true
1651*cdf0e10cSrcweir    	end if
1652*cdf0e10cSrcweir    else
1653*cdf0e10cSrcweir    	bindingDialog.Model.Browse.enabled = false
1654*cdf0e10cSrcweir    	if not (dialogName = &quot;EditDebug&quot;) then
1655*cdf0e10cSrcweir    		bindingDialog.Model.fsonly.enabled = false
1656*cdf0e10cSrcweir    	end if
1657*cdf0e10cSrcweir    endif
1658*cdf0e10cSrcweir
1659*cdf0e10cSrcweir    &apos; extra dialog dependant processing
1660*cdf0e10cSrcweir    if dialogName = &quot;Menu&quot; then
1661*cdf0e10cSrcweir    	&apos; will set New button to false if no text in LableBox
1662*cdf0e10cSrcweir    	MenuLabelBoxListener()
1663*cdf0e10cSrcweir    elseif dialogName = &quot;Key&quot; then
1664*cdf0e10cSrcweir    	&apos; will set Assigne button to false if appropriate
1665*cdf0e10cSrcweir    	KeyListListener()
1666*cdf0e10cSrcweir    elseif dialogName = &quot;Event&quot; then
1667*cdf0e10cSrcweir    	EventListListener()
1668*cdf0e10cSrcweir    end if
1669*cdf0e10cSrcweir
1670*cdf0e10cSrcweirend sub
1671*cdf0e10cSrcweir
1672*cdf0e10cSrcweirREM a keypress listener that in turn fires the KeyCL on a return key even only
1673*cdf0e10cSrcweirsub fireKeyComboListernerOnRet( eventobj as object )
1674*cdf0e10cSrcweir	if (eventobj.KeyCode = 1280 ) then
1675*cdf0e10cSrcweir		KeyComboListener()
1676*cdf0e10cSrcweir	endif
1677*cdf0e10cSrcweirend sub
1678*cdf0e10cSrcweir
1679*cdf0e10cSrcweir&apos;Populates the KeyList with the appropriate key combos from the Top-level key group selected from the combo box
1680*cdf0e10cSrcweirsub KeyComboListener()
1681*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;KeyCombo&quot; )
1682*cdf0e10cSrcweir	keyGroup = combo.text
1683*cdf0e10cSrcweir	for n = lbound ( allKeyGroupsArray() ) to ubound ( allKeyGroupsArray() )
1684*cdf0e10cSrcweir		if ( allKeyGroupsArray( n ) = keyGroup )then
1685*cdf0e10cSrcweir			keyGroupIndex = n
1686*cdf0e10cSrcweir			exit for
1687*cdf0e10cSrcweir		end if
1688*cdf0e10cSrcweir    next n
1689*cdf0e10cSrcweir	PopulateKeyBindingList( keyGroupIndex )
1690*cdf0e10cSrcweirend sub
1691*cdf0e10cSrcweir
1692*cdf0e10cSrcweir
1693*cdf0e10cSrcweirsub MenuLabelBoxListener()
1694*cdf0e10cSrcweir	menuScriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
1695*cdf0e10cSrcweir	selectedScript = menuScriptList.getSelectedItem()
1696*cdf0e10cSrcweir	&apos;if the SubMenuList is from a dynamically created menu (e.g. Format)
1697*cdf0e10cSrcweir	&apos;or if the Menu Label text box is empty
1698*cdf0e10cSrcweir	subMenuList = bindingDialog.getControl( &quot;SubMenuList&quot; )
1699*cdf0e10cSrcweir	firstItem = subMenuList.getItem( 0 )
1700*cdf0e10cSrcweir	if bindingDialog.Model.MenuLabelBox.text = &quot;&quot; OR firstItem = &quot;Unable to Assign Scripts to this menu&quot; OR  selectedScript = &quot;&quot; then
1701*cdf0e10cSrcweir		bindingDialog.Model.NewButton.enabled = false
1702*cdf0e10cSrcweir	else
1703*cdf0e10cSrcweir		bindingDialog.Model.NewButton.enabled = true
1704*cdf0e10cSrcweir	end if
1705*cdf0e10cSrcweirend sub
1706*cdf0e10cSrcweir
1707*cdf0e10cSrcweirsub AppDocEventListener()
1708*cdf0e10cSrcweir	populateEventList( 0 )
1709*cdf0e10cSrcweir	EventListListener()
1710*cdf0e10cSrcweirend sub
1711*cdf0e10cSrcweir
1712*cdf0e10cSrcweir
1713*cdf0e10cSrcweirsub EventListListener()
1714*cdf0e10cSrcweir	on error goto ErrorHandler
1715*cdf0e10cSrcweir
1716*cdf0e10cSrcweir    eventList = bindingDialog.getControl( &quot;EventList&quot; )
1717*cdf0e10cSrcweir    eventPos = eventList.getSelectedItemPos()
1718*cdf0e10cSrcweir
1719*cdf0e10cSrcweir    allApps = bindingDialog.getControl( &quot;AllAppsOption&quot; )
1720*cdf0e10cSrcweir
1721*cdf0e10cSrcweir	menuScriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
1722*cdf0e10cSrcweir	selectedScript = menuScriptList.getSelectedItem()
1723*cdf0e10cSrcweir
1724*cdf0e10cSrcweir    dim binding as integer
1725*cdf0e10cSrcweir    if allApps.state = true then
1726*cdf0e10cSrcweir    	binding = allEventTypesApp( eventPos ).Value
1727*cdf0e10cSrcweir    else
1728*cdf0e10cSrcweir	    binding = allEventTypesDoc( eventPos ).Value
1729*cdf0e10cSrcweir    endif
1730*cdf0e10cSrcweir
1731*cdf0e10cSrcweir    if ( binding &gt; 1 ) then
1732*cdf0e10cSrcweir       	bindingDialog.Model.Delete.enabled = true
1733*cdf0e10cSrcweir    else
1734*cdf0e10cSrcweir       	bindingDialog.Model.Delete.enabled = false
1735*cdf0e10cSrcweir    end if
1736*cdf0e10cSrcweir
1737*cdf0e10cSrcweir	if ( binding = 1 ) then
1738*cdf0e10cSrcweir		&apos; staroffice binding, can&apos;t assign
1739*cdf0e10cSrcweir		bindingDialog.Model.NewButton.enabled = false
1740*cdf0e10cSrcweir	elseif (  selectedScript &lt;&gt; &quot;&quot; ) then
1741*cdf0e10cSrcweir		bindingDialog.Model.NewButton.enabled = true
1742*cdf0e10cSrcweir	end if
1743*cdf0e10cSrcweir    exit sub
1744*cdf0e10cSrcweir
1745*cdf0e10cSrcweir    ErrorHandler:
1746*cdf0e10cSrcweir    reset
1747*cdf0e10cSrcweir    bindingDialog.Model.Delete.enabled = false
1748*cdf0e10cSrcweir
1749*cdf0e10cSrcweirend sub
1750*cdf0e10cSrcweir
1751*cdf0e10cSrcweir
1752*cdf0e10cSrcweirREM ------ Event Handling Functions (Buttons) ------
1753*cdf0e10cSrcweir
1754*cdf0e10cSrcweirfunction getFilePicker() as Object
1755*cdf0e10cSrcweir    REM file dialog
1756*cdf0e10cSrcweir    oFilePicker = CreateUnoService( &quot;com.sun.star.ui.dialogs.FilePicker&quot; )
1757*cdf0e10cSrcweir
1758*cdf0e10cSrcweir    combo = bindingDialog.getControl( &quot;LanguageCombo&quot; )
1759*cdf0e10cSrcweir    language = combo.text
1760*cdf0e10cSrcweir    currentFilter = &quot;&quot;
1761*cdf0e10cSrcweir
1762*cdf0e10cSrcweir    for langIndex = 0 to ubound(languages())
1763*cdf0e10cSrcweir        if( languages(langIndex) &lt;&gt; &quot;Java&quot; ) then
1764*cdf0e10cSrcweir        	filterName = languages(langIndex) + &quot; (&quot;
1765*cdf0e10cSrcweir        	filterVal=&quot;&quot;
1766*cdf0e10cSrcweir        	extns = extensions(langIndex)
1767*cdf0e10cSrcweir        	for extnIndex = lbound(extns()) to ubound(extns())
1768*cdf0e10cSrcweir            	filterName = filterName + &quot;*.&quot; + extns(extnIndex) + &quot;,&quot;
1769*cdf0e10cSrcweir           	 	filterVal = filterVal + &quot;*.&quot; + extns(extnIndex) + &quot;,&quot;
1770*cdf0e10cSrcweir        	next extnIndex
1771*cdf0e10cSrcweir        	filterName = left(filterName, len(filterName) -1) + &quot;)&quot;
1772*cdf0e10cSrcweir        	filterVal = left(filterVal, len(filterVal) -1)
1773*cdf0e10cSrcweir        	if(instr(filterName,language) = 1 ) then
1774*cdf0e10cSrcweir            	currentFilter = filterName
1775*cdf0e10cSrcweir        	end if
1776*cdf0e10cSrcweir        	oFilePicker.AppendFilter(filterName, filterVal)
1777*cdf0e10cSrcweir        end if
1778*cdf0e10cSrcweir    next langIndex
1779*cdf0e10cSrcweir    if(len(currentFilter) &gt; 0 ) then
1780*cdf0e10cSrcweir        oFilePicker.SetCurrentFilter( currentFilter )
1781*cdf0e10cSrcweir    end if
1782*cdf0e10cSrcweir
1783*cdf0e10cSrcweir    If sFileURL = &quot;&quot; Then
1784*cdf0e10cSrcweir        oSettings = CreateUnoService( &quot;com.sun.star.frame.Settings&quot; )
1785*cdf0e10cSrcweir        oPathSettings = oSettings.getByName( &quot;PathSettings&quot; )
1786*cdf0e10cSrcweir        sFileURL = oPathSettings.getPropertyValue( &quot;Work&quot; )
1787*cdf0e10cSrcweir    End If
1788*cdf0e10cSrcweir
1789*cdf0e10cSrcweir    REM set display directory
1790*cdf0e10cSrcweir    oSimpleFileAccess = CreateUnoService( &quot;com.sun.star.ucb.SimpleFileAccess&quot; )
1791*cdf0e10cSrcweir
1792*cdf0e10cSrcweir    If oSimpleFileAccess.exists( sFileURL ) And oSimpleFileAccess.isFolder( sFileURL ) Then
1793*cdf0e10cSrcweir        oFilePicker.setDisplayDirectory( sFileURL )
1794*cdf0e10cSrcweir    End If
1795*cdf0e10cSrcweir    getFilePicker() = oFilePicker
1796*cdf0e10cSrcweirend function
1797*cdf0e10cSrcweir
1798*cdf0e10cSrcweirSub DoBrowseAndEdit()
1799*cdf0e10cSrcweir    Dim oFilePicker As Object, oSimpleFileAccess As Object
1800*cdf0e10cSrcweir    Dim oSettings As Object, oPathSettings As Object
1801*cdf0e10cSrcweir    Dim sFileURL As String
1802*cdf0e10cSrcweir    Dim sFiles As Variant
1803*cdf0e10cSrcweir
1804*cdf0e10cSrcweir    oFilePicker = getFilePicker()
1805*cdf0e10cSrcweir    REM execute file dialog
1806*cdf0e10cSrcweir    If oFilePicker.execute() Then
1807*cdf0e10cSrcweir        sFiles = oFilePicker.getFiles()
1808*cdf0e10cSrcweir
1809*cdf0e10cSrcweir        sFileURL = sFiles(0)
1810*cdf0e10cSrcweir    	oSimpleFileAccess = CreateUnoService( &quot;com.sun.star.ucb.SimpleFileAccess&quot; )
1811*cdf0e10cSrcweir        If oSimpleFileAccess.exists( sFileURL ) Then
1812*cdf0e10cSrcweir            for langIndex = 0 to ubound(languages())
1813*cdf0e10cSrcweir                If (instr(oFilePicker.GetCurrentFilter, languages(langIndex)) = 1 ) then
1814*cdf0e10cSrcweir                	RunDebugger(languages(langIndex), sFileURL, &quot;&quot;)
1815*cdf0e10cSrcweir            	End If
1816*cdf0e10cSrcweir            next langIndex
1817*cdf0e10cSrcweir        End If
1818*cdf0e10cSrcweir        bindingDialog.endExecute()
1819*cdf0e10cSrcweir    End If
1820*cdf0e10cSrcweirEnd Sub
1821*cdf0e10cSrcweir
1822*cdf0e10cSrcweirSub RunDebugger(lang as String, uri as String, filename as String)
1823*cdf0e10cSrcweir    dim document   as object
1824*cdf0e10cSrcweir    dim dispatcher as object
1825*cdf0e10cSrcweir    dim parser     as object
1826*cdf0e10cSrcweir    dim url        as new com.sun.star.util.URL
1827*cdf0e10cSrcweir
1828*cdf0e10cSrcweir    document = ThisComponent.CurrentController.Frame
1829*cdf0e10cSrcweir    parser   = createUnoService(&quot;com.sun.star.util.URLTransformer&quot;)
1830*cdf0e10cSrcweir    dim args(2) as new com.sun.star.beans.PropertyValue
1831*cdf0e10cSrcweir    args(0).Name = &quot;language&quot;
1832*cdf0e10cSrcweir    args(0).Value = lang
1833*cdf0e10cSrcweir    args(1).Name = &quot;uri&quot;
1834*cdf0e10cSrcweir    args(1).Value = uri
1835*cdf0e10cSrcweir    args(2).Name = &quot;filename&quot;
1836*cdf0e10cSrcweir    args(2).Value = filename
1837*cdf0e10cSrcweir
1838*cdf0e10cSrcweir    url.Complete = &quot;script://_$DebugRunner.Debug?&quot; _
1839*cdf0e10cSrcweir        + &quot;language=Java&amp;function=DebugRunner.go&quot; _
1840*cdf0e10cSrcweir        + &quot;&amp;location=share&quot;
1841*cdf0e10cSrcweir
1842*cdf0e10cSrcweir    parser.parseStrict(url)
1843*cdf0e10cSrcweir    disp = document.queryDispatch(url,&quot;&quot;,0)
1844*cdf0e10cSrcweir    disp.dispatch(url, args())
1845*cdf0e10cSrcweirEnd Sub
1846*cdf0e10cSrcweir
1847*cdf0e10cSrcweirsub DoEdit()
1848*cdf0e10cSrcweir    Dim scriptInfo as Object
1849*cdf0e10cSrcweir
1850*cdf0e10cSrcweir    menuScriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
1851*cdf0e10cSrcweir    selectedScript = menuScriptList.getSelectedItem()
1852*cdf0e10cSrcweir
1853*cdf0e10cSrcweir    if not (selectedScript = &quot;&quot;) then
1854*cdf0e10cSrcweir        scripts() = scriptDisplayList(0)
1855*cdf0e10cSrcweir        for n = LBOUND( scripts() ) to UBOUND( scripts() )
1856*cdf0e10cSrcweir            if ( scripts( n ).Name = selectedScript ) then
1857*cdf0e10cSrcweir                scriptInfo = scripts( n ).Value
1858*cdf0e10cSrcweir                exit for
1859*cdf0e10cSrcweir            end if
1860*cdf0e10cSrcweir        next n
1861*cdf0e10cSrcweir
1862*cdf0e10cSrcweir        RunDebugger(scriptInfo.getLanguage, scriptInfo.getParcelURI, scriptInfo.getFunctionName)
1863*cdf0e10cSrcweir        bindingDialog.endExecute()
1864*cdf0e10cSrcweir    end if
1865*cdf0e10cSrcweirend sub
1866*cdf0e10cSrcweir
1867*cdf0e10cSrcweirsub MenuOKButton()
1868*cdf0e10cSrcweir	WriteXMLFromArray()
1869*cdf0e10cSrcweir	bindingDialog.endExecute()
1870*cdf0e10cSrcweirend sub
1871*cdf0e10cSrcweir
1872*cdf0e10cSrcweir
1873*cdf0e10cSrcweirsub MenuCancelButton()
1874*cdf0e10cSrcweir	bindingDialog.endExecute()
1875*cdf0e10cSrcweirend sub
1876*cdf0e10cSrcweir
1877*cdf0e10cSrcweir
1878*cdf0e10cSrcweirsub MenuHelpButton()
1879*cdf0e10cSrcweir	helpDialog = LoadDialog( &quot;ScriptBindingLibrary&quot;, &quot;HelpBinding&quot; )
1880*cdf0e10cSrcweir	helpDialog.execute()
1881*cdf0e10cSrcweirend sub
1882*cdf0e10cSrcweir
1883*cdf0e10cSrcweir
1884*cdf0e10cSrcweirsub MenuDeleteButton()
1885*cdf0e10cSrcweir	subMenuList = bindingDialog.getControl( &quot;SubMenuList&quot; )
1886*cdf0e10cSrcweir	linePos = subMenuItemLinePosition( subMenuList.getSelectedItemPos() + 1 )
1887*cdf0e10cSrcweir
1888*cdf0e10cSrcweir	RemoveBinding( linePos )
1889*cdf0e10cSrcweir
1890*cdf0e10cSrcweir	REM Update the top-level menu&apos;s line positions
1891*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;MenuCombo&quot; )
1892*cdf0e10cSrcweir	newToplevelMenu = combo.text
1893*cdf0e10cSrcweir	counter = 0
1894*cdf0e10cSrcweir	do
1895*cdf0e10cSrcweir		counter = counter + 1
1896*cdf0e10cSrcweir	loop while not( newToplevelMenu = menuItems( counter ) )
1897*cdf0e10cSrcweir	UpdateTopLevelMenus( counter + 1, false )
1898*cdf0e10cSrcweir
1899*cdf0e10cSrcweir	MenuComboListener()
1900*cdf0e10cSrcweir
1901*cdf0e10cSrcweir	subMenuList.selectItemPos( subMenuList.getSelectedItemPos(), true )
1902*cdf0e10cSrcweirend sub
1903*cdf0e10cSrcweir
1904*cdf0e10cSrcweir
1905*cdf0e10cSrcweirsub MenuNewButton()
1906*cdf0e10cSrcweir	menuScriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
1907*cdf0e10cSrcweir	selectedScript = menuScriptList.getSelectedItem()
1908*cdf0e10cSrcweir    scriptURI = getScriptURI( selectedScript )
1909*cdf0e10cSrcweir	newMenuLabel = bindingDialog.Model.MenuLabelBox.text
1910*cdf0e10cSrcweir
1911*cdf0e10cSrcweir	subMenuList = bindingDialog.getControl( &quot;SubMenuList&quot; )
1912*cdf0e10cSrcweir
1913*cdf0e10cSrcweir	REM Update the top-level menu&apos;s line positions
1914*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;MenuCombo&quot; )
1915*cdf0e10cSrcweir	newToplevelMenu = combo.text
1916*cdf0e10cSrcweir	counter = 0
1917*cdf0e10cSrcweir	do
1918*cdf0e10cSrcweir		counter = counter + 1
1919*cdf0e10cSrcweir	loop while not( newToplevelMenu = menuItems( counter ) )
1920*cdf0e10cSrcweir	UpdateTopLevelMenus( counter + 1, true )
1921*cdf0e10cSrcweir
1922*cdf0e10cSrcweir	REM New line position is one ahead of the selected sub menu item
1923*cdf0e10cSrcweir	linePos = subMenuItemLinePosition( subMenuList.getSelectedItemPos() + 1 ) + 1
1924*cdf0e10cSrcweir
1925*cdf0e10cSrcweir	AddNewMenuBinding( scriptURI, newMenuLabel, linePos )
1926*cdf0e10cSrcweir
1927*cdf0e10cSrcweir	MenuComboListener()
1928*cdf0e10cSrcweir	subMenuList.selectItemPos( subMenuList.getSelectedItemPos() + 1, true )
1929*cdf0e10cSrcweir	SubMenuListListener()
1930*cdf0e10cSrcweirend sub
1931*cdf0e10cSrcweir
1932*cdf0e10cSrcweirsub BrowseButton()
1933*cdf0e10cSrcweir	Dim oFilePicker As Object, oSimpleFileAccess As Object
1934*cdf0e10cSrcweir	Dim oSettings As Object, oPathSettings As Object
1935*cdf0e10cSrcweir	Dim sFileURL As String
1936*cdf0e10cSrcweir	Dim sFiles As Variant
1937*cdf0e10cSrcweir
1938*cdf0e10cSrcweir	oFilePicker = getFilePicker()
1939*cdf0e10cSrcweir
1940*cdf0e10cSrcweir	REM execute file dialog
1941*cdf0e10cSrcweir	If oFilePicker.execute() Then
1942*cdf0e10cSrcweir		sFiles = oFilePicker.getFiles()
1943*cdf0e10cSrcweir		sFileURL = sFiles(0)
1944*cdf0e10cSrcweir		oSimpleFileAccess = CreateUnoService( &quot;com.sun.star.ucb.SimpleFileAccess&quot; )
1945*cdf0e10cSrcweir		If oSimpleFileAccess.exists( sFileURL ) Then
1946*cdf0e10cSrcweir			REM add sFileURL to the list
1947*cdf0e10cSrcweir			ReDim preserve filesysScripts(filesysCount) as String
1948*cdf0e10cSrcweir			filesysScripts( filesysCount ) = sFileURL
1949*cdf0e10cSrcweir			filesysCount=filesysCount+1
1950*cdf0e10cSrcweir			&apos; if user changed filter in file picker then populate
1951*cdf0e10cSrcweir			&apos; language with language associated with that in file picker
1952*cdf0e10cSrcweir			sFilter = oFilePicker.getCurrentFilter()
1953*cdf0e10cSrcweir			langCombo = bindingDialog.getControl( &quot;LanguageCombo&quot; )
1954*cdf0e10cSrcweir			dim items() as String
1955*cdf0e10cSrcweir			items() = langCombo.getItems()
1956*cdf0e10cSrcweir			for index = lbound(items()) to ubound(items())
1957*cdf0e10cSrcweir				iPos = inStr(sFilter,&quot; &quot;)
1958*cdf0e10cSrcweir				Dim theLanguage as String
1959*cdf0e10cSrcweir				if( iPos &gt; 0 ) then
1960*cdf0e10cSrcweir					theLanguage = Left( sFilter, iPos - 1)
1961*cdf0e10cSrcweir				    if ( theLanguage = items( index ) ) then
1962*cdf0e10cSrcweir				 		langCombo.text = items( index )
1963*cdf0e10cSrcweir				 		exit for
1964*cdf0e10cSrcweir				 	end if
1965*cdf0e10cSrcweir				end if
1966*cdf0e10cSrcweir			next index
1967*cdf0e10cSrcweir		End If
1968*cdf0e10cSrcweir	End If
1969*cdf0e10cSrcweir	LangLocComboListener()
1970*cdf0e10cSrcweirEnd Sub
1971*cdf0e10cSrcweir
1972*cdf0e10cSrcweirsub KeyOKButton()
1973*cdf0e10cSrcweir	WriteXMLFromArray()
1974*cdf0e10cSrcweir	bindingDialog.endExecute()
1975*cdf0e10cSrcweirend sub
1976*cdf0e10cSrcweir
1977*cdf0e10cSrcweir
1978*cdf0e10cSrcweirsub KeyCancelButton()
1979*cdf0e10cSrcweir	bindingDialog.endExecute()
1980*cdf0e10cSrcweirend sub
1981*cdf0e10cSrcweir
1982*cdf0e10cSrcweir
1983*cdf0e10cSrcweirsub KeyHelpButton()
1984*cdf0e10cSrcweir	helpDialog = LoadDialog( &quot;ScriptBindingLibrary&quot;, &quot;HelpBinding&quot; )
1985*cdf0e10cSrcweir	helpDialog.execute()
1986*cdf0e10cSrcweirend sub
1987*cdf0e10cSrcweir
1988*cdf0e10cSrcweir
1989*cdf0e10cSrcweirsub KeyNewButton()
1990*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;KeyCombo&quot; )
1991*cdf0e10cSrcweir	keyGroup = combo.text
1992*cdf0e10cSrcweir	for n = lbound ( allKeyGroupsArray() ) to ubound ( allKeyGroupsArray() )
1993*cdf0e10cSrcweir		if ( allKeyGroupsArray( n ) = keyGroup )then
1994*cdf0e10cSrcweir			keyGroupIndex = n
1995*cdf0e10cSrcweir			exit for
1996*cdf0e10cSrcweir		end if
1997*cdf0e10cSrcweir	next n
1998*cdf0e10cSrcweir	menuScriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
1999*cdf0e10cSrcweir	script = menuScriptList.getSelectedItem()
2000*cdf0e10cSrcweir	scriptURI = getScriptURI( script )
2001*cdf0e10cSrcweir
2002*cdf0e10cSrcweir	keyList = bindingDialog.getControl( &quot;KeyList&quot; )
2003*cdf0e10cSrcweir	keyIndex = keyList.getSelectedItemPos()
2004*cdf0e10cSrcweir	ShortCutKeyArray() = KeyBindArrayOfArrays( keyGroupIndex )
2005*cdf0e10cSrcweir	keyText = ShortCutKeyArray( keyIndex )
2006*cdf0e10cSrcweir
2007*cdf0e10cSrcweir	AddNewKeyBinding( scriptURI, HasShiftKey( keyText ), HasControlKey( keyText ), ExtractKeyFromCombo( keyText ) )
2008*cdf0e10cSrcweir
2009*cdf0e10cSrcweir	KeyComboListener()
2010*cdf0e10cSrcweirend sub
2011*cdf0e10cSrcweir
2012*cdf0e10cSrcweir
2013*cdf0e10cSrcweirsub KeyDeleteButton()
2014*cdf0e10cSrcweir
2015*cdf0e10cSrcweir	keyShortCutList = bindingDialog.getControl( &quot;KeyList&quot; )
2016*cdf0e10cSrcweir	selectedShortCut = keyShortCutList.getSelectedItem()
2017*cdf0e10cSrcweir	combo = bindingDialog.getControl( &quot;KeyCombo&quot; )
2018*cdf0e10cSrcweir
2019*cdf0e10cSrcweir	keyGroup = combo.text
2020*cdf0e10cSrcweir	dim keyGroupIndex as Integer
2021*cdf0e10cSrcweir	dim selectedKeyIndex as Integer
2022*cdf0e10cSrcweir	for n = lbound ( allKeyGroupsArray() ) to ubound ( allKeyGroupsArray() )
2023*cdf0e10cSrcweir		if ( allKeyGroupsArray( n ) = keyGroup )then
2024*cdf0e10cSrcweir			keyGroupIndex = n
2025*cdf0e10cSrcweir			exit for
2026*cdf0e10cSrcweir		end if
2027*cdf0e10cSrcweir	next n
2028*cdf0e10cSrcweir	selectedKeyIndex = keyShortCutList.getSelectedItemPos()
2029*cdf0e10cSrcweir	linePosition = keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Value
2030*cdf0e10cSrcweir	keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Value = 0
2031*cdf0e10cSrcweir	keyAllocationMap( keyGroupIndex, selectedKeyIndex ).Name = &quot;&quot;
2032*cdf0e10cSrcweir	RemoveBinding( linePosition )
2033*cdf0e10cSrcweir	KeyComboListener()
2034*cdf0e10cSrcweirend sub
2035*cdf0e10cSrcweir
2036*cdf0e10cSrcweir
2037*cdf0e10cSrcweirsub EventNewButton()
2038*cdf0e10cSrcweir	eventScriptList = bindingDialog.getControl( &quot;ScriptList&quot; )
2039*cdf0e10cSrcweir	selectedScript = eventScriptList.getSelectedItem()
2040*cdf0e10cSrcweir	scriptURI = getScriptURI( selectedScript )
2041*cdf0e10cSrcweir	eventList = bindingDialog.getControl( &quot;EventList&quot; )
2042*cdf0e10cSrcweir	eventPosition = eventList.getSelectedItemPos()
2043*cdf0e10cSrcweir
2044*cdf0e10cSrcweir	allApps = bindingDialog.getControl( &quot;AllAppsOption&quot; )
2045*cdf0e10cSrcweir	dim isApp as boolean
2046*cdf0e10cSrcweir	if allApps.state = true then &apos;Application
2047*cdf0e10cSrcweir		isApp = true
2048*cdf0e10cSrcweir	else &apos;Document
2049*cdf0e10cSrcweir		isApp = false
2050*cdf0e10cSrcweir	end if
2051*cdf0e10cSrcweir	AddNewEventBinding( scriptURI, eventPosition, isApp )
2052*cdf0e10cSrcweir
2053*cdf0e10cSrcweir	populateEventList( eventPosition )
2054*cdf0e10cSrcweir	EventListListener()
2055*cdf0e10cSrcweirend sub
2056*cdf0e10cSrcweir
2057*cdf0e10cSrcweir
2058*cdf0e10cSrcweirsub EventDeleteButton()
2059*cdf0e10cSrcweir	eventList = bindingDialog.getControl( &quot;EventList&quot; )
2060*cdf0e10cSrcweir	REM Check that combo is a script
2061*cdf0e10cSrcweir	eventPosition = eventList.getSelectedItemPos()
2062*cdf0e10cSrcweir
2063*cdf0e10cSrcweir	allApps = bindingDialog.getControl( &quot;AllAppsOption&quot; )
2064*cdf0e10cSrcweir	if allApps.state = true then &apos;Application
2065*cdf0e10cSrcweir		linePosition = allEventTypesApp( eventPosition ).Value
2066*cdf0e10cSrcweir		&apos;dim eventProp as new com.sun.star.beans.PropertyValue
2067*cdf0e10cSrcweir		&apos;eventProp.Name = &quot;&quot;
2068*cdf0e10cSrcweir		&apos;eventProp.Value = 0
2069*cdf0e10cSrcweir		allEventTypesApp( eventPosition ).Name = &quot;&quot;
2070*cdf0e10cSrcweir		allEventTypesApp( eventPosition ).Value = 0
2071*cdf0e10cSrcweir		RemoveBinding( linePosition )
2072*cdf0e10cSrcweir	else &apos;Document
2073*cdf0e10cSrcweir		&apos;DeleteEvent( allEventTypes( eventPosition ) )
2074*cdf0e10cSrcweir		allEventTypesDoc( eventPosition ).Name = &quot;&quot;
2075*cdf0e10cSrcweir		allEventTypesDoc( eventPosition ).Value = 0
2076*cdf0e10cSrcweir	end if
2077*cdf0e10cSrcweir
2078*cdf0e10cSrcweir	PopulateEventList( eventPosition )
2079*cdf0e10cSrcweir	EventListListener()
2080*cdf0e10cSrcweirend sub
2081*cdf0e10cSrcweir
2082*cdf0e10cSrcweir
2083*cdf0e10cSrcweirsub EventOKButton
2084*cdf0e10cSrcweir	WriteEventsToDoc()
2085*cdf0e10cSrcweir	WriteXMLFromArray()
2086*cdf0e10cSrcweir	bindingDialog.endExecute()
2087*cdf0e10cSrcweirend sub
2088*cdf0e10cSrcweir
2089*cdf0e10cSrcweir
2090*cdf0e10cSrcweirsub HelpOKButton()
2091*cdf0e10cSrcweir	helpDialog.endExecute()
2092*cdf0e10cSrcweirend sub
2093*cdf0e10cSrcweir</script:module>
2094