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