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